From d79eeefe978eb8426c94ac98d043a409869aa75b Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Tue, 23 Dec 2014 15:39:19 +0100 Subject: [PATCH] Write pidfile and pidfile2 only after successful start --- core/utils.c | 7 +++++++ core/uwsgi.c | 15 +++++++-------- uwsgi.h | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/utils.c b/core/utils.c index d6c749b3..5ca81bfc 100755 --- a/core/utils.c +++ b/core/utils.c @@ -3587,6 +3587,13 @@ void uwsgi_write_pidfile(char *pidfile_name) { } } +void uwsgi_write_pidfile_explicit(char *pidfile_name, pid_t pid) { + uwsgi_log("writing pidfile to %s\n", pidfile_name); + if (uwsgi_write_intfile(pidfile_name, (int) pid)) { + uwsgi_log("could not write pidfile.\n"); + } +} + char *uwsgi_expand_path(char *dir, int dir_len, char *ptr) { char src[PATH_MAX + 1]; memcpy(src, dir, dir_len); diff --git a/core/uwsgi.c b/core/uwsgi.c index 3ec74882..99bde3e3 100755 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2420,10 +2420,6 @@ configure: uwsgi_log("*** running under screen session %s ***\n", uwsgi.screen_session); } - if (uwsgi.pidfile && !uwsgi.is_a_reload) { - uwsgi_write_pidfile(uwsgi.pidfile); - } - uwsgi_log_initial("detected binary path: %s\n", uwsgi.binary_path); if (uwsgi.is_a_reload) { @@ -2523,6 +2519,10 @@ configure: #if defined(__linux__) && !defined(__ia64__) } #endif + + if (uwsgi.pidfile && !uwsgi.is_a_reload) { + uwsgi_write_pidfile_explicit(uwsgi.pidfile, masterpid); + } } @@ -2595,10 +2595,6 @@ int uwsgi_start(void *v_argv) { } } - if (uwsgi.pidfile2 && !uwsgi.is_a_reload) { - uwsgi_write_pidfile(uwsgi.pidfile2); - } - if (!uwsgi.master_process && !uwsgi.command_mode) { uwsgi_log_initial("*** WARNING: you are running uWSGI without its master process manager ***\n"); } @@ -3258,6 +3254,9 @@ next2: } } + if (uwsgi.pidfile2 && !uwsgi.is_a_reload) { + uwsgi_write_pidfile_explicit(uwsgi.pidfile2, masterpid); + } // END OF INITIALIZATION return 0; diff --git a/uwsgi.h b/uwsgi.h index 96278587..cce402cd 100755 --- a/uwsgi.h +++ b/uwsgi.h @@ -3958,6 +3958,7 @@ void uwsgi_setup_post_buffering(void); struct uwsgi_lock_item *uwsgi_lock_ipcsem_init(char *); void uwsgi_write_pidfile(char *); +void uwsgi_write_pidfile_explicit(char *, pid_t); int uwsgi_write_intfile(char *, int); void uwsgi_protected_close(int);