summaryrefslogtreecommitdiff
path: root/src/daemontools-extras/s6-envdir.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
commit90b12bd71bb9fc79a4640b9112c13ef529d0196a (patch)
tree523b3f4ee2969e7a729bab2ba749c4b924ae62af /src/daemontools-extras/s6-envdir.c
downloads6-90b12bd71bb9fc79a4640b9112c13ef529d0196a.tar.xz
Initial commit
Diffstat (limited to 'src/daemontools-extras/s6-envdir.c')
-rw-r--r--src/daemontools-extras/s6-envdir.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/daemontools-extras/s6-envdir.c b/src/daemontools-extras/s6-envdir.c
new file mode 100644
index 0000000..394253e
--- /dev/null
+++ b/src/daemontools-extras/s6-envdir.c
@@ -0,0 +1,40 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/env.h>
+#include <skalibs/djbunix.h>
+
+#define USAGE "s6-envdir [ -I | -i ] [ -n ] [ -f ] [ -c nullchar ] dir prog..."
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ stralloc modifs = STRALLOC_ZERO ;
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ int insist = 1 ;
+ unsigned int options = 0 ;
+ char nullis = '\n' ;
+ PROG = "s6-envdir" ;
+ for (;;)
+ {
+ register int opt = subgetopt_r(argc, argv, "Iinfc:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'I' : insist = 0 ; break ;
+ case 'i' : insist = 1 ; break ;
+ case 'n' : options |= SKALIBS_ENVDIR_NOCHOMP ; break ;
+ case 'f' : options |= SKALIBS_ENVDIR_VERBATIM ; break ;
+ case 'c' : nullis = *l.arg ; break ;
+ default : strerr_dieusage(100, USAGE) ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ if (argc < 2) strerr_dieusage(100, USAGE) ;
+ if ((envdir_internal(*argv++, &modifs, options, nullis) < 0) && (insist || (errno != ENOENT)))
+ strerr_diefu1sys(111, "envdir") ;
+ pathexec_r(argv, envp, env_len(envp), modifs.s, modifs.len) ;
+ strerr_dieexec(111, argv[0]) ;
+}