summaryrefslogtreecommitdiff
path: root/src/supervision/s6-svscan.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-01-15 14:15:42 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-01-15 14:15:42 +0000
commit597dc96fec06714019afe95487cd1065239b8049 (patch)
tree1dc3a583fed0bf803874b23d1f1af6e992f2da90 /src/supervision/s6-svscan.c
parentf59b79de8c8f49ffd5133b2a37e11a52edc2bdbd (diff)
downloads6-597dc96fec06714019afe95487cd1065239b8049.tar.xz
Add console holder functionality to s6-svscan
Diffstat (limited to 'src/supervision/s6-svscan.c')
-rw-r--r--src/supervision/s6-svscan.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/supervision/s6-svscan.c b/src/supervision/s6-svscan.c
index ffc257d..c818498 100644
--- a/src/supervision/s6-svscan.c
+++ b/src/supervision/s6-svscan.c
@@ -21,13 +21,14 @@
#include <s6/config.h>
#include <s6/s6-supervise.h>
-#define USAGE "s6-svscan [ -S | -s ] [ -c maxservices ] [ -t timeout ] [ -d notif ] [ dir ]"
+#define USAGE "s6-svscan [ -S | -s ] [ -c maxservices ] [ -t timeout ] [ -d notif ] [ -X consoleholder ] [ dir ]"
#define dieusage() strerr_dieusage(100, USAGE)
#define FINISH_PROG S6_SVSCAN_CTLDIR "/finish"
#define CRASH_PROG S6_SVSCAN_CTLDIR "/crash"
#define SIGNAL_PROG S6_SVSCAN_CTLDIR "/SIG"
#define SIGNAL_PROG_LEN (sizeof(SIGNAL_PROG) - 1)
+#define SPECIAL_LOGGER_SERVICE "s6-svscan-log"
#define DIR_RETRY_TIMEOUT 3
#define CHECK_RETRY_TIMEOUT 4
@@ -52,6 +53,7 @@ static int wantreap = 1 ;
static int wantscan = 1 ;
static unsigned int wantkill = 0 ;
static int cont = 1 ;
+static unsigned int consoleholder = 0 ;
static void panicnosp (char const *) gccattr_noreturn ;
static void panicnosp (char const *errmsg)
@@ -298,6 +300,10 @@ static void trystart (unsigned int i, char const *name, int islog)
if (services[i].flaglog)
if (fd_move(!islog, services[i].p[!islog]) == -1)
strerr_diefu2sys(111, "set fds for ", name) ;
+ if (consoleholder
+ && !strcmp(name, SPECIAL_LOGGER_SERVICE)
+ && fd_move(2, consoleholder) < 0) /* autoclears coe */
+ strerr_diefu1sys(111, "restore console fd for service " SPECIAL_LOGGER_SERVICE) ;
xpathexec_run(S6_BINPREFIX "s6-supervise", cargv, (char const **)environ) ;
}
}
@@ -458,7 +464,7 @@ int main (int argc, char const *const *argv)
unsigned int t = 0 ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "Sst:c:d:", &l) ;
+ int opt = subgetopt_r(argc, argv, "Sst:c:d:X:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -471,6 +477,11 @@ int main (int argc, char const *const *argv)
if (notif < 3) strerr_dief1x(100, "notification fd must be 3 or more") ;
if (fcntl(notif, F_GETFD) < 0) strerr_dief1sys(100, "invalid notification fd") ;
break ;
+ case 'X' :
+ if (!uint0_scan(l.arg, &consoleholder)) dieusage() ;
+ if (consoleholder < 3) strerr_dief1x(100, "console holder fd must be 3 or more") ;
+ if (fcntl(consoleholder, F_GETFD) < 0) strerr_dief1sys(100, "invalid console holder fd") ;
+ break ;
default : dieusage() ;
}
}
@@ -487,6 +498,7 @@ int main (int argc, char const *const *argv)
*/
if (argc && (chdir(argv[0]) < 0)) strerr_diefu1sys(111, "chdir") ;
+ if (consoleholder && coe(consoleholder) < 0) strerr_diefu1sys(111, "coe console holder") ;
x[1].fd = s6_supervise_lock(S6_SVSCAN_CTLDIR) ;
x[0].fd = selfpipe_init() ;
if (x[0].fd < 0) strerr_diefu1sys(111, "selfpipe_init") ;
@@ -509,7 +521,6 @@ int main (int argc, char const *const *argv)
}
if (selfpipe_trapset(&set) < 0) strerr_diefu1sys(111, "trap signals") ;
}
-
if (notif)
{
fd_write(notif, "\n", 1) ;