From b799e4629c3f2860b9186f7c5379ce01ea6f5934 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Mon, 18 Apr 2011 21:34:52 +0200 Subject: [PATCH] [luad] move the #restarts check to the end of the loop, so that it does not get triggered when booting in the first 60secs of epoch time --- mote/v2/openwrt/package/flukso/src/luad.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mote/v2/openwrt/package/flukso/src/luad.c b/mote/v2/openwrt/package/flukso/src/luad.c index 5c52095..619f786 100644 --- a/mote/v2/openwrt/package/flukso/src/luad.c +++ b/mote/v2/openwrt/package/flukso/src/luad.c @@ -339,13 +339,7 @@ int main(int argc, char *argv[]) struct restart_s restart; restart_init(&restart); - while(1) { - /* Stop when allowed number of restarts have occurred in specified time window */ - if (restart_max(&restart)) { - daemon_log(LOG_ERR, "%d restarts within a %d sec window", SUP_ALLOWED_RESTARTS, SUP_MAX_SECONDS); - break; - } - + do { /* Create a new Lua environment */ L = luaL_newstate(); /* And load the standard libraries into the Lua environment */ @@ -356,11 +350,17 @@ int main(int argc, char *argv[]) } /* Clean up the Lua state */ lua_close(L); - /* Wait for one second before restarting the Lua daemon */ - sleep(1); - restart_add(&restart, time(NULL)); - } + /* Wait for one second before restarting the Lua daemon */ + restart_add(&restart, time(NULL)); + sleep(1); + + } while (!restart_max(&restart)); + + /* Stop when allowed number of restarts have occurred in specified time window */ + daemon_log(LOG_ERR, "%d restarts within a %d sec window", SUP_ALLOWED_RESTARTS, SUP_MAX_SECONDS); + + /* Do a cleanup */ finish: daemon_log(LOG_INFO, "Exiting...");