summaryrefslogtreecommitdiff
path: root/src/supervision
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-04-07 15:22:11 +0000
committerLaurent Bercot <ska@appnovation.com>2023-04-07 15:22:11 +0000
commit146da0d33300e8200537fb9b73ce1985a338f746 (patch)
tree16af5c8e44bd5f93fd06624f8303b90f132f4a42 /src/supervision
parent763cabcda00c56c9644989a310dbbe3bc8502862 (diff)
downloads6-146da0d33300e8200537fb9b73ce1985a338f746.tar.xz
Simplify selfpipe management
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/supervision')
-rw-r--r--src/supervision/s6-svlisten.c8
-rw-r--r--src/supervision/s6-svlisten.h2
-rw-r--r--src/supervision/s6-svlisten1.c8
-rw-r--r--src/supervision/s6_svlisten_loop.c1
-rw-r--r--src/supervision/s6_svlisten_signal_handler.c6
5 files changed, 12 insertions, 13 deletions
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 <skalibs/tai.h>
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
+#include <skalibs/selfpipe.h>
#include <s6/compat.h>
#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 <skalibs/tai.h>
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
+#include <skalibs/selfpipe.h>
#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 <skalibs/iopause.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
+#include <skalibs/selfpipe.h>
#include <s6/ftrigw.h>
#include <s6/ftrigr.h>
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)