diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-09-08 08:03:58 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-09-08 08:03:58 +0000 |
commit | a646c96d5f7ec4b4e0bb538a41fc202c2cdb3309 (patch) | |
tree | a5260aa8fe9c4f1ee2772d318024b5cb208f9bf2 | |
parent | 1f2d5f95684e93f8523e369ef1fed7a75c444082 (diff) | |
download | skalibs-a646c96d5f7ec4b4e0bb538a41fc202c2cdb3309.tar.xz |
Make child_spawn_workaround public
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | package/deps.mak | 7 | ||||
-rw-r--r-- | src/include/skalibs/djbunix.h | 8 | ||||
-rw-r--r-- | src/libstddjb/child_spawn-internal.h | 16 | ||||
-rw-r--r-- | src/libstddjb/child_spawn.c | 4 | ||||
-rw-r--r-- | src/libstddjb/child_spawn0.c | 6 | ||||
-rw-r--r-- | src/libstddjb/child_spawn1_internal.c | 4 | ||||
-rw-r--r-- | src/libstddjb/child_spawn2.c | 4 | ||||
-rw-r--r-- | src/libstddjb/child_spawn3.c | 4 | ||||
-rw-r--r-- | src/libstddjb/child_spawn_workaround.c | 17 | ||||
-rw-r--r-- | src/libstddjb/slurpn.c | 2 |
10 files changed, 27 insertions, 45 deletions
diff --git a/package/deps.mak b/package/deps.mak index dbef6b6..84eeb85 100644 --- 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 index 1b08f77..1ac2d03 100644 --- 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 deleted file mode 100644 index b0f701c..0000000 --- a/src/libstddjb/child_spawn-internal.h +++ /dev/null @@ -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 index e5f5115..7c59fba 100644 --- 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 index cfd78f8..ea7a5b1 100644 --- 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 index 2fe0ee2..9e6eeff 100644 --- 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 index 44d748f..986fd15 100644 --- 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 index 81ffb0c..6eb7519 100644 --- 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 index 516ade5..b5fb4f0 100644 --- 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 index 317e300..d6a20da 100644 --- 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) { |