From b06e35c610083f9ca7af4a579b9adab4db04bb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 18 Oct 2013 22:31:43 +0200 Subject: [PATCH] fixed sleep in daemons throttle code, sleep() only accepts unsigned int, but in some cases uWSGI could pass value < 0 --- core/daemons.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/daemons.c b/core/daemons.c index 59915e39..b4039c19 100644 --- a/core/daemons.c +++ b/core/daemons.c @@ -263,6 +263,8 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) { if (uwsgi.current_time - ud->last_spawn <= 3) { throttle = ud->respawns - (uwsgi.current_time - ud->last_spawn); + // if ud->respawns == 0 then we can end up with throttle < 0 + if (throttle <= 0) throttle = 1; } pid_t pid = uwsgi_fork("uWSGI external daemon"); @@ -323,7 +325,7 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) { if (throttle) { uwsgi_log("[uwsgi-daemons] throttling \"%s\" for %d seconds\n", ud->command, throttle); - sleep(throttle); + sleep((unsigned int) throttle); } uwsgi_log("[uwsgi-daemons] %sspawning \"%s\"\n", ud->respawns > 0 ? "re" : "", ud->command);