From 18e43565574b700befc832ed4d25d25e40951f68 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 24 Nov 2020 21:45:56 +0000 Subject: Complete revamp of the pathexec functions - pathexec_run is now called exec_ae a for provided file name (default: argv[0]) e for provided envp (default: environ) - pathexec is now called mexec. m for merge environment. Option letters are: a for provided file name (default: argv[0]) e for provided envp (default: environ) f for provided envp *and* length of the envp m for provided modif string plus its length (the length is always needed because the modifs are null-terminated) n for provided modif string, length *and* number of modifs - functions have a foo0 version for _exit(0) when argv[0] is null - functions have a xfoo version to die if the exec fails - and a xfoo0 - Compatibility #defines and #includes are there until the next major bump --- NEWS | 1 + doc/upgrade.html | 1 + package/deps.mak | 69 +++++++++------- src/include/skalibs/djbunix.h | 22 +----- src/include/skalibs/env.h | 8 +- src/include/skalibs/exec.h | 160 ++++++++++++++++++++++++++++++++++++++ src/include/skalibs/stddjb.h | 1 + src/libenvexec/env_addmodif.c | 19 +++++ src/libenvexec/env_dump.c | 54 +++++++++++++ src/libenvexec/env_get.c | 9 +++ src/libenvexec/env_get2.c | 17 ++++ src/libenvexec/env_len.c | 10 +++ src/libenvexec/env_make.c | 16 ++++ src/libenvexec/env_merg.c | 8 ++ src/libenvexec/env_merge.c | 9 +++ src/libenvexec/env_mergen.c | 26 +++++++ src/libenvexec/env_mergn.c | 8 ++ src/libenvexec/env_string.c | 19 +++++ src/libenvexec/envalloc_0.c | 10 +++ src/libenvexec/envalloc_make.c | 18 +++++ src/libenvexec/envalloc_merge.c | 15 ++++ src/libenvexec/envalloc_uniq.c | 32 ++++++++ src/libenvexec/envdir.c | 85 ++++++++++++++++++++ src/libenvexec/exec0_ae.c | 11 +++ src/libenvexec/exec_ae.c | 14 ++++ src/libenvexec/mexec0_af.c | 11 +++ src/libenvexec/mexec0_afm.c | 11 +++ src/libenvexec/mexec0_afn.c | 11 +++ src/libenvexec/mexec_af.c | 17 ++++ src/libenvexec/mexec_afm.c | 9 +++ src/libenvexec/mexec_afn.c | 11 +++ src/libenvexec/xexec0_ae.c | 11 +++ src/libenvexec/xexec_ae.c | 12 +++ src/libenvexec/xexecvep.c | 13 ++++ src/libenvexec/xexecvep_loose.c | 13 ++++ src/libenvexec/xmexec0_af.c | 12 +++ src/libenvexec/xmexec0_afm.c | 12 +++ src/libenvexec/xmexec0_afn.c | 12 +++ src/libenvexec/xmexec_af.c | 12 +++ src/libenvexec/xmexec_afm.c | 12 +++ src/libenvexec/xmexec_afn.c | 12 +++ src/libstddjb/env_addmodif.c | 19 ----- src/libstddjb/env_dump.c | 54 ------------- src/libstddjb/env_get.c | 9 --- src/libstddjb/env_get2.c | 17 ---- src/libstddjb/env_len.c | 10 --- src/libstddjb/env_make.c | 16 ---- src/libstddjb/env_merge.c | 26 ------- src/libstddjb/env_string.c | 19 ----- src/libstddjb/envalloc_0.c | 10 --- src/libstddjb/envalloc_make.c | 18 ----- src/libstddjb/envalloc_merge.c | 15 ---- src/libstddjb/envalloc_uniq.c | 32 -------- src/libstddjb/envdir.c | 85 -------------------- src/libstddjb/pathexec.c | 12 --- src/libstddjb/pathexec0.c | 10 --- src/libstddjb/pathexec0_run.c | 10 --- src/libstddjb/pathexec_fromenv.c | 17 ---- src/libstddjb/pathexec_r.c | 8 -- src/libstddjb/pathexec_r_name.c | 13 ---- src/libstddjb/pathexec_run.c | 13 ---- src/libstddjb/xexecvep.c | 12 --- src/libstddjb/xpathexec.c | 12 --- src/libstddjb/xpathexec0.c | 12 --- src/libstddjb/xpathexec0_run.c | 12 --- src/libstddjb/xpathexec_fromenv.c | 12 --- src/libstddjb/xpathexec_r.c | 12 --- src/libstddjb/xpathexec_r_name.c | 12 --- src/libstddjb/xpathexec_run.c | 12 --- 69 files changed, 784 insertions(+), 558 deletions(-) create mode 100644 src/include/skalibs/exec.h create mode 100644 src/libenvexec/env_addmodif.c create mode 100644 src/libenvexec/env_dump.c create mode 100644 src/libenvexec/env_get.c create mode 100644 src/libenvexec/env_get2.c create mode 100644 src/libenvexec/env_len.c create mode 100644 src/libenvexec/env_make.c create mode 100644 src/libenvexec/env_merg.c create mode 100644 src/libenvexec/env_merge.c create mode 100644 src/libenvexec/env_mergen.c create mode 100644 src/libenvexec/env_mergn.c create mode 100644 src/libenvexec/env_string.c create mode 100644 src/libenvexec/envalloc_0.c create mode 100644 src/libenvexec/envalloc_make.c create mode 100644 src/libenvexec/envalloc_merge.c create mode 100644 src/libenvexec/envalloc_uniq.c create mode 100644 src/libenvexec/envdir.c create mode 100644 src/libenvexec/exec0_ae.c create mode 100644 src/libenvexec/exec_ae.c create mode 100644 src/libenvexec/mexec0_af.c create mode 100644 src/libenvexec/mexec0_afm.c create mode 100644 src/libenvexec/mexec0_afn.c create mode 100644 src/libenvexec/mexec_af.c create mode 100644 src/libenvexec/mexec_afm.c create mode 100644 src/libenvexec/mexec_afn.c create mode 100644 src/libenvexec/xexec0_ae.c create mode 100644 src/libenvexec/xexec_ae.c create mode 100644 src/libenvexec/xexecvep.c create mode 100644 src/libenvexec/xexecvep_loose.c create mode 100644 src/libenvexec/xmexec0_af.c create mode 100644 src/libenvexec/xmexec0_afm.c create mode 100644 src/libenvexec/xmexec0_afn.c create mode 100644 src/libenvexec/xmexec_af.c create mode 100644 src/libenvexec/xmexec_afm.c create mode 100644 src/libenvexec/xmexec_afn.c delete mode 100644 src/libstddjb/env_addmodif.c delete mode 100644 src/libstddjb/env_dump.c delete mode 100644 src/libstddjb/env_get.c delete mode 100644 src/libstddjb/env_get2.c delete mode 100644 src/libstddjb/env_len.c delete mode 100644 src/libstddjb/env_make.c delete mode 100644 src/libstddjb/env_merge.c delete mode 100644 src/libstddjb/env_string.c delete mode 100644 src/libstddjb/envalloc_0.c delete mode 100644 src/libstddjb/envalloc_make.c delete mode 100644 src/libstddjb/envalloc_merge.c delete mode 100644 src/libstddjb/envalloc_uniq.c delete mode 100644 src/libstddjb/envdir.c delete mode 100644 src/libstddjb/pathexec.c delete mode 100644 src/libstddjb/pathexec0.c delete mode 100644 src/libstddjb/pathexec0_run.c delete mode 100644 src/libstddjb/pathexec_fromenv.c delete mode 100644 src/libstddjb/pathexec_r.c delete mode 100644 src/libstddjb/pathexec_r_name.c delete mode 100644 src/libstddjb/pathexec_run.c delete mode 100644 src/libstddjb/xexecvep.c delete mode 100644 src/libstddjb/xpathexec.c delete mode 100644 src/libstddjb/xpathexec0.c delete mode 100644 src/libstddjb/xpathexec0_run.c delete mode 100644 src/libstddjb/xpathexec_fromenv.c delete mode 100644 src/libstddjb/xpathexec_r.c delete mode 100644 src/libstddjb/xpathexec_r_name.c delete mode 100644 src/libstddjb/xpathexec_run.c diff --git a/NEWS b/NEWS index 8823eeb..deb04ba 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ In 2.9.4.0 unconditionally deleting the socket. - ipc_bind_reuse() rewritten to use ipc_bind_reuse_lock(), so it does the right thing instead of clobbering sockets. + - Complete revamping of the pathexec functions, see exec.h In 2.9.3.0 diff --git a/doc/upgrade.html b/doc/upgrade.html index 56b00c6..da2185c 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -24,6 +24,7 @@
  • New ipc_bind_reuse_lock() function, which takes a lock before deleting a Unix domain socket. The ipc_bind_reuse() function now uses it, so it won't unconditionally clobber sockets in the filesystem anymore.
  • +
  • Complete revamping of the pathexec functions, see exec.h.
  • in 2.9.3.0

    diff --git a/package/deps.mak b/package/deps.mak index 17be060..a0150fe 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -19,11 +19,12 @@ src/include/skalibs/cdb.h: src/include/skalibs/gccattributes.h src/include/skalibs/cdb_make.h: src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/datastruct.h: src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/avltreen.h src/include/skalibs/bigkv.h src/include/skalibs/genqdyn.h src/include/skalibs/genset.h src/include/skalibs/gensetdyn.h src/include/skalibs/djbtime.h: src/include/skalibs/tai.h src/include/skalibs/uint64.h -src/include/skalibs/djbunix.h: src/include/skalibs/envalloc.h src/include/skalibs/gccattributes.h src/include/skalibs/posixplz.h src/include/skalibs/stralloc.h +src/include/skalibs/djbunix.h: src/include/skalibs/exec.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/env.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/envalloc.h: src/include/skalibs/genalloc.h src/include/skalibs/environ.h: src/include/skalibs/posixplz.h src/include/skalibs/error.h: src/include/skalibs/gccattributes.h +src/include/skalibs/exec.h: src/include/skalibs/env.h src/include/skalibs/environ.h src/include/skalibs/gccattributes.h src/include/skalibs/fmtscan.h: src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h: src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/genqdyn.h: src/include/skalibs/stralloc.h @@ -32,6 +33,7 @@ src/include/skalibs/gensetdyn.h: src/include/skalibs/functypes.h src/include/ska src/include/skalibs/getpeereid.h: src/include/skalibs/posixplz.h src/include/skalibs/iobuffer.h: src/include/skalibs/buffer.h src/include/skalibs/djbunix.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/strerr2.h src/include/skalibs/netstring.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h @@ -47,12 +49,15 @@ src/include/skalibs/skalibs.h: src/include/skalibs/biguint.h src/include/skalibs src/include/skalibs/skamisc.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/socket.h: src/include/skalibs/djbunix.h src/include/skalibs/gccattributes.h src/include/skalibs/tai.h src/include/skalibs/webipc.h src/include/skalibs/stdcrypto.h: src/include/skalibs/md5.h src/include/skalibs/rc4.h src/include/skalibs/sha1.h src/include/skalibs/sha256.h src/include/skalibs/sha512.h -src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iobuffer.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/netstring.h src/include/skalibs/nsig.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/strerr.h src/include/skalibs/strerr2.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/webipc.h +src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/exec.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iobuffer.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/netstring.h src/include/skalibs/nsig.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/strerr.h src/include/skalibs/strerr2.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/webipc.h src/include/skalibs/strerr.h: src/include/skalibs/gccattributes.h 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/stralloc.h src/include/skalibs/uint64.h src/include/skalibs/unixconnection.h: src/include/skalibs/unixmessage.h @@ -144,6 +149,40 @@ src/libdatastruct/gensetdyn_iter_withcancel.o src/libdatastruct/gensetdyn_iter_w src/libdatastruct/gensetdyn_new.o src/libdatastruct/gensetdyn_new.lo: src/libdatastruct/gensetdyn_new.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_ready.o src/libdatastruct/gensetdyn_ready.lo: src/libdatastruct/gensetdyn_ready.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h src/libdatastruct/gensetdyn_zero.o src/libdatastruct/gensetdyn_zero.lo: src/libdatastruct/gensetdyn_zero.c src/include/skalibs/gensetdyn.h +src/libenvexec/env_addmodif.o src/libenvexec/env_addmodif.lo: src/libenvexec/env_addmodif.c src/include/skalibs/env.h src/include/skalibs/stralloc.h +src/libenvexec/env_dump.o src/libenvexec/env_dump.lo: src/libenvexec/env_dump.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/nonposix.h src/include/skalibs/unix-transactional.h +src/libenvexec/env_get.o src/libenvexec/env_get.lo: src/libenvexec/env_get.c src/include/skalibs/posixplz.h +src/libenvexec/env_get2.o src/libenvexec/env_get2.lo: src/libenvexec/env_get2.c src/include/skalibs/bytestr.h src/include/skalibs/env.h +src/libenvexec/env_len.o src/libenvexec/env_len.lo: src/libenvexec/env_len.c src/include/skalibs/env.h +src/libenvexec/env_make.o src/libenvexec/env_make.lo: src/libenvexec/env_make.c src/include/skalibs/env.h +src/libenvexec/env_merg.o src/libenvexec/env_merg.lo: src/libenvexec/env_merg.c src/include/skalibs/env.h +src/libenvexec/env_merge.o src/libenvexec/env_merge.lo: src/libenvexec/env_merge.c src/include/skalibs/bytestr.h src/include/skalibs/env.h +src/libenvexec/env_mergen.o src/libenvexec/env_mergen.lo: src/libenvexec/env_mergen.c src/include/skalibs/bytestr.h src/include/skalibs/env.h +src/libenvexec/env_mergn.o src/libenvexec/env_mergn.lo: src/libenvexec/env_mergn.c src/include/skalibs/env.h +src/libenvexec/env_string.o src/libenvexec/env_string.lo: src/libenvexec/env_string.c src/include/skalibs/env.h src/include/skalibs/stralloc.h +src/libenvexec/envalloc_0.o src/libenvexec/envalloc_0.lo: src/libenvexec/envalloc_0.c src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h +src/libenvexec/envalloc_make.o src/libenvexec/envalloc_make.lo: src/libenvexec/envalloc_make.c src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h +src/libenvexec/envalloc_merge.o src/libenvexec/envalloc_merge.lo: src/libenvexec/envalloc_merge.c src/include/skalibs/bytestr.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h +src/libenvexec/envalloc_uniq.o src/libenvexec/envalloc_uniq.lo: src/libenvexec/envalloc_uniq.c src/include/skalibs/bytestr.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h +src/libenvexec/envdir.o src/libenvexec/envdir.lo: src/libenvexec/envdir.c src/include/skalibs/bytestr.h src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/stralloc.h +src/libenvexec/exec0_ae.o src/libenvexec/exec0_ae.lo: src/libenvexec/exec0_ae.c src/include/skalibs/exec.h +src/libenvexec/exec_ae.o src/libenvexec/exec_ae.lo: src/libenvexec/exec_ae.c src/include/skalibs/config.h src/include/skalibs/exec.h src/include/skalibs/posixplz.h +src/libenvexec/mexec0_af.o src/libenvexec/mexec0_af.lo: src/libenvexec/mexec0_af.c src/include/skalibs/exec.h +src/libenvexec/mexec0_afm.o src/libenvexec/mexec0_afm.lo: src/libenvexec/mexec0_afm.c src/include/skalibs/exec.h +src/libenvexec/mexec0_afn.o src/libenvexec/mexec0_afn.lo: src/libenvexec/mexec0_afn.c src/include/skalibs/exec.h +src/libenvexec/mexec_af.o src/libenvexec/mexec_af.lo: src/libenvexec/mexec_af.c src/include/skalibs/env.h src/include/skalibs/exec.h src/include/skalibs/stralloc.h +src/libenvexec/mexec_afm.o src/libenvexec/mexec_afm.lo: src/libenvexec/mexec_afm.c src/include/skalibs/bytestr.h src/include/skalibs/exec.h +src/libenvexec/mexec_afn.o src/libenvexec/mexec_afn.lo: src/libenvexec/mexec_afn.c src/include/skalibs/env.h src/include/skalibs/exec.h +src/libenvexec/xexec0_ae.o src/libenvexec/xexec0_ae.lo: src/libenvexec/xexec0_ae.c src/include/skalibs/exec.h +src/libenvexec/xexec_ae.o src/libenvexec/xexec_ae.lo: src/libenvexec/xexec_ae.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h +src/libenvexec/xexecvep.o src/libenvexec/xexecvep.lo: src/libenvexec/xexecvep.c src/include/skalibs/exec.h src/include/skalibs/posixplz.h src/include/skalibs/strerr2.h +src/libenvexec/xexecvep_loose.o src/libenvexec/xexecvep_loose.lo: src/libenvexec/xexecvep_loose.c src/include/skalibs/exec.h src/include/skalibs/posixplz.h src/include/skalibs/strerr2.h +src/libenvexec/xmexec0_af.o src/libenvexec/xmexec0_af.lo: src/libenvexec/xmexec0_af.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h +src/libenvexec/xmexec0_afm.o src/libenvexec/xmexec0_afm.lo: src/libenvexec/xmexec0_afm.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h +src/libenvexec/xmexec0_afn.o src/libenvexec/xmexec0_afn.lo: src/libenvexec/xmexec0_afn.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h +src/libenvexec/xmexec_af.o src/libenvexec/xmexec_af.lo: src/libenvexec/xmexec_af.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h +src/libenvexec/xmexec_afm.o src/libenvexec/xmexec_afm.lo: src/libenvexec/xmexec_afm.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h +src/libenvexec/xmexec_afn.o src/libenvexec/xmexec_afn.lo: src/libenvexec/xmexec_afn.c src/include/skalibs/exec.h src/include/skalibs/strerr2.h src/libposixplz/doublefork.o src/libposixplz/doublefork.lo: src/libposixplz/doublefork.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/include/skalibs/uint64.h src/libposixplz/execvep.o src/libposixplz/execvep.lo: src/libposixplz/execvep.c src/libposixplz/posixplz-internal.h src/include/skalibs/posixplz.h src/libposixplz/execvep_internal.o src/libposixplz/execvep_internal.lo: src/libposixplz/execvep_internal.c src/include/skalibs/bytestr.h src/include/skalibs/posixplz.h @@ -303,19 +342,6 @@ src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalib src/libstddjb/deepsleepuntil.o src/libstddjb/deepsleepuntil.lo: src/libstddjb/deepsleepuntil.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/dir_close.o src/libstddjb/dir_close.lo: src/libstddjb/dir_close.c src/include/skalibs/direntry.h src/libstddjb/dir_fd.o src/libstddjb/dir_fd.lo: src/libstddjb/dir_fd.c src/include/skalibs/direntry.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h -src/libstddjb/env_addmodif.o src/libstddjb/env_addmodif.lo: src/libstddjb/env_addmodif.c src/include/skalibs/env.h src/include/skalibs/stralloc.h -src/libstddjb/env_dump.o src/libstddjb/env_dump.lo: src/libstddjb/env_dump.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/nonposix.h src/include/skalibs/unix-transactional.h -src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c src/include/skalibs/posixplz.h -src/libstddjb/env_get2.o src/libstddjb/env_get2.lo: src/libstddjb/env_get2.c src/include/skalibs/bytestr.h src/include/skalibs/env.h -src/libstddjb/env_len.o src/libstddjb/env_len.lo: src/libstddjb/env_len.c src/include/skalibs/env.h -src/libstddjb/env_make.o src/libstddjb/env_make.lo: src/libstddjb/env_make.c src/include/skalibs/env.h -src/libstddjb/env_merge.o src/libstddjb/env_merge.lo: src/libstddjb/env_merge.c src/include/skalibs/bytestr.h src/include/skalibs/env.h -src/libstddjb/env_string.o src/libstddjb/env_string.lo: src/libstddjb/env_string.c src/include/skalibs/env.h src/include/skalibs/stralloc.h -src/libstddjb/envalloc_0.o src/libstddjb/envalloc_0.lo: src/libstddjb/envalloc_0.c src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h -src/libstddjb/envalloc_make.o src/libstddjb/envalloc_make.lo: src/libstddjb/envalloc_make.c src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h -src/libstddjb/envalloc_merge.o src/libstddjb/envalloc_merge.lo: src/libstddjb/envalloc_merge.c src/include/skalibs/bytestr.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h -src/libstddjb/envalloc_uniq.o src/libstddjb/envalloc_uniq.lo: src/libstddjb/envalloc_uniq.c src/include/skalibs/bytestr.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h -src/libstddjb/envdir.o src/libstddjb/envdir.lo: src/libstddjb/envdir.c src/include/skalibs/bytestr.h src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/stralloc.h src/libstddjb/error_isalready.o src/libstddjb/error_isalready.lo: src/libstddjb/error_isalready.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/error.h src/libstddjb/error_temp.o src/libstddjb/error_temp.lo: src/libstddjb/error_temp.c src/include/skalibs/error.h src/libstddjb/fd_cat.o src/libstddjb/fd_cat.lo: src/libstddjb/fd_cat.c src/include/skalibs/djbunix.h src/include/skalibs/iobuffer.h @@ -474,13 +500,6 @@ src/libstddjb/openwritevnclose.o src/libstddjb/openwritevnclose.lo: src/libstddj src/libstddjb/openwritevnclose_suffix.o src/libstddjb/openwritevnclose_suffix.lo: src/libstddjb/openwritevnclose_suffix.c src/include/skalibs/djbunix.h src/libstddjb/openwritevnclose_unsafe.o src/libstddjb/openwritevnclose_unsafe.lo: src/libstddjb/openwritevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/libstddjb/path_canonicalize.o src/libstddjb/path_canonicalize.lo: src/libstddjb/path_canonicalize.c src/include/skalibs/djbunix.h -src/libstddjb/pathexec.o src/libstddjb/pathexec.lo: src/libstddjb/pathexec.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/posixplz.h -src/libstddjb/pathexec0.o src/libstddjb/pathexec0.lo: src/libstddjb/pathexec0.c src/include/skalibs/djbunix.h -src/libstddjb/pathexec0_run.o src/libstddjb/pathexec0_run.lo: src/libstddjb/pathexec0_run.c src/include/skalibs/djbunix.h -src/libstddjb/pathexec_fromenv.o src/libstddjb/pathexec_fromenv.lo: src/libstddjb/pathexec_fromenv.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/stralloc.h -src/libstddjb/pathexec_r.o src/libstddjb/pathexec_r.lo: src/libstddjb/pathexec_r.c src/include/skalibs/djbunix.h -src/libstddjb/pathexec_r_name.o src/libstddjb/pathexec_r_name.lo: src/libstddjb/pathexec_r_name.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/env.h -src/libstddjb/pathexec_run.o src/libstddjb/pathexec_run.lo: src/libstddjb/pathexec_run.c src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/libstddjb/pipe_internal.o src/libstddjb/pipe_internal.lo: src/libstddjb/pipe_internal.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/prog.o src/libstddjb/prog.lo: src/libstddjb/prog.c src/include/skalibs/strerr2.h src/libstddjb/rm_rf.o src/libstddjb/rm_rf.lo: src/libstddjb/rm_rf.c src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h @@ -734,12 +753,6 @@ src/libstddjb/waitpid_nointr.o src/libstddjb/waitpid_nointr.lo: src/libstddjb/wa src/libstddjb/writenclose_unsafe.o src/libstddjb/writenclose_unsafe.lo: src/libstddjb/writenclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/libstddjb/writevnclose_unsafe.o src/libstddjb/writevnclose_unsafe.lo: src/libstddjb/writevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h src/libstddjb/xexecvep.o src/libstddjb/xexecvep.lo: src/libstddjb/xexecvep.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/include/skalibs/strerr2.h -src/libstddjb/xpathexec.o src/libstddjb/xpathexec.lo: src/libstddjb/xpathexec.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h -src/libstddjb/xpathexec0.o src/libstddjb/xpathexec0.lo: src/libstddjb/xpathexec0.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h -src/libstddjb/xpathexec0_run.o src/libstddjb/xpathexec0_run.lo: src/libstddjb/xpathexec0_run.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h -src/libstddjb/xpathexec_fromenv.o src/libstddjb/xpathexec_fromenv.lo: src/libstddjb/xpathexec_fromenv.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h -src/libstddjb/xpathexec_r.o src/libstddjb/xpathexec_r.lo: src/libstddjb/xpathexec_r.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h -src/libstddjb/xpathexec_r_name.o src/libstddjb/xpathexec_r_name.lo: src/libstddjb/xpathexec_r_name.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec_run.o src/libstddjb/xpathexec_run.lo: src/libstddjb/xpathexec_run.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libunixonacid/access_at.o src/libunixonacid/access_at.lo: src/libunixonacid/access_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h src/libunixonacid/ancil_recv_fd.o src/libunixonacid/ancil_recv_fd.lo: src/libunixonacid/ancil_recv_fd.c src/include/skalibs/allreadwrite.h src/include/skalibs/ancil.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/sysdeps.h diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h index 03cc1af..885a623 100644 --- a/src/include/skalibs/djbunix.h +++ b/src/include/skalibs/djbunix.h @@ -6,10 +6,10 @@ #include #include #include + #include #include -#include -#include +#include /* compat */ #define DJBUNIX_FLAG_NB 0x01U #define DJBUNIX_FLAG_COE 0x02U @@ -64,24 +64,6 @@ extern int socketpair_internal (int, int, int, unsigned int, int *) ; extern size_t path_canonicalize (char *, char const *, int) ; -extern int pathexec_env (char const *, char const *) ; -extern void pathexec_r (char const *const *, char const *const *, size_t, char const *, size_t) ; -extern void pathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ; -extern void pathexec_fromenv (char const *const *, char const *const *, size_t) ; -extern void pathexec_run (char const *, char const *const *, char const *const *) ; -extern void pathexec0_run (char const *const *, char const *const *) ; -extern void pathexec (char const *const *) ; -extern void pathexec0 (char const *const *) ; - -extern void xpathexec_r (char const *const *, char const *const *, size_t, char const *, size_t) gccattr_noreturn ; -extern void xpathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t) gccattr_noreturn ; -extern void xpathexec_fromenv (char const *const *, char const *const *, size_t) gccattr_noreturn ; -extern void xexecvep (char const *, char const *const *, char const *const *, char const *) gccattr_noreturn ; -extern void xpathexec_run (char const *, char const *const *, char const *const *) gccattr_noreturn ; -extern void xpathexec0_run (char const *const *, char const *const *) gccattr_noreturn ; -extern void xpathexec (char const *const *) gccattr_noreturn ; -extern void xpathexec0 (char const *const *) gccattr_noreturn ; - extern pid_t wait_nointr (int *) ; extern pid_t waitpid_nointr (pid_t, int *, int) ; #define wait_pid(pid, wstat) waitpid_nointr(pid, (wstat), 0) diff --git a/src/include/skalibs/env.h b/src/include/skalibs/env.h index bc8177b..73398c2 100644 --- a/src/include/skalibs/env.h +++ b/src/include/skalibs/env.h @@ -4,6 +4,7 @@ #define SKALIBS_ENV_H #include + #include #include @@ -11,11 +12,16 @@ extern size_t env_len (char const *const *) gccattr_pure ; extern char const *env_get (char const *) gccattr_deprecated ; extern char const *env_get2 (char const *const *, char const *) gccattr_pure ; extern char const *ucspi_get (char const *) gccattr_pure ; + extern int env_addmodif (stralloc *, char const *, char const *) ; extern int env_make (char const **, size_t, char const *, size_t) ; -extern size_t env_merge (char const **, size_t, char const *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_merge (char const **, size_t, char const *const *, size_t, char const *, size_t) ; +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 extern int envdir_internal (char const *, stralloc *, unsigned int, char) ; diff --git a/src/include/skalibs/exec.h b/src/include/skalibs/exec.h new file mode 100644 index 0000000..46b4c8a --- /dev/null +++ b/src/include/skalibs/exec.h @@ -0,0 +1,160 @@ +/* ISC license. */ + +#ifndef SKALIBS_EXEC_H +#define SKALIBS_EXEC_H + +#include + +#include +#include +#include + + + /* Without environment modifications */ + +extern void xexecvep (char const *, char const *const *, char const *const *, char const *) gccattr_noreturn ; +extern void xexecvep_loose (char const *, char const *const *, char const *const *, char const *) gccattr_noreturn ; + +extern void exec_ae (char const *, char const *const *, char const *const *) ; +#define exec_a(file, argv) exec_ae(file, (argv), (char const *const *)environ) +#define exec_e(argv, envp) exec_ae((argv)[0], (argv), envp) +#define exec(argv) exec_a((argv)[0], (argv)) + +extern void xexec_ae (char const *, char const *const *, char const *const *) gccattr_noreturn ; +#define xexec_a(file, argv) xexec_ae(file, (argv), (char const *const *)environ) +#define xexec_e(argv, envp) xexec_ae((argv)[0], (argv), envp) +#define xexec(argv) xexec_a((argv)[0], (argv)) + +extern void exec0_ae (char const *, char const *const *, char const *const *) ; +#define exec0_a(file, argv) exec0_ae(file, (argv), (char const *const *)environ) +#define exec0_e(argv, envp) exec0_ae((argv)[0], (argv), envp) +#define exec0(argv) exec0_a((argv)[0], (argv)) + +extern void xexec0_ae (char const *, char const *const *, char const *const *) gccattr_noreturn ; +#define xexec0_a(file, argv) xexec0_ae(file, (argv), (char const *const *)environ) +#define xexec0_e(argv, envp) xexec0_ae((argv)[0], (argv), envp) +#define xexec0(argv) xexec0_a((argv)[0], (argv)) + + + /* With environment modifications : env_merge and exec */ + +extern int env_mexec (char const *, char const *) ; + +extern void mexec_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t) ; +extern void mexec_afm (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ; +extern void mexec_af (char const *, char const *const *, char const *const *, size_t) ; + +#define mexec_aen(file, argv, envp, modif, modiflen, modifn) mexec_afn(file, argv, envp, env_len(envp), modif, modiflen, modifn) +#define mexec_aem(file, argv, envp, modif, modiflen) mexec_afm(file, argv, envp, env_len(envp), modif, modiflen) +#define mexec_ae(file, argv, envp) mexec_af(file, argv, envp, env_len(envp)) + +#define mexec_an(file, argv, modif, modiflen, modifn) mexec_aen(file, argv, (char const *const *)environ, modif, modiflen, modifn) +#define mexec_am(file, argv, modif, modiflen) mexec_aem(file, argv, (char const *const *)environ, modif, modiflen) +#define mexec_a(file, argv) mexec_ae(file, argv, (char const *const *)environ) + +#define mexec_fn(argv, envp, envlen, modif, modiflen, modifn) mexec_afn((argv)[0], (argv), envp, envlen, modif, modiflen, modifn) +#define mexec_fm(argv, envp, envlen, modif, modiflen) mexec_afm((argv)[0], (argv), envp, envlen, modif, modiflen) +#define mexec_f(argv, envp, envlen) mexec_af((argv)[0], (argv), envp, envlen) + +#define mexec_en(argv, envp, modif, modiflen, modifn) mexec_aen((argv)[0], (argv), envp, modif, modiflen, modifn) +#define mexec_em(argv, envp, modif, modiflen) mexec_aem((argv)[0], (argv), envp, modif, modiflen) +#define mexec_e(argv, envp) mexec_a((argv)[0], (argv), envp) + +#define mexec_n(argv, modif, modiflen, modifn) mexec_an((argv)[0], (argv), modif, modiflen, modifn) +#define mexec_m(argv, modif, modiflen) mexec_am((argv)[0], (argv), modif, modiflen) +#define mexec(argv) mexec_a((argv)[0], (argv)) + +extern void mexec0_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t) ; +extern void mexec0_afm (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ; +extern void mexec0_af (char const *, char const *const *, char const *const *, size_t) ; + +#define mexec0_aen(file, argv, envp, modif, modiflen, modifn) mexec0_afn(file, argv, envp, env_len(envp), modif, modiflen, modifn) +#define mexec0_aem(file, argv, envp, modif, modiflen) mexec0_afm(file, argv, envp, env_len(envp), modif, modiflen) +#define mexec0_ae(file, argv, envp) mexec0_af(file, argv, envp, env_len(envp)) + +#define mexec0_an(file, argv, modif, modiflen, modifn) mexec0_aen(file, argv, (char const *const *)environ, modif, modiflen, modifn) +#define mexec0_am(file, argv, modif, modiflen) mexec0_aem(file, argv, (char const *const *)environ, modif, modiflen) +#define mexec0_a(file, argv) mexec0_ae(file, argv, (char const *const *)environ) + +#define mexec0_fn(argv, envp, envlen, modif, modiflen, modifn) mexec0_afn((argv)[0], (argv), envp, envlen, modif, modiflen, modifn) +#define mexec0_fm(argv, envp, envlen, modif, modiflen) mexec0_afm((argv)[0], (argv), envp, envlen, modif, modiflen) +#define mexec0_f(argv, envp, envlen) mexec0_af((argv)[0], (argv), envp, envlen) + +#define mexec0_en(argv, envp, modif, modiflen, modifn) mexec0_aen((argv)[0], (argv), envp, modif, modiflen, modifn) +#define mexec0_em(argv, envp, modif, modiflen) mexec0_aem((argv)[0], (argv), envp, modif, modiflen) +#define mexec0_e(argv, envp) mexec0_a((argv)[0], (argv), envp) + +#define mexec0_n(argv, modif, modiflen, modifn) mexec0_an((argv)[0], (argv), modif, modiflen, modifn) +#define mexec0_m(argv, modif, modiflen) mexec0_am((argv)[0], (argv), modif, modiflen) +#define mexec0(argv) mexec0_a((argv)[0], (argv)) + +extern void xmexec_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t) gccattr_noreturn ; +extern void xmexec_afm (char const *, char const *const *, char const *const *, size_t, char const *, size_t) gccattr_noreturn ; +extern void xmexec_af (char const *, char const *const *, char const *const *, size_t) gccattr_noreturn ; + +#define xmexec_aen(file, argv, envp, modif, modiflen, modifn) xmexec_afn(file, argv, envp, env_len(envp), modif, modiflen, modifn) +#define xmexec_aem(file, argv, envp, modif, modiflen) xmexec_afm(file, argv, envp, env_len(envp), modif, modiflen) +#define xmexec_ae(file, argv, envp) xmexec_af(file, argv, envp, env_len(envp)) + +#define xmexec_an(file, argv, modif, modiflen, modifn) xmexec_aen(file, argv, (char const *const *)environ, modif, modiflen, modifn) +#define xmexec_am(file, argv, modif, modiflen) xmexec_aem(file, argv, (char const *const *)environ, modif, modiflen) +#define xmexec_a(file, argv) xmexec_ae(file, argv, (char const *const *)environ) + +#define xmexec_fn(argv, envp, envlen, modif, modiflen, modifn) xmexec_afn((argv)[0], (argv), envp, envlen, modif, modiflen, modifn) +#define xmexec_fm(argv, envp, envlen, modif, modiflen) xmexec_afm((argv)[0], (argv), envp, envlen, modif, modiflen) +#define xmexec_f(argv, envp, envlen) xmexec_af((argv)[0], (argv), envp, envlen) + +#define xmexec_en(argv, envp, modif, modiflen, modifn) xmexec_aen((argv)[0], (argv), envp, modif, modiflen, modifn) +#define xmexec_em(argv, envp, modif, modiflen) xmexec_aem((argv)[0], (argv), envp, modif, modiflen) +#define xmexec_e(argv, envp) xmexec_a((argv)[0], (argv), envp) + +#define xmexec_n(argv, modif, modiflen, modifn) xmexec_an((argv)[0], (argv), modif, modiflen, modifn) +#define xmexec_m(argv, modif, modiflen) xmexec_am((argv)[0], (argv), modif, modiflen) +#define xmexec(argv) xmexec_a((argv)[0], (argv)) + +extern void xmexec0_afn (char const *, char const *const *, char const *const *, size_t, char const *, size_t, size_t) ; +extern void xmexec0_afm (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ; +extern void xmexec0_af (char const *, char const *const *, char const *const *, size_t) ; + +#define xmexec0_aen(file, argv, envp, modif, modiflen, modifn) xmexec0_afn(file, argv, envp, env_len(envp), modif, modiflen, modifn) +#define xmexec0_aem(file, argv, envp, modif, modiflen) xmexec0_afm(file, argv, envp, env_len(envp), modif, modiflen) +#define xmexec0_ae(file, argv, envp) xmexec0_af(file, argv, envp, env_len(envp)) + +#define xmexec0_an(file, argv, modif, modiflen, modifn) xmexec0_aen(file, argv, (char const *const *)environ, modif, modiflen, modifn) +#define xmexec0_am(file, argv, modif, modiflen) xmexec0_aem(file, argv, (char const *const *)environ, modif, modiflen) +#define xmexec0_a(file, argv) xmexec0_ae(file, argv, (char const *const *)environ) + +#define xmexec0_fn(argv, envp, envlen, modif, modiflen, modifn) xmexec0_afn((argv)[0], (argv), envp, envlen, modif, modiflen, modifn) +#define xmexec0_fm(argv, envp, envlen, modif, modiflen) xmexec0_afm((argv)[0], (argv), envp, envlen, modif, modiflen) +#define xmexec0_f(argv, envp, envlen) xmexec0_af((argv)[0], (argv), envp, envlen) + +#define xmexec0_en(argv, envp, modif, modiflen, modifn) xmexec0_aen((argv)[0], (argv), envp, modif, modiflen, modifn) +#define xmexec0_em(argv, envp, modif, modiflen) xmexec0_aem((argv)[0], (argv), envp, modif, modiflen) +#define xmexec0_e(argv, envp) xmexec0_a((argv)[0], (argv), envp) + +#define xmexec0_n(argv, modif, modiflen, modifn) xmexec0_an((argv)[0], (argv), modif, modiflen, modifn) +#define xmexec0_m(argv, modif, modiflen) xmexec0_am((argv)[0], (argv), modif, modiflen) +#define xmexec0(argv) xmexec0_a((argv)[0], (argv)) + + + /* Compatibility */ + +#define pathexec_run(file, argv, envp) exec_ae(file, argv, envp) +#define pathexec0_run(file, argv, envp) exec0_ae(file, argv, envp) +#define xpathexec_run(file, argv, envp) xexec_ae(file, argv, envp) +#define xpathexec0_run(file, argv, envp) xexec0_ae(file, argv, envp) + +#define pathexec_env(key, value) env_mexec(key, value) +#define pathexec_fromenv(argv, envp, envlen) mexec_f(argv, envp, envlen) +#define pathexec(argv) mexec(argv) +#define pathexec0(argv) mexec0(argv) +#define xpathexec_fromenv(argv, envp, envlen) xmexec_f(argv, envp, envlen) +#define xpathexec(argv) xmexec(argv) +#define xpathexec0(argv) xmexec0(argv) + +#define pathexec_r_name(file, argv, envp, envlen, modif, modiflen) mexec_afm(file, argv, envp, envlen, modif, modiflen) +#define pathexec_r(argv, envp, envlen, modif, modiflen) mexec_fm(argv, envp, envlen, modif, modiflen) +#define xpathexec_r_name(file, argv, envp, envlen, modif, modiflen) xmexec_afm(file, argv, envp, envlen, modif, modiflen) +#define xpathexec_r(argv, envp, envlen, modif, modiflen) xmexec_fm(argv, envp, envlen, modif, modiflen) + +#endif diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h index 232b5f3..071c913 100644 --- a/src/include/skalibs/stddjb.h +++ b/src/include/skalibs/stddjb.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libenvexec/env_addmodif.c b/src/libenvexec/env_addmodif.c new file mode 100644 index 0000000..ddd1be3 --- /dev/null +++ b/src/libenvexec/env_addmodif.c @@ -0,0 +1,19 @@ +/* ISC license. */ + +#include +#include +#include + +int env_addmodif (stralloc *sa, char const *s, char const *t) +{ + size_t oldlen = sa->len ; + if (!s) return 1 ; + if (!stralloc_cats(sa, s)) return 0 ; + if ((t && (!stralloc_catb(sa, "=", 1) || !stralloc_cats(sa, t))) + || !stralloc_0(sa)) + { + sa->len = oldlen ; + return 0 ; + } + return 1 ; +} diff --git a/src/libenvexec/env_dump.c b/src/libenvexec/env_dump.c new file mode 100644 index 0000000..10f5913 --- /dev/null +++ b/src/libenvexec/env_dump.c @@ -0,0 +1,54 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + /* XXX: breaks layering, but really openat() should be supported everywhere */ +#include + +#define SUFFIX ":envdump:XXXXXX" + +int env_dump (char const *dir, mode_t mode, char const *const *envp) +{ + int fd ; + size_t dirlen = strlen(dir) ; + char tmpdir[dirlen + sizeof(SUFFIX)] ; + memcpy(tmpdir, dir, dirlen) ; + memcpy(tmpdir + dirlen, SUFFIX, sizeof(SUFFIX)) ; + if (!mkdtemp(tmpdir)) return 0 ; + fd = open_read(tmpdir) ; + if (fd == -1) goto err ; + for (; *envp ; envp++) + { + size_t len = str_chr(*envp, '=') ; + size_t vallen = strlen(*envp + len + 1) ; + char fn[len + 1] ; + memcpy(fn, *envp, len) ; + fn[len] = 0 ; + len = openwritenclose_at(fd, fn, *envp + len + 1, vallen) ; + if (len < vallen) goto cerr ; + } + fd_close(fd) ; + if (chmod(tmpdir, mode) == -1) goto err ; + if (rename(tmpdir, dir) == -1) goto err ; + return 1 ; + + cerr: + fd_close(fd) ; + err: + { + int e = errno ; + rm_rf(tmpdir) ; + errno = e ; + } + return 0 ; +} diff --git a/src/libenvexec/env_get.c b/src/libenvexec/env_get.c new file mode 100644 index 0000000..d809461 --- /dev/null +++ b/src/libenvexec/env_get.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include +#include + +char const *env_get (char const *s) +{ + return getenv(s) ; +} diff --git a/src/libenvexec/env_get2.c b/src/libenvexec/env_get2.c new file mode 100644 index 0000000..5909ea6 --- /dev/null +++ b/src/libenvexec/env_get2.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include +#include +#include + +char const *env_get2 (char const *const *envp, char const *s) +{ + size_t len, i ; + if (!s) return 0 ; + len = strlen(s) ; + for (i = 0 ; envp[i] ; ++i) + if (str_start(envp[i], s) + && (envp[i][len] == '=')) + return envp[i] + len + 1 ; + return 0 ; +} diff --git a/src/libenvexec/env_len.c b/src/libenvexec/env_len.c new file mode 100644 index 0000000..eef30c4 --- /dev/null +++ b/src/libenvexec/env_len.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include + +size_t env_len (char const *const *e) +{ + size_t i = 0 ; + while (*e++) i++ ; + return i ; +} diff --git a/src/libenvexec/env_make.c b/src/libenvexec/env_make.c new file mode 100644 index 0000000..60148f8 --- /dev/null +++ b/src/libenvexec/env_make.c @@ -0,0 +1,16 @@ +/* ISC license. */ + +#include +#include +#include + +int env_make (char const **v, size_t argc, char const *s, size_t len) +{ + while (argc--) + { + size_t n = strlen(s) + 1 ; + if (n > len) return (errno = EINVAL, 0) ; + *v++ = s ; s += n ; len -= n ; + } + return 1 ; +} diff --git a/src/libenvexec/env_merg.c b/src/libenvexec/env_merg.c new file mode 100644 index 0000000..3c403ae --- /dev/null +++ b/src/libenvexec/env_merg.c @@ -0,0 +1,8 @@ +/* ISC license. */ + +#include + +size_t env_merg (char const **v, size_t vmax, char const *const *envp, char const *modifs, size_t modiflen) +{ + return env_merge(v, vmax, envp, env_len(envp), modifs, modiflen) ; +} diff --git a/src/libenvexec/env_merge.c b/src/libenvexec/env_merge.c new file mode 100644 index 0000000..ac3e17c --- /dev/null +++ b/src/libenvexec/env_merge.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include +#include + +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')) ; +} diff --git a/src/libenvexec/env_mergen.c b/src/libenvexec/env_mergen.c new file mode 100644 index 0000000..acc7c39 --- /dev/null +++ b/src/libenvexec/env_mergen.c @@ -0,0 +1,26 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +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 + n + 1 > vmax) return (errno = ENAMETOOLONG, 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]) v[vlen++] = modifs + i ; + } + v[vlen++] = 0 ; + return vlen ; +} diff --git a/src/libenvexec/env_mergn.c b/src/libenvexec/env_mergn.c new file mode 100644 index 0000000..a8a93c1 --- /dev/null +++ b/src/libenvexec/env_mergn.c @@ -0,0 +1,8 @@ +/* ISC license. */ + +#include + +size_t env_mergn (char const **v, size_t vmax, char const *const *envp, char const *modifs, size_t modiflen, size_t modifn) +{ + return env_mergen(v, vmax, envp, env_len(envp), modifs, modiflen, modifn) ; +} diff --git a/src/libenvexec/env_string.c b/src/libenvexec/env_string.c new file mode 100644 index 0000000..e30f095 --- /dev/null +++ b/src/libenvexec/env_string.c @@ -0,0 +1,19 @@ +/* ISC license. */ + +#include +#include + +int env_string (stralloc *sa, char const *const *envp, size_t envlen) +{ + size_t salen = sa->len ; + size_t i = 0 ; + for (; i < envlen ; i++) + { + if (!stralloc_cats(sa, envp[i]) || !stralloc_0(sa)) + { + sa->len = salen ; + return 0 ; + } + } + return 1 ; +} diff --git a/src/libenvexec/envalloc_0.c b/src/libenvexec/envalloc_0.c new file mode 100644 index 0000000..114f69e --- /dev/null +++ b/src/libenvexec/envalloc_0.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include +#include + +int envalloc_0 (genalloc *v) +{ + char const *z = 0 ; + return genalloc_append(char const *, v, &z) ; +} diff --git a/src/libenvexec/envalloc_make.c b/src/libenvexec/envalloc_make.c new file mode 100644 index 0000000..f8c459a --- /dev/null +++ b/src/libenvexec/envalloc_make.c @@ -0,0 +1,18 @@ +/* ISC license. */ + +#include +#include +#include + +int envalloc_make (genalloc *v, size_t argc, char const *s, size_t len) +{ + int wasnull = !v->s ; + if (!genalloc_readyplus(char const *, v, argc+1)) return 0 ; + if (!env_make(genalloc_s(char const *, v) + genalloc_len(char const *, v), argc, s, len)) + { + if (wasnull) genalloc_free(char const *, v) ; + return 0 ; + } + genalloc_setlen(char const *, v, genalloc_len(char const *, v) + argc) ; + return 1 ; +} diff --git a/src/libenvexec/envalloc_merge.c b/src/libenvexec/envalloc_merge.c new file mode 100644 index 0000000..84716e4 --- /dev/null +++ b/src/libenvexec/envalloc_merge.c @@ -0,0 +1,15 @@ +/* ISC license. */ + +#include +#include +#include +#include + +int envalloc_merge (genalloc *v, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) +{ + size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; + if (!genalloc_readyplus(char const *, v, n)) return 0 ; + n = env_mergen(genalloc_s(char const *, v) + genalloc_len(char const *, v), n, envp, envlen, modifs, modiflen, n) ; + genalloc_setlen(char const *, v, genalloc_len(char const *, v) + n) ; + return 1 ; +} diff --git a/src/libenvexec/envalloc_uniq.c b/src/libenvexec/envalloc_uniq.c new file mode 100644 index 0000000..cf60b44 --- /dev/null +++ b/src/libenvexec/envalloc_uniq.c @@ -0,0 +1,32 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +int envalloc_uniq (genalloc *v, char delim) +{ + unsigned int m = 0 ; + size_t i = 0 ; + for (; i < genalloc_len(char const *, v) ; i++) + { + size_t j = i+1 ; + char const *s = genalloc_s(char const *, v)[i] ; + size_t n = str_chr(s, delim) ; + if (delim && !s[n]) return (errno = EINVAL, -1) ; + for (; j < genalloc_len(char const *, v) ; j++) + { + char const **p = genalloc_s(char const *, v) ; + if (!strncmp(s, p[j], n)) + { + size_t len = genalloc_len(char const *, v) - 1 ; + genalloc_setlen(char const *, v, len) ; + p[j] = p[len] ; + m++ ; + } + } + } + return m ; +} diff --git a/src/libenvexec/envdir.c b/src/libenvexec/envdir.c new file mode 100644 index 0000000..6992654 --- /dev/null +++ b/src/libenvexec/envdir.c @@ -0,0 +1,85 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXVARSIZE 4095 + +int envdir_internal (char const *path, stralloc *modifs, unsigned int options, char nullis) +{ + char buf[MAXVARSIZE + 1] ; + unsigned int n = 0 ; + size_t pathlen = strlen(path) ; + size_t modifbase = modifs->len ; + int wasnull = !modifs->s ; + DIR *dir ; + if (!nullis) return (errno = EINVAL, -1) ; + dir = opendir(path) ; + if (!dir) return -1 ; + for (;;) + { + direntry *d ; + size_t len ; + ssize_t r ; + errno = 0 ; + d = readdir(dir) ; + if (!d) break ; + if (d->d_name[0] == '.') continue ; + len = strlen(d->d_name) ; + if (str_chr(d->d_name, '=') < len) continue ; + { + char tmp[pathlen + len + 2] ; + memcpy(tmp, path, pathlen) ; + tmp[pathlen] = '/' ; + memcpy(tmp + pathlen + 1, d->d_name, len + 1) ; + r = openreadnclose(tmp, buf, MAXVARSIZE) ; + } + if (r < 0) + { + if (errno == ENOENT) errno = EIDRM ; + goto err ; + } + else if (r > 0) + { + if (options & SKALIBS_ENVDIR_VERBATIM) + { + if (!(options & SKALIBS_ENVDIR_NOCHOMP) && (buf[r-1] == '\n')) r-- ; + } + else + { + r = byte_chr(buf, r, '\n') ; + if (!(options & SKALIBS_ENVDIR_NOCHOMP)) + { + while (r--) if ((buf[r] != ' ') && (buf[r] != '\t') && (buf[r] != '\r')) break ; + r++ ; + } + } + { + size_t i = 0 ; + for (; i < (size_t)r ; i++) if (!buf[i]) buf[i] = nullis ; + } + buf[r++] = 0 ; + if (!env_addmodif(modifs, d->d_name, buf)) goto err ; + } + else if (!env_addmodif(modifs, d->d_name, 0)) goto err ; + n++ ; + } + if (errno) goto err ; + dir_close(dir) ; + return n ; + + err: + { + int e = errno ; + dir_close(dir) ; + if (wasnull) stralloc_free(modifs) ; else modifs->len = modifbase ; + errno = e ; + return -1 ; + } +} diff --git a/src/libenvexec/exec0_ae.c b/src/libenvexec/exec0_ae.c new file mode 100644 index 0000000..14aac8b --- /dev/null +++ b/src/libenvexec/exec0_ae.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include + +#include + +void exec0_ae (char const *file, char const *const *argv, char const *const *envp) +{ + if (!argv[0]) _exit(0) ; + exec_ae(file, argv, envp) ; +} diff --git a/src/libenvexec/exec_ae.c b/src/libenvexec/exec_ae.c new file mode 100644 index 0000000..3c28722 --- /dev/null +++ b/src/libenvexec/exec_ae.c @@ -0,0 +1,14 @@ +/* ISC license. */ + +#include + +#include +#include +#include + +void exec_ae (char const *file, char const *const *argv, char const *const *envp) +{ + char const *path = getenv("PATH") ; + if (!path) path = SKALIBS_DEFAULTPATH ; + execvep(file, argv, envp, path) ; +} diff --git a/src/libenvexec/mexec0_af.c b/src/libenvexec/mexec0_af.c new file mode 100644 index 0000000..97e228d --- /dev/null +++ b/src/libenvexec/mexec0_af.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include + +#include + +void mexec0_af (char const *file, char const *const *argv, char const *const *envp, size_t envlen) +{ + if (!argv[0]) _exit(0) ; + mexec_af(file, argv, envp, envlen) ; +} diff --git a/src/libenvexec/mexec0_afm.c b/src/libenvexec/mexec0_afm.c new file mode 100644 index 0000000..1ece07e --- /dev/null +++ b/src/libenvexec/mexec0_afm.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include + +#include + +void mexec0_afm (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen) +{ + if (!argv[0]) _exit(0) ; + mexec_afm(file, argv, envp, envlen, modif, modiflen) ; +} diff --git a/src/libenvexec/mexec0_afn.c b/src/libenvexec/mexec0_afn.c new file mode 100644 index 0000000..160a509 --- /dev/null +++ b/src/libenvexec/mexec0_afn.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include + +#include + +void mexec0_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn) +{ + if (!argv[0]) _exit(0) ; + mexec_afn(file, argv, envp, envlen, modif, modiflen, modifn) ; +} diff --git a/src/libenvexec/mexec_af.c b/src/libenvexec/mexec_af.c new file mode 100644 index 0000000..34c266a --- /dev/null +++ b/src/libenvexec/mexec_af.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include +#include +#include + +static stralloc modifsa = STRALLOC_ZERO ; + +int env_mexec (char const *key, char const *value) +{ + return env_addmodif(&modifsa, key, value) ; +} + +void mexec_af (char const *file, char const *const *argv, char const *const *envp, size_t envlen) +{ + mexec_afm(file, argv, envp, envlen, modifsa.s, modifsa.len) ; +} diff --git a/src/libenvexec/mexec_afm.c b/src/libenvexec/mexec_afm.c new file mode 100644 index 0000000..01571a1 --- /dev/null +++ b/src/libenvexec/mexec_afm.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include +#include + +void mexec_afm (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen) +{ + mexec_afn(file, argv, envp, envlen, modif, modiflen, byte_count(modif, modiflen, '\0')) ; +} diff --git a/src/libenvexec/mexec_afn.c b/src/libenvexec/mexec_afn.c new file mode 100644 index 0000000..278be11 --- /dev/null +++ b/src/libenvexec/mexec_afn.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include +#include + +void mexec_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn) +{ + char const *newenvp[envlen + modifn + 1] ; + env_mergen(newenvp, envlen + modifn + 1, envp, envlen, modif, modiflen, modifn) ; + exec_ae(file, argv, newenvp) ; +} diff --git a/src/libenvexec/xexec0_ae.c b/src/libenvexec/xexec0_ae.c new file mode 100644 index 0000000..f0bd39c --- /dev/null +++ b/src/libenvexec/xexec0_ae.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include + +#include + +void xexec0_ae (char const *file, char const *const *argv, char const *const *envp) +{ + if (!argv[0]) _exit(0) ; + xexec_ae(file, argv, envp) ; +} diff --git a/src/libenvexec/xexec_ae.c b/src/libenvexec/xexec_ae.c new file mode 100644 index 0000000..55b7c70 --- /dev/null +++ b/src/libenvexec/xexec_ae.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xexec_ae (char const *file, char const *const *argv, char const *const *envp) +{ + exec_ae(file, argv, envp) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xexecvep.c b/src/libenvexec/xexecvep.c new file mode 100644 index 0000000..c272401 --- /dev/null +++ b/src/libenvexec/xexecvep.c @@ -0,0 +1,13 @@ +/* ISC license. */ + +#include + +#include +#include +#include + +void xexecvep (char const *file, char const *const *argv, char const *const *envp, char const *path) +{ + execvep(file, argv, envp, path) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xexecvep_loose.c b/src/libenvexec/xexecvep_loose.c new file mode 100644 index 0000000..a9935a6 --- /dev/null +++ b/src/libenvexec/xexecvep_loose.c @@ -0,0 +1,13 @@ +/* ISC license. */ + +#include + +#include +#include +#include + +void xexecvep_loose (char const *file, char const *const *argv, char const *const *envp, char const *path) +{ + xexecvep_loose(file, argv, envp, path) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xmexec0_af.c b/src/libenvexec/xmexec0_af.c new file mode 100644 index 0000000..a0bf84d --- /dev/null +++ b/src/libenvexec/xmexec0_af.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xmexec0_af (char const *file, char const *const *argv, char const *const *envp, size_t envlen) +{ + xmexec0_af(file, argv, envp, envlen) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xmexec0_afm.c b/src/libenvexec/xmexec0_afm.c new file mode 100644 index 0000000..a43cb49 --- /dev/null +++ b/src/libenvexec/xmexec0_afm.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xmexec0_afm (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen) +{ + mexec0_afm(file, argv, envp, envlen, modif, modiflen) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xmexec0_afn.c b/src/libenvexec/xmexec0_afn.c new file mode 100644 index 0000000..73eeb04 --- /dev/null +++ b/src/libenvexec/xmexec0_afn.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xmexec0_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn) +{ + mexec0_afn(file, argv, envp, envlen, modif, modiflen, modifn) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xmexec_af.c b/src/libenvexec/xmexec_af.c new file mode 100644 index 0000000..240220b --- /dev/null +++ b/src/libenvexec/xmexec_af.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xmexec_af (char const *file, char const *const *argv, char const *const *envp, size_t envlen) +{ + xmexec_af(file, argv, envp, envlen) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xmexec_afm.c b/src/libenvexec/xmexec_afm.c new file mode 100644 index 0000000..ac86c3a --- /dev/null +++ b/src/libenvexec/xmexec_afm.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xmexec_afm (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen) +{ + mexec_afm(file, argv, envp, envlen, modif, modiflen) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libenvexec/xmexec_afn.c b/src/libenvexec/xmexec_afn.c new file mode 100644 index 0000000..93f0c33 --- /dev/null +++ b/src/libenvexec/xmexec_afn.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include + +#include +#include + +void xmexec_afn (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modif, size_t modiflen, size_t modifn) +{ + mexec_afn(file, argv, envp, envlen, modif, modiflen, modifn) ; + strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; +} diff --git a/src/libstddjb/env_addmodif.c b/src/libstddjb/env_addmodif.c deleted file mode 100644 index ddd1be3..0000000 --- a/src/libstddjb/env_addmodif.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -int env_addmodif (stralloc *sa, char const *s, char const *t) -{ - size_t oldlen = sa->len ; - if (!s) return 1 ; - if (!stralloc_cats(sa, s)) return 0 ; - if ((t && (!stralloc_catb(sa, "=", 1) || !stralloc_cats(sa, t))) - || !stralloc_0(sa)) - { - sa->len = oldlen ; - return 0 ; - } - return 1 ; -} diff --git a/src/libstddjb/env_dump.c b/src/libstddjb/env_dump.c deleted file mode 100644 index 10f5913..0000000 --- a/src/libstddjb/env_dump.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - /* XXX: breaks layering, but really openat() should be supported everywhere */ -#include - -#define SUFFIX ":envdump:XXXXXX" - -int env_dump (char const *dir, mode_t mode, char const *const *envp) -{ - int fd ; - size_t dirlen = strlen(dir) ; - char tmpdir[dirlen + sizeof(SUFFIX)] ; - memcpy(tmpdir, dir, dirlen) ; - memcpy(tmpdir + dirlen, SUFFIX, sizeof(SUFFIX)) ; - if (!mkdtemp(tmpdir)) return 0 ; - fd = open_read(tmpdir) ; - if (fd == -1) goto err ; - for (; *envp ; envp++) - { - size_t len = str_chr(*envp, '=') ; - size_t vallen = strlen(*envp + len + 1) ; - char fn[len + 1] ; - memcpy(fn, *envp, len) ; - fn[len] = 0 ; - len = openwritenclose_at(fd, fn, *envp + len + 1, vallen) ; - if (len < vallen) goto cerr ; - } - fd_close(fd) ; - if (chmod(tmpdir, mode) == -1) goto err ; - if (rename(tmpdir, dir) == -1) goto err ; - return 1 ; - - cerr: - fd_close(fd) ; - err: - { - int e = errno ; - rm_rf(tmpdir) ; - errno = e ; - } - return 0 ; -} diff --git a/src/libstddjb/env_get.c b/src/libstddjb/env_get.c deleted file mode 100644 index d809461..0000000 --- a/src/libstddjb/env_get.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include -#include - -char const *env_get (char const *s) -{ - return getenv(s) ; -} diff --git a/src/libstddjb/env_get2.c b/src/libstddjb/env_get2.c deleted file mode 100644 index 5909ea6..0000000 --- a/src/libstddjb/env_get2.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -char const *env_get2 (char const *const *envp, char const *s) -{ - size_t len, i ; - if (!s) return 0 ; - len = strlen(s) ; - for (i = 0 ; envp[i] ; ++i) - if (str_start(envp[i], s) - && (envp[i][len] == '=')) - return envp[i] + len + 1 ; - return 0 ; -} diff --git a/src/libstddjb/env_len.c b/src/libstddjb/env_len.c deleted file mode 100644 index eef30c4..0000000 --- a/src/libstddjb/env_len.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include - -size_t env_len (char const *const *e) -{ - size_t i = 0 ; - while (*e++) i++ ; - return i ; -} diff --git a/src/libstddjb/env_make.c b/src/libstddjb/env_make.c deleted file mode 100644 index 60148f8..0000000 --- a/src/libstddjb/env_make.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -int env_make (char const **v, size_t argc, char const *s, size_t len) -{ - while (argc--) - { - size_t n = strlen(s) + 1 ; - if (n > len) return (errno = EINVAL, 0) ; - *v++ = s ; s += n ; len -= n ; - } - return 1 ; -} diff --git a/src/libstddjb/env_merge.c b/src/libstddjb/env_merge.c deleted file mode 100644 index 5543e08..0000000 --- a/src/libstddjb/env_merge.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include - -size_t env_merge (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - size_t n = byte_count(modifs, modiflen, '\0') ; - size_t vlen = envlen ; - size_t i = 0 ; - if (envlen + n + 1 > vmax) return (errno = ENAMETOOLONG, 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]) v[vlen++] = modifs + i ; - } - v[vlen++] = 0 ; - return vlen ; -} diff --git a/src/libstddjb/env_string.c b/src/libstddjb/env_string.c deleted file mode 100644 index e30f095..0000000 --- a/src/libstddjb/env_string.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include -#include - -int env_string (stralloc *sa, char const *const *envp, size_t envlen) -{ - size_t salen = sa->len ; - size_t i = 0 ; - for (; i < envlen ; i++) - { - if (!stralloc_cats(sa, envp[i]) || !stralloc_0(sa)) - { - sa->len = salen ; - return 0 ; - } - } - return 1 ; -} diff --git a/src/libstddjb/envalloc_0.c b/src/libstddjb/envalloc_0.c deleted file mode 100644 index 114f69e..0000000 --- a/src/libstddjb/envalloc_0.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include -#include - -int envalloc_0 (genalloc *v) -{ - char const *z = 0 ; - return genalloc_append(char const *, v, &z) ; -} diff --git a/src/libstddjb/envalloc_make.c b/src/libstddjb/envalloc_make.c deleted file mode 100644 index f8c459a..0000000 --- a/src/libstddjb/envalloc_make.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -int envalloc_make (genalloc *v, size_t argc, char const *s, size_t len) -{ - int wasnull = !v->s ; - if (!genalloc_readyplus(char const *, v, argc+1)) return 0 ; - if (!env_make(genalloc_s(char const *, v) + genalloc_len(char const *, v), argc, s, len)) - { - if (wasnull) genalloc_free(char const *, v) ; - return 0 ; - } - genalloc_setlen(char const *, v, genalloc_len(char const *, v) + argc) ; - return 1 ; -} diff --git a/src/libstddjb/envalloc_merge.c b/src/libstddjb/envalloc_merge.c deleted file mode 100644 index 2747f50..0000000 --- a/src/libstddjb/envalloc_merge.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include - -int envalloc_merge (genalloc *v, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; - if (!genalloc_readyplus(char const *, v, n)) return 0 ; - n = env_merge(genalloc_s(char const *, v) + genalloc_len(char const *, v), n, envp, envlen, modifs, modiflen) ; - genalloc_setlen(char const *, v, genalloc_len(char const *, v) + n) ; - return 1 ; -} diff --git a/src/libstddjb/envalloc_uniq.c b/src/libstddjb/envalloc_uniq.c deleted file mode 100644 index cf60b44..0000000 --- a/src/libstddjb/envalloc_uniq.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include - -int envalloc_uniq (genalloc *v, char delim) -{ - unsigned int m = 0 ; - size_t i = 0 ; - for (; i < genalloc_len(char const *, v) ; i++) - { - size_t j = i+1 ; - char const *s = genalloc_s(char const *, v)[i] ; - size_t n = str_chr(s, delim) ; - if (delim && !s[n]) return (errno = EINVAL, -1) ; - for (; j < genalloc_len(char const *, v) ; j++) - { - char const **p = genalloc_s(char const *, v) ; - if (!strncmp(s, p[j], n)) - { - size_t len = genalloc_len(char const *, v) - 1 ; - genalloc_setlen(char const *, v, len) ; - p[j] = p[len] ; - m++ ; - } - } - } - return m ; -} diff --git a/src/libstddjb/envdir.c b/src/libstddjb/envdir.c deleted file mode 100644 index 6992654..0000000 --- a/src/libstddjb/envdir.c +++ /dev/null @@ -1,85 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAXVARSIZE 4095 - -int envdir_internal (char const *path, stralloc *modifs, unsigned int options, char nullis) -{ - char buf[MAXVARSIZE + 1] ; - unsigned int n = 0 ; - size_t pathlen = strlen(path) ; - size_t modifbase = modifs->len ; - int wasnull = !modifs->s ; - DIR *dir ; - if (!nullis) return (errno = EINVAL, -1) ; - dir = opendir(path) ; - if (!dir) return -1 ; - for (;;) - { - direntry *d ; - size_t len ; - ssize_t r ; - errno = 0 ; - d = readdir(dir) ; - if (!d) break ; - if (d->d_name[0] == '.') continue ; - len = strlen(d->d_name) ; - if (str_chr(d->d_name, '=') < len) continue ; - { - char tmp[pathlen + len + 2] ; - memcpy(tmp, path, pathlen) ; - tmp[pathlen] = '/' ; - memcpy(tmp + pathlen + 1, d->d_name, len + 1) ; - r = openreadnclose(tmp, buf, MAXVARSIZE) ; - } - if (r < 0) - { - if (errno == ENOENT) errno = EIDRM ; - goto err ; - } - else if (r > 0) - { - if (options & SKALIBS_ENVDIR_VERBATIM) - { - if (!(options & SKALIBS_ENVDIR_NOCHOMP) && (buf[r-1] == '\n')) r-- ; - } - else - { - r = byte_chr(buf, r, '\n') ; - if (!(options & SKALIBS_ENVDIR_NOCHOMP)) - { - while (r--) if ((buf[r] != ' ') && (buf[r] != '\t') && (buf[r] != '\r')) break ; - r++ ; - } - } - { - size_t i = 0 ; - for (; i < (size_t)r ; i++) if (!buf[i]) buf[i] = nullis ; - } - buf[r++] = 0 ; - if (!env_addmodif(modifs, d->d_name, buf)) goto err ; - } - else if (!env_addmodif(modifs, d->d_name, 0)) goto err ; - n++ ; - } - if (errno) goto err ; - dir_close(dir) ; - return n ; - - err: - { - int e = errno ; - dir_close(dir) ; - if (wasnull) stralloc_free(modifs) ; else modifs->len = modifbase ; - errno = e ; - return -1 ; - } -} diff --git a/src/libstddjb/pathexec.c b/src/libstddjb/pathexec.c deleted file mode 100644 index da8788c..0000000 --- a/src/libstddjb/pathexec.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -/* MT-unsafe */ - -#include -#include -#include - -void pathexec (char const *const *argv) -{ - pathexec_fromenv(argv, (char const **)environ, env_len((char const **)environ)) ; -} diff --git a/src/libstddjb/pathexec0.c b/src/libstddjb/pathexec0.c deleted file mode 100644 index bfddfdf..0000000 --- a/src/libstddjb/pathexec0.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include -#include - -void pathexec0 (char const *const *argv) -{ - if (!argv[0]) _exit(0) ; - pathexec(argv) ; -} diff --git a/src/libstddjb/pathexec0_run.c b/src/libstddjb/pathexec0_run.c deleted file mode 100644 index 818877e..0000000 --- a/src/libstddjb/pathexec0_run.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include -#include - -void pathexec0_run (char const *const *argv, char const *const *envp) -{ - if (!argv[0]) _exit(0) ; - pathexec_run(argv[0], argv, envp) ; -} diff --git a/src/libstddjb/pathexec_fromenv.c b/src/libstddjb/pathexec_fromenv.c deleted file mode 100644 index f9c973b..0000000 --- a/src/libstddjb/pathexec_fromenv.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -static stralloc plus = STRALLOC_ZERO ; - -int pathexec_env (char const *s, char const *t) /* historic, bad name */ -{ - return env_addmodif(&plus, s, t) ; -} - -void pathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) -{ - pathexec_r(argv, envp, envlen, plus.s, plus.len) ; -} diff --git a/src/libstddjb/pathexec_r.c b/src/libstddjb/pathexec_r.c deleted file mode 100644 index fe05434..0000000 --- a/src/libstddjb/pathexec_r.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include - -void pathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - pathexec_r_name(argv[0], argv, envp, envlen, modifs, modiflen) ; -} diff --git a/src/libstddjb/pathexec_r_name.c b/src/libstddjb/pathexec_r_name.c deleted file mode 100644 index 29c0863..0000000 --- a/src/libstddjb/pathexec_r_name.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -void pathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; - char const *v[n] ; - if (env_merge(v, n, envp, envlen, modifs, modiflen)) - pathexec_run(file, argv, v) ; -} diff --git a/src/libstddjb/pathexec_run.c b/src/libstddjb/pathexec_run.c deleted file mode 100644 index 5888ba2..0000000 --- a/src/libstddjb/pathexec_run.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include - -void pathexec_run (char const *file, char const *const *argv, char const *const *envp) -{ - char const *path = getenv("PATH") ; - if (!path) path = SKALIBS_DEFAULTPATH ; - execvep(file, argv, envp, path) ; -} diff --git a/src/libstddjb/xexecvep.c b/src/libstddjb/xexecvep.c deleted file mode 100644 index 17a3abf..0000000 --- a/src/libstddjb/xexecvep.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include - -void xexecvep (char const *file, char const *const *argv, char const *const *envp, char const *path) -{ - execvep(file, argv, envp, path) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; -} diff --git a/src/libstddjb/xpathexec.c b/src/libstddjb/xpathexec.c deleted file mode 100644 index 473f682..0000000 --- a/src/libstddjb/xpathexec.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec (char const *const *argv) -{ - pathexec(argv) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec0.c b/src/libstddjb/xpathexec0.c deleted file mode 100644 index ed0848c..0000000 --- a/src/libstddjb/xpathexec0.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec0 (char const *const *argv) -{ - pathexec0(argv) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec0_run.c b/src/libstddjb/xpathexec0_run.c deleted file mode 100644 index ab3e645..0000000 --- a/src/libstddjb/xpathexec0_run.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec0_run (char const *const *argv, char const *const *envp) -{ - pathexec0_run(argv, envp) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec_fromenv.c b/src/libstddjb/xpathexec_fromenv.c deleted file mode 100644 index c434331..0000000 --- a/src/libstddjb/xpathexec_fromenv.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) -{ - pathexec_fromenv(argv, envp, envlen) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec_r.c b/src/libstddjb/xpathexec_r.c deleted file mode 100644 index a44fc0f..0000000 --- a/src/libstddjb/xpathexec_r.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - pathexec_r(argv, envp, envlen, modifs, modiflen) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec_r_name.c b/src/libstddjb/xpathexec_r_name.c deleted file mode 100644 index cd118f5..0000000 --- a/src/libstddjb/xpathexec_r_name.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - pathexec_r_name(file, argv, envp, envlen, modifs, modiflen) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; -} diff --git a/src/libstddjb/xpathexec_run.c b/src/libstddjb/xpathexec_run.c deleted file mode 100644 index 7c054ee..0000000 --- a/src/libstddjb/xpathexec_run.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include - -#include -#include - -void xpathexec_run (char const *file, char const *const *argv, char const *const *envp) -{ - pathexec_run(file, argv, envp) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; -} -- cgit v1.2.3