diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/supervision/s6-svc.c | 10 | ||||
-rw-r--r-- | src/supervision/s6-svlisten.c | 19 | ||||
-rw-r--r-- | src/supervision/s6-svlisten1.c | 14 |
3 files changed, 32 insertions, 11 deletions
diff --git a/src/supervision/s6-svc.c b/src/supervision/s6-svc.c index 308075d..467c174 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 ] [ -T timeout ] [ -abqhkti12pcoduxOX ] servicedir" +#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcoduxOX ] servicedir" #define dieusage() strerr_dieusage(100, USAGE) #define DATASIZE 63 @@ -55,7 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'T' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ; case 'w' : { - if (byte_chr("dDuU", 4, l.arg[0]) >= 4) dieusage() ; + if (byte_chr("dDuUrR", 6, l.arg[0]) >= 6) dieusage() ; updown[1] = l.arg[0] ; break ; } @@ -68,7 +68,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (argc > 1) strerr_warn1x("ignoring extra arguments") ; if (datalen <= 1) return 0 ; - if (updown[1] == 'U') + if (updown[1] == 'U' || updown[1] == 'R') { unsigned int arglen = str_len(argv[0]) ; char fn[arglen + 17] ; @@ -77,8 +77,8 @@ int main (int argc, char const *const *argv, char const *const *envp) if (access(fn, F_OK) < 0) { if (errno != ENOENT) strerr_diefu2sys(111, "access ", fn) ; - updown[1] = 'u' ; - strerr_warnw2x(fn, " not present - converting -wU to -wu") ; + updown[1] = updown[1] == 'U' ? 'u' : 'r' ; + strerr_warnw2x(fn, " not present - ignoring request for readiness notification") ; } } diff --git a/src/supervision/s6-svlisten.c b/src/supervision/s6-svlisten.c index 1241d72..e53fa76 100644 --- a/src/supervision/s6-svlisten.c +++ b/src/supervision/s6-svlisten.c @@ -11,7 +11,7 @@ #include <execline/execline.h> #include "s6-svlisten.h" -#define USAGE "s6-svlisten [ -U | -u | -d | -D ] [ -a | -o ] [ -t timeout ] servicedir... \"\" prog..." +#define USAGE "s6-svlisten [ -U | -u | -d | -D | -r | -R ] [ -a | -o ] [ -t timeout ] servicedir... \"\" prog..." #define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const **argv, char const *const *envp) @@ -20,14 +20,14 @@ int main (int argc, char const **argv, char const *const *envp) int spfd ; int argc1 ; int or = 0 ; - int wantup = 1, wantready = 0 ; + int wantup = 1, wantready = 0, wantrestart = 0 ; PROG = "s6-svlisten" ; { subgetopt_t l = SUBGETOPT_ZERO ; unsigned int t = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "uUdDaot:", &l) ; + register int opt = subgetopt_r(argc, argv, "uUdDrRaot:", &l) ; if (opt == -1) break ; switch (opt) { @@ -35,6 +35,8 @@ int main (int argc, char const **argv, char const *const *envp) case 'U' : wantup = 1 ; wantready = 1 ; break ; case 'd' : wantup = 0 ; wantready = 0 ; break ; case 'D' : wantup = 0 ; wantready = 1 ; break ; + case 'r' : wantrestart = 1 ; wantready = 0 ; break ; + case 'R' : wantrestart = 1 ; wantready = 1 ; break ; case 'a' : or = 0 ; break ; case 'o' : or = 1 ; break ; case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; @@ -49,6 +51,11 @@ int main (int argc, char const **argv, char const *const *envp) argc1 = el_semicolon(argv) ; if (!argc1 || argc == argc1 + 1) dieusage() ; if (argc1 >= argc) strerr_dief1x(100, "unterminated servicedir block") ; + if (wantrestart && or) + { + or = 0 ; + strerr_warnw3x("-o is unsupported when combined with -", wantready ? "R" : "r", "- using -a instead") ; + } tain_now_g() ; tain_add_g(&deadline, &tto) ; @@ -63,6 +70,12 @@ int main (int argc, char const **argv, char const *const *envp) s6_svlisten_init(argc1, argv, &foo, ids, upstate, readystate, &deadline) ; pid = child_spawn0(argv[argc1 + 1], argv + argc1 + 1, 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 ; + wantup = 1 ; + } return s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, spfd, &s6_svlisten_signal_handler) ; } } diff --git a/src/supervision/s6-svlisten1.c b/src/supervision/s6-svlisten1.c index 32fef1f..6c4bb36 100644 --- a/src/supervision/s6-svlisten1.c +++ b/src/supervision/s6-svlisten1.c @@ -9,7 +9,7 @@ #include <skalibs/djbunix.h> #include "s6-svlisten.h" -#define USAGE "s6-svlisten1 [ -U | -u | -d | -D ] [ -t timeout ] servicedir prog..." +#define USAGE "s6-svlisten1 [ -U | -u | -d | -D | -r | -R ] [ -t timeout ] servicedir prog..." #define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const *const *argv, char const *const *envp) @@ -18,7 +18,7 @@ int main (int argc, char const *const *argv, char const *const *envp) tain_t deadline, tto ; pid_t pid ; int spfd ; - int wantup = 1, wantready = 0 ; + int wantup = 1, wantready = 0, wantrestart = 0 ; uint16 id ; unsigned char upstate, readystate ; PROG = "s6-svlisten1" ; @@ -27,7 +27,7 @@ int main (int argc, char const *const *argv, char const *const *envp) unsigned int t = 0 ; for (;;) { - register int opt = subgetopt_r(argc, argv, "uUdDt:", &l) ; + register int opt = subgetopt_r(argc, argv, "uUdDrRt:", &l) ; if (opt == -1) break ; switch (opt) { @@ -35,6 +35,8 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'U' : wantup = 1 ; wantready = 1 ; break ; case 'd' : wantup = 0 ; wantready = 0 ; break ; case 'D' : wantup = 0 ; wantready = 1 ; break ; + case 'r' : wantrestart = 1 ; wantready = 0 ; break ; + case 'R' : wantrestart = 1 ; wantready = 1 ; break ; case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; default : dieusage() ; } @@ -49,5 +51,11 @@ int main (int argc, char const *const *argv, char const *const *envp) s6_svlisten_init(1, argv, &foo, &id, &upstate, &readystate, &deadline) ; pid = child_spawn0(argv[1], argv + 1, envp) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[1]) ; + if (wantrestart) + { + register int r = s6_svlisten_loop(&foo, 0, 1, 1, &deadline, spfd, &s6_svlisten_signal_handler) ; + if (r) return r ; + wantup = 1 ; + } return s6_svlisten_loop(&foo, wantup, wantready, 1, &deadline, spfd, &s6_svlisten_signal_handler) ; } |