summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-09 03:55:38 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-09 03:55:38 +0000
commit4cce87557feb6933c284d234c448bd8bde4facae (patch)
tree7417e8558b0770da2ae24df8abd755dbc913855f /src/include
parenta646c96d5f7ec4b4e0bb538a41fc202c2cdb3309 (diff)
downloadskalibs-4cce87557feb6933c284d234c448bd8bde4facae.tar.xz
cspawn revamp, part 1. Prepare for 2.14.0.0.
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/skalibs/cspawn.h81
-rw-r--r--src/include/skalibs/djbunix.h50
-rw-r--r--src/include/skalibs/stddjb.h1
3 files changed, 82 insertions, 50 deletions
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 <sys/types.h>
+#include <stdint.h>
+
+#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 <skalibs/cbuffer.h>
#include <skalibs/cdb.h>
#include <skalibs/cdbmake.h>
+#include <skalibs/cspawn.h>
#include <skalibs/devino.h>
#include <skalibs/direntry.h>
#include <skalibs/diuint32.h>