From 25b29df65ef77f147aade323aecc70b4025c1391 Mon Sep 17 00:00:00 2001 From: unbit Date: Wed, 28 Nov 2012 20:52:59 +0100 Subject: [PATCH] core: make smart-attach-daemon smart enough Avoid call storming of pidfile check that leads to multiple daemons running instead of one. Fix #65. --- core/daemons.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/daemons.c b/core/daemons.c index 37cacb57..ab5c1854 100644 --- a/core/daemons.c +++ b/core/daemons.c @@ -30,6 +30,16 @@ extern struct uwsgi_server uwsgi; */ void uwsgi_daemons_smart_check() { + static time_t last_run = 0; + + time_t now = uwsgi_now(); + + if (now - last_run <= 0) { + return; + } + + last_run = now; + struct uwsgi_daemon *ud = uwsgi.daemons; while (ud) { if (ud->pidfile) { @@ -41,14 +51,14 @@ void uwsgi_daemons_smart_check() { } else { ud->pidfile_checks++; - if (ud->pidfile_checks >= (uint64_t) ud->freq) { + if (ud->pidfile_checks >= (unsigned int) ud->freq) { uwsgi_log("[uwsgi-daemons] found changed pidfile for \"%s\" (old_pid: %d new_pid: %d)\n", ud->command, (int) ud->pid, (int) checked_pid); uwsgi_spawn_daemon(ud); } } } else if (checked_pid != ud->pid) { - uwsgi_log("[uwsgi-daemons] found changed pidfile for \"%s\" (old_pid: %d new_pid: %d)\n", ud->command, (int) ud->pid, (int) checked_pid); + uwsgi_log("[uwsgi-daemons] found changed pid for \"%s\" (old_pid: %d new_pid: %d)\n", ud->command, (int) ud->pid, (int) checked_pid); ud->pid = checked_pid; } // all ok, pidfile and process found