From e2f01f98672c501b6ec4b445956b48041267138f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 17 Jun 2015 10:38:04 +0000 Subject: - Add support for SIGUSR1 for poweroff in s6-svscan - Optimize respawn delay in s6-supervise --- doc/s6-svscan.html | 3 ++- src/supervision/s6-supervise.c | 15 +++++++++++---- src/supervision/s6-svscan.c | 10 +++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/doc/s6-svscan.html b/doc/s6-svscan.html index 1a79d8e..a0a6790 100644 --- a/doc/s6-svscan.html +++ b/doc/s6-svscan.html @@ -92,7 +92,8 @@ scan (and a reap) every 5 seconds. It is strongly discouraged to set
  • SIGHUP : acts as if a s6-svscanctl -h command had been received.
  • SIGQUIT : acts as if a s6-svscanctl -q command had been received.
  • SIGABRT : acts as if a s6-svscanctl -b command had been received.
  • -
  • SIGINT : acts as if a s6-svscanctl -i command had been received.
  • +
  • SIGINT : acts as if a s6-svscanctl -6 command had been received.
  • +
  • SIGUSR1 : acts as if a s6-svscanctl -7 command had been received.
  • The reaper

    diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c index 13c751e..e422da0 100644 --- a/src/supervision/s6-supervise.c +++ b/src/supervision/s6-supervise.c @@ -44,11 +44,19 @@ typedef void action_t (void) ; typedef action_t *action_t_ref ; static tain_t deadline ; +static tain_t dontrespawnbefore = TAIN_EPOCH ; static s6_svstatus_t status = { .stamp = TAIN_ZERO, .pid = 0, .flagwant = 1, .flagwantup = 1, .flagpaused = 0, .flagfinishing = 0, .wstat = 0 } ; static state_t state = DOWN ; static int cont = 1 ; static int notifyfd = -1 ; +static inline void down_and_delay (void) +{ + state = DOWN ; + if (tain_future(&dontrespawnbefore)) deadline = dontrespawnbefore ; + else tain_copynow(&deadline) ; +} + static inline void settimeout (int secs) { tain_addsec_g(&deadline, secs) ; @@ -247,6 +255,7 @@ static void trystart (void) state = UP ; status.pid = pid ; tain_copynow(&status.stamp) ; + tain_addsec_g(&dontrespawnbefore, 1) ; announce() ; ftrigw_notifyb_nosig(S6_SUPERVISE_EVENTDIR, "u", 1) ; } @@ -291,8 +300,7 @@ static inline void tryfinish (int islast) { strerr_warnwu2sys("fork for ", "./finish") ; if (islast) bail() ; - state = DOWN ; - settimeout(1) ; + down_and_delay() ; return ; } else if (!pid) @@ -385,9 +393,8 @@ static void finish_z (void) { status.pid = 0 ; status.flagfinishing = 0 ; - state = DOWN ; + down_and_delay() ; announce() ; - settimeout(1) ; } static void finish_u (void) diff --git a/src/supervision/s6-svscan.c b/src/supervision/s6-svscan.c index e07ff35..7ab959c 100644 --- a/src/supervision/s6-svscan.c +++ b/src/supervision/s6-svscan.c @@ -109,6 +109,12 @@ static void intr (void) term() ; } +static void usr1 (void) +{ + finish_arg = "poweroff" ; + term() ; +} + static void handle_signals (void) { for (;;) @@ -124,6 +130,7 @@ static void handle_signals (void) case SIGQUIT : quit() ; break ; case SIGABRT : cont = 0 ; break ; case SIGINT : intr() ; break ; + case SIGUSR1 : usr1() ; break ; } } } @@ -152,7 +159,7 @@ static void handle_control (int fd) case 'i' : intr() ; return ; case 'q' : quit() ; return ; case '0' : finish_arg = "halt" ; term() ; return ; - case '7' : finish_arg = "poweroff" ; term() ; return ; + case '7' : usr1() ; return ; case '8' : finish_arg = "other" ; term() ; return ; default : { @@ -446,6 +453,7 @@ int main (int argc, char const *const *argv) sigaddset(&set, SIGQUIT) ; sigaddset(&set, SIGABRT) ; sigaddset(&set, SIGINT) ; + sigaddset(&set, SIGUSR1) ; if (selfpipe_trapset(&set) < 0) strerr_diefu1sys(111, "trap signals") ; } -- cgit v1.2.3