コード例 #1
0
ファイル: s6rc_read_uint.c プロジェクト: skarnet/s6-rc
int s6rc_read_uint (char const *file, unsigned int *u)
{
  char buf[UINT_FMT + 1] ;
  register int r = openreadnclose(file, buf, UINT_FMT) ;
  if (r < 0) return (errno == ENOENT) ? 0 : -1 ;
  buf[byte_chr(buf, r, '\n')] = 0 ;
  if (!uint0_scan(buf, u)) return (errno = EINVAL, -1) ;
  return 1 ;
}
コード例 #2
0
ファイル: aa-kill.c プロジェクト: linsam/anopa
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;
}