s6-envdir.c (1225B)
1 /* ISC license. */ 2 3 #include <errno.h> 4 5 #include <skalibs/sgetopt.h> 6 #include <skalibs/strerr.h> 7 #include <skalibs/stralloc.h> 8 #include <skalibs/env.h> 9 #include <skalibs/exec.h> 10 11 #define USAGE "s6-envdir [ -I | -i ] [ -n ] [ -f ] [ -L ] [ -c nullchar ] dir prog..." 12 13 int main (int argc, char const *const *argv) 14 { 15 stralloc modifs = STRALLOC_ZERO ; 16 subgetopt l = SUBGETOPT_ZERO ; 17 int insist = 1 ; 18 unsigned int options = 0 ; 19 char nullis = '\n' ; 20 PROG = "s6-envdir" ; 21 for (;;) 22 { 23 int opt = subgetopt_r(argc, argv, "IinfLc:", &l) ; 24 if (opt == -1) break ; 25 switch (opt) 26 { 27 case 'I' : insist = 0 ; break ; 28 case 'i' : insist = 1 ; break ; 29 case 'n' : options |= SKALIBS_ENVDIR_NOCHOMP ; break ; 30 case 'f' : options |= SKALIBS_ENVDIR_VERBATIM ; break ; 31 case 'L' : options |= SKALIBS_ENVDIR_NOCLAMP ; break ; 32 case 'c' : nullis = *l.arg ; break ; 33 default : strerr_dieusage(100, USAGE) ; 34 } 35 } 36 argc -= l.ind ; argv += l.ind ; 37 if (argc < 2) strerr_dieusage(100, USAGE) ; 38 if ((envdir_internal(*argv++, &modifs, options, nullis) < 0) && (insist || (errno != ENOENT))) 39 strerr_diefu2sys(111, "envdir ", argv[-1]) ; 40 xmexec_m(argv, modifs.s, modifs.len) ; 41 }