script: fix possible negative delay
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 5 Apr 2018 14:51:19 +0000 (16:51 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 5 Apr 2018 16:22:00 +0000 (18:22 +0200)
Fix delay becoming negative when killing a running script

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/script.c

index 5696b7f9c955308a542e63af50095b50b21e9f19..fcdbb276b88bac082a574e626972cf01f31ff44f 100644 (file)
@@ -393,8 +393,15 @@ void script_call(const char *status, int delay, bool resume)
        bool running_script = false;
 
        if (running) {
+               time_t diff = now - started;
+
                kill(running, SIGTERM);
-               delay -= now - started;
+
+               if (diff > delay)
+                       delay -= diff;
+               else
+                       delay = 0;
+
                running_script = true;
        }