From 146da0d33300e8200537fb9b73ce1985a338f746 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 7 Apr 2023 15:22:11 +0000 Subject: Simplify selfpipe management Signed-off-by: Laurent Bercot --- src/supervision/s6-svlisten.c | 8 ++++---- src/supervision/s6-svlisten.h | 2 +- src/supervision/s6-svlisten1.c | 8 ++++---- src/supervision/s6_svlisten_loop.c | 1 + src/supervision/s6_svlisten_signal_handler.c | 6 ++---- 5 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src/supervision') diff --git a/src/supervision/s6-svlisten.c b/src/supervision/s6-svlisten.c index 1e060cf..205a382 100644 --- a/src/supervision/s6-svlisten.c +++ b/src/supervision/s6-svlisten.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "s6-svlisten.h" @@ -18,7 +19,6 @@ int main (int argc, char const **argv, char const *const *envp) { tain deadline, tto ; - int spfd ; int argc1 ; int or = 0 ; int wantup = 1, wantready = 0 ; @@ -59,7 +59,7 @@ int main (int argc, char const **argv, char const *const *envp) tain_now_set_stopwatch_g() ; tain_add_g(&deadline, &tto) ; - spfd = s6_svlisten_selfpipe_init() ; + s6_svlisten_selfpipe_init() ; { s6_svlisten_t foo = S6_SVLISTEN_ZERO ; @@ -74,10 +74,10 @@ int main (int argc, char const **argv, char const *const *envp) if (wantup == 2) { wantup = 1 ; - e = s6_svlisten_loop(&foo, 0, 1, or, &deadline, spfd, &s6_svlisten_signal_handler) ; + e = s6_svlisten_loop(&foo, 0, 1, or, &deadline, selfpipe_fd(), &s6_svlisten_signal_handler) ; if (e) strerr_dief1x(e, "some services reported permanent failure or their supervisor died") ; } - e = s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, spfd, &s6_svlisten_signal_handler) ; + e = s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, selfpipe_fd(), &s6_svlisten_signal_handler) ; if (e) strerr_dief1x(e, "some services reported permanent failure or their supervisor died") ; } return 0 ; diff --git a/src/supervision/s6-svlisten.h b/src/supervision/s6-svlisten.h index 92636ee..a0aa591 100644 --- a/src/supervision/s6-svlisten.h +++ b/src/supervision/s6-svlisten.h @@ -22,7 +22,7 @@ struct s6_svlisten_s #define S6_SVLISTEN_ZERO { .a = FTRIGR_ZERO, .n = 0, .ids = 0, .upstate = 0, .readystate = 0 } extern void s6_svlisten_signal_handler (void) ; -extern int s6_svlisten_selfpipe_init (void) ; +extern void s6_svlisten_selfpipe_init (void) ; extern void s6_svlisten_init (int, char const *const *, s6_svlisten_t *, uint16_t *, unsigned char *, unsigned char *, tain const *) ; extern unsigned int s6_svlisten_loop (s6_svlisten_t *, int, int, int, tain const *, int, action_func_ref) ; diff --git a/src/supervision/s6-svlisten1.c b/src/supervision/s6-svlisten1.c index 7102685..ab4f44c 100644 --- a/src/supervision/s6-svlisten1.c +++ b/src/supervision/s6-svlisten1.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "s6-svlisten.h" @@ -18,7 +19,6 @@ int main (int argc, char const *const *argv, char const *const *envp) s6_svlisten_t foo = S6_SVLISTEN_ZERO ; tain deadline, tto ; pid_t pid ; - int spfd ; int wantup = 1, wantready = 0, wantrestart = 0 ; uint16_t id ; unsigned char upstate, readystate ; @@ -48,14 +48,14 @@ int main (int argc, char const *const *argv, char const *const *envp) if (argc < 2) dieusage() ; tain_now_set_stopwatch_g() ; tain_add_g(&deadline, &tto) ; - spfd = s6_svlisten_selfpipe_init() ; + s6_svlisten_selfpipe_init() ; 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) - if (s6_svlisten_loop(&foo, 0, 1, 1, &deadline, spfd, &s6_svlisten_signal_handler)) + if (s6_svlisten_loop(&foo, 0, 1, 1, &deadline, selfpipe_fd(), &s6_svlisten_signal_handler)) strerr_dief2x(1, argv[0], " failed permanently or its supervisor died") ; - if (s6_svlisten_loop(&foo, wantup, wantready, 1, &deadline, spfd, &s6_svlisten_signal_handler)) + if (s6_svlisten_loop(&foo, wantup, wantready, 1, &deadline, selfpipe_fd(), &s6_svlisten_signal_handler)) strerr_dief2x(1, argv[0], " failed permanently or its supervisor died") ; return 0 ; } diff --git a/src/supervision/s6_svlisten_loop.c b/src/supervision/s6_svlisten_loop.c index 97b155e..d7234b1 100644 --- a/src/supervision/s6_svlisten_loop.c +++ b/src/supervision/s6_svlisten_loop.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/src/supervision/s6_svlisten_signal_handler.c b/src/supervision/s6_svlisten_signal_handler.c index 723771f..bf47146 100644 --- a/src/supervision/s6_svlisten_signal_handler.c +++ b/src/supervision/s6_svlisten_signal_handler.c @@ -9,13 +9,11 @@ #include "s6-svlisten.h" -int s6_svlisten_selfpipe_init (void) +void s6_svlisten_selfpipe_init (void) { - int spfd = selfpipe_init() ; - if (spfd < 0) strerr_diefu1sys(111, "selfpipe_init") ; + if (selfpipe_init() == -1) strerr_diefu1sys(111, "selfpipe_init") ; if (!selfpipe_trap(SIGCHLD)) strerr_diefu1sys(111, "selfpipe_trap") ; if (!sig_altignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ; - return spfd ; } void s6_svlisten_signal_handler (void) -- cgit v1.2.3