summaryrefslogtreecommitdiff
path: root/src/supervision
diff options
context:
space:
mode:
Diffstat (limited to 'src/supervision')
-rw-r--r--src/supervision/s6-supervise.c48
-rw-r--r--src/supervision/s6-svc.c22
2 files changed, 55 insertions, 15 deletions
diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c
index e422da0..5ce718f 100644
--- a/src/supervision/s6-supervise.c
+++ b/src/supervision/s6-supervise.c
@@ -27,7 +27,7 @@ enum trans_e
{
V_TIMEOUT, V_CHLD, V_TERM, V_HUP, V_QUIT,
V_a, V_b, V_q, V_h, V_k, V_t, V_i, V_1, V_2, V_f, V_F, V_p, V_c,
- V_o, V_d, V_u, V_x, V_O
+ V_o, V_d, V_u, V_x, V_O, V_X
} ;
typedef enum state_e state_t, *state_t_ref ;
@@ -85,6 +85,16 @@ static void bail (void)
cont = 0 ;
}
+static void closethem (void)
+{
+ fd_close(0) ;
+ fd_close(1) ;
+ fd_close(2) ;
+ open_readb("/dev/null") ;
+ open_write("/dev/null") ; ndelay_off(1) ;
+ open_write("/dev/null") ; ndelay_off(2) ;
+}
+
static void killa (void)
{
kill(status.pid, SIGALRM) ;
@@ -376,6 +386,12 @@ static void up_x (void)
state = LASTUP ;
}
+static void up_X (void)
+{
+ closethem() ;
+ up_x() ;
+}
+
static void up_term (void)
{
up_x() ;
@@ -409,28 +425,34 @@ static void finish_x (void)
state = LASTFINISH ;
}
+static void finish_X (void)
+{
+ closethem() ;
+ finish_x() ;
+}
+
static void lastup_z (void)
{
uplastup_z(1) ;
}
-static action_t_ref const actions[5][23] =
+static action_t_ref const actions[5][24] =
{
{ &downtimeout, &nop, &bail, &bail, &bail,
&nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop,
- &down_o, &down_d, &down_u, &bail, &down_O },
- { &uptimeout, &up_z, &up_term, &up_x, &up_term,
+ &down_o, &down_d, &down_u, &bail, &down_O, &bail },
+ { &uptimeout, &up_z, &up_term, &up_x, &up_X,
&killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &nop, &nop, &killp, &killc,
- &up_o, &up_d, &up_u, &up_x, &up_o },
- { &finishtimeout, &finish_z, &finish_x, &finish_x, &finish_x,
+ &up_o, &up_d, &up_u, &up_x, &up_o, &up_X },
+ { &finishtimeout, &finish_z, &finish_x, &finish_x, &finish_X,
&nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop,
- &up_o, &down_d, &finish_u, &finish_x, &up_o },
- { &uptimeout, &lastup_z, &up_d, &nop, &up_d,
+ &up_o, &down_d, &finish_u, &finish_x, &up_o, &finish_X },
+ { &uptimeout, &lastup_z, &up_d, &nop, &closethem,
&killa, &killb, &killq, &killh, &killk, &killt, &killi, &kill1, &kill2, &nop, &nop, &killp, &killc,
- &up_o, &up_d, &nop, &nop, &up_o },
- { &finishtimeout, &bail, &nop, &nop, &nop,
+ &up_o, &up_d, &nop, &nop, &up_o, &closethem },
+ { &finishtimeout, &bail, &nop, &nop, &closethem,
&nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop, &nop,
- &nop, &nop, &nop, &nop, &nop }
+ &nop, &nop, &nop, &nop, &nop, &closethem }
} ;
@@ -511,8 +533,8 @@ static inline void handle_control (int fd)
else if (!r) break ;
else
{
- register unsigned int pos = byte_chr("abqhkti12fFpcoduxO", 18, c) ;
- if (pos < 18) (*actions[state][V_a + pos])() ;
+ register unsigned int pos = byte_chr("abqhkti12fFpcoduxOX", 19, c) ;
+ if (pos < 19) (*actions[state][V_a + pos])() ;
}
}
}
diff --git a/src/supervision/s6-svc.c b/src/supervision/s6-svc.c
index 7f3e538..f4eba63 100644
--- a/src/supervision/s6-svc.c
+++ b/src/supervision/s6-svc.c
@@ -1,5 +1,7 @@
/* ISC license. */
+#include <unistd.h>
+#include <errno.h>
#include <skalibs/uint.h>
#include <skalibs/bytestr.h>
#include <skalibs/sgetopt.h>
@@ -8,7 +10,7 @@
#include <s6/config.h>
#include <s6/s6-supervise.h>
-#define USAGE "s6-svc [ -D | -U ] [ -T timeout ] [ -abqhkti12pcoduxO ] servicedir"
+#define USAGE "s6-svc [ -D | -U ] [ -T timeout ] [ -abqhkti12pcoduxOX ] servicedir"
#define dieusage() strerr_dieusage(100, USAGE)
#define DATASIZE 63
@@ -24,7 +26,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "DUabqhkti12pcoduxOT:", &l) ;
+ register int opt = subgetopt_r(argc, argv, "DUabqhkti12pcoduxOXT:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -46,6 +48,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'u' :
case 'x' :
case 'O' :
+ case 'X' :
{
if (datalen >= DATASIZE) strerr_dief1x(100, "too many commands") ;
data[datalen++] = opt ;
@@ -59,6 +62,21 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
if (!argc) dieusage() ;
if (argc > 1) strerr_warn1x("ignoring extra arguments") ;
+
+ if (updown[1] == 'U')
+ {
+ unsigned int arglen = str_len(argv[0]) ;
+ char fn[arglen + 17] ;
+ byte_copy(fn, arglen, argv[0]) ;
+ byte_copy(fn + arglen, 17, "/notification-fd") ;
+ if (access(fn, F_OK) < 0)
+ {
+ if (errno != ENOENT) strerr_diefu2sys(111, "access ", fn) ;
+ updown[1] = 0 ;
+ strerr_warnw2x(fn, "not present - ignoring -U option") ;
+ }
+ }
+
if (updown[1])
{
char const *newargv[11] ;