s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 2598c3ce94f6f292bdd234020709af034c27d262
parent 029ffa3f14ebdf94f1d6e0cf2df34d13a6de574d
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Wed,  8 Nov 2023 14:08:58 +0000

 bugfix: s6-svscan didn't delay killing until scan. Prepare for 2.12.0.1.

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Mdoc/index.html | 2+-
Mdoc/upgrade.html | 6++++++
Mpackage/info | 2+-
Msrc/supervision/s6-svscan.c | 41++++++++++++++++++++++++++++-------------
4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/doc/index.html b/doc/index.html @@ -115,7 +115,7 @@ want nsswitch-like functionality: <h3> Download </h3> <ul> - <li> The current released version of s6 is <a href="s6-2.12.0.0.tar.gz">2.12.0.0</a>. </li> + <li> The current released version of s6 is <a href="s6-2.12.0.1.tar.gz">2.12.0.1</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/s6/">s6 git repository</a>: diff --git a/doc/upgrade.html b/doc/upgrade.html @@ -18,6 +18,12 @@ <h1> What has changed in s6 </h1> +<h2> in 2.12.0.1 </h2> + +<ul> + <li> No functional changes. </li> +</ul> + <h2> in 2.12.0.0 </h2> <ul> diff --git a/package/info b/package/info @@ -1,4 +1,4 @@ package=s6 -version=2.12.0.0 +version=2.12.0.1 category=admin package_macro_name=S6 diff --git a/src/supervision/s6-svscan.c b/src/supervision/s6-svscan.c @@ -177,6 +177,15 @@ static inline void waitthem (void) /* Misc utility */ + /* + what: + 1 -> kill all services + 2 -> kill inactive services + 4 -> send a SIGTERM to loggers instead of SIGHUP + 8 -> reap + 16 -> delay killing until the next scan + */ + static inline int is_logger (uint32_t i) { return !!strchr(NAME(i), '/') ; @@ -189,8 +198,9 @@ static inline void chld (unsigned int *what) *what |= 8 ; } -static inline void alrm (void) +static inline void alrm (unsigned int *what) { + *what |= 16 ; tain_copynow(&scan_deadline) ; } @@ -202,7 +212,7 @@ static inline void abrt (void) static void hup (unsigned int *what) { - *what |= 2 ; + *what |= 18 ; tain_copynow(&scan_deadline) ; } @@ -230,7 +240,7 @@ static void handle_signals (unsigned int *what) case -1 : panic("selfpipe_read") ; case 0 : return ; case SIGCHLD : chld(what) ; break ; - case SIGALRM : alrm() ; break ; + case SIGALRM : alrm(what) ; break ; case SIGABRT : abrt() ; break ; default : { @@ -241,7 +251,7 @@ static void handle_signals (unsigned int *what) char const *const newargv[2] = { fn, 0 } ; memcpy(fn, SIGNAL_PROG, SIGNAL_PROG_LEN) ; memcpy(fn + SIGNAL_PROG_LEN, name, len + 1) ; - if (access(newargv[0], X_OK) == 0) /* avoids a fork, don't care about the toctou */ + if (access(newargv[0], X_OK) == 0) /* avoids a spawn, don't care about the toctou */ { if (cspawn(newargv[0], newargv, (char const **)environ, CSPAWN_FLAGS_SELFPIPE_FINISH, 0, 0)) usebuiltin = 0 ; @@ -270,7 +280,7 @@ static void handle_control (int fd, unsigned int *what) switch (c) { case 'z' : chld(what) ; break ; - case 'a' : alrm() ; break ; + case 'a' : alrm(what) ; break ; case 'b' : abrt() ; break ; case 'h' : hup(what) ; break ; case 'i' : @@ -300,9 +310,11 @@ static int killthem_iter (void *data, void *aux) return 1 ; } -static inline void killthem (unsigned int what) +static inline void killthem (unsigned int *what) { - genset_iter(services, &killthem_iter, &what) ; + if (*what & 16 || !(*what & 7)) return ; + genset_iter(services, &killthem_iter, what) ; + *what &= ~7 ; } @@ -334,8 +346,10 @@ static void remove_service (service *sv) genset_delete(services, sv - SERVICE(0)) ; } -static void reap (void) +static void reap (unsigned int *what) { + if (!(*what & 8)) return ; + *what &= ~8 ; for (;;) { uint32_t i ; @@ -459,7 +473,7 @@ static int remove_deadinactive_iter (void *data, void *aux) return 1 ; } -static void scan (void) +static void scan (unsigned int *what) { DIR *dir = opendir(".") ; char tmpactive[bitarray_div8(max)] ; @@ -520,6 +534,7 @@ static void scan (void) uint32_t n = genset_n(services) - avltreen_len(by_devino) ; if (n) genset_iter(services, &remove_deadinactive_iter, &n) ; } + *what &= ~16 ; } @@ -701,6 +716,7 @@ int main (int argc, char const *const *argv) } { + unsigned int what = 0 ; service services_storage[max] ; uint32_t services_freelist[max] ; avlnode bydevino_storage[max] ; @@ -732,16 +748,17 @@ int main (int argc, char const *const *argv) int r ; tain deadline = scan_deadline ; tain_earliest1(&deadline, &start_deadline) ; + killthem(&what) ; + reap(&what) ; r = iopause_g(x, 2, &deadline) ; if (r < 0) panic("iopause") ; else if (!r) { - if (!tain_future(&scan_deadline)) scan() ; + if (!tain_future(&scan_deadline)) scan(&what) ; if (!tain_future(&start_deadline)) start() ; } else { - unsigned int what = 0 ; if ((x[0].revents | x[1].revents) & IOPAUSE_EXCEPT) { errno = EIO ; @@ -749,8 +766,6 @@ int main (int argc, char const *const *argv) } if (x[0].revents & IOPAUSE_READ) handle_signals(&what) ; if (x[1].revents & IOPAUSE_READ) handle_control(x[1].fd, &what) ; - if (what & 7) killthem(what & 7) ; - if (what & 8) reap() ; } }