diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-06-15 12:36:00 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-06-15 12:36:00 +0000 |
commit | 50a00de6e4aa6337b17a179019ec7689a2cc6b6d (patch) | |
tree | 64436fc16abf67e0880c22231a58a12ef06d8469 /src/supervision | |
parent | 6577467acca3fd281273b95c3906a85dbf19e6f8 (diff) | |
download | s6-50a00de6e4aa6337b17a179019ec7689a2cc6b6d.tar.xz |
Down signal customization: add ./down-signal file and s6-svc -r
Diffstat (limited to 'src/supervision')
-rw-r--r-- | src/supervision/s6-supervise.c | 44 | ||||
-rw-r--r-- | src/supervision/s6-svc.c | 5 |
2 files changed, 35 insertions, 14 deletions
diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c index 9d821bd..bdc4730 100644 --- a/src/supervision/s6-supervise.c +++ b/src/supervision/s6-supervise.c @@ -30,7 +30,7 @@ typedef enum trans_e trans_t, *trans_t_ref ; enum trans_e { V_TIMEOUT, V_CHLD, V_TERM, V_HUP, V_QUIT, - V_a, V_b, V_q, V_h, V_k, V_t, V_i, V_1, V_2, V_f, V_F, V_p, V_c, V_y, + V_a, V_b, V_q, V_h, V_k, V_t, V_i, V_1, V_2, V_f, V_F, V_p, V_c, V_y, V_r, V_o, V_d, V_u, V_x, V_O, V_X } ; @@ -71,16 +71,22 @@ static inline void announce (void) strerr_warnwu1sys("write status file") ; } -static int read_uint (char const *file, unsigned int *fd) +static int read_file (char const *file, char *buf, size_t n) { - char buf[UINT_FMT + 1] ; - ssize_t r = openreadnclose_nb(file, buf, UINT_FMT) ; + ssize_t r = openreadnclose_nb(file, buf, n) ; if (r < 0) { if (errno != ENOENT) strerr_warnwu2sys("open ", file) ; return 0 ; } buf[byte_chr(buf, r, '\n')] = 0 ; + return 1 ; +} + +static int read_uint (char const *file, unsigned int *fd) +{ + char buf[UINT_FMT + 1] ; + if (!read_file(file, buf, UINT_FMT)) return 0 ; if (!uint0_scan(buf, fd)) { strerr_warnw2x("invalid ", file) ; @@ -89,6 +95,15 @@ static int read_uint (char const *file, unsigned int *fd) return 1 ; } +static inline int read_downsig (void) +{ + int sig = SIGTERM ; + char buf[16] ; + if (read_file("down-signal", buf, 15) && !sig0_scan(buf, &sig)) + strerr_warnw1x("invalid down-signal") ; + return sig ; +} + static void set_down_and_ready (char const *s, unsigned int n) { status.pid = 0 ; @@ -188,6 +203,11 @@ static void killy (void) kill(status.pid, SIGWINCH) ; } +static void killr (void) +{ + kill(status.pid, read_downsig()) ; +} + static void failcoe (int fd) { int e = errno ; @@ -430,7 +450,7 @@ static void up_d (void) tain_t tto ; unsigned int timeout ; status.flagwantup = 0 ; - killt() ; + killr() ; killc() ; if (!read_uint("timeout-kill", &timeout)) timeout = 0 ; if (timeout && tain_from_millisecs(&tto, timeout)) @@ -505,22 +525,22 @@ static void lastfinish_z (void) bail() ; } -static action_t_ref const actions[5][25] = +static action_t_ref const actions[5][26] = { { &downtimeout, &nop, &bail, &bail, &bail, - &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, + &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &down_o, &down_d, &down_u, &bail, &down_O, &bail }, { &uptimeout, &up_z, &up_term, &up_x, &up_X, - &killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &nop, &nop, &killp, &killc, &killy, + &killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &nop, &nop, &killp, &killc, &killy, &killr, &up_o, &up_d, &up_u, &up_x, &up_o, &up_X }, { &finishtimeout, &finish_z, &finish_x, &finish_x, &finish_X, - &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, + &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &up_o, &down_d, &finish_u, &finish_x, &up_o, &finish_X }, { &uptimeout, &lastup_z, &up_d, &nop, &closethem, - &killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &nop, &nop, &killp, &killc, &killy, + &killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &nop, &nop, &killp, &killc, &killy, &killr, &up_o, &up_d, &nop, &nop, &up_o, &closethem }, { &finishtimeout, &lastfinish_z, &nop, &nop, &closethem, - &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, + &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &closethem } } ; @@ -600,7 +620,7 @@ static inline void handle_control (int fd) else if (!r) break ; else { - size_t pos = byte_chr("abqhkti12fFpcyoduxOX", 20, c) ; + size_t pos = byte_chr("abqhkti12fFpcyroduxOX", 20, c) ; if (pos < 20) (*actions[state][V_a + pos])() ; } } diff --git a/src/supervision/s6-svc.c b/src/supervision/s6-svc.c index d844b20..2166551 100644 --- a/src/supervision/s6-svc.c +++ b/src/supervision/s6-svc.c @@ -10,7 +10,7 @@ #include <s6/config.h> #include <s6/s6-supervise.h> -#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcoduxOX ] servicedir" +#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduxOX ] servicedir" #define dieusage() strerr_dieusage(100, USAGE) #define DATASIZE 63 @@ -41,13 +41,14 @@ int main (int argc, char const *const *argv, char const *const *envp) case '2' : case 'p' : case 'c' : + case 'y' : + case 'r' : case 'o' : case 'd' : case 'u' : case 'x' : case 'O' : case 'X' : - case 'y' : { if (datalen >= DATASIZE) strerr_dief1x(100, "too many commands") ; data[datalen++] = opt ; |