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/fdholder/s6-fdholderd.c | 6 ++---- src/libs6/s6lockd.c | 6 ++---- 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 ++---- 7 files changed, 16 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/fdholder/s6-fdholderd.c b/src/fdholder/s6-fdholderd.c index 073f7bf..d357127 100644 --- a/src/fdholder/s6-fdholderd.c +++ b/src/fdholder/s6-fdholderd.c @@ -645,7 +645,6 @@ static inline int new_connection (int fd, regex_t *rre, regex_t *wre, unsigned i int main (int argc, char const *const *argv, char const *const *envp) { - int spfd ; int flag1 = 0 ; uint32_t maxconn = 16 ; PROG = "s6-fdholderd" ; @@ -700,8 +699,7 @@ int main (int argc, char const *const *argv, char const *const *envp) strerr_dief1sys(100, "called with option -1 but stdout said") ; } else close(1) ; - spfd = selfpipe_init() ; - if (spfd < 0) strerr_diefu1sys(111, "selfpipe_init") ; + if (selfpipe_init() == -1) strerr_diefu1sys(111, "selfpipe_init") ; if (!sig_ignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ; { sigset_t set ; @@ -743,7 +741,7 @@ int main (int argc, char const *const *argv, char const *const *envp) avltreen_init(&fddeadlineinfo, fddeadlinestorage, fddeadlinefreelist, maxfds, &fds_deadline_dtok, &fds_deadline_cmp, 0) ; fds_by_deadline = &fddeadlineinfo ; - x[0].fd = spfd ; x[0].events = IOPAUSE_READ ; + x[0].fd = selfpipe_fd() ; x[0].events = IOPAUSE_READ ; x[1].fd = 0 ; if (flag1) diff --git a/src/libs6/s6lockd.c b/src/libs6/s6lockd.c index 04861ba..e7303af 100644 --- a/src/libs6/s6lockd.c +++ b/src/libs6/s6lockd.c @@ -180,7 +180,6 @@ static int parse_protocol (struct iovec const *v, void *context) int main (int argc, char const *const *argv) { tain deadline ; - int sfd ; PROG = "s6lockd" ; if (argc < 2) strerr_dieusage(100, USAGE) ; @@ -189,8 +188,7 @@ int main (int argc, char const *const *argv) if (ndelay_on(1) < 0) strerr_diefu2sys(111, "ndelay_on ", "1") ; if (!sig_altignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ; - sfd = selfpipe_init() ; - if (sfd < 0) strerr_diefu1sys(111, "selfpipe_init") ; + if (selfpipe_init() == -1) strerr_diefu1sys(111, "selfpipe_init") ; { sigset_t set ; sigemptyset(&set) ; @@ -222,7 +220,7 @@ int main (int argc, char const *const *argv) x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_1) ? 0 : IOPAUSE_WRITE ) ; x[2].fd = textmessage_sender_fd(textmessage_sender_x) ; x[2].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_x) ? 0 : IOPAUSE_WRITE) ; - x[3].fd = sfd ; x[3].events = IOPAUSE_READ ; + x[3].fd = selfpipe_fd() ; x[3].events = IOPAUSE_READ ; for (; i < n ; i++) { s6lockio_t *p = genalloc_s(s6lockio_t, &a) + i ; 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