diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-03-20 20:34:12 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-03-20 20:34:12 +0000 |
commit | bb9a68add4feef7c53ba3994256745ea99cffef8 (patch) | |
tree | deac3ebb8326e97d8432a8a7cabab34e1e16bda8 /src/supervision | |
parent | b4518d79cc80e7ea0f4e53345ca29afa21e4f0f3 (diff) | |
download | s6-bb9a68add4feef7c53ba3994256745ea99cffef8.tar.xz |
Implement permanent failure for services via ./finish exiting 125
Diffstat (limited to 'src/supervision')
-rw-r--r-- | src/supervision/s6-supervise.c | 8 | ||||
-rw-r--r-- | src/supervision/s6-svlisten.c | 9 | ||||
-rw-r--r-- | src/supervision/s6-svlisten1.c | 9 | ||||
-rw-r--r-- | src/supervision/s6-svwait.c | 5 | ||||
-rw-r--r-- | src/supervision/s6_svlisten_loop.c | 20 |
5 files changed, 38 insertions, 13 deletions
diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c index 8bb55c8..2e8ce6a 100644 --- a/src/supervision/s6-supervise.c +++ b/src/supervision/s6-supervise.c @@ -436,7 +436,13 @@ static void finishtimeout (void) static void finish_z (void) { - set_down_and_ready("D", 1) ; + int wstat = (int)status.pid ; + if (WIFEXITED(wstat) && WEXITSTATUS(wstat) == 125) + { + status.flagwant = 0 ; + set_down_and_ready("OD", 2) ; + } + else set_down_and_ready("D", 1) ; } static void finish_u (void) diff --git a/src/supervision/s6-svlisten.c b/src/supervision/s6-svlisten.c index f2191fd..d15557a 100644 --- a/src/supervision/s6-svlisten.c +++ b/src/supervision/s6-svlisten.c @@ -63,6 +63,7 @@ int main (int argc, char const **argv, char const *const *envp) { s6_svlisten_t foo = S6_SVLISTEN_ZERO ; pid_t pid ; + int e ; uint16_t ids[argc1] ; unsigned char upstate[bitarray_div8(argc1)] ; unsigned char readystate[bitarray_div8(argc1)] ; @@ -71,10 +72,12 @@ int main (int argc, char const **argv, char const *const *envp) if (!pid) strerr_diefu2sys(111, "spawn ", argv[argc1 + 1]) ; if (wantrestart) { - argc1 = s6_svlisten_loop(&foo, 0, 1, or, &deadline, spfd, &s6_svlisten_signal_handler) ; - if (argc1) return argc1 ; + e = s6_svlisten_loop(&foo, 0, 1, or, &deadline, spfd, &s6_svlisten_signal_handler) ; + if (e) strerr_dief1x(e, "some services reported permanent failure") ; wantup = 1 ; } - return s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, spfd, &s6_svlisten_signal_handler) ; + e = s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, spfd, &s6_svlisten_signal_handler) ; + if (e) strerr_dief1x(e, "some services reported permanent failure") ; } + return 0 ; } diff --git a/src/supervision/s6-svlisten1.c b/src/supervision/s6-svlisten1.c index d9a5de4..af9959a 100644 --- a/src/supervision/s6-svlisten1.c +++ b/src/supervision/s6-svlisten1.c @@ -17,6 +17,7 @@ int main (int argc, char const *const *argv, char const *const *envp) tain_t deadline, tto ; pid_t pid ; int spfd ; + int e ; int wantup = 1, wantready = 0, wantrestart = 0 ; uint16_t id ; unsigned char upstate, readystate ; @@ -52,9 +53,11 @@ int main (int argc, char const *const *argv, char const *const *envp) if (!pid) strerr_diefu2sys(111, "spawn ", argv[1]) ; if (wantrestart) { - int r = s6_svlisten_loop(&foo, 0, 1, 1, &deadline, spfd, &s6_svlisten_signal_handler) ; - if (r) return r ; + int e = s6_svlisten_loop(&foo, 0, 1, 1, &deadline, spfd, &s6_svlisten_signal_handler) ; + if (e) strerr_dief2x(1, argv[0], " failed permanently: the finish script exited 125") ; wantup = 1 ; } - return s6_svlisten_loop(&foo, wantup, wantready, 1, &deadline, spfd, &s6_svlisten_signal_handler) ; + e = s6_svlisten_loop(&foo, wantup, wantready, 1, &deadline, spfd, &s6_svlisten_signal_handler) ; + if (e) strerr_dief2x(1, argv[0], " failed permanently: the finish script exited 125") ; + return 0 ; } diff --git a/src/supervision/s6-svwait.c b/src/supervision/s6-svwait.c index 752da69..28d1c3d 100644 --- a/src/supervision/s6-svwait.c +++ b/src/supervision/s6-svwait.c @@ -46,10 +46,13 @@ int main (int argc, char const *const *argv) { s6_svlisten_t foo = S6_SVLISTEN_ZERO ; + int e ; uint16_t ids[argc] ; unsigned char upstate[bitarray_div8(argc)] ; unsigned char readystate[bitarray_div8(argc)] ; s6_svlisten_init(argc, argv, &foo, ids, upstate, readystate, &deadline) ; - return s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, -1, 0) ; + e = s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, -1, 0) ; + if (e) strerr_dief1x(e, "some services reported permanent failure") ; } + return 0 ; } diff --git a/src/supervision/s6_svlisten_loop.c b/src/supervision/s6_svlisten_loop.c index 3cab3ff..942abf0 100644 --- a/src/supervision/s6_svlisten_loop.c +++ b/src/supervision/s6_svlisten_loop.c @@ -26,7 +26,7 @@ void s6_svlisten_init (int argc, char const *const *argv, s6_svlisten_t *foo, ui memcpy(s, argv[i], len) ; s[len] = '/' ; memcpy(s + len + 1, S6_SUPERVISE_EVENTDIR, sizeof(S6_SUPERVISE_EVENTDIR)) ; - foo->ids[i] = ftrigr_subscribe_g(&foo->a, s, "[DuUd]", FTRIGR_REPEAT, deadline) ; + foo->ids[i] = ftrigr_subscribe_g(&foo->a, s, "[DuUdO]", FTRIGR_REPEAT, deadline) ; if (!foo->ids[i]) strerr_diefu2sys(111, "subscribe to events for ", argv[i]) ; if (!s6_svstatus_read(argv[i], &status)) strerr_diefu1sys(111, "s6_svstatus_read") ; bitarray_poke(foo->upstate, i, status.pid && !status.flagfinishing) ; @@ -47,6 +47,7 @@ static inline int got (s6_svlisten_t const *foo, int wantup, int wantready, int int s6_svlisten_loop (s6_svlisten_t *foo, int wantup, int wantready, int or, tain_t const *deadline, int spfd, action_func_t_ref handler) { iopause_fd x[2] = { { .fd = ftrigr_fd(&foo->a), .events = IOPAUSE_READ }, { .fd = spfd, .events = IOPAUSE_READ, .revents = 0 } } ; + unsigned int e = 0 ; while (!got(foo, wantup, wantready, or)) { int r = iopause_g(x, 1 + (spfd >= 0), deadline) ; @@ -64,12 +65,21 @@ int s6_svlisten_loop (s6_svlisten_t *foo, int wantup, int wantready, int or, tai if (r < 0) strerr_diefu1sys(111, "ftrigr_check") ; if (r) { - unsigned int d = byte_chr("dDuU", 4, what) ; - bitarray_poke(foo->upstate, i, d & 2) ; - bitarray_poke(foo->readystate, i, d & 1) ; + if (what == 'O') + { + bitarray_poke(foo->upstate, i, wantup) ; + bitarray_poke(foo->readystate, i, wantready) ; + e++ ; + } + else + { + unsigned int d = byte_chr("dDuU", 4, what) ; + bitarray_poke(foo->upstate, i, d & 2) ; + bitarray_poke(foo->readystate, i, d & 1) ; + } } } } } - return 0 ; + return e ; } |