int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; int nl = 1 ; PROG = "s6-dirname" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "n", &l) ; if (opt == -1) break ; switch (opt) { case 'n' : nl = 0 ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; if (!sadirname(&sa, argv[0], str_len(argv[0]))) strerr_diefu2sys(111, "get dirname of ", argv[0]) ; if (nl && !stralloc_catb(&sa, "\n", 1)) strerr_diefu2sys(111, "get dirname of ", argv[0]) ; if (allwrite(1, sa.s, sa.len) < sa.len) strerr_diefu1sys(111, "write to stdout") ; return 0 ; }
int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; unsigned int n = 8 ; PROG = "s6-uniquename" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "n:", &l) ; if (opt == -1) break ; switch (opt) { case 'n' : if (!uint0_scan(l.arg, &n)) usage() ; break ; default : usage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 1) usage() ; if (!stralloc_cats(&sa, argv[0])) strerr_diefu1sys(111, "stralloc_cats") ; if ((n ? random_sauniquename(&sa, n) : sauniquename(&sa)) < 0) strerr_diefu1sys(111, "make unique name") ; if (!stralloc_catb(&sa, "\n", 1)) strerr_diefu1sys(111, "stralloc_cats") ; if (allwrite(1, sa.s, sa.len) < sa.len) strerr_diefu1sys(111, "write to stdout") ; return 0 ; }
int main (int argc, char const *const *argv) { unsigned int mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH ; PROG = "s6-mkfifo" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "m:", &l) ; if (opt == -1) break ; switch (opt) { case 'm': if (uint0_oscan(l.arg, &mode)) break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; umask(S_IXUSR|S_IXGRP|S_IXOTH) ; for (; *argv ; argv++) if (mkfifo(*argv, mode) < 0) strerr_diefu2sys(111, "mkfifo ", *argv) ; return 0 ; }
int main (int argc, char const *const *argv, char const *const *envp) { unsigned int backlog = 20 ; int flagreuse = 1 ; PROG = "s6-ipcserver-socketbinder" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "Ddb:", &l) ; if (opt == -1) break ; switch (opt) { case 'D' : flagreuse = 0 ; break ; case 'd' : flagreuse = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 2) dieusage() ; close(0) ; if (ipc_stream()) strerr_diefu1sys(111, "create socket") ; { mode_t m = umask(0) ; if ((flagreuse ? ipc_bind_reuse(0, argv[0]) : ipc_bind(0, argv[0])) < 0) strerr_diefu2sys(111, "bind to ", argv[0]) ; umask(m) ; } if (ipc_listen(0, backlog) < 0) strerr_diefu2sys(111, "listen to ", argv[0]) ; pathexec_run(argv[1], argv + 1, envp) ; strerr_dieexec(111, argv[1]) ; }
int main (int argc, char const *const *argv, char const *const *envp) { int incr = 10 ; int strict = 0 ; PROG = "s6-nice" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "Iin:", &l) ; if (opt == -1) break ; switch (opt) { case 'I' : strict = 0 ; break ; case 'i' : strict = 1 ; break ; case 'n': if (!int_scan(l.arg, &incr)) strerr_dieusage(100, USAGE) ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; errno = 0 ; if ((nice(incr) < 0) && errno) { char fmt[1+UINT_FMT] ; fmt[int_fmt(fmt, incr)] = 0 ; if (strict) strerr_diefu2sys(111, "nice to ", fmt) ; else strerr_warnwu2sys("nice to ", fmt) ; } pathexec_run(argv[0], argv, envp) ; strerr_dieexec((errno == ENOENT) ? 127 : 126, argv[0]) ; }
int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; int path = 0, nl = 1 ; PROG = "s6-linkname" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "nf", &l) ; if (opt == -1) break ; switch(opt) { case 'n' : nl = 0 ; break ; case 'f' : path = 1 ; break ; default : dieusage() ; } } argv += l.ind ; argc -= l.ind ; } if (!argc) dieusage() ; if ((path ? sarealpath(&sa, *argv) : sareadlink(&sa, *argv)) == -1) strerr_diefu2sys(111, "resolve ", *argv) ; if ((buffer_putalign(buffer_1small, sa.s, sa.len) == -1) || (nl && (buffer_putalign(buffer_1small, "\n", 1)) == -1) || (buffer_flush(buffer_1small) == -1)) strerr_diefu1sys(111, "write to stdout") ; /* stralloc_free(&sa) ; */ return 0 ; }
int main (int argc, char const *const *argv) { genalloc lines = GENALLOC_ZERO ; /* array of stralloc */ char sep = '\n' ; int flagcheck = 0 ; PROG = "s6-sort" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "bcfru0", &l) ; if (opt == -1) break ; switch (opt) { case 'b' : flagnoblanks = 1 ; break ; case 'c' : flagcheck = 1 ; break ; case 'f' : comp = &strncasecmp ; break ; case 'r' : flagreverse = 1 ; break ; case 'u' : flaguniq = 1 ; break ; case '0' : sep = '\0' ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (slurplines(&lines, sep) < 0) strerr_diefu1sys(111, "read from stdin") ; if (flagcheck) return !check(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)) ; qsort(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines), sizeof(stralloc), (qsortcmp_t_ref)&sacmp) ; if (flaguniq) uniq(&lines) ; if (!outputlines(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines))) strerr_diefu1sys(111, "write to stdout") ; return 0 ; }
int main (int argc, char const *const *argv, char const *const *envp) { unsigned int fd ; int block = 1 ; PROG = "fdblock" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "n", &l) ; if (opt == -1) break ; switch (opt) { case 'n' : block = 0 ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if ((argc < 2) || !uint0_scan(argv[0], &fd)) strerr_dieusage(100, USAGE) ; if ((block ? ndelay_off(fd) : ndelay_on(fd)) < 0) strerr_diefu1sys(111, block ? "ndelay_off" : "ndelay_on") ; pathexec_run(argv[1], argv+1, envp) ; strerr_dieexec(111, argv[1]) ; }
int main (int argc, char const *const *argv, char const *const *envp) { int fd, fd2 ; unsigned int flags = 0 ; int what = -1 ; int changemode = 0 ; PROG = "redirfd" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "rwuacxnb", &l) ; if (opt == -1) break ; switch (opt) { case 'r' : what = O_RDONLY ; flags &= ~(O_APPEND|O_CREAT|O_TRUNC|O_EXCL) ; break ; case 'w' : what = O_WRONLY ; flags |= O_CREAT|O_TRUNC ; flags &= ~(O_APPEND|O_EXCL) ; break ; case 'u' : what = O_RDWR ; flags &= ~(O_APPEND|O_CREAT|O_TRUNC|O_EXCL) ; break ; case 'a' : what = O_WRONLY ; flags |= O_CREAT|O_APPEND ; flags &= ~(O_TRUNC|O_EXCL) ; break ; case 'c' : what = O_WRONLY ; flags |= O_APPEND ; flags &= ~(O_CREAT|O_TRUNC|O_EXCL) ; break ; case 'x' : what = O_WRONLY ; flags |= O_CREAT|O_EXCL ; flags &= ~(O_APPEND|O_TRUNC) ; break ; case 'n' : flags |= O_NONBLOCK ; break ; case 'b' : changemode = 1 ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if ((argc < 3) || (what == -1)) dieusage() ; if (!uint0_scan(argv[0], (unsigned int *)&fd)) dieusage() ; flags |= what ; fd2 = open3(argv[1], flags, 0666) ; if ((fd2 == -1) && (what == O_WRONLY) && (errno == ENXIO)) { register int e ; int fdr = open_read(argv[1]) ; if (fdr == -1) strerr_diefu2sys(111, "open_read ", argv[1]) ; fd2 = open3(argv[1], flags, 0666) ; e = errno ; fd_close(fdr) ; errno = e ; } if (fd2 == -1) strerr_diefu2sys(111, "open ", argv[1]) ; if (fd_move(fd, fd2) == -1) { char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, fd2)] = 0 ; strerr_diefu4sys(111, "move fd ", fmt, " to fd ", argv[0]) ; } if (changemode) { if (((flags & O_NONBLOCK) ? ndelay_off(fd) : ndelay_on(fd)) < 0) strerr_diefu1sys(111, "change blocking mode") ; } pathexec_run(argv[2], argv+2, envp) ; strerr_dieexec(111, argv[2]) ; }
int sgetopt_r (int argc, char const *const *argv, char const *opts, subgetopt_t *o) { int c = subgetopt_r(argc, argv, opts, o) ; if (o->err && ((c == '?') || (c == ':'))) { buffer_puts(buffer_2, o->prog ? o->prog : argv[0]) ; buffer_put(buffer_2, ": ", 2) ; buffer_puts(buffer_2, ((c == '?') && argv[o->ind] && (o->ind < argc)) ? "illegal option" : "option requires an argument") ; buffer_putflush(buffer_2, "\n", 1) ; } return c ; }
int main (int argc, char const *const *argv, char const *const *envp) { unsigned int timeout = 0 ; int dodelete = 0 ; PROG = "s6-fdholder-retrieve" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "Dt:", &l) ; if (opt == -1) break ; switch (opt) { case 'D' : dodelete = 1 ; break ; case 't' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; if (argc < 3) dieusage() ; } { char const *newargv[13 + argc] ; unsigned int m = 0 ; char fmtt[UINT_FMT] ; newargv[m++] = S6_BINPREFIX "s6-ipcclient" ; newargv[m++] = "-l0" ; newargv[m++] = "--" ; newargv[m++] = *argv++ ; newargv[m++] = S6_BINPREFIX "s6-fdholder-retrievec" ; if (dodelete) newargv[m++] = "-D" ; if (timeout) { fmtt[uint_fmt(fmtt, timeout)] = 0 ; newargv[m++] = "-t" ; newargv[m++] = fmtt ; } newargv[m++] = "--" ; newargv[m++] = *argv++ ; newargv[m++] = EXECLINE_EXTBINPREFIX "fdclose" ; newargv[m++] = "6" ; newargv[m++] = EXECLINE_EXTBINPREFIX "fdclose" ; newargv[m++] = "7" ; while (*argv) newargv[m++] = *argv++ ; newargv[m++] = 0 ; pathexec_run(newargv[0], newargv, envp) ; strerr_dieexec(111, newargv[0]) ; } }
int main (int argc, char const *const *argv, char const *const *envp) { int uid = -1, gid = -1 ; PROG = "s6-chown" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "Uu:g:", &l) ; if (opt == -1) break ; switch (opt) { case 'u': { unsigned int u ; if (!uint0_scan(l.arg, &u)) strerr_dieusage(100, USAGE) ; uid = u ; break ; } case 'g': { unsigned int g ; if (!uint0_scan(l.arg, &g)) strerr_dieusage(100, USAGE) ; gid = g ; break ; } case 'U': { unsigned int x ; char const *s = env_get2(envp, "UID") ; if (!s) strerr_dienotset(100, "UID") ; if (!uint0_scan(s, &x)) strerr_dieinvalid(100, "UID") ; uid = x ; s = env_get2(envp, "GID") ; if (!s) strerr_dienotset(100, "GID") ; if (!uint0_scan(s, &x)) strerr_dieinvalid(100, "GID") ; gid = x ; break ; } default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; if (chown(*argv, uid, gid) == -1) strerr_diefu2sys(111, "chown ", argv[0]) ; return 0 ; }
int main (int argc, char const *const *argv, char const *const *envp) { char const *s = env_get2(envp, VAR) ; unsigned int fd = 1 ; unsigned int timeout = 0 ; int df = 1, keep = 0 ; PROG = "sdnotify-wrapper" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "d:ft:k", &l) ; if (opt == -1) break ; switch (opt) { case 'd' : if (!uint0_scan(l.arg, &fd)) dieusage() ; break ; case 'f' : df = 0 ; break ; case 't' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ; case 'k' : keep = 1 ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) dieusage() ; if (!s) xpathexec_run(argv[0], argv, envp) ; else { pid_t parent = getpid() ; pid_t child ; int p[2] ; if (pipe(p) < 0) strerr_diefu1sys(111, "pipe") ; child = df ? doublefork() : fork() ; if (child < 0) strerr_diefu1sys(111, df ? "doublefork" : "fork") ; else if (!child) { PROG = "sdnotify-wrapper (child)" ; close(p[1]) ; return run_child(p[0], timeout, parent, s) ; } close(p[0]) ; if (fd_move((int)fd, p[1]) < 0) strerr_diefu1sys(111, "move descriptor") ; if (keep) xpathexec_run(argv[0], argv, envp) ; else xpathexec_r(argv, envp, env_len(envp), VAR, sizeof(VAR)) ; } }
int main (int argc, char const *const *argv) { stralloc src = STRALLOC_ZERO ; PROG = "s6-unquote-filter" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "qQvwd:", &l) ; if (opt == -1) break ; switch (opt) { case 'q': strictness = 0 ; break ; case 'Q': strictness = 1 ; break ; case 'v': strictness = 2 ; break ; case 'w': strictness = 3 ; break ; case 'd': delim = l.arg ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } delimlen = str_len(delim) ; for (;;) { int r ; src.len = 0 ; r = skagetln(buffer_0f1, &src, '\n') ; if (!r) break ; if (r < 0) { if (errno != EPIPE) strerr_diefu1sys(111, "read from stdin") ; } else src.len-- ; if (!doit(src.s, src.len)) { if (buffer_putalign(buffer_1, src.s, src.len) < (int)src.len) strerr_diefu1sys(111, "write to stdout") ; } if (r > 0) { if (buffer_putalign(buffer_1, "\n", 1) < 1) strerr_diefu1sys(111, "write to stdout") ; } } return 0 ; }
int main (int argc, char const *const *argv, char const *const *envp) { int df = 0 ; PROG = "heredoc" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "d", &l) ; if (opt == -1) break ; switch (opt) { case 'd' : df = 1 ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 3) dieusage() ; { int fd[2] ; unsigned int fdr ; int pid ; if (!uint0_scan(argv[0], &fdr)) strerr_dieusage(100, USAGE) ; if (pipe(fd) < 0) strerr_diefu1sys(111, "pipe") ; pid = df ? doublefork() : fork() ; switch (pid) { case -1: strerr_diefu2sys(111, df ? "double" : "", "fork") ; case 0: { unsigned int len = str_len(argv[1]) ; PROG = "heredoc (child)" ; fd_close(fd[0]) ; if (allwrite(fd[1], argv[1], len) < len) strerr_diefu1sys(111, "allwrite") ; return 0 ; } } fd_close(fd[1]) ; if (fd_move((int)fdr, fd[0]) == -1) strerr_diefu2sys(111, "read on fd ", argv[0]) ; } pathexec_run(argv[2], argv+2, envp) ; strerr_dieexec(111, argv[2]) ; }
int exlsn_exlp (int argc, char const **argv, char const *const *envp, exlsn_t *info) { subgetopt_t localopt = SUBGETOPT_ZERO ; unsigned int nmin = 0 ; int n ; for (;;) { register int opt = subgetopt_r(argc, argv, "P:", &localopt) ; if (opt < 0) break ; switch (opt) { case 'P' : if (uint0_scan(localopt.arg, &nmin)) break ; default : return -3 ; } } argc -= localopt.ind ; argv += localopt.ind ; if (!argc) return -3 ; n = exlp(nmin, envp, info) ; if (n < 0) return n ; return localopt.ind ; }
int main (int argc, char const *const *argv) { unsigned int verbosity = 1 ; tain_t deadline ; PROG = "s6-rc-dryrun" ; { unsigned int t = 1000 ; subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "v:t:", &l) ; if (opt == -1) break ; switch (opt) { case 'v': if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; case 't': if (!uint0_scan(l.arg, &t)) dieusage() ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; tain_from_millisecs(&deadline, t) ; } if (!argc) dieusage() ; if (verbosity) { buffer_puts(buffer_1, PROG) ; buffer_put(buffer_1, ":", 1) ; for (; *argv ; argv++) { buffer_put(buffer_1, " ", 1) ; buffer_puts(buffer_1, *argv) ; } buffer_putflush(buffer_1, "\n", 1) ; } tain_now_g() ; tain_add_g(&deadline, &deadline) ; deepsleepuntil_g(&deadline) ; return 0 ; }
int main (int argc, char const *const *argv, char const *const *envp) { char data[DATASIZE+1] = "-" ; unsigned int datalen = 1 ; unsigned int timeout = 0 ; char updown[3] = "-\0" ; PROG = "s6-svc" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "abqhkti12pcoduxOXyT:w:", &l) ; if (opt == -1) break ; switch (opt) { case 'a' : case 'b' : case 'q' : case 'h' : case 'k' : case 't' : case 'i' : case '1' : case '2' : case 'p' : case 'c' : case 'o' : case 'd' : case 'u' : case 'x' : case 'O' : case 'X' : case 'y' : { if (datalen >= DATASIZE) strerr_dief1x(100, "too many commands") ; data[datalen++] = opt ; break ; } case 'T' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ; case 'w' : { if (byte_chr("dDuUrR", 6, l.arg[0]) >= 6) dieusage() ; updown[1] = l.arg[0] ; break ; } default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) dieusage() ; if (argc > 1) strerr_warn1x("ignoring extra arguments") ; if (datalen <= 1) return 0 ; if (updown[1] == 'U' || updown[1] == 'R') { unsigned int arglen = str_len(argv[0]) ; char fn[arglen + 17] ; byte_copy(fn, arglen, argv[0]) ; byte_copy(fn + arglen, 17, "/notification-fd") ; if (access(fn, F_OK) < 0) { if (errno != ENOENT) strerr_diefu2sys(111, "access ", fn) ; updown[1] = updown[1] == 'U' ? 'u' : 'r' ; strerr_warnw2x(fn, " not present - ignoring request for readiness notification") ; } } if (updown[1]) { char const *newargv[11] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; newargv[m++] = S6_BINPREFIX "s6-svlisten1" ; newargv[m++] = updown ; if (timeout) { fmt[uint_fmt(fmt, timeout)] = 0 ; newargv[m++] = "-t" ; newargv[m++] = fmt ; } newargv[m++] = "--" ; newargv[m++] = argv[0] ; newargv[m++] = S6_BINPREFIX "s6-svc" ; newargv[m++] = data ; newargv[m++] = "--" ; newargv[m++] = argv[0] ; newargv[m++] = 0 ; pathexec_run(newargv[0], newargv, envp) ; strerr_dieexec(111, newargv[0]) ; } else { register int r = s6_svc_writectl(argv[0], S6_SUPERVISE_CTLDIR, data + 1, datalen - 1) ; if (r < 0) strerr_diefu2sys(111, "control ", argv[0]) ; else if (!r) strerr_diefu3x(100, "control ", argv[0], ": supervisor not listening") ; } return 0 ; }
int main (int argc, char const **argv, char const *const *envp) { char const *x ; int argc1 ; unsigned short okcodes[256] ; unsigned int nbc = 0 ; int flagpar = 0, not = 1 ; PROG = "forx" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "epo:x:", &l) ; if (opt == -1) break ; switch (opt) { case 'e' : break ; /* compat */ case 'p' : flagpar = 1 ; break ; case 'o' : not = 0 ; if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ; break ; case 'x' : not = 1 ; if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 2) dieusage() ; x = argv[0] ; if (!*x) dieusage() ; argv++ ; argc-- ; argc1 = el_semicolon(argv) ; if (argc1 >= argc) strerr_dief1x(100, "unterminated block") ; if (!argc1 || (argc1 + 1 == argc)) return 0 ; { unsigned int envlen = env_len(envp) ; unsigned int varlen = str_len(x) ; unsigned int i = 0 ; pid_t pids[flagpar ? argc1 : 1] ; char const *newenv[envlen + 2] ; for (; i < (unsigned int)argc1 ; i++) { pid_t pid ; unsigned int vallen = str_len(argv[i]) ; char modif[varlen + vallen + 2] ; byte_copy(modif, varlen, x) ; modif[varlen] = '=' ; byte_copy(modif + varlen + 1, vallen, argv[i]) ; modif[varlen + vallen + 1] = 0 ; if (!env_merge(newenv, envlen + 2, envp, envlen, modif, varlen + vallen + 2)) strerr_diefu1sys(111, "build new environment") ; pid = el_spawn0(argv[argc1+1], argv + argc1 + 1, newenv) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[argc1+1]) ; if (flagpar) pids[i] = pid ; else { int wstat ; if (wait_pid(pid, &wstat) == -1) strerr_diefu2sys(111, "wait for ", argv[argc1+1]) ; if (not == isok(okcodes, nbc, wait_estatus(wstat))) return wait_estatus(wstat) ; } } if (flagpar) if (!waitn(pids, argc1)) strerr_diefu1sys(111, "waitn") ; } return 0 ; }
int main (int argc, char const *const *argv) { iopause_fd x[2] = { { -1, IOPAUSE_READ, 0 }, { -1, IOPAUSE_READ, 0 } } ; PROG = "s6-svscan" ; { subgetopt_t l = SUBGETOPT_ZERO ; unsigned int t = 5000 ; for (;;) { register int opt = subgetopt_r(argc, argv, "t:c:", &l) ; if (opt == -1) break ; switch (opt) { case 't' : if (uint0_scan(l.arg, &t)) break ; case 'c' : if (uint0_scan(l.arg, &max)) break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; if (t) tain_from_millisecs(&defaulttimeout, t) ; else defaulttimeout = tain_infinite_relative ; if (max < 2) max = 2 ; } /* Init phase. If something fails here, we can die, because it means that something is seriously wrong with the system, and we can't run correctly anyway. */ if (argc && (chdir(argv[0]) < 0)) strerr_diefu1sys(111, "chdir") ; x[1].fd = s6_supervise_lock(S6_SVSCAN_CTLDIR) ; x[0].fd = selfpipe_init() ; if (x[0].fd < 0) strerr_diefu1sys(111, "selfpipe_init") ; if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ; { sigset_t set ; sigemptyset(&set) ; sigaddset(&set, SIGCHLD) ; sigaddset(&set, SIGALRM) ; sigaddset(&set, SIGTERM) ; sigaddset(&set, SIGHUP) ; sigaddset(&set, SIGQUIT) ; sigaddset(&set, SIGABRT) ; sigaddset(&set, SIGINT) ; sigaddset(&set, SIGUSR1) ; if (selfpipe_trapset(&set) < 0) strerr_diefu1sys(111, "trap signals") ; } { struct svinfo_s blob[max] ; /* careful with that stack, Eugene */ services = blob ; tain_now_g() ; /* Loop phase. From now on, we must not die. Temporize on recoverable errors, and panic on serious ones. */ while (cont) { int r ; tain_add_g(&deadline, &defaulttimeout) ; reap() ; scan() ; killthem() ; r = iopause_g(x, 2, &deadline) ; if (r < 0) panic("iopause") ; else if (!r) wantscan = 1 ; else { if ((x[0].revents | x[1].revents) & IOPAUSE_EXCEPT) { errno = EIO ; panic("check internal pipes") ; } if (x[0].revents & IOPAUSE_READ) handle_signals() ; if (x[1].revents & IOPAUSE_READ) handle_control(x[1].fd) ; } } /* Finish phase. */ selfpipe_finish() ; killthem() ; reap() ; } { char const *eargv[3] = { FINISH_PROG, finish_arg, 0 } ; execve(eargv[0], (char **)eargv, (char *const *)environ) ; } panicnosp("exec finish script " FINISH_PROG) ; }
int main (int argc, char const *const *argv, char const *const *envp) { char const *def = 0 ; int insist = 0, chomp = 0 ; PROG = "backtick" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "eniD:", &l) ; if (opt == -1) break ; switch (opt) { case 'e' : break ; /* compat */ case 'n' : chomp = 1 ; break ; case 'i' : insist = 1 ; break ; case 'D' : def = l.arg ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 2) dieusage() ; if (!argv[0][0]) dieusage() ; if (!argv[1][0]) strerr_dief1x(100, "empty block") ; { unsigned int m = 0, i = 1 ; int fd = dup(0) ; char const *newargv[argc + 15] ; char fmt[UINT_FMT] ; if (fd < 0) { if (errno != EBADF) strerr_diefu1sys(111, "dup stdin") ; } else fmt[uint_fmt(fmt, (unsigned int)fd)] = 0 ; newargv[m++] = EXECLINE_BINPREFIX "pipeline" ; newargv[m++] = "--" ; while (argv[i] && argv[i][0] != EXECLINE_BLOCK_END_CHAR && (!EXECLINE_BLOCK_END_CHAR || (argv[i][0] && argv[i][1]))) newargv[m++] = argv[i++] ; if (!argv[i]) strerr_dief1x(100, "unterminated block") ; newargv[m++] = "" ; i++ ; newargv[m++] = EXECLINE_BINPREFIX "withstdinas" ; if (insist) newargv[m++] = "-i" ; if (chomp) newargv[m++] = "-n" ; if (def) { newargv[m++] = "-D" ; newargv[m++] = def ; } newargv[m++] = "-!" ; newargv[m++] = "--" ; newargv[m++] = argv[0] ; if (fd < 0) { newargv[m++] = EXECLINE_BINPREFIX "fdclose" ; newargv[m++] = "0" ; } else { newargv[m++] = EXECLINE_BINPREFIX "fdmove" ; newargv[m++] = "0" ; newargv[m++] = fmt ; } while (argv[i]) newargv[m++] = argv[i++] ; newargv[m++] = 0 ; pathexec_run(newargv[0], newargv, envp) ; strerr_dieexec(111, newargv[0]) ; } }
int main (int argc, char const *const *argv, char const *const *envp) { unsigned int strict = el_getstrict() ; unsigned int b = 0 ; unsigned int n = 0 ; unsigned int sharp ; unsigned int i = 0 ; PROG = "shift" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "n:b:", &l) ; if (opt == -1) break ; switch (opt) { case 'n' : if (!uint0_scan(l.arg, &n)) dieusage() ; i = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &b)) dieusage() ; i = 1 ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) dieusage() ; if (i) i = 0 ; else n = 1 ; { char const *x = env_get2(envp, "#") ; if (!x) strerr_dienotset(100, "#") ; if (!uint0_scan(x, &sharp)) strerr_dieinvalid(100, "#") ; } /* Shift n args */ if (n > sharp) { if (strict) { char fmtn[UINT_FMT] ; char fmtsharp[UINT_FMT] ; fmtn[uint_fmt(fmtn, n)] = 0 ; fmtsharp[uint_fmt(fmtsharp, sharp)] = 0 ; if (strict == 1) strerr_warnwu5x("shift", " ", fmtn, " arguments: got ", fmtsharp) ; else strerr_diefu5x(100, "shift", " ", fmtn, " arguments: got ", fmtsharp) ; } n = sharp ; } /* Shift b blocks */ for (; i < b ; i++) { for (;;) { char const *x ; unsigned int base = n ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, ++n)] = 0 ; if (n > sharp) { char fmti[UINT_FMT] ; fmti[uint_fmt(fmt, i)] = 0 ; strerr_diefu6x(100, "shift", " block ", fmti, ": too few arguments (", fmt, ")") ; } x = env_get2(envp, fmt) ; if (!x) strerr_dienotset(100, fmt) ; if ((x[0] == EXECLINE_BLOCK_END_CHAR) && (!EXECLINE_BLOCK_END_CHAR || !x[1])) break ; if ((x[0] != EXECLINE_BLOCK_QUOTE_CHAR) && strict) { char fmti[UINT_FMT] ; char fmtp[UINT_FMT] ; fmti[uint_fmt(fmti, i)] = 0 ; fmtp[uint_fmt(fmtp, n - base)] = 0 ; if (strict == 1) strerr_warnw6x("unquoted positional ", x, " at block ", fmti, " position ", fmtp) ; else strerr_dief6x(100, "unquoted positional ", x, " at block ", fmti, " position ", fmtp) ; } } } /* n = shift value; modify the env */ { register unsigned int i = 1 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, sharp - n)] = 0 ; if (!pathexec_env("#", fmt)) strerr_diefu1sys(111, "pathexec_env") ; for (; i <= sharp ; i++) { char fmu[UINT_FMT] ; fmt[uint_fmt(fmt, i)] = 0 ; fmu[uint_fmt(fmu, i + n)] = 0 ; if (!pathexec_env(fmt, i <= (sharp - n) ? env_get2(envp, fmu) : 0)) strerr_diefu1sys(111, "pathexec_env") ; } } pathexec(argv) ; strerr_dieexec(111, argv[0]) ; }
int main (int argc, char const *const *argv, char const *const *envp) { char const *delim = DELIM_DEFAULT ; char const *codes = 0 ; int crunch = 0, chomp = 0, not = 1, par = 0 ; PROG = "forbacktickx" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "epnCc0d:o:x:", &l) ; if (opt == -1) break ; switch (opt) { case 'e' : break ; /* compat */ case 'p' : par = 1 ; break ; case 'n' : chomp = 1 ; break ; case 'C' : crunch = 1 ; break ; case 'c' : crunch = 0 ; break ; case '0' : delim = 0 ; break ; case 'd' : delim = l.arg ; break ; case 'o' : { unsigned short okcodes[256] ; unsigned int nbc ; if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ; codes = l.arg ; not = 0 ; break ; } case 'x' : { unsigned short okcodes[256] ; unsigned int nbc ; if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ; codes = l.arg ; not = 1 ; break ; } default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 2) dieusage() ; if (!argv[0][0]) dieusage() ; if (!argv[1][0]) strerr_dief1x(100, "empty block") ; { unsigned int m = 0, i = 1 ; int fd = dup(0) ; char const *newargv[argc + 18] ; char fmt[UINT_FMT] ; if (fd < 0) { if (errno != EBADF) strerr_diefu1sys(111, "dup stdin") ; } else fmt[uint_fmt(fmt, (unsigned int)fd)] = 0 ; newargv[m++] = EXECLINE_BINPREFIX "pipeline" ; newargv[m++] = "--" ; while (argv[i] && argv[i][0] != EXECLINE_BLOCK_END_CHAR && (!EXECLINE_BLOCK_END_CHAR || (argv[i][0] && argv[i][1]))) newargv[m++] = argv[i++] ; if (!argv[i]) strerr_dief1x(100, "unterminated block") ; newargv[m++] = "" ; i++ ; newargv[m++] = EXECLINE_BINPREFIX "unexport" ; newargv[m++] = "!" ; newargv[m++] = EXECLINE_BINPREFIX "forstdin" ; if (par) newargv[m++] = "-p" ; if (chomp) newargv[m++] = "-n" ; if (crunch) newargv[m++] = "-C" ; if (!delim) newargv[m++] = "-0" ; else if (str_diff(delim, DELIM_DEFAULT)) { newargv[m++] = "-d" ; newargv[m++] = delim ; } if (codes) { newargv[m++] = not ? "-x" : "-o" ; newargv[m++] = codes ; } newargv[m++] = "--" ; newargv[m++] = argv[0] ; if (fd < 0) { newargv[m++] = EXECLINE_BINPREFIX "fdclose" ; newargv[m++] = "0" ; } else { newargv[m++] = EXECLINE_BINPREFIX "fdmove" ; newargv[m++] = "0" ; newargv[m++] = fmt ; } while (argv[i]) newargv[m++] = argv[i++] ; newargv[m++] = 0 ; pathexec_run(newargv[0], newargv, envp) ; strerr_dieexec(111, newargv[0]) ; } }
int main (int argc, char const *const *argv) { unsigned int count = 0 ; flags_t flags = FLAGS_ZERO ; PROG = "s6-grep" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "Fcnqv", &l) ; if (opt == -1) break ; switch (opt) { case 'F': flags.fixed = 1 ; break ; case 'c': flags.count = 1 ; break ; case 'n': flags.num = 1 ; break ; case 'q': flags.quiet = 1 ; break ; case 'v': flags.not = 1 ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; { stralloc line = STRALLOC_ZERO ; struct sredfa *re = 0 ; unsigned int num = 0 ; unsigned int arglen = 0 ; if (flags.fixed) arglen = str_len(argv[0]) ; else { re = sredfa_new() ; if (!re) strerr_diefu1sys(111, "sredfa_new") ; if (!sredfa_from_regexp(re, argv[0])) strerr_diefu1sys(111, "compile regular expression") ; } for (;;) { register int r ; line.len = 0 ; r = skagetln(buffer_0f1, &line, '\n') ; if (!r) break ; if (r < 0) { if ((errno != EPIPE) || !stralloc_catb(&line, "\n", 1)) strerr_diefu1sys(111, "read from stdin") ; } num++ ; r = flags.fixed ? (str_strn(line.s, line.len-1, argv[0], arglen) < line.len - 1) : sredfa_match(re, line.s, line.len-1) ; if (r < 0) { int e = errno ; buffer_flush(buffer_1) ; errno = e ; strerr_diefu1sys(111, "match line against pattern") ; } if (r ^ flags.not) { count++ ; if (!flags.quiet && !flags.count) { if (flags.num) { char fmt[UINT_FMT] ; register unsigned int n = uint_fmt(fmt, num) ; fmt[n++] = ':' ; if (buffer_putalign(buffer_1, fmt, n) < (int)n) strerr_diefu1sys(111, "write to stdout") ; } if (buffer_putalign(buffer_1, line.s, line.len) < (int)line.len) strerr_diefu1sys(111, "write to stdout") ; } } } if (flags.quiet) return !count ; stralloc_free(&line) ; if (!flags.fixed) sredfa_delete(re) ; } if (flags.count) { char fmt[UINT_FMT] ; register unsigned int n = uint_fmt(fmt, count) ; fmt[n++] = '\n' ; if (buffer_putalign(buffer_1, fmt, n) < (int)n) strerr_diefu1sys(111, "write to stdout") ; } return !count ; }
int main (int argc, char const *const *argv) { genalloc list = GENALLOC_ZERO ; /* array of diuint */ char delim = '\t' ; unsigned long what = 0 ; PROG = "s6-cut" ; { subgetopt_t l = SUBGETOPT_ZERO ; int flagnodel = 1 ; for (;;) { register int opt = subgetopt_r(argc, argv, "nsb:c:f:d:", &l) ; if (opt == -1) break ; switch (opt) { case 'n': break ; /* ignored */ case 's': flagnodel = 0 ; break ; case 'd': delim = *l.arg ; break ; case 'b': case 'c': { if (what) strerr_dieusage(100, USAGE) ; what = 2 ; scanlist(&list, l.arg) ; break ; } case 'f': { if (what) strerr_dieusage(100, USAGE) ; what = 4 ; scanlist(&list, l.arg) ; break ; } default : strerr_dieusage(100, USAGE) ; } } what += flagnodel ; argc -= l.ind ; argv += l.ind ; } if (!genalloc_len(diuint, &list)) strerr_dieusage(100, USAGE) ; diuintalloc_normalize(&list) ; if (!argc) { if (!doit(0, genalloc_s(diuint, &list), genalloc_len(diuint, &list), what, delim)) strerr_diefu1sys(111, "cut stdin") ; } else { for (; *argv ; argv++) { if ((*argv[0] == '-') && !*argv[1]) { if (!doit(0, genalloc_s(diuint, &list), genalloc_len(diuint, &list), what, delim)) strerr_diefu1sys(111, "process stdin") ; } else { int fd = open_readb(*argv) ; if (fd == -1) strerr_diefu3sys(111, "open ", *argv, " for reading") ; if (!doit(fd, genalloc_s(diuint, &list), genalloc_len(diuint, &list), what, delim)) strerr_diefu2sys(111, "cut ", *argv) ; fd_close(fd) ; } } } return 0 ; }
int main (int argc, char const *const *argv, char const *const *envp) { unsigned int kbufsz = 65536, verbosity = 1 ; char const *linevar = 0 ; char const *targ = 0 ; PROG = "s6-devd" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "qvb:l:t:", &l) ; if (opt == -1) break ; switch (opt) { case 'q' : if (verbosity) verbosity-- ; break ; case 'v' : verbosity++ ; break ; case 'b' : if (!uint0_scan(l.arg, &kbufsz)) dieusage() ; break ; case 'l' : linevar = l.arg ; break ; case 't' : if (!check_targ(l.arg)) dieusage() ; targ = l.arg ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; { unsigned int m = 0, pos = 0 ; char fmt[UINT_FMT * 3] ; char const *newargv[argc + 15] ; newargv[m++] = S6_LINUX_UTILS_BINPREFIX "s6-uevent-listener" ; if (verbosity != 1) { newargv[m++] = "-v" ; newargv[m++] = fmt + pos ; pos += uint_fmt(fmt + pos, verbosity) ; fmt[pos++] = 0 ; } if (kbufsz != 65536) { newargv[m++] = "-b" ; newargv[m++] = fmt + pos ; pos += uint_fmt(fmt + pos, kbufsz) ; fmt[pos++] = 0 ; } newargv[m++] = "--" ; newargv[m++] = S6_LINUX_UTILS_BINPREFIX "s6-uevent-spawner" ; if (verbosity != 1) { newargv[m++] = "-v" ; newargv[m++] = fmt + pos ; pos += uint_fmt(fmt + pos, verbosity) ; fmt[pos++] = 0 ; } if (linevar) { newargv[m++] = "-l" ; newargv[m++] = linevar ; } if (targ) { newargv[m++] = "-t" ; newargv[m++] = targ ; } newargv[m++] = "--" ; while (*argv) newargv[m++] = *argv++ ; newargv[m++] = 0 ; pathexec_run(newargv[0], newargv, envp) ; strerr_dieexec(111, newargv[0]) ; } }
int main (int argc, char const *const *argv) { tain_t deadline, tto ; unsigned int dirlen ; char const *live = S6RC_LIVE_BASE ; char const *compiled = S6RC_COMPILED_BASE ; PROG = "s6-rc-init" ; { unsigned int t = 0 ; subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "c:l:t:", &l) ; if (opt == -1) break ; switch (opt) { case 'c' : compiled = l.arg ; break ; case 'l' : live = l.arg ; break ; case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; } if (!argc) dieusage() ; if (compiled[0] != '/') strerr_dief2x(100, compiled, " is not an absolute path") ; if (live[0] != '/') strerr_dief2x(100, live, " is not an absolute path") ; if (argv[0][0] != '/') strerr_dief2x(100, argv[0], " is not an absolute path") ; tain_now_g() ; tain_add_g(&deadline, &tto) ; if (!s6rc_sanitize_dir(&satmp, live, &dirlen)) dienomem() ; llen = satmp.len ; if (!stralloc_cats(&satmp, ":initial") || !stralloc_0(&satmp)) strerr_diefu1sys(111, "stralloc_catb") ; { int fdlock ; int fdcompiled ; int ok ; s6rc_db_t db ; unsigned int n ; char lfn[llen + 13] ; char cfn[llen + 23] ; /* Create the real dir, lock it, symlink */ unlink(live) ; rm_rf(satmp.s) ; if (mkdir(satmp.s, 0755) < 0) strerr_diefu2sys(111, "mkdir ", satmp.s) ; if (!s6rc_lock(satmp.s, 2, &fdlock, 0, 0, 0)) { char tmp[satmp.len] ; byte_copy(tmp, satmp.len, satmp.s) ; cleanup() ; strerr_diefu2sys(111, "take lock on ", tmp) ; } byte_copy(lfn, llen, satmp.s) ; lfn[llen] = 0 ; if (symlink(satmp.s + dirlen, lfn) < 0) { char tmp[satmp.len - dirlen] ; byte_copy(tmp, satmp.len - dirlen, satmp.s + dirlen) ; cleanup() ; strerr_diefu4sys(111, "symlink ", tmp, " to ", lfn) ; } /* compiled */ fdcompiled = open_readb(compiled) ; if (fdcompiled < 0) { cleanup() ; strerr_diefu2sys(111, "open ", compiled) ; } byte_copy(lfn + llen, 10, "/compiled") ; if (symlink(compiled, lfn) < 0) { cleanup() ; strerr_diefu4sys(111, "symlink ", compiled, " to ", lfn) ; } /* scandir */ byte_copy(lfn + llen + 1, 8, "scandir") ; if (symlink(argv[0], lfn) < 0) { cleanup() ; strerr_diefu4sys(111, "symlink ", argv[0], " to ", lfn) ; } /* state */ byte_copy(lfn + llen + 1, 6, "state") ; { register int r = s6rc_db_read_sizes(fdcompiled, &db) ; if (r <= 0) { cleanup() ; if (r < 0) strerr_diefu2sys(111, "read database size in ", compiled) ; else strerr_dief2x(4, "invalid database size in ", compiled) ; } close(fdcompiled) ; n = db.nshort + db.nlong ; { char zero[n] ; byte_zero(zero, n) ; if (!openwritenclose_unsafe(lfn, zero, n)) { cleanup() ; strerr_diefu2sys(111, "write ", lfn) ; } } } /* servicedirs */ byte_copy(lfn + llen + 1, 12, "servicedirs") ; byte_copy(cfn, llen + 1, lfn) ; byte_copy(cfn + llen + 1, 21, "compiled/servicedirs") ; if (!hiercopy(cfn, lfn)) { cleanup() ; strerr_diefu4sys(111, "recursively copy ", cfn, " to ", lfn) ; } /* start the supervisors */ lfn[llen] = 0 ; ok = s6rc_servicedir_manage_g(lfn, &deadline) ; if (!ok) { cleanup() ; strerr_diefu3sys(111, "supervise service directories in ", lfn, "/servicedirs") ; } if (ok & 2) strerr_warnw3x("s6-svscan not running on ", lfn, "/scandir") ; } return 0 ; }
int main (int argc, char const **argv, char const *const *envp) { tain_t deadline, tto ; int spfd ; int argc1 ; int or = 0 ; int wantup = 1, wantready = 0, wantrestart = 0 ; PROG = "s6-svlisten" ; { subgetopt_t l = SUBGETOPT_ZERO ; unsigned int t = 0 ; for (;;) { register int opt = subgetopt_r(argc, argv, "uUdDrRaot:", &l) ; if (opt == -1) break ; switch (opt) { case 'u' : wantup = 1 ; wantready = 0 ; break ; case 'U' : wantup = 1 ; wantready = 1 ; break ; case 'd' : wantup = 0 ; wantready = 0 ; break ; case 'D' : wantup = 0 ; wantready = 1 ; break ; case 'r' : wantrestart = 1 ; wantready = 0 ; break ; case 'R' : wantrestart = 1 ; wantready = 1 ; break ; case 'a' : or = 0 ; break ; case 'o' : or = 1 ; break ; case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; } if (argc < 3) dieusage() ; argc1 = el_semicolon(argv) ; if (!argc1 || argc == argc1 + 1) dieusage() ; if (argc1 >= argc) strerr_dief1x(100, "unterminated servicedir block") ; if (wantrestart && or) { or = 0 ; strerr_warnw3x("-o is unsupported when combined with -", wantready ? "R" : "r", "- using -a instead") ; } tain_now_g() ; tain_add_g(&deadline, &tto) ; spfd = s6_svlisten_selfpipe_init() ; { s6_svlisten_t foo = S6_SVLISTEN_ZERO ; pid_t pid ; uint16 ids[argc1] ; unsigned char upstate[bitarray_div8(argc1)] ; unsigned char readystate[bitarray_div8(argc1)] ; s6_svlisten_init(argc1, argv, &foo, ids, upstate, readystate, &deadline) ; pid = child_spawn0(argv[argc1 + 1], argv + argc1 + 1, envp) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[argc1 + 1]) ; if (wantrestart) { argc1 = s6_svlisten_loop(&foo, 0, 1, or, &deadline, spfd, &s6_svlisten_signal_handler) ; if (argc1) return argc1 ; wantup = 1 ; } return s6_svlisten_loop(&foo, wantup, wantready, or, &deadline, spfd, &s6_svlisten_signal_handler) ; } }