From 3787d5e84aa7ff004b9a0bd45d29ce4f3004fc05 Mon Sep 17 00:00:00 2001 From: "roberto@precise64" Date: Thu, 23 Feb 2012 07:48:54 +0100 Subject: [PATCH] flush logs on exit --- master.c | 6 +++--- uwsgi.c | 19 +++++++++++++++++++ uwsgi.h | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/master.c b/master.c index 6b6128cc..b024bec9 100644 --- a/master.c +++ b/master.c @@ -68,7 +68,7 @@ void expire_rb_timeouts(struct rb_root *root) { } } -void master_log(void) { +void uwsgi_master_log(void) { char log_buf[4096]; @@ -99,7 +99,7 @@ void *logger_thread_loop(void *noarg) { int ret = poll(&logpoll, 1, -1); if (ret > 0 && logpoll.revents & POLLIN) { pthread_mutex_lock(&uwsgi.threaded_logger_lock); - master_log(); + uwsgi_master_log(); pthread_mutex_unlock(&uwsgi.threaded_logger_lock); } } @@ -777,7 +777,7 @@ int master_loop(char **argv, char **environ) { if (uwsgi.log_master && !uwsgi.threaded_logger) { if (interesting_fd == uwsgi.shared->worker_log_pipe[0]) { - master_log(); + uwsgi_master_log(); goto health_cycle; } } diff --git a/uwsgi.c b/uwsgi.c index 20a206f8..f3fd7348 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1118,6 +1118,24 @@ void uwsgi_fpe(int signum) { exit(1); } +void uwsgi_flush_logs() { + + struct pollfd pfd; + + if (!uwsgi.workers) return; + if (!uwsgi.master_process) return; + if (!uwsgi.log_master) return; + + if (getpid() == uwsgi.workers[0].pid) { + // check for data in logpipe + pfd.events = POLLIN; + pfd.fd = uwsgi.shared->worker_log_pipe[0]; + while(poll(&pfd, 1, 0) > 0) { + uwsgi_master_log(); + } + } +} + #ifdef UWSGI_AS_SHARED_LIBRARY int uwsgi_init(int argc, char *argv[], char *envp[]) { @@ -1170,6 +1188,7 @@ int main(int argc, char *argv[], char *envp[]) { init_magic_table(uwsgi.magic_table); atexit(vacuum); + atexit(uwsgi_flush_logs); atexit(uwsgi_plugins_atexit); diff --git a/uwsgi.h b/uwsgi.h index 1ea52404..9aac9de2 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2647,6 +2647,8 @@ int uwsgi_calc_cheaper(void); int uwsgi_cheaper_algo_spare(void); int uwsgi_cheaper_algo_backlog(void); +void uwsgi_master_log(void); + #ifdef UWSGI_AS_SHARED_LIBRARY int uwsgi_init(int, char **, char **); #endif