s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 7a991b6adb985ca13a28350a10e0324239bb39a2
parent 4f804382997c41efa078e2e085bbc42aafdebb2b
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Wed, 28 Sep 2022 12:06:40 +0000

 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:
Msrc/supervision/s6-svscan.c | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git 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() ;