commit 47d2b12795e1fa9ec55af648b661e58618aec834
parent 1c57f7df313bf9d3c8be1f7accfe2c6f732ec42f
Author: ccx <root@dorje.wpr.cz>
Date: Wed, 15 Sep 2021 17:50:33 +0200
Rewrote CLONE_NEWPID patch for s6 from scratch using clone3 syscall.
Diffstat:
2 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/install-all b/install-all
@@ -21,7 +21,8 @@ install_skalibs() {
install_s6() {
git checkout --force || exit $?
git clean -fx || exit $?
- patch -up 1 -i ../s6_clone_newpid.patch || exit $?
+ #patch -up 1 -i ../s6_clone_newpid.patch || exit $?
+ patch -up 1 -i ../s6_clone3_newpid.patch || exit $?
./configure --disable-shared --enable-static --enable-allstatic --enable-static-libc --enable-slashpackage="$slashpackage" || exit $?
make -j${jobs} CFLAGS=-DWANT_CLONE_NEWPID || exit $?
make install || exit $?
diff --git a/s6_clone3_newpid.patch b/s6_clone3_newpid.patch
@@ -0,0 +1,64 @@
+diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c
+index cc6779a..1ce20ec 100644
+--- a/src/supervision/s6-supervise.c
++++ b/src/supervision/s6-supervise.c
+@@ -12,6 +12,11 @@
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #include <sys/wait.h>
++#ifdef WANT_CLONE_NEWPID
++# include <syscall.h> /* For calling clone3 syscall (currently not in libc) */
++# include <linux/sched.h> /* Definition of struct clone_args */
++# include <sched.h> /* Definition of CLONE_* constants */
++#endif
+
+ #include <skalibs/allreadwrite.h>
+ #include <skalibs/bytestr.h>
+@@ -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) ;