skalibs

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

commit a646c96d5f7ec4b4e0bb538a41fc202c2cdb3309
parent 1f2d5f95684e93f8523e369ef1fed7a75c444082
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri,  8 Sep 2023 08:03:58 +0000

 Make child_spawn_workaround public

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

Diffstat:
Mpackage/deps.mak | 7+++++--
Msrc/include/skalibs/djbunix.h | 8++++++++
Dsrc/libstddjb/child_spawn-internal.h | 16----------------
Msrc/libstddjb/child_spawn.c | 4----
Msrc/libstddjb/child_spawn0.c | 6+-----
Msrc/libstddjb/child_spawn1_internal.c | 4----
Msrc/libstddjb/child_spawn2.c | 4----
Msrc/libstddjb/child_spawn3.c | 4----
Msrc/libstddjb/child_spawn_workaround.c | 17++++++++++++-----
Msrc/libstddjb/slurpn.c | 2+-
10 files changed, 27 insertions(+), 45 deletions(-)

diff --git a/package/deps.mak b/package/deps.mak @@ -29,6 +29,7 @@ src/include/skalibs/genqdyn.h: src/include/skalibs/stralloc.h src/include/skalibs/genset.h: src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h: src/include/skalibs/functypes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/iopause.h: src/include/skalibs/tai.h +src/include/skalibs/ip46.h: src/include/skalibs/fmtscan.h src/include/skalibs/socket.h src/include/skalibs/kolbak.h: src/include/skalibs/unixmessage.h src/include/skalibs/lolstdio.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/strerr.h src/include/skalibs/netstring.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h @@ -50,6 +51,9 @@ src/include/skalibs/strerr2.h: src/include/skalibs/strerr.h src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint64.h src/include/skalibs/textclient.h: src/include/skalibs/allreadwrite.h src/include/skalibs/tai.h src/include/skalibs/textmessage.h src/include/skalibs/textmessage.h: src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h +src/include/skalibs/types.h: src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h +src/include/skalibs/uint16.h: src/include/skalibs/uint64.h +src/include/skalibs/uint32.h: src/include/skalibs/uint64.h src/include/skalibs/unix-timed.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-transactional.h: src/include/skalibs/direntry.h src/include/skalibs/stralloc.h src/include/skalibs/unixconnection.h: src/include/skalibs/unixmessage.h @@ -64,7 +68,6 @@ src/libstdcrypto/sha256-internal.h: src/include/skalibs/sha256.h src/libstdcrypto/sha512-internal.h: src/include/skalibs/sha512.h src/libstddjb/cdb-internal.h: src/include/skalibs/cdb.h src/include/skalibs/gccattributes.h src/libstddjb/cdbmake-internal.h: src/include/skalibs/cdbmake.h -src/libstddjb/child_spawn-internal.h: src/include/skalibs/sysdeps.h src/libstddjb/djbtime-internal.h: src/include/skalibs/uint64.h src/libstddjb/fmtscan-internal.h: src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libunixonacid/skaclient-internal.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h @@ -309,7 +312,7 @@ src/libstddjb/child_spawn1_pipe.o src/libstddjb/child_spawn1_pipe.lo: src/libstd src/libstddjb/child_spawn1_socket.o src/libstddjb/child_spawn1_socket.lo: src/libstddjb/child_spawn1_socket.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h src/include/skalibs/socket.h src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_spawn2.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/exec.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/libstddjb/child_spawn3.o src/libstddjb/child_spawn3.lo: src/libstddjb/child_spawn3.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/exec.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/include/skalibs/types.h -src/libstddjb/child_spawn_workaround.o src/libstddjb/child_spawn_workaround.lo: src/libstddjb/child_spawn_workaround.c src/include/skalibs/allreadwrite.h src/libstddjb/child_spawn-internal.h src/include/skalibs/djbunix.h src/include/skalibs/sysdeps.h +src/libstddjb/child_spawn_workaround.o src/libstddjb/child_spawn_workaround.lo: src/libstddjb/child_spawn_workaround.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/sysdeps.h src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalibs/djbunix.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 diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h @@ -169,6 +169,8 @@ extern int hiercopy_loose (char const *, char const *) ; extern int hiercopy_loose_tmp (char const *, char const *, stralloc *) ; extern int hiercopy_internal (char const *, char const *, stralloc *, unsigned int) ; + + /* Simple spawn functions with 0 or 1 communicating fds. */ extern pid_t child_spawn0 (char const *, char const *const *, char const *const *) ; @@ -206,4 +208,10 @@ extern pid_t child_spawn3 (char const *, char const *const *, char const *const extern pid_t child_spawn (char const *, char const *const *, char const *const *, int *, unsigned int) ; + + /* Work around buggy posix_spawn */ + +extern pid_t child_spawn_workaround (pid_t, int const *) ; /* closes the pipe if defined */ + + #endif diff --git a/src/libstddjb/child_spawn-internal.h b/src/libstddjb/child_spawn-internal.h @@ -1,16 +0,0 @@ -/* ISC license. */ - -#ifndef CHILD_SPAWN_INTERNAL_H -#define CHILD_SPAWN_INTERNAL_H - -#include <skalibs/sysdeps.h> - -#ifdef SKALIBS_HASPOSIXSPAWNEARLYRETURN - -#include <sys/types.h> - -extern pid_t child_spawn_workaround (pid_t, int const *) ; /* closes the pipe */ - -#endif - -#endif diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c @@ -20,10 +20,6 @@ #include <skalibs/config.h> #include <skalibs/env.h> -#ifdef SKALIBS_HASPOSIXSPAWNEARLYRETURN -# include "child_spawn-internal.h" -#endif - pid_t child_spawn (char const *prog, char const *const *argv, char const *const *envp, int *fds, unsigned int n) { pid_t pid ; diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c @@ -11,11 +11,7 @@ #include <spawn.h> #include <skalibs/config.h> - -#ifdef SKALIBS_HASPOSIXSPAWNEARLYRETURN -# include <skalibs/djbunix.h> -# include "child_spawn-internal.h" -#endif +#include <skalibs/djbunix.h> pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const *envp) { diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libstddjb/child_spawn1_internal.c @@ -14,10 +14,6 @@ #include <skalibs/config.h> -#ifdef SKALIBS_HASPOSIXSPAWNEARLYRETURN -# include "child_spawn-internal.h" -#endif - pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to) { pid_t pid ; diff --git a/src/libstddjb/child_spawn2.c b/src/libstddjb/child_spawn2.c @@ -17,10 +17,6 @@ #include <skalibs/config.h> -#ifdef SKALIBS_HASPOSIXSPAWNEARLYRETURN -# include "child_spawn-internal.h" -#endif - pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const *envp, int *fds) { pid_t pid ; diff --git a/src/libstddjb/child_spawn3.c b/src/libstddjb/child_spawn3.c @@ -19,10 +19,6 @@ #include <skalibs/config.h> #include <skalibs/env.h> -#ifdef SKALIBS_HASPOSIXSPAWNEARLYRETURN -# include "child_spawn-internal.h" -#endif - pid_t child_spawn3 (char const *prog, char const *const *argv, char const *const *envp, int *fds) { pid_t pid ; diff --git a/src/libstddjb/child_spawn_workaround.c b/src/libstddjb/child_spawn_workaround.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <skalibs/sysdeps.h> +#include <skalibs/djbunix.h> #if defined(SKALIBS_HASPOSIXSPAWN) && defined(SKALIBS_HASPOSIXSPAWNEARLYRETURN) @@ -9,8 +10,8 @@ #include <sys/wait.h> #include <skalibs/allreadwrite.h> -#include <skalibs/djbunix.h> -#include "child_spawn-internal.h" + + /* when posix_spawn returns too early, you need this */ pid_t child_spawn_workaround (pid_t pid, int const *p) { @@ -41,8 +42,14 @@ pid_t child_spawn_workaround (pid_t pid, int const *p) #else - /* avoid empty TUs */ - -extern int skalibs_child_spawn_workaround_dummy_ ; +pid_t child_spawn_workaround (pid_t pid, int const *p) +{ + if (p) + { + fd_close(p[1]) ; + fd_close(p[0]) ; + } + return pid ; +} #endif diff --git a/src/libstddjb/slurpn.c b/src/libstddjb/slurpn.c @@ -16,7 +16,7 @@ int slurpn (int fd, stralloc *sa, size_t max) ssize_t r ; size_t n = max && sa->len + N > max ? max - sa->len : N ; if (!n) return (errno = ENOBUFS, 0) ; - if (!stralloc_readyplus(sa, n)) break ; + if (!stralloc_readyplus(sa, n)) return 0 ; r = fd_read(fd, sa->s + sa->len, n) ; switch (r) {