[LEDE-DEV] [PATCH] procd: add cancel_timeout on rc scripts when a runtime_timeout is specified

Jurgen Van Ham juvanham.tc at gmail.com
Thu Feb 9 22:55:23 PST 2017


Enable procd to restrict the execution time of a rc scripts during shutdown, even
when a script ignores the SIGTERM signal by insisting after 10s with a SIGKILL.


Signed-off-by: Jurgen Van Ham <juvanham.tc at gmail.com>
---
file /etc/rc.d/K01test reproduces the problem that this patch addresses.
 #!/bin/sh
 h_sigterm() { 
   echo $0 SIGTERM > /dev/console
 }

 stop() {
   local x=0
   while true; do
         x=$(($x+1))
         echo $0 PING $x > /dev/console
         sleep 1
    done
 }

 trap h_sigterm SIGTERM
 case "$1" in
   stop|shutdown)
    stop
    ;;
 esac
creating the above file results in a board that cannot complete the 'reboot' command.

 rcS.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/rcS.c b/rcS.c
index 1e38d39..0208a75 100644
--- a/rcS.c
+++ b/rcS.c
@@ -121,8 +121,10 @@ static void add_initd(struct runqueue *q, char *file, char *param)
 	}
 	s->proc.task.type = &initd_type;
 	s->proc.task.complete = q_initd_complete;
-	if (!strcmp(param, "stop") || !strcmp(param, "shutdown"))
+	if (!strcmp(param, "stop") || !strcmp(param, "shutdown")) {
 		s->proc.task.run_timeout = 15000;
+		s->proc.task.cancel_timeout = 10000;
+	}
 	s->param = p;
 	s->file = f;
 	strcpy(s->param, param);
-- 
1.7.9.5




More information about the Lede-dev mailing list