From 0458aa8eb406e4b879a120897056d3cac467b8f8 Mon Sep 17 00:00:00 2001 From: "roberto@precise64" Date: Thu, 5 Apr 2012 12:15:04 +0200 Subject: [PATCH] use ctime_r instead of ctime --- logging.c | 4 ++-- plugins/rsyslog/rsyslog_plugin.c | 5 +++-- utils.c | 10 ++++++---- uwsgi.c | 11 +++++++---- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/logging.c b/logging.c index 8db77ba8..e1d9a688 100644 --- a/logging.c +++ b/logging.c @@ -113,7 +113,7 @@ void uwsgi_check_logrotate(void) { void log_request(struct wsgi_request *wsgi_req) { // optimize this (please) - char *time_request; + char time_request[26]; time_t microseconds, microseconds2; int rlen; int app_req = -1; @@ -160,7 +160,7 @@ void log_request(struct wsgi_request *wsgi_req) { via = msg3; } - time_request = ctime((const time_t *) &wsgi_req->start_of_request.tv_sec); + ctime_r((const time_t *) &wsgi_req->start_of_request.tv_sec, time_request); microseconds = wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec; microseconds2 = wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec; diff --git a/plugins/rsyslog/rsyslog_plugin.c b/plugins/rsyslog/rsyslog_plugin.c index 86bfd0b4..4dd8fa86 100644 --- a/plugins/rsyslog/rsyslog_plugin.c +++ b/plugins/rsyslog/rsyslog_plugin.c @@ -7,6 +7,7 @@ extern struct uwsgi_server uwsgi; ssize_t uwsgi_rsyslog_logger(struct uwsgi_logger *ul, char *message, size_t len) { char buf[MAX_SYSLOG_PKT]; + char ctime_storage[26]; time_t current_time; int portn = 514; int rlen; @@ -55,8 +56,8 @@ ssize_t uwsgi_rsyslog_logger(struct uwsgi_logger *ul, char *message, size_t len) // drop newline if (message[len-1] == '\n') len--; - - rlen = snprintf(buf, MAX_SYSLOG_PKT, "<29>%.*s %s: %.*s", 15, ctime(¤t_time)+4, (char *) ul->data, (int) len, message); + ctime_r(¤t_time, ctime_storage); + rlen = snprintf(buf, MAX_SYSLOG_PKT, "<29>%.*s %s: %.*s", 15, ctime_storage+4, (char *) ul->data, (int) len, message); if (rlen > 0) { return sendto(ul->fd, buf, rlen, 0, (const struct sockaddr *) &ul->addr, ul->addr_len); } diff --git a/utils.c b/utils.c index abe00e15..574ebb11 100644 --- a/utils.c +++ b/utils.c @@ -1189,6 +1189,7 @@ void uwsgi_log(const char *fmt, ...) { struct timeval tv; char sftime[64]; + char ctime_storage[26]; time_t now; if (uwsgi.logdate) { @@ -1201,8 +1202,8 @@ void uwsgi_log(const char *fmt, ...) { } else { gettimeofday(&tv, NULL); - - memcpy(logpkt, ctime((const time_t *) &tv.tv_sec), 24); + ctime_r((const time_t *) &tv.tv_sec, ctime_storage); + memcpy(logpkt, ctime_storage, 24); memcpy(logpkt + 24, " - ", 3); rlen = 24 + 3; @@ -1238,6 +1239,7 @@ void uwsgi_log_verbose(const char *fmt, ...) { struct timeval tv; char sftime[64]; time_t now; + char ctime_storage[26]; if (uwsgi.log_strftime) { now = time(NULL); @@ -1248,8 +1250,8 @@ void uwsgi_log_verbose(const char *fmt, ...) { } else { gettimeofday(&tv, NULL); - - memcpy(logpkt, ctime((const time_t *) &tv.tv_sec), 24); + ctime_r((const time_t *) &tv.tv_sec, ctime_storage); + memcpy(logpkt, ctime_storage, 24); memcpy(logpkt + 24, " - ", 3); rlen = 24 + 3; diff --git a/uwsgi.c b/uwsgi.c index 674d7402..bab4dcf4 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -871,6 +871,7 @@ void what_i_am_doing() { struct wsgi_request *wsgi_req; int i; + char ctime_storage[26]; uwsgi_backtrace(uwsgi.backtrace_depth); @@ -878,11 +879,12 @@ void what_i_am_doing() { for (i = 0; i < uwsgi.cores; i++) { wsgi_req = uwsgi.wsgi_requests[i]; if (wsgi_req->uri_len > 0) { + ctime_r((const time_t *) &wsgi_req->start_of_request.tv_sec, ctime_storage); if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < time(NULL)) { - uwsgi_log("HARAKIRI: --- uWSGI worker %d core %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, i, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime((const time_t *) &wsgi_req->start_of_request.tv_sec)); + uwsgi_log("HARAKIRI: --- uWSGI worker %d core %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, i, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage); } else { - uwsgi_log("SIGUSR2: --- uWSGI worker %d core %d (pid: %d) is managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, i, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime((const time_t *) &wsgi_req->start_of_request.tv_sec)); + uwsgi_log("SIGUSR2: --- uWSGI worker %d core %d (pid: %d) is managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, i, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage); } } } @@ -890,11 +892,12 @@ void what_i_am_doing() { else { wsgi_req = uwsgi.wsgi_requests[0]; if (wsgi_req->uri_len > 0) { + ctime_r((const time_t *) &wsgi_req->start_of_request.tv_sec, ctime_storage); if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < time(NULL)) { - uwsgi_log("HARAKIRI: --- uWSGI worker %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime((const time_t *) &wsgi_req->start_of_request.tv_sec)); + uwsgi_log("HARAKIRI: --- uWSGI worker %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage); } else { - uwsgi_log("SIGUSR2: --- uWSGI worker %d (pid: %d) is managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime((const time_t *) &wsgi_req->start_of_request.tv_sec)); + uwsgi_log("SIGUSR2: --- uWSGI worker %d (pid: %d) is managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage); } } else if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < time(NULL) && uwsgi.workers[uwsgi.mywid].sig) {