From 597dc96fec06714019afe95487cd1065239b8049 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 15 Jan 2020 14:15:42 +0000 Subject: Add console holder functionality to s6-svscan --- COPYING | 2 +- NEWS | 1 + doc/s6-svscan.html | 10 +++++++++- doc/upgrade.html | 3 +++ src/supervision/s6-svscan.c | 17 ++++++++++++++--- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/COPYING b/COPYING index f019bc7..b956149 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2011-2019 Laurent Bercot +Copyright (c) 2011-2020 Laurent Bercot Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/NEWS b/NEWS index 10e4176..cedcd29 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ In 2.9.1.0 - execline support is now optional. Some functionality is not available when execline support is disabled. - New '?' directive to s6-log, to spawn a processor with /bin/sh. + - New console holder functionality for easier s6-svscan-log support. In 2.9.0.1 diff --git a/doc/s6-svscan.html b/doc/s6-svscan.html index 665fd75..b826847 100644 --- a/doc/s6-svscan.html +++ b/doc/s6-svscan.html @@ -27,7 +27,7 @@ the root or a branch of a supervision tree.

Interface

-     s6-svscan [ -S | -s ] [ -d notif ] [ -c max ] [ -t rescan ] [ scandir ]
+     s6-svscan [ -S | -s ] [ -d notif ] [ -X consoleholder ] [ -c max ] [ -t rescan ] [ scandir ]
 
    @@ -73,6 +73,14 @@ even that the relevant s6-supervise processes ha been started. If you need to test for deep readiness, meaning that all the services in the supervision tree have been started and are ready, you cannot rely on this option. +
  • -X consoleholder : assume the output console is available +on descriptor consoleholder. If this option is given, and a s6-svscan-log +service exists, the s6-supervise process for that service +will be run with consoleholder as its standard error. This is mainly useful +for a setup done via s6-linux-init, +where all error messages go to the s6-svscan-log catch-all logger service by +default, except messages from this service itself, which fall back to consoleholder. +If you're not sure what to use this option for, or how, you don't need it.
  • -c max : maintain services for up to max service directories. Default is 500. Lower limit is 2. There is no upper limit, but:
      diff --git a/doc/upgrade.html b/doc/upgrade.html index d3ce8ef..e876665 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -28,6 +28,9 @@ disabled when execline support is disabled.
    • A new '?' directive has been added to s6-log, it declares a processor command line that is spawned with the /bin/sh interpreter.
    • +
    • A new -X option has been added to s6-linux-init +installations.

    in 2.9.0.1

    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 #include -#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) ; -- cgit v1.2.3