skalibs

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

commit ab2813a10a7fe6edbbef2acdfd22c0666171f566
parent 4cce87557feb6933c284d234c448bd8bde4facae
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sat,  9 Sep 2023 03:58:19 +0000

 Revamp cspawn, part 2

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Mpackage/deps.mak | 1-
Dsrc/libstddjb/cspawn_workaround.c | 55-------------------------------------------------------
2 files changed, 0 insertions(+), 56 deletions(-)

diff --git a/package/deps.mak b/package/deps.mak @@ -310,7 +310,6 @@ src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_ src/libstddjb/child_spawn3.o src/libstddjb/child_spawn3.lo: src/libstddjb/child_spawn3.c src/include/skalibs/cspawn.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/types.h src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalibs/djbunix.h src/libstddjb/cspawn.o src/libstddjb/cspawn.lo: src/libstddjb/cspawn.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/cspawn.h src/include/skalibs/djbunix.h src/include/skalibs/exec.h src/include/skalibs/selfpipe.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h -src/libstddjb/cspawn_workaround.o src/libstddjb/cspawn_workaround.lo: src/libstddjb/cspawn_workaround.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/sysdeps.h src/libstddjb/deepsleepuntil.o src/libstddjb/deepsleepuntil.lo: src/libstddjb/deepsleepuntil.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/devino_cmp.o src/libstddjb/devino_cmp.lo: src/libstddjb/devino_cmp.c src/include/skalibs/devino.h src/libstddjb/dir_close.o src/libstddjb/dir_close.lo: src/libstddjb/dir_close.c src/include/skalibs/direntry.h diff --git a/src/libstddjb/cspawn_workaround.c b/src/libstddjb/cspawn_workaround.c @@ -1,55 +0,0 @@ -/* ISC license. */ - -#include <skalibs/sysdeps.h> -#include <skalibs/djbunix.h> - -#if defined(SKALIBS_HASPOSIXSPAWN) && defined(SKALIBS_HASPOSIXSPAWNEARLYRETURN) - -#include <errno.h> -#include <signal.h> -#include <sys/wait.h> - -#include <skalibs/allreadwrite.h> - - /* when posix_spawn returns too early, you need this */ - -pid_t cspawn_workaround (pid_t pid, int const *p) -{ - siginfo_t si ; - int e ; - ssize_t r ; - char c ; - - fd_close(p[1]) ; - r = fd_read(p[0], &c, 1) ; - fd_close(p[0]) ; - if (r == -1) return 0 ; - if (r) return (errno = EILSEQ, 0) ; /* child wrote, wtf */ - - do e = waitid(P_PID, pid, &si, WEXITED | WNOHANG | WNOWAIT) ; - while (e == -1 && errno == EINTR) ; - if (e == -1) return pid ; /* we're in trouble, but don't leak a child */ - if (!si.si_pid) return pid ; /* child is running */ - if (si.si_code != CLD_EXITED || si.si_status != 127) return pid ; /* child died after execve(), let caller handle it */ - /* - child exited 127, so either execve() failed, which is what we want to catch, - or it raced like a mofo, execve()d and then exited 127 on its own, in which - case, tough luck, it never existed. - */ - wait_pid(pid, 0) ; - return (errno = 0, 0) ; -} - -#else - -pid_t cspawn_workaround (pid_t pid, int const *p) -{ - if (p) - { - fd_close(p[1]) ; - fd_close(p[0]) ; - } - return pid ; -} - -#endif