Beispiel #1
0
static inline int check_targ (char const *s)
{
  unsigned int t = 0, pos = 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 ;
}
Beispiel #2
0
static void scanlist (genalloc *list, char const *s)
{
  register unsigned int i = 0 ;
  genalloc_setlen(diuint, list, 0) ;
  while (s[i])
  {
    char const sep[4] = ", \t" ;
    diuint iv ;
    if (s[i] == '-') iv.left = 1 ;
    else
    {
      unsigned int j = uint_scan(s+i, &iv.left) ;
      if (!j || !iv.left) strerr_dief2x(100, "invalid list argument: ", s) ;
      i += j ;
    }
    if (s[i] != '-') iv.right = iv.left ;
    else
    {
      unsigned int j = uint_scan(s + ++i, &iv.right) ;
      if (!j) iv.right = 0 ;
      else if (iv.right < iv.left)
        strerr_dief2x(100, "invalid list argument: ", s) ;
      else i += j ;
    }
    switch (byte_chr(sep, 4, s[i]))
    {
      case 0 :
      case 1 :
      case 2 : i++ ;
      case 3 : break ;
      case 4 :
        strerr_dief2x(100, "invalid list argument: ", s) ;
    }
    if (!genalloc_append(diuint, list, &iv))
      strerr_diefu1sys(111, "build interval list") ;
  }
}
Beispiel #3
0
static int
it_kill (direntry *d, void *data)
{
    stralloc *sa = data;
    char c;
    int l;
    int r;

    /* ignore files, not-number dirs, PID 1 and ourself */
    if (d->d_type != DT_DIR || *d->d_name < '1' || *d->d_name > '9'
            || str_equal (d->d_name, "1") || str_equal (d->d_name, ownpid))
        return 0;

    l = sa->len;
    sa->s[l - 1] = '/';
    if (stralloc_cats (sa, d->d_name)
            && stralloc_catb (sa, "/cmdline", sizeof ("/cmdline")))
        r = openreadnclose (sa->s, &c, 1);
    else
        r = -1;
    sa->len = l;
    sa->s[l - 1] = '\0';

    /* skip empty cmdline (kernel threads) and anything starting with '@' */
    if (r == 1 && c != '@')
    {
        unsigned int u;
        pid_t pid;

        if (!uint_scan (d->d_name, &u))
            goto done;
        pid = (pid_t) u;
        if (pid != u)
            goto done;
        if (send.hup)
            _kill (pid, SIGHUP);
        if (send.term)
        {
            _kill (pid, SIGTERM);
            _kill (pid, SIGCONT);
        }
        if (send.kill)
            _kill (pid, SIGKILL);
    }

done:
    return 0;
}
int netstring_get (buffer_ref b, stralloc *sa, unsigned int *unread)
{
  unsigned int written ;
  int ok = 1 ;
  int r ;
  if (!sa->s || (!sa->len && !*unread))
  {
    char *x ;
    unsigned int n ;
    unsigned int len ;
    for (;;)
    {
      x = buffer_PEEK(b) ;
      n = byte_chr(x, buffer_len(b), ':') ;  /* XXX: accepts :, as a valid netstring */
      if (n >= ULONG_FMT) return (errno = EINVAL, -1) ; /* XXX: breaks on too many leading '0's */
      if (n < buffer_len(b)) break ;
      r = buffer_fill(b) ;
      if (r == -1) return -1 ;
      if (!r) return (buffer_isempty(b) ? 0 : (errno = EPIPE, -1)) ;
      ok = 2 ;
    }
    if (n != uint_scan(x, &len)) return (errno = EINVAL, -1) ;
    if (!stralloc_readyplus(sa, len+1)) return -1 ;
    buffer_SEEK(b, n+1) ;
    *unread = len + 1 ;
  }
  written = sa->len ;
  r = buffer_getall(b, sa->s + sa->len, sa->len + *unread, &written) ;
  if (r <= 0)
  {
    *unread -= written - sa->len ;
    sa->len = written ;
    return r ? r : (errno = EINVAL, -1) ;
  }
  if (r == 2) ok = 2 ;
  sa->len += *unread ;
  *unread = 0 ;
  return (sa->s[--sa->len] == ',') ? ok : (errno = EINVAL, -1) ;
}
Beispiel #5
0
int el_popenv (stralloc *sa, char const *const *envp, unsigned int envlen, char const *const *list, unsigned int listlen)
{
  unsigned int i = 0, salen = sa->len, count = 0 ;
  for (; i < envlen ; i++)
  {
    unsigned int equal, colon, n ;
    unsigned int j = 0 ;
    for (; j < listlen ; j++) if (str_start(envp[i], list[j])) break ;
    if (j == listlen) goto copyit ;
    j = str_len(list[j]) ;
    colon = j + str_chr(envp[i] + j, ':') ;
    equal = j + str_chr(envp[i] + j, '=') ;
    if (!envp[i][equal]) goto badenv ;
    if (colon >= equal) { count++ ; continue ; }
    if (colon + 1 + uint_scan(envp[i] + colon + 1, &n) != equal) goto copyit ;
    if (!n) goto copyit ;
    if (!stralloc_catb(sa, envp[i], colon)) goto err ;
    if (n > 1)
    {
      char fmt[UINT_FMT+1] = ":" ;
      n = 1 + uint_fmt(fmt+1, n-1) ;
      if (!stralloc_catb(sa, fmt, n)) goto err ;
    }
    if (!stralloc_catb(sa, envp[i] + equal, str_len(envp[i] + equal) + 1)) goto err ;
    continue ;
copyit:
    if (!stralloc_catb(sa, envp[i], str_len(envp[i]) + 1)) goto err ;
  }
  return (int)count ;

badenv :
  errno = EINVAL ;
err:
  sa->len = salen ;
  return -1 ;
}