From 4e6edfeca4f5536cbb0a0a68d8f3822b81dfe79b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 27 Apr 2017 14:39:17 +0000 Subject: Adapt s6-devd to the new s6-uevent-listener|s6-uevent-spawner interface --- src/minutils/s6-devd.c | 67 +++++++++++++++++++++------------------ src/minutils/s6-uevent-listener.c | 8 ++--- 2 files changed, 39 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/minutils/s6-devd.c b/src/minutils/s6-devd.c index f14a8f1..7122e13 100644 --- a/src/minutils/s6-devd.c +++ b/src/minutils/s6-devd.c @@ -30,6 +30,7 @@ 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 ; + char fmtv[UINT_FMT] ; PROG = "s6-devd" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -50,50 +51,54 @@ int main (int argc, char const *const *argv, char const *const *envp) argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; + if (verbosity != 1) fmtv[uint_fmt(fmtv, verbosity)] = 0 ; { - size_t pos = 0 ; unsigned int m = 0 ; - char fmt[UINT_FMT * 3] ; - char const *newargv[argc + 15] ; - newargv[m++] = S6_LINUX_UTILS_BINPREFIX "s6-uevent-listener" ; + int fd ; + char const *cargv[argc + 9] ; + cargv[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 ; + cargv[m++] = "-v" ; + cargv[m++] = fmtv ; } - if (kbufsz != 65536) + if (linevar) { - newargv[m++] = "-b" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, kbufsz) ; - fmt[pos++] = 0 ; + cargv[m++] = "-l" ; + cargv[m++] = linevar ; } - newargv[m++] = "--" ; - newargv[m++] = S6_LINUX_UTILS_BINPREFIX "s6-uevent-spawner" ; - if (verbosity != 1) + if (targ) { - newargv[m++] = "-v" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, verbosity) ; - fmt[pos++] = 0 ; + cargv[m++] = "-t" ; + cargv[m++] = targ ; } - if (linevar) + cargv[m++] = "--" ; + while (*argv) cargv[m++] = *argv++ ; + cargv[m++] = 0 ; + if (!child_spawn1_pipe(cargv[0], cargv, envp, &fd, 0)) + strerr_diefu2sys(111, "spawn ", cargv[0]) ; + if (fd_move(1, fd) < 0) strerr_diefu1sys(111, "fd_move") ; + } + + { + unsigned int m = 0 ; + char const *pargv[6] ; + char fmtk[UINT_FMT] ; + pargv[m++] = S6_LINUX_UTILS_BINPREFIX "s6-uevent-listener" ; + if (verbosity != 1) { - newargv[m++] = "-l" ; - newargv[m++] = linevar ; + pargv[m++] = "-v" ; + pargv[m++] = fmtv ; } - if (targ) + if (kbufsz != 65536) { - newargv[m++] = "-t" ; - newargv[m++] = targ ; + pargv[m++] = "-b" ; + pargv[m++] = fmtk ; + fmtk[uint_fmt(fmtk, kbufsz)] = 0 ; } - newargv[m++] = "--" ; - while (*argv) newargv[m++] = *argv++ ; - newargv[m++] = 0 ; - pathexec_run(newargv[0], newargv, envp) ; - strerr_dieexec(111, newargv[0]) ; + pargv[m++] = 0 ; + pathexec_run(pargv[0], pargv, envp) ; + strerr_dieexec(111, pargv[0]) ; } } diff --git a/src/minutils/s6-uevent-listener.c b/src/minutils/s6-uevent-listener.c index e882821..4998cd9 100644 --- a/src/minutils/s6-uevent-listener.c +++ b/src/minutils/s6-uevent-listener.c @@ -156,12 +156,10 @@ int main (int argc, char const *const *argv, char const *const *envp) r = iopause(x, 2 + cont, 0, 0) ; if (r < 0) strerr_diefu1sys(111, "iopause") ; if (!r) continue ; - for (r = 0 ; r < 2 ; r++) - if (x[r].revents & IOPAUSE_EXCEPT) - x[r].revents |= IOPAUSE_READ | IOPAUSE_WRITE ; - if (x[0].revents & IOPAUSE_READ) handle_signals() ; + if (x[1].revents & IOPAUSE_EXCEPT) break ; if (x[1].revents & IOPAUSE_WRITE) handle_stdout() ; - if (cont && x[2].events & IOPAUSE_READ && x[2].revents & IOPAUSE_READ) + if (x[0].revents & (IOPAUSE_READ | IOPAUSE_EXCEPT)) handle_signals() ; + if (cont && x[2].events & IOPAUSE_READ && x[2].revents & (IOPAUSE_READ | IOPAUSE_EXCEPT)) handle_netlink() ; } if (verbosity >= 2) strerr_warni1x("exiting") ; -- cgit v1.2.3