mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-15 16:48:22 -04:00
[httpd/logger] Use gmtime_r/localtime_r instead of gmtime/localtime
gmtime and localtime are not thread safe credit lgtm.com
This commit is contained in:
parent
fada4c0ee7
commit
5e6b5fbe8a
@ -325,11 +325,12 @@ httpd_request_not_modified_since(struct evhttp_request *req, time_t mtime)
|
|||||||
struct evkeyvalq *output_headers;
|
struct evkeyvalq *output_headers;
|
||||||
char last_modified[1000];
|
char last_modified[1000];
|
||||||
const char *modified_since;
|
const char *modified_since;
|
||||||
|
struct tm timebuf;
|
||||||
|
|
||||||
input_headers = evhttp_request_get_input_headers(req);
|
input_headers = evhttp_request_get_input_headers(req);
|
||||||
modified_since = evhttp_find_header(input_headers, "If-Modified-Since");
|
modified_since = evhttp_find_header(input_headers, "If-Modified-Since");
|
||||||
|
|
||||||
strftime(last_modified, sizeof(last_modified), "%a, %d %b %Y %H:%M:%S %Z", gmtime(&mtime));
|
strftime(last_modified, sizeof(last_modified), "%a, %d %b %Y %H:%M:%S %Z", gmtime_r(&mtime, &timebuf));
|
||||||
|
|
||||||
// Return not modified, if given timestamp matches "If-Modified-Since" request header
|
// Return not modified, if given timestamp matches "If-Modified-Since" request header
|
||||||
if (modified_since && (strcasecmp(last_modified, modified_since) == 0))
|
if (modified_since && (strcasecmp(last_modified, modified_since) == 0))
|
||||||
|
@ -117,6 +117,7 @@ vlogger_writer(int severity, int domain, const char *fmt, va_list args)
|
|||||||
char content[2048];
|
char content[2048];
|
||||||
char stamp[32];
|
char stamp[32];
|
||||||
time_t t;
|
time_t t;
|
||||||
|
struct tm timebuf;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
va_copy(ap, args);
|
va_copy(ap, args);
|
||||||
@ -136,7 +137,7 @@ vlogger_writer(int severity, int domain, const char *fmt, va_list args)
|
|||||||
if (logfile)
|
if (logfile)
|
||||||
{
|
{
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
ret = strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M:%S", localtime(&t));
|
ret = strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M:%S", localtime_r(&t, &timebuf));
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
stamp[0] = '\0';
|
stamp[0] = '\0';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user