summaryrefslogtreecommitdiff
path: root/src/skaembutils/s6-env.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-19 02:53:32 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-19 02:53:32 +0000
commitbea0037dbdd979603fb0b5be8b43f5478c1f6fec (patch)
tree5776ae3af5a3e83d41c7087f70713952b6360988 /src/skaembutils/s6-env.c
downloads6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.tar.xz
initial commit
Diffstat (limited to 'src/skaembutils/s6-env.c')
-rw-r--r--src/skaembutils/s6-env.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/skaembutils/s6-env.c b/src/skaembutils/s6-env.c
new file mode 100644
index 0000000..b2e1312
--- /dev/null
+++ b/src/skaembutils/s6-env.c
@@ -0,0 +1,43 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/env.h>
+#include <skalibs/djbunix.h>
+#include <s6-portable-utils/config.h>
+
+#define USAGE "s6-env [ -i ] [ name=value... ] prog..."
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ stralloc modifs = STRALLOC_ZERO ;
+ char const *arg_zero[2] = { S6_PORTABLE_UTILS_BINPREFIX "s6-printenv", 0 } ;
+ char const *env_zero[1] = { 0 } ;
+ PROG = "s6-env" ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ register int opt = subgetopt_r(argc, argv, "i", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'i': envp = env_zero ; break ;
+ default : strerr_dieusage(100, USAGE) ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ }
+ for (; argc ; argc--, argv++)
+ {
+ if (!(*argv)[str_chr(*argv, '=')]) break ;
+ if (!stralloc_cats(&modifs, *argv) || !stralloc_0(&modifs))
+ strerr_diefu1sys(111, "stralloc_cats") ;
+ }
+ if (!argc) argv = arg_zero ;
+ pathexec_r(argv, envp, env_len(envp), modifs.s, modifs.len) ;
+ stralloc_free(&modifs) ;
+ strerr_dieexec((errno == ENOENT) ? 127 : 126, argv[0]) ;
+}