From 4c43193fa3f7b49e68778d7345759f27c883072f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 19 May 2017 11:52:33 +0000 Subject: Add the timeout-kill feature to s6-supervise. Prepare for version 2.5.1.0. --- src/supervision/s6-supervise.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c index a1a52f8..7527668 100644 --- a/src/supervision/s6-supervise.c +++ b/src/supervision/s6-supervise.c @@ -51,6 +51,7 @@ static tain_t deadline ; static tain_t dontrespawnbefore = TAIN_EPOCH ; static s6_svstatus_t status = S6_SVSTATUS_ZERO ; static state_t state = DOWN ; +static int flagdying = 0 ; static int cont = 1 ; static int notifyfd = -1 ; @@ -331,6 +332,7 @@ static int uplastup_z (void) status.wstat = (int)status.pid ; status.flagpaused = 0 ; status.flagready = 0 ; + flagdying = 0 ; tain_copynow(&status.stamp) ; if (notifyfd >= 0) { @@ -383,8 +385,16 @@ static void lastup_z (void) static void uptimeout (void) { - settimeout_infinite() ; - strerr_warnw1x("can't happen: timeout while the service is up!") ; + if (flagdying) + { + killk() ; + settimeout(5) ; + } + else + { + settimeout_infinite() ; + strerr_warnw1x("can't happen: timeout while the service is up!") ; + } } static void up_o (void) @@ -395,9 +405,18 @@ static void up_o (void) static void up_d (void) { + tain_t tto ; + unsigned int timeout ; status.flagwantup = 0 ; killt() ; killc() ; + if (!read_uint("timeout-kill", &timeout)) timeout = 0 ; + if (timeout && tain_from_millisecs(&tto, timeout)) + { + tain_add_g(&deadline, &tto) ; + flagdying = 1 ; + } + else settimeout_infinite() ; } static void up_u (void) -- cgit v1.2.3