From 4cce87557feb6933c284d234c448bd8bde4facae Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 9 Sep 2023 03:55:38 +0000 Subject: cspawn revamp, part 1. Prepare for 2.14.0.0. Signed-off-by: Laurent Bercot --- src/include/skalibs/cspawn.h | 81 +++++++++++++++++++++++++++++++++++++++++++ src/include/skalibs/djbunix.h | 50 -------------------------- src/include/skalibs/stddjb.h | 1 + 3 files changed, 82 insertions(+), 50 deletions(-) create mode 100644 src/include/skalibs/cspawn.h (limited to 'src/include') diff --git a/src/include/skalibs/cspawn.h b/src/include/skalibs/cspawn.h new file mode 100644 index 0000000..f76fa62 --- /dev/null +++ b/src/include/skalibs/cspawn.h @@ -0,0 +1,81 @@ +/* ISC license. */ + +#ifndef SKALIBS_CSPAWN_H +#define SKALIBS_CSPAWN_H + +#include +#include + +#define CSPAWN_FLAGS_SELFPIPE_FINISH 0x0001U +#define CSPAWN_FLAGS_SIGBLOCKNONE 0x0002U + +#define CSPAWN_FA_CLOSE 0x0000U +#define CSPAWN_FA_COPY 0x0001U +#define CSPAWN_FA_MOVE 0x0002U +#define CSPAWN_FA_OPEN 0x0003U + +struct cspawn_fa_openinfo_s +{ + int fd ; + char const *file ; + int oflag ; + mode_t mode ; +} ; + +union cspawn_fileaction_u +{ + int fd ; + int fd2[2] ; + struct cspawn_fa_openinfo_s openinfo ; +} ; + +typedef struct cspawn_fileaction_s cspawn_fileaction, *cspawn_fileaction_ref ; +struct cspawn_fileaction_s +{ + uint32_t type ; + union cspawn_fileaction_u x ; +} ; + + + /* Generic interface for posix_spawn() with a fork()+execve() fallback */ + +extern pid_t cspawn (char const *, char const *const *, char const *const *, uint32_t, cspawn_fileaction const *, size_t) ; + + + /* Simple spawn functions with 0 or 1 communicating fds. */ + +extern pid_t child_spawn0 (char const *, char const *const *, char const *const *) ; +extern pid_t child_spawn1_pipe (char const *, char const *const *, char const *const *, int *, int) ; +extern pid_t child_spawn1_socket (char const *, char const *const *, char const *const *, int *) ; + + + /* + Spawn function with 2 communicating pipes. The int * points to 2 fds. + Input: fds[0] and fds[1] are the fds to move the pipes to in the child. + Output: fds[0] and fds[1] contain the pipes to the child. + */ + +extern pid_t child_spawn2 (char const *, char const *const *, char const *const *, int *) ; + + + /* + Same, with an additional pipe from the child to the parent. + The int * points to 3 fds. + The additional fd# is available to the child in the defined env variable. + */ + +#define SKALIBS_CHILD_SPAWN_FDS_ENVVAR "SKALIBS_CHILD_SPAWN_FDS" + +extern pid_t child_spawn3 (char const *, char const *const *, char const *const *, int *) ; + + + /* + Generalization of the previous functions. + * requests n (the last arg) communication fds between parent and child. Uses pipes. + * if n=1, equivalent to child_spawn1_pipe; child writes, parent reads. + * if n>=2, parent reads on even and writes on odd. + */ + +extern pid_t child_spawn (char const *, char const *const *, char const *const *, int *, size_t) ; + +#endif diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h index 1ac2d03..b95a5ab 100644 --- a/src/include/skalibs/djbunix.h +++ b/src/include/skalibs/djbunix.h @@ -83,13 +83,8 @@ extern int sagetcwd (stralloc *) ; extern int sareadlink (stralloc *, char const *) ; extern int sagethostname (stralloc *) ; -extern int slurp (stralloc *, int) ; -extern int openslurpclose (stralloc *, char const *) ; -/* - TODO: next ABI break: change to #define slurp(sa, fd) slurpn((fd), (sa), 0) #define openslurpclose(sa, fn) openslurpnclose((fn), (sa), 0) -*/ extern int slurpn (int, stralloc *, size_t) ; extern int openslurpnclose (char const *, stralloc *, size_t) ; @@ -169,49 +164,4 @@ 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 *) ; -extern pid_t child_spawn1_pipe (char const *, char const *const *, char const *const *, int *, int) ; -extern pid_t child_spawn1_socket (char const *, char const *const *, char const *const *, int *) ; - - - /* - Spawn function with 2 communicating pipes. The int * points to 2 fds. - Input: fds[0] and fds[1] are the fds to move the pipes to in the child. - Output: fds[0] and fds[1] contain the pipes to the child. - */ - -extern pid_t child_spawn2 (char const *, char const *const *, char const *const *, int *) ; - - - /* - Same, with an additional pipe from the child to the parent. - The int * points to 3 fds. - The additional fd# is available to the child in the defined env variable. - */ - -#define SKALIBS_CHILD_SPAWN_FDS_ENVVAR "SKALIBS_CHILD_SPAWN_FDS" - -extern pid_t child_spawn3 (char const *, char const *const *, char const *const *, int *) ; - - - /* - Generalization of the previous functions. - * uses posix_spawn() if available, else uses fork+exec - * requests n (the last arg) communication fds between parent and child. Uses pipes. - * if n=1, equivalent to child_spawn1_pipe; child writes, parent reads. - * if n>=2, parent reads on even and writes on odd. - */ - -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/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h index 3ba1a51..d241de8 100644 --- a/src/include/skalibs/stddjb.h +++ b/src/include/skalibs/stddjb.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3