diff --git a/core/logging.c b/core/logging.c index 12441608..5fc0b06a 100644 --- a/core/logging.c +++ b/core/logging.c @@ -520,39 +520,40 @@ void uwsgi_check_logrotate(void) { } void uwsgi_log_rotate() { - if (!uwsgi.logfile) return; + if (!uwsgi.logfile) + return; char *rot_name = uwsgi.log_backupname; - int need_free = 0; - if (rot_name == NULL) { - char *ts_str = uwsgi_num2str((int) uwsgi_now()); - rot_name = uwsgi_concat3(uwsgi.logfile, ".", ts_str); - free(ts_str); - need_free = 1; - } - // this will be rawly written to the logfile - uwsgi_logfile_write("logsize: %llu, triggering rotation to %s...\n", (unsigned long long) uwsgi.shared->logsize, rot_name); - if (rename(uwsgi.logfile, rot_name) == 0) { - // reopen logfile and dup'it, on dup2 error, exit(1) - int fd = open(uwsgi.logfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP); - if (fd < 0) { - // this will be written to the original file - uwsgi_error_open(uwsgi.logfile); + int need_free = 0; + if (rot_name == NULL) { + char *ts_str = uwsgi_num2str((int) uwsgi_now()); + rot_name = uwsgi_concat3(uwsgi.logfile, ".", ts_str); + free(ts_str); + need_free = 1; + } + // this will be rawly written to the logfile + uwsgi_logfile_write("logsize: %llu, triggering rotation to %s...\n", (unsigned long long) uwsgi.shared->logsize, rot_name); + if (rename(uwsgi.logfile, rot_name) == 0) { + // reopen logfile and dup'it, on dup2 error, exit(1) + int fd = open(uwsgi.logfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP); + if (fd < 0) { + // this will be written to the original file + uwsgi_error_open(uwsgi.logfile); + exit(1); + } + else { + if (dup2(fd, uwsgi.original_log_fd) < 0) { + // this could be lost :( + uwsgi_error("uwsgi_log_rotate()/dup2()"); exit(1); - } - else { - if (dup2(fd, uwsgi.original_log_fd) < 0) { - // this could be lost :( - uwsgi_error("uwsgi_log_rotate()/dup2()"); - exit(1); - } - close(fd); - } - } - else { - uwsgi_error("unable to rotate log: rename()"); - } - if (need_free) - free(rot_name); + } + close(fd); + } + } + else { + uwsgi_error("unable to rotate log: rename()"); + } + if (need_free) + free(rot_name); } void uwsgi_log_reopen() {