diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c index cc6779a..a814f8e 100644 --- a/src/supervision/s6-supervise.c +++ b/src/supervision/s6-supervise.c @@ -12,6 +12,11 @@ #include #include #include +#ifdef WANT_CLONE_NEWPID +# include /* For calling clone3 syscall (currently not in libc) */ +# include /* Definition of struct clone_args */ +# include /* Definition of CLONE_* constants */ +#endif #include #include @@ -231,6 +236,38 @@ static void failcoe (int fd) errno = e ; } +#ifdef WANT_CLONE_NEWPID +pid_t newpid_fork(void) +{ + struct clone_args args = { + .flags = CLONE_NEWPID, + .exit_signal = SIGCHLD, + }; + + return syscall(__NR_clone3, &args, sizeof(struct clone_args)); +} + +pid_t conditional_newpid_fork(void) +{ + if (access("clone-newpid", F_OK) < 0) + { + if(errno == ENOENT) { + return fork(); + } + else + { + return -1; /* propagate the filesystem access error upwards */ + } + } + else + { + return newpid_fork(); + } +} +#else +#define conditional_newpid_fork fork +#endif /* defined(WANT_CLONE_NEWPID) */ + static void trystart (void) { int p[2] ; @@ -296,7 +333,7 @@ static void trystart (void) strerr_warnwu2sys("pipe", " (waiting 60 seconds)") ; goto errn ; } - pid = fork() ; + pid = conditional_newpid_fork() ; if (pid < 0) { settimeout(60) ;