diff --git a/core/uwsgi.c b/core/uwsgi.c index 99bde3e3..d346a5ca 100755 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -354,6 +354,8 @@ static struct uwsgi_option uwsgi_base_options[] = { {"pidfile", required_argument, 0, "create pidfile (before privileges drop)", uwsgi_opt_set_str, &uwsgi.pidfile, 0}, {"pidfile2", required_argument, 0, "create pidfile (after privileges drop)", uwsgi_opt_set_str, &uwsgi.pidfile2, 0}, + {"safe-pidfile", required_argument, 0, "create safe pidfile (before privileges drop)", uwsgi_opt_set_str, &uwsgi.safe_pidfile, 0}, + {"safe-pidfile2", required_argument, 0, "create safe pidfile (after privileges drop)", uwsgi_opt_set_str, &uwsgi.safe_pidfile2, 0}, {"chroot", required_argument, 0, "chroot() to the specified directory", uwsgi_opt_set_str, &uwsgi.chroot, 0}, #ifdef __linux__ {"pivot-root", required_argument, 0, "pivot_root() to the specified directories (new_root and put_old must be separated with a space)", uwsgi_opt_set_str, &uwsgi.pivot_root, 0}, @@ -1604,6 +1606,22 @@ static void vacuum(void) { uwsgi_log("VACUUM: pidfile2 removed.\n"); } } + if (uwsgi.safe_pidfile && !uwsgi.uid) { + if (unlink(uwsgi.safe_pidfile)) { + uwsgi_error("unlink()"); + } + else { + uwsgi_log("VACUUM: safe pidfile removed.\n"); + } + } + if (uwsgi.safe_pidfile2) { + if (unlink(uwsgi.safe_pidfile2)) { + uwsgi_error("unlink()"); + } + else { + uwsgi_log("VACUUM: safe pidfile2 removed.\n"); + } + } if (uwsgi.chdir) { if (chdir(uwsgi.chdir)) { uwsgi_error("chdir()"); @@ -2420,6 +2438,10 @@ 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) { @@ -2520,8 +2542,8 @@ configure: } #endif - if (uwsgi.pidfile && !uwsgi.is_a_reload) { - uwsgi_write_pidfile_explicit(uwsgi.pidfile, masterpid); + if (uwsgi.safe_pidfile && !uwsgi.is_a_reload) { + uwsgi_write_pidfile_explicit(uwsgi.safe_pidfile, masterpid); } } @@ -2595,6 +2617,10 @@ 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"); } @@ -3254,8 +3280,8 @@ next2: } } - if (uwsgi.pidfile2 && !uwsgi.is_a_reload) { - uwsgi_write_pidfile_explicit(uwsgi.pidfile2, masterpid); + if (uwsgi.safe_pidfile2 && !uwsgi.is_a_reload) { + uwsgi_write_pidfile_explicit(uwsgi.safe_pidfile2, masterpid); } // END OF INITIALIZATION @@ -4892,6 +4918,12 @@ void uwsgi_update_pidfiles() { if (uwsgi.pidfile2) { uwsgi_write_pidfile(uwsgi.pidfile2); } + if (uwsgi.safe_pidfile) { + uwsgi_write_pidfile(uwsgi.safe_pidfile); + } + if (uwsgi.safe_pidfile2) { + uwsgi_write_pidfile(uwsgi.safe_pidfile2); + } } void uwsgi_opt_binary_append_data(char *opt, char *value, void *none) { diff --git a/uwsgi.h b/uwsgi.h index cce402cd..3da28b77 100755 --- a/uwsgi.h +++ b/uwsgi.h @@ -2408,6 +2408,9 @@ struct uwsgi_server { char *pidfile; char *pidfile2; + char *safe_pidfile; + char *safe_pidfile2; + char *flock2; char *flock_wait2;