diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2022-09-28 12:06:40 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2022-09-28 12:06:40 +0000 |
commit | 7a991b6adb985ca13a28350a10e0324239bb39a2 (patch) | |
tree | ec42b10ba1ff75ed42596b7bf50b6a5f71526d73 /src/supervision/s6-svscan.c | |
parent | 4f804382997c41efa078e2e085bbc42aafdebb2b (diff) | |
download | s6-7a991b6adb985ca13a28350a10e0324239bb39a2.tar.gz s6-7a991b6adb985ca13a28350a10e0324239bb39a2.tar.xz s6-7a991b6adb985ca13a28350a10e0324239bb39a2.zip |
s6-svscan QoL: close stdout on exit if catch-all logger is present
This should allow the catch-all logger to exit at the same time. Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/supervision/s6-svscan.c')
-rw-r--r-- | src/supervision/s6-svscan.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/supervision/s6-svscan.c b/src/supervision/s6-svscan.c index ae77ab4..0c0e665 100644 --- a/src/supervision/s6-svscan.c +++ b/src/supervision/s6-svscan.c @@ -108,11 +108,20 @@ static void killthem (void) static inline void closethem (void) { + int gotspecial = 0 ; unsigned int i = 0 ; - for (; i < n ; i++) if (services[i].flaglog) + for (; i < n ; i++) + if (services[i].flagspecial) gotspecial = 1 ; + else if (services[i].flaglog) + { + if (services[i].p[1] >= 0) close(services[i].p[1]) ; + if (services[i].p[0] >= 0) close(services[i].p[0]) ; + } + if (gotspecial) { - if (services[i].p[1] >= 0) close(services[i].p[1]) ; - if (services[i].p[0] >= 0) close(services[i].p[0]) ; + close(1) ; + if (open("/dev/null", O_WRONLY) < 0) + strerr_warnwu1sys("open /dev/null") ; } } @@ -574,6 +583,7 @@ int main (int argc, char const *const *argv) if (fcntl(consoleholder, F_GETFD) < 0) strerr_dief1sys(100, "invalid console holder fd") ; if (coe(consoleholder) < 0) strerr_diefu1sys(111, "coe console holder") ; } + if (!fd_sanitize()) strerr_diefu1x(100, "sanitize standard fds") ; if (argc && (chdir(argv[0]) < 0)) strerr_diefu1sys(111, "chdir") ; x[1].fd = control_init() ; |