about summary refs log tree commit diff
path: root/src/minutils
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-08-14 20:22:43 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-08-14 20:22:43 +0000
commitf703916c3702d8f32dc535161571874cb007ca6d (patch)
tree0298bb0de1d464c3868a6547a225534a4ccc40cc /src/minutils
parent3e34202f32ab10017d55aedb2665cf55fb5af5c0 (diff)
downloads6-linux-utils-f703916c3702d8f32dc535161571874cb007ca6d.tar.gz
s6-linux-utils-f703916c3702d8f32dc535161571874cb007ca6d.tar.xz
s6-linux-utils-f703916c3702d8f32dc535161571874cb007ca6d.zip
Remove s6-devd, s6-uevent-listener, s6-uevent-spawner, prepare for 2.5.0.0
Diffstat (limited to 'src/minutils')
-rw-r--r--src/minutils/deps-exe/s6-devd1
-rw-r--r--src/minutils/deps-exe/s6-uevent-listener2
-rw-r--r--src/minutils/deps-exe/s6-uevent-spawner2
-rw-r--r--src/minutils/s6-devd.c103
-rw-r--r--src/minutils/s6-uevent-listener.c168
-rw-r--r--src/minutils/s6-uevent-spawner.c243
6 files changed, 0 insertions, 519 deletions
diff --git a/src/minutils/deps-exe/s6-devd b/src/minutils/deps-exe/s6-devd
deleted file mode 100644
index e7187fe..0000000
--- a/src/minutils/deps-exe/s6-devd
+++ /dev/null
@@ -1 +0,0 @@
--lskarnet
diff --git a/src/minutils/deps-exe/s6-uevent-listener b/src/minutils/deps-exe/s6-uevent-listener
deleted file mode 100644
index 39597dd..0000000
--- a/src/minutils/deps-exe/s6-uevent-listener
+++ /dev/null
@@ -1,2 +0,0 @@
--lskarnet
-${SPAWN_LIB}
diff --git a/src/minutils/deps-exe/s6-uevent-spawner b/src/minutils/deps-exe/s6-uevent-spawner
deleted file mode 100644
index 39597dd..0000000
--- a/src/minutils/deps-exe/s6-uevent-spawner
+++ /dev/null
@@ -1,2 +0,0 @@
--lskarnet
-${SPAWN_LIB}
diff --git a/src/minutils/s6-devd.c b/src/minutils/s6-devd.c
deleted file mode 100644
index f3b0932..0000000
--- a/src/minutils/s6-devd.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/* ISC license. */
-
-#include <sys/types.h>
-#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr2.h>
-#include <skalibs/djbunix.h>
-#include <s6-linux-utils/config.h>
-
-#define USAGE "s6-devd [ -q | -v ] [ -b kbufsz ] [ -l linevar ] [ -t maxlife:maxterm:maxkill ] helperprogram..."
-#define dieusage() strerr_dieusage(100, USAGE)
-
-static inline int check_targ (char const *s)
-{
-  size_t pos = 0 ;
-  unsigned int t = 0 ;
-  pos += uint_scan(s + pos, &t) ;
-  if (s[pos] && s[pos++] != ':') return 0 ;
-  if (!t) return 1 ;
-  pos += uint_scan(s + pos, &t) ;
-  if (s[pos] && s[pos++] != ':') return 0 ;
-  if (!t) return 1 ;
-  pos += uint_scan(s + pos, &t) ;
-  if (s[pos]) return 0 ;
-  return 1 ;
-}
-
-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 ;
-    for (;;)
-    {
-      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) ;
-  if (verbosity != 1) fmtv[uint_fmt(fmtv, verbosity)] = 0 ;
-
-  {
-    unsigned int m = 0 ;
-    int fd ;
-    char const *cargv[argc + 9] ;
-    cargv[m++] = S6_LINUX_UTILS_BINPREFIX "s6-uevent-spawner" ;
-    if (verbosity != 1)
-    {
-      cargv[m++] = "-v" ;
-      cargv[m++] = fmtv ;
-    }
-    if (linevar)
-    {
-      cargv[m++] = "-l" ;
-      cargv[m++] = linevar ;
-    }
-    if (targ)
-    {
-      cargv[m++] = "-t" ;
-      cargv[m++] = targ ;
-    }
-    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)
-    {
-      pargv[m++] = "-v" ;
-      pargv[m++] = fmtv ;
-    }
-    if (kbufsz != 65536)
-    {
-      pargv[m++] = "-b" ;
-      pargv[m++] = fmtk ;
-      fmtk[uint_fmt(fmtk, kbufsz)] = 0 ;
-    }
-    pargv[m++] = 0 ;
-    xpathexec_run(pargv[0], pargv, envp) ;
-  }
-}
diff --git a/src/minutils/s6-uevent-listener.c b/src/minutils/s6-uevent-listener.c
deleted file mode 100644
index 4175b54..0000000
--- a/src/minutils/s6-uevent-listener.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/* ISC license. */
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <skalibs/types.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/siovec.h>
-#include <skalibs/buffer.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/error.h>
-#include <skalibs/strerr2.h>
-#include <skalibs/iopause.h>
-#include <skalibs/djbunix.h>
-#include <skalibs/sig.h>
-#include <skalibs/selfpipe.h>
-
-#define USAGE "s6-uevent-listener [ -v verbosity ] [ -b kbufsz ]"
-#define dieusage() strerr_dieusage(100, USAGE)
-#define dienomem() strerr_diefu1sys(111, "build string") ;
-
-#define MAXNLSIZE 4096
-
-static unsigned int cont = 1, verbosity = 1 ;
-
-static inline ssize_t fd_recvmsg (int fd, struct msghdr *hdr)
-{
-  ssize_t r ;
-  do r = recvmsg(fd, hdr, MSG_DONTWAIT) ;
-  while ((r == -1) && (errno == EINTR)) ;
-  return r ;
-}
-
-static inline int netlink_init_stdin (unsigned int kbufsz)
-{
-  struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_pad = 0, .nl_groups = 1, .nl_pid = 0 } ;
-  close(0) ;
-  return socket_internal(AF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT, DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) == 0
-   && bind(0, (struct sockaddr *)&nl, sizeof(struct sockaddr_nl)) == 0
-   && setsockopt(0, SOL_SOCKET, SO_RCVBUFFORCE, &kbufsz, sizeof(unsigned int)) == 0 ;
-}
-
-static inline void handle_signals (void)
-{
-  for (;;)
-  {
-    int c = selfpipe_read() ;
-    switch (c)
-    {
-      case -1 : strerr_diefu1sys(111, "selfpipe_read") ;
-      case 0 : return ;
-      case SIGTERM :
-        cont = 0 ;
-        fd_close(0) ;
-        break ;
-      default :
-        strerr_dief1x(101, "internal error: inconsistent signal state. Please submit a bug-report.") ;
-    }
-  }
-}
-
-static inline void handle_stdout (void)
-{
-  if (!buffer_flush(buffer_1) && !error_isagain(errno))
-    strerr_diefu1sys(111, "flush stdout") ;
-}
-
-static inline void handle_netlink (void)
-{
-  struct sockaddr_nl nl;
-  struct iovec v[2] ;
-  struct msghdr msg =
-  {
-    .msg_name = &nl,
-    .msg_namelen = sizeof(struct sockaddr_nl),
-    .msg_iov = v,
-    .msg_iovlen = 2,
-    .msg_control = 0,
-    .msg_controllen = 0,
-    .msg_flags = 0
-  } ;
-  ssize_t r ;
-  buffer_wpeek(buffer_1, v) ;
-  siovec_trunc(v, 2, siovec_len(v, 2) - 1) ;
-  r = sanitize_read(fd_recvmsg(0, &msg)) ;
-  if (r < 0)
-  {
-    if (errno == EPIPE)
-    {
-      if (verbosity >= 2) strerr_warnw1x("received EOF on netlink") ;
-      cont = 0 ;
-      fd_close(0) ;
-      return ;
-    }
-    else strerr_diefu1sys(111, "receive netlink message") ;
-  }
-  if (!r) return ;
-  if (msg.msg_flags & MSG_TRUNC)
-    strerr_diefu2x(111, "buffer too small for ", "netlink message") ;
-  if (nl.nl_pid)
-  {
-    if (verbosity >= 3)
-    {
-      char fmt[PID_FMT] ;
-      fmt[pid_fmt(fmt, nl.nl_pid)] = 0 ;
-      strerr_warnw3x("netlink message", " from userspace process ", fmt) ;
-    }
-    return ;
-  }
-  buffer_wseek(buffer_1, r) ;
-  buffer_putnoflush(buffer_1, "", 1) ;
-}
-
-
-int main (int argc, char const *const *argv, char const *const *envp)
-{
-  iopause_fd x[3] = { { .events = IOPAUSE_READ }, { .fd = 1 }, { .fd = 0 } } ;
-  PROG = "s6-uevent-listener" ;
-  strerr_warnw1x("this program is deprecated, see https://skarnet.org/software/mdevd/") ;
-  {
-    unsigned int kbufsz = 65536 ;
-    subgetopt_t l = SUBGETOPT_ZERO ;
-    for (;;)
-    {
-      int opt = subgetopt_r(argc, argv, "v:b:", &l) ;
-      if (opt == -1) break ;
-      switch (opt)
-      {
-        case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ;
-        case 'b' : if (!uint0_scan(l.arg, &kbufsz)) dieusage() ; break ;
-        default : dieusage() ;
-      }
-    }
-    argc -= l.ind ; argv += l.ind ;
-    if (!netlink_init_stdin(kbufsz)) strerr_diefu1sys(111, "init netlink") ;
-  }
-
-  x[0].fd = selfpipe_init() ;
-  if (x[0].fd < 0) strerr_diefu1sys(111, "init selfpipe") ;
-  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ;
-  if (selfpipe_trap(SIGTERM) < 0) strerr_diefu1sys(111, "trap SIGTERM") ;
-
-  if (verbosity >= 2) strerr_warni1x("starting") ;
-
-  while (cont || buffer_len(buffer_1))
-  {
-    int r ;
-    x[1].events = buffer_len(buffer_1) ? IOPAUSE_WRITE : 0 ;
-    x[2].events = buffer_available(buffer_1) >= MAXNLSIZE + 1 ? IOPAUSE_READ : 0 ;
-    r = iopause(x, 2 + cont, 0, 0) ;
-    if (r < 0) strerr_diefu1sys(111, "iopause") ;
-    if (!r) continue ;
-    if (x[1].revents & IOPAUSE_EXCEPT) break ;
-    if (x[1].revents & IOPAUSE_WRITE) handle_stdout() ;
-    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") ;
-  return 0 ;
-}
diff --git a/src/minutils/s6-uevent-spawner.c b/src/minutils/s6-uevent-spawner.c
deleted file mode 100644
index 87dea11..0000000
--- a/src/minutils/s6-uevent-spawner.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/* ISC license. */
-
-#include <string.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <spawn.h>
-#include <signal.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <skalibs/config.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/bytestr.h>
-#include <skalibs/buffer.h>
-#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr2.h>
-#include <skalibs/tai.h>
-#include <skalibs/iopause.h>
-#include <skalibs/env.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/djbunix.h>
-#include <skalibs/sig.h>
-#include <skalibs/selfpipe.h>
-#include <skalibs/skamisc.h>
-
-#define USAGE "s6-uevent-spawner [ -v verbosity ] [ -l linevar ] [ -t maxlife:maxterm:maxkill ] helperprogram..."
-#define dieusage() strerr_dieusage(100, USAGE)
-#define dienomem() strerr_diefu1sys(111, "build string") ;
-
-static unsigned int cont = 1, state = 0, verbosity = 1 ;
-static pid_t pid = 0 ;
-static tain_t lifetto = TAIN_INFINITE_RELATIVE,
-              termtto = TAIN_INFINITE_RELATIVE,
-              killtto = TAIN_INFINITE_RELATIVE,
-              deadline ;
-
-static inline void on_death (void)
-{
-  pid = 0 ;
-  state = 0 ;
-  tain_add_g(&deadline, &tain_infinite_relative) ;
-}
-
-static inline void on_event (char const *const *argv, char const *const *envp, char const *s, unsigned int len)
-{
-  posix_spawnattr_t attr ;
-  posix_spawn_file_actions_t actions ;
-  size_t envlen = env_len(envp) ;
-  size_t n = envlen + 1 + byte_count(s, len, '\0') ;
-  pid_t mypid ;
-  int e ;
-  char const *v[n] ;
-  if (!env_merge(v, n, envp, envlen, s, len))
-    strerr_diefu1sys(111, "env_merge") ;
-
-  e = posix_spawnattr_init(&attr) ;
-  if (e) { errno = e ; strerr_diefu1sys(111, "posix_spawnattr_init") ; }
-  {
-    sigset_t set ;
-    sigemptyset(&set) ;
-    e = posix_spawnattr_setsigmask(&attr, &set) ;
-    if (e) { errno = e ; strerr_diefu1sys(111, "posix_spawnattr_setsigmask") ; }
-    sigfillset(&set) ;
-    e = posix_spawnattr_setsigdefault(&attr, &set) ;
-    if (e) { errno = e ; strerr_diefu1sys(111, "posix_spawnattr_setsigdefault") ; }
-  }
-  e = posix_spawn_file_actions_init(&actions) ;
-  if (e) { errno = e ; strerr_diefu1sys(111, "posix_spawn_file_actions_init") ; }
-  e = posix_spawn_file_actions_addopen(&actions, 0, "/dev/null", O_RDONLY, S_IRUSR) ;
-  if (e) { errno = e ; strerr_diefu1sys(111, "posix_spawn_file_actions_addopen") ; }
-  e = posix_spawnp(&mypid, argv[0], &actions, &attr, (char *const *)argv, (char * const *)v) ;
-  if (e) { errno = e ; strerr_diefu2sys(111, "spawn ", argv[0]) ; }
-  posix_spawn_file_actions_destroy(&actions) ;
-  posix_spawnattr_destroy(&attr) ;
-  state = 1 ;
-  pid = mypid ;
-  tain_add_g(&deadline, &lifetto) ;
-}
-
-static inline void handle_timeout (void)
-{
-  switch (state)
-  {
-    case 0 :
-      tain_add_g(&deadline, &tain_infinite_relative) ;
-      break ;
-    case 1 :
-      kill(pid, SIGTERM) ;
-      tain_add_g(&deadline, &termtto) ;
-      state++ ;
-      break ;
-    case 2 :
-      kill(pid, SIGKILL) ;
-      tain_add_g(&deadline, &killtto) ;
-      state++ ;
-      break ;
-    case 3 :
-      strerr_dief1x(99, "child resisted SIGKILL - check your kernel logs.") ;
-    default :
-      strerr_dief1x(101, "internal error: inconsistent state. Please submit a bug-report.") ;
-  }
-}
-
-static inline void handle_signals (void)
-{
-  for (;;)
-  {
-    int c = selfpipe_read() ;
-    switch (c)
-    {
-      case -1 : strerr_diefu1sys(111, "selfpipe_read") ;
-      case 0 : return ;
-      case SIGCHLD :
-        if (!pid) wait_reap() ;
-        else
-        {
-          int wstat ;
-          int r = wait_pid_nohang(pid, &wstat) ;
-          if (r < 0)
-            if (errno != ECHILD) strerr_diefu1sys(111, "wait_pid_nohang") ;
-            else break ;
-          else if (!r) break ;
-          on_death() ;
-        }
-        break ;
-      default :
-        strerr_dief1x(101, "internal error: inconsistent signal handling. Please submit a bug-report.") ;
-    }
-  }
-}
-
-static inline void handle_stdin (stralloc *sa, char const *linevar, char const *const *argv, char const *const *envp)
-{
-  while (!pid)
-  {
-    size_t start ;
-    ssize_t r ;
-    if (!sa->len && linevar)
-      if (!stralloc_cats(sa, linevar) || !stralloc_catb(sa, "=", 1))
-        dienomem() ;
-    start = sa->len ;
-    r = sanitize_read(skagetln(buffer_0, sa, 0)) ;
-    if (r < 0)
-    {
-      cont = 0 ;
-      if (errno != EPIPE && verbosity) strerr_warnwu1sys("read from stdin") ;
-    }
-    if (r <= 0) break ;
-    if (sa->len == start + 1)
-    {
-      start = linevar ? 0 : strlen(sa->s) + 1 ;
-      if (start >= sa->len)
-      {
-        if (verbosity) strerr_warnw1x("read an empty event!") ;
-      }
-      else on_event(argv, envp, sa->s + start, sa->len - 1 - start) ;
-      sa->len = 0 ;
-    }
-  }
-}
-
-static inline int make_ttos (char const *s)
-{
-  size_t pos = 0 ;
-  unsigned int tlife = 0, tterm = 0, tkill = 0 ;
-  pos += uint_scan(s + pos, &tlife) ;
-  if (s[pos] && s[pos++] != ':') return 0 ;
-  if (!tlife) return 1 ;
-  tain_from_millisecs(&lifetto, tlife) ;
-  pos += uint_scan(s + pos, &tterm) ;
-  if (s[pos] && s[pos++] != ':') return 0 ;
-  if (!tterm) return 1 ;
-  tain_from_millisecs(&termtto, tterm) ;
-  tain_add(&termtto, &termtto, &lifetto) ;
-  pos += uint_scan(s + pos, &tkill) ;
-  if (s[pos]) return 0 ;
-  if (!tkill) return 1 ;
-  tain_from_millisecs(&killtto, tkill) ;
-  tain_add(&killtto, &killtto, &termtto) ;
-  return 1 ;
-}
-
-int main (int argc, char const *const *argv, char const *const *envp)
-{
-  iopause_fd x[2] = { { .events = IOPAUSE_READ }, { .fd = 0, .events = IOPAUSE_READ } } ;
-  char const *linevar = 0 ;
-  stralloc sa = STRALLOC_ZERO ;
-  PROG = "s6-uevent-spawner" ;
-  strerr_warnw1x("this program is deprecated, see https://skarnet.org/software/mdevd/") ;
-  {
-    subgetopt_t l = SUBGETOPT_ZERO ;
-    for (;;)
-    {
-      int opt = subgetopt_r(argc, argv, "l:v:t:", &l) ;
-      if (opt == -1) break ;
-      switch (opt)
-      {
-        case 'l' : linevar = l.arg ; break ;
-        case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ;
-        case 't' : if (!make_ttos(l.arg)) dieusage() ; break ;
-        default : dieusage() ;
-      }
-    }
-    argc -= l.ind ; argv += l.ind ;
-    if (!argc) strerr_dieusage(100, USAGE) ;
-  }
-  if (linevar && strchr(linevar, '='))
-    strerr_dief2x(100, "invalid variable: ", linevar) ;
-
-  if (ndelay_on(0) < 0) strerr_diefu1sys(111, "set stdin nonblocking") ;
-  x[0].fd = selfpipe_init() ;
-  if (x[0].fd == -1) strerr_diefu1sys(111, "init selfpipe") ;
-  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ;
-  if (selfpipe_trap(SIGCHLD) < 0) strerr_diefu1sys(111, "trap SIGCHLD") ;
-  if (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)
-    strerr_diefu1sys(111, "setenv PATH") ;
-
-  tain_now_g() ;
-  tain_add_g(&deadline, &tain_infinite_relative) ;
-  if (verbosity >= 2) strerr_warni1x("starting") ;
-
-  while (cont || pid)
-  {
-    int r ;
-    if (buffer_len(buffer_0))
-      handle_stdin(&sa, linevar, argv, envp) ;
-    r = iopause_g(x, 1 + (!pid && cont), &deadline) ;
-    if (r < 0) strerr_diefu1sys(111, "iopause") ;
-    else if (!r) handle_timeout() ;
-    else
-    {
-      if (x[0].revents & IOPAUSE_EXCEPT)
-        strerr_diefu1x(111, "iopause: trouble with selfpipe") ;
-      if (x[0].revents & IOPAUSE_READ)
-        handle_signals() ;
-      else if (cont && !pid && x[1].revents & IOPAUSE_READ)
-        handle_stdin(&sa, linevar, argv, envp) ;
-    }
-  }
-  if (verbosity >= 2) strerr_warni1x("exiting") ;
-  return 0 ;
-}