mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
access-log: use localtime_r instead of localtime if possible
Also replace the WIN32 check to global LWS_HAVE_LOCALTIME_R in logs.c
This commit is contained in:
parent
9453d246d9
commit
932527a3e7
4 changed files with 17 additions and 11 deletions
|
@ -551,6 +551,7 @@ CHECK_FUNCTION_EXISTS(atoll LWS_HAVE_ATOLL)
|
|||
CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64)
|
||||
CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64)
|
||||
CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME)
|
||||
CHECK_FUNCTION_EXISTS(localtime_r LWS_HAVE_LOCALTIME_R)
|
||||
CHECK_FUNCTION_EXISTS(getgrgid_r LWS_HAVE_GETGRGID_R)
|
||||
CHECK_FUNCTION_EXISTS(getgrnam_r LWS_HAVE_GETGRNAM_R)
|
||||
CHECK_FUNCTION_EXISTS(getpwuid_r LWS_HAVE_GETPWUID_R)
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#cmakedefine LWS_HAVE_EVP_aes_128_xts
|
||||
#cmakedefine LWS_HAVE_EVP_PKEY_new_raw_private_key
|
||||
#cmakedefine LWS_HAVE_EXECVPE
|
||||
#cmakedefine LWS_HAVE_LOCALTIME_R
|
||||
#cmakedefine LWS_HAVE_GETGRGID_R
|
||||
#cmakedefine LWS_HAVE_GETGRNAM_R
|
||||
#cmakedefine LWS_HAVE_GETPWUID_R
|
||||
|
|
|
@ -200,7 +200,7 @@ lwsl_timestamp(int level, char *p, size_t len)
|
|||
unsigned long long now;
|
||||
struct timeval tv;
|
||||
struct tm *ptm = NULL;
|
||||
#ifndef WIN32
|
||||
#if defined(LWS_HAVE_LOCALTIME_R)
|
||||
struct tm tm;
|
||||
#endif
|
||||
int n;
|
||||
|
@ -209,13 +209,10 @@ lwsl_timestamp(int level, char *p, size_t len)
|
|||
o_now = tv.tv_sec;
|
||||
now = ((unsigned long long)tv.tv_sec * 10000) + (unsigned int)(tv.tv_usec / 100);
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
#ifdef WIN32
|
||||
ptm = localtime(&o_now);
|
||||
#if defined(LWS_HAVE_LOCALTIME_R)
|
||||
ptm = localtime_r(&o_now, &tm);
|
||||
#else
|
||||
if (localtime_r(&o_now, &tm))
|
||||
ptm = &tm;
|
||||
#endif
|
||||
ptm = localtime(&o_now);
|
||||
#endif
|
||||
p[0] = '\0';
|
||||
for (n = 0; n < LLL_COUNT; n++) {
|
||||
|
|
|
@ -48,7 +48,10 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met
|
|||
struct lws *nwsi;
|
||||
const char *me;
|
||||
int l = 256, m;
|
||||
struct tm *tmp;
|
||||
struct tm *ptm = NULL;
|
||||
#if defined(LWS_HAVE_LOCALTIME_R)
|
||||
struct tm tm;
|
||||
#endif
|
||||
|
||||
if (!wsi->a.vhost)
|
||||
return;
|
||||
|
@ -64,9 +67,13 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met
|
|||
if (!wsi->http.access_log.header_log)
|
||||
return;
|
||||
|
||||
tmp = localtime(&t);
|
||||
if (tmp)
|
||||
strftime(da, sizeof(da), "%d/%b/%Y:%H:%M:%S %z", tmp);
|
||||
#if defined(LWS_HAVE_LOCALTIME_R)
|
||||
ptm = localtime_r(&t, &tm);
|
||||
#else
|
||||
ptm = localtime(&t);
|
||||
#endif
|
||||
if (ptm)
|
||||
strftime(da, sizeof(da), "%d/%b/%Y:%H:%M:%S %z", ptm);
|
||||
else
|
||||
strcpy(da, "01/Jan/1970:00:00:00 +0000");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue