about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/cspawn.h55
-rw-r--r--src/include/skalibs/env.h4
-rw-r--r--src/include/skalibs/stddjb.h2
-rw-r--r--src/libenvexec/child_spawn.c (renamed from src/libstddjb/child_spawn.c)0
-rw-r--r--src/libenvexec/child_spawn0.c (renamed from src/libstddjb/child_spawn0.c)0
-rw-r--r--src/libenvexec/child_spawn1_internal.c (renamed from src/libstddjb/child_spawn1_internal.c)0
-rw-r--r--src/libenvexec/child_spawn1_pipe.c (renamed from src/libstddjb/child_spawn1_pipe.c)0
-rw-r--r--src/libenvexec/child_spawn1_socket.c (renamed from src/libstddjb/child_spawn1_socket.c)0
-rw-r--r--src/libenvexec/child_spawn2.c (renamed from src/libstddjb/child_spawn2.c)0
-rw-r--r--src/libenvexec/child_spawn3.c (renamed from src/libstddjb/child_spawn3.c)0
-rw-r--r--src/libenvexec/cspawn-internal.h (renamed from src/libstddjb/cspawn-internal.h)0
-rw-r--r--src/libenvexec/cspawn.c (renamed from src/libstddjb/cspawn.c)0
-rw-r--r--src/libenvexec/env_merge.c24
-rw-r--r--src/libenvexec/env_mergen.c31
-rw-r--r--src/libenvexec/gcspawn.c (renamed from src/libstddjb/gcspawn.c)0
-rw-r--r--src/libenvexec/gmspawn_afn.c11
-rw-r--r--src/libenvexec/mspawn_af.c17
-rw-r--r--src/libenvexec/mspawn_afm.c9
-rw-r--r--src/libenvexec/mspawn_afn.c11
-rw-r--r--src/libenvexec/xmspawn_af.c13
-rw-r--r--src/libenvexec/xmspawn_afm.c13
-rw-r--r--src/libenvexec/xmspawn_afn.c13
22 files changed, 168 insertions, 35 deletions
diff --git a/src/include/skalibs/cspawn.h b/src/include/skalibs/cspawn.h
index 061fbfb..0d8dd50 100644
--- a/src/include/skalibs/cspawn.h
+++ b/src/include/skalibs/cspawn.h
@@ -90,4 +90,59 @@ extern pid_t child_spawn (char const *, char const *const *, char const *const *
 
 extern pid_t gcspawn (char const *, char const *const *, char const *const *, uint16_t, cspawn_fileaction const *, size_t) ;
 
+
+ /* mexec (see skalibs/exec.h), but with cspawn instead */
+
+extern int env_mspawn (char const *, char const *) ;
+
+extern pid_t mspawn_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+extern pid_t mspawn_afm (char const *, char const *const *, char const *const *, size_t, char const *, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+extern pid_t mspawn_af (char const *, char const *const *, char const *const *, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+
+#define mspawn_aen(file, argv, envp, modif, modiflen, modifn, flags, fa, n) mspawn_afn(file, argv, envp, env_len(envp), modif, modiflen, modifn, flags, fa, n)
+#define mspawn_aem(file, argv, envp, modif, modiflen, flags, fa, n) mspawn_afm(file, argv, envp, env_len(envp), modif, modiflen, flags, fa, n)
+#define mspawn_ae(file, argv, envp, flags, fa, n) mspawn_af(file, argv, (envp), env_len(envp), flags, fa, n)
+
+#define mspawn_an(file, argv, modif, modiflen, modifn, flags, fa, n) mspawn_aen(file, argv, (char const *const *)environ, modif, modiflen, modifn, flags, fa, n)
+#define mspawn_am(file, argv, modif, modiflen, flags, fa, n) mspawn_aem(file, argv, (char const *const *)environ, modif, modiflen, flaga, fa, n)
+#define mspawn_a(file, argv, flags, fa, n) mspawn_ae(file, (argv), (char const *const *)environ, flags, fa, n)
+
+#define mspawn_fn(argv, envp, envlen, modif, modiflen, modifn, flags, fa, n) mspawn_afn((argv)[0], (argv), envp, envlen, modif, modiflen, modifn, flags, fa, n)
+#define mspawn_fm(argv, envp, envlen, modif, modiflen, flags, fa, n) mspawn_afm((argv)[0], (argv), envp, envlen, modif, modiflen, flags, fa, n)
+#define mspawn_f(argv, envp, envlen, flags, fa, n) mspawn_af((argv)[0], (argv), envp, envlen, flags, fa, n)
+
+#define mspawn_en(argv, envp, modif, modiflen, modifn, flags, fa, n) mspawn_aen((argv)[0], (argv), envp, modif, modiflen, modifn, flags, fa, n)
+#define mspawn_em(argv, envp, modif, modiflen, flags, fa, n) mspawn_aem((argv)[0], (argv), envp, modif, modiflen, flags, fa, n)
+#define mspawn_e(argv, envp, flags, fa, n) mspawn_ae((argv)[0], (argv), envp, flags, fa, n)
+
+#define mspawn_n(argv, modif, modiflen, modifn, flags, fa, n) mspawn_an((argv)[0], (argv), modif, modiflen, modifn, flags, fa, n)
+#define mspawn_m(argv, modif, modiflen, flags, fa, n) mspawn_am((argv)[0], (argv), modif, modiflen, flags, fa, n)
+#define mspawn(argv, flags, fa, n) mspawn_a((argv)[0], (argv), flags, fa, n)
+
+extern pid_t xmspawn_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+extern pid_t xmspawn_afm (char const *, char const *const *, char const *const *, size_t, char const *, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+extern pid_t xmspawn_af (char const *, char const *const *, char const *const *, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+
+#define xmspawn_aen(file, argv, envp, modif, modiflen, modifn, flags, fa, n) xmspawn_afn(file, argv, envp, env_len(envp), modif, modiflen, modifn, flags, fa, n)
+#define xmspawn_aem(file, argv, envp, modif, modiflen, flags, fa, n) xmspawn_afm(file, argv, envp, env_len(envp), modif, modiflen, flags, fa, n)
+#define xmspawn_ae(file, argv, envp, flags, fa, n) xmspawn_af(file, argv, envp, env_len(envp), flags, fa, n)
+
+#define xmspawn_an(file, argv, modif, modiflen, modifn, flags, fa, n) xmspawn_aen(file, argv, (char const *const *)environ, modif, modiflen, modifn, flags, fa, n)
+#define xmspawn_am(file, argv, modif, modiflen, flags, fa, n) xmspawn_aem(file, argv, (char const *const *)environ, modif, modiflen, flags, fa, n)
+#define xmspawn_a(file, argv, flags, fa, n) xmspawn_ae(file, argv, (char const *const *)environ, flags, fa, n)
+
+#define xmspawn_fn(argv, envp, envlen, modif, modiflen, modifn, flags, fa, n) xmspawn_afn((argv)[0], (argv), envp, envlen, modif, modiflen, modifn, flags, fa, n)
+#define xmspawn_fm(argv, envp, envlen, modif, modiflen, flags, fa, n) xmspawn_afm((argv)[0], (argv), envp, envlen, modif, modiflen, flags, fa, n)
+#define xmspawn_f(argv, envp, envlen, flags, fa, n) xmspawn_af((argv)[0], (argv), envp, envlen, flags, fa, n)
+
+#define xmspawn_en(argv, envp, modif, modiflen, modifn, flags, fa, n) xmspawn_aen((argv)[0], (argv), envp, modif, modiflen, modifn, flags, fa, n)
+#define xmspawn_em(argv, envp, modif, modiflen, flags, fa, n) xmspawn_aem((argv)[0], (argv), envp, modif, modiflen, flags, fa, n)
+#define xmspawn_e(argv, envp, flags, fa, n) xmspawn_ae((argv)[0], (argv), envp, flags, fa, n)
+
+#define xmspawn_n(argv, modif, modiflen, modifn, flags, fa, n) xmspawn_an((argv)[0], (argv), modif, modiflen, modifn, flags, fa, n)
+#define xmspawn_m(argv, modif, modiflen, flags, fa, n) xmspawn_am((argv)[0], (argv), modif, modiflen, flags, fa, n)
+#define xmspawn(argv, flags, fa, n) xmspawn_a((argv)[0], (argv), flags, fa, n)
+
+extern pid_t gmspawn_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t, uint16_t, cspawn_fileaction const *, size_t) ;
+
 #endif
diff --git a/src/include/skalibs/env.h b/src/include/skalibs/env.h
index 5e17dfa..e5dfd1d 100644
--- a/src/include/skalibs/env.h
+++ b/src/include/skalibs/env.h
@@ -17,10 +17,10 @@ extern int env_addmodif (stralloc *, char const *, char const *) ;
 extern int env_make (char const **, size_t, char const *, size_t) ;
 extern int env_string (stralloc *, char const *const *, size_t) ;
 
-extern size_t env_mergen (char const **, size_t, char const *const *, size_t, char const *, size_t, size_t) ;
+extern size_t env_merg (char const **, size_t, char const *const *, char const *, size_t) ;
 extern size_t env_merge (char const **, size_t, char const *const *, size_t, char const *, size_t) ;
+#define env_mergen(v, vmax, envp, envlen, modifs, modiflen, modifn) env_merge(v, vmax, envp, envlen, modifs, modiflen)
 extern size_t env_mergn (char const **, size_t, char const *const *, char const *, size_t, size_t) ;
-extern size_t env_merg (char const **, size_t, char const *const *, char const *, size_t) ;
 
 #define SKALIBS_ENVDIR_VERBATIM 0x01
 #define SKALIBS_ENVDIR_NOCHOMP 0x02
diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h
index d241de8..ab5bcaf 100644
--- a/src/include/skalibs/stddjb.h
+++ b/src/include/skalibs/stddjb.h
@@ -20,7 +20,6 @@
 #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>
@@ -31,6 +30,7 @@
 #include <skalibs/envalloc.h>
 #include <skalibs/env.h>
 #include <skalibs/exec.h>
+#include <skalibs/cspawn.h>
 #include <skalibs/fmtscan.h>
 #include <skalibs/functypes.h>
 #include <skalibs/gccattributes.h>
diff --git a/src/libstddjb/child_spawn.c b/src/libenvexec/child_spawn.c
index 164f1b2..164f1b2 100644
--- a/src/libstddjb/child_spawn.c
+++ b/src/libenvexec/child_spawn.c
diff --git a/src/libstddjb/child_spawn0.c b/src/libenvexec/child_spawn0.c
index b1353b6..b1353b6 100644
--- a/src/libstddjb/child_spawn0.c
+++ b/src/libenvexec/child_spawn0.c
diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libenvexec/child_spawn1_internal.c
index e65b588..e65b588 100644
--- a/src/libstddjb/child_spawn1_internal.c
+++ b/src/libenvexec/child_spawn1_internal.c
diff --git a/src/libstddjb/child_spawn1_pipe.c b/src/libenvexec/child_spawn1_pipe.c
index a31e091..a31e091 100644
--- a/src/libstddjb/child_spawn1_pipe.c
+++ b/src/libenvexec/child_spawn1_pipe.c
diff --git a/src/libstddjb/child_spawn1_socket.c b/src/libenvexec/child_spawn1_socket.c
index 684842e..684842e 100644
--- a/src/libstddjb/child_spawn1_socket.c
+++ b/src/libenvexec/child_spawn1_socket.c
diff --git a/src/libstddjb/child_spawn2.c b/src/libenvexec/child_spawn2.c
index f287c0b..f287c0b 100644
--- a/src/libstddjb/child_spawn2.c
+++ b/src/libenvexec/child_spawn2.c
diff --git a/src/libstddjb/child_spawn3.c b/src/libenvexec/child_spawn3.c
index 75551d2..75551d2 100644
--- a/src/libstddjb/child_spawn3.c
+++ b/src/libenvexec/child_spawn3.c
diff --git a/src/libstddjb/cspawn-internal.h b/src/libenvexec/cspawn-internal.h
index 0e5efc7..0e5efc7 100644
--- a/src/libstddjb/cspawn-internal.h
+++ b/src/libenvexec/cspawn-internal.h
diff --git a/src/libstddjb/cspawn.c b/src/libenvexec/cspawn.c
index 683a0a3..683a0a3 100644
--- a/src/libstddjb/cspawn.c
+++ b/src/libenvexec/cspawn.c
diff --git a/src/libenvexec/env_merge.c b/src/libenvexec/env_merge.c
index ac3e17c..b6281ee 100644
--- a/src/libenvexec/env_merge.c
+++ b/src/libenvexec/env_merge.c
@@ -1,9 +1,31 @@
 /* ISC license. */
 
+#include <string.h>
+#include <errno.h>
+
 #include <skalibs/bytestr.h>
 #include <skalibs/env.h>
 
 size_t env_merge (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen)
 {
-  return env_mergen(v, vmax, envp, envlen, modifs, modiflen, byte_count(modifs, modiflen, '\0')) ;
+  size_t vlen = envlen ;
+  size_t i = 0 ;
+  if (envlen >= vmax) return 0 ;
+  for (; i < envlen ; i++) v[i] = envp[i] ;
+  for (i = 0 ; i < modiflen ; i += strlen(modifs + i) + 1)
+  {
+    size_t split = str_chr(modifs + i, '=') ;
+    size_t j = 0 ;
+    for (; j < vlen ; j++)
+      if (!strncmp(modifs + i, v[j], split) && (v[j][split] == '=')) break ;
+    if (j < vlen) v[j] = v[--vlen] ;
+    if (modifs[i + split])
+    {
+      if (vlen >= vmax) return 0 ;
+      v[vlen++] = modifs + i ;
+    }
+  }
+  if (vlen >= vmax) return 0 ;
+  v[vlen++] = 0 ;
+  return vlen ;
 }
diff --git a/src/libenvexec/env_mergen.c b/src/libenvexec/env_mergen.c
deleted file mode 100644
index 64a77cb..0000000
--- a/src/libenvexec/env_mergen.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* ISC license. */
-
-#include <string.h>
-#include <errno.h>
-
-#include <skalibs/bytestr.h>
-#include <skalibs/env.h>
-
-size_t env_mergen (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen, size_t n)
-{
-  size_t vlen = envlen ;
-  size_t i = 0 ;
-  if (envlen >= vmax) return 0 ;
-  for (; i < envlen ; i++) v[i] = envp[i] ;
-  for (i = 0 ; i < modiflen ; i += strlen(modifs + i) + 1)
-  {
-    size_t split = str_chr(modifs + i, '=') ;
-    size_t j = 0 ;
-    for (; j < vlen ; j++)
-      if (!strncmp(modifs + i, v[j], split) && (v[j][split] == '=')) break ;
-    if (j < vlen) v[j] = v[--vlen] ;
-    if (modifs[i + split])
-    {
-      if (vlen >= vmax) return 0 ;
-      v[vlen++] = modifs + i ;
-    }
-  }
-  if (vlen >= vmax) return 0 ;
-  v[vlen++] = 0 ;
-  return vlen ;
-}
diff --git a/src/libstddjb/gcspawn.c b/src/libenvexec/gcspawn.c
index 7e9e602..7e9e602 100644
--- a/src/libstddjb/gcspawn.c
+++ b/src/libenvexec/gcspawn.c
diff --git a/src/libenvexec/gmspawn_afn.c b/src/libenvexec/gmspawn_afn.c
new file mode 100644
index 0000000..dc49017
--- /dev/null
+++ b/src/libenvexec/gmspawn_afn.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/env.h>
+#include <skalibs/cspawn.h>
+
+pid_t gmspawn_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  char const *newenvp[envlen + modifn + 1] ;
+  env_merge(newenvp, envlen + modifn + 1, envp, envlen, modif, modiflen) ;
+  return gcspawn(file, argv, newenvp, flags, fa, n) ;
+}
diff --git a/src/libenvexec/mspawn_af.c b/src/libenvexec/mspawn_af.c
new file mode 100644
index 0000000..97dc877
--- /dev/null
+++ b/src/libenvexec/mspawn_af.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <skalibs/stralloc.h>
+#include <skalibs/env.h>
+#include <skalibs/cspawn.h>
+
+static stralloc modifsa = STRALLOC_ZERO ;
+
+int env_mspawn (char const *key, char const *value)
+{
+  return env_addmodif(&modifsa, key, value) ;
+}
+
+pid_t mspawn_af (char const *file, char const *const *argv, char const *const *envp, size_t envlen, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  return mspawn_afm(file, argv, envp, envlen, modifsa.s, modifsa.len, flags, fa, n) ;
+}
diff --git a/src/libenvexec/mspawn_afm.c b/src/libenvexec/mspawn_afm.c
new file mode 100644
index 0000000..4b3711e
--- /dev/null
+++ b/src/libenvexec/mspawn_afm.c
@@ -0,0 +1,9 @@
+/* ISC license. */
+
+#include <skalibs/bytestr.h>
+#include <skalibs/cspawn.h>
+
+pid_t mspawn_afm (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  return mspawn_afn(file, argv, envp, envlen, modif, modiflen, byte_count(modif, modiflen, '\0'), flags, fa, n) ;
+}
diff --git a/src/libenvexec/mspawn_afn.c b/src/libenvexec/mspawn_afn.c
new file mode 100644
index 0000000..fe36fca
--- /dev/null
+++ b/src/libenvexec/mspawn_afn.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/env.h>
+#include <skalibs/cspawn.h>
+
+pid_t mspawn_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  char const *newenvp[envlen + modifn + 1] ;
+  env_merge(newenvp, envlen + modifn + 1, envp, envlen, modif, modiflen) ;
+  return cspawn(file, argv, newenvp, flags, fa, n) ;
+}
diff --git a/src/libenvexec/xmspawn_af.c b/src/libenvexec/xmspawn_af.c
new file mode 100644
index 0000000..3e79114
--- /dev/null
+++ b/src/libenvexec/xmspawn_af.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <skalibs/strerr.h>
+#include <skalibs/cspawn.h>
+
+pid_t xmspawn_af (char const *file, char const *const *argv, char const *const *envp, size_t envlen, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  pid_t pid = mspawn_af(file, argv, envp, envlen, flags, fa, n) ;
+  if (!pid) strerr_diefu2sys(errno == ENOENT ? 127 : 126, "spawn ", file) ;
+  return pid ;
+}
diff --git a/src/libenvexec/xmspawn_afm.c b/src/libenvexec/xmspawn_afm.c
new file mode 100644
index 0000000..5335fb1
--- /dev/null
+++ b/src/libenvexec/xmspawn_afm.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <skalibs/strerr.h>
+#include <skalibs/cspawn.h>
+
+pid_t xmspawn_afm (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  pid_t pid = mspawn_afm(file, argv, envp, envlen, modif, modiflen, flags, fa, n) ;
+  if (!pid) strerr_diefu2sys(errno == ENOENT ? 127 : 126, "spawn ", file) ;
+  return pid ;
+}
diff --git a/src/libenvexec/xmspawn_afn.c b/src/libenvexec/xmspawn_afn.c
new file mode 100644
index 0000000..5af7c2e
--- /dev/null
+++ b/src/libenvexec/xmspawn_afn.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <skalibs/strerr.h>
+#include <skalibs/cspawn.h>
+
+pid_t xmspawn_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn, uint16_t flags, cspawn_fileaction const *fa, size_t n)
+{
+  pid_t pid = mspawn_afn(file, argv, envp, envlen, modif, modiflen, modifn, flags, fa, n) ;
+  if (!pid) strerr_diefu2sys(errno == ENOENT ? 127 : 126, "spawn ", file) ;
+  return pid ;
+}