summaryrefslogtreecommitdiff
path: root/src/libexecline/el_forx_pidinfo.c
blob: 61c5a26922ad9303979749fff5c0a03b798f9914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* ISC license. */

#include <skalibs/djbunix.h>

#include <execline/execline.h>

el_forx_pidinfo_t *el_forx_pidinfo = 0 ;

int el_forx_isok (unsigned short const *tab, unsigned int n, unsigned short code)
{
  unsigned int i = 0 ;
  for (; i < n ; i++) if (code == tab[i]) break ;
  return i < n ;
}

void el_forx_sigchld_handler (int sig)
{
  for (;;)
  {
    ssize_t r = wait_pids_nohang(el_forx_pidinfo->tab, el_forx_pidinfo->len, &el_forx_pidinfo->wstat) ;
    if (r <= 0) break ;
    el_forx_pidinfo->tab[r-1] = el_forx_pidinfo->tab[--el_forx_pidinfo->len] ;
  }
  (void)sig ;
}