summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_db_check_pipelines.c
blob: 19f4993fb55bf7ba699ec01ee8481a5097590b06 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ISC license. */

#include <stdint.h>
#include <skalibs/diuint32.h>
#include <skalibs/bytestr.h>
#include <skalibs/bitarray.h>
#include <s6-rc/s6rc-db.h>

int s6rc_db_check_pipelines (s6rc_db_t const *db, diuint32 *problem)
{
  uint32_t i = db->nlong ;
  unsigned char black[bitarray_div8(db->nlong)] ;
  byte_zero(black, bitarray_div8(db->nlong)) ;
  while (i--) if (!bitarray_peek(black, i))
  {
    uint32_t j = i ;
    uint32_t start ;
    for (;;)
    {
      register uint32_t k = db->services[j].x.longrun.pipeline[0] ;
      if (k >= db->nlong) break ;
      if (k == i || bitarray_peek(black, k))
      {
        problem->left = i ;
        problem->right = k ;
        return 1 + (k == i) ;
      }
      j = k ;
    }
    start = j ;
    j = i ;
    for (;;)
    {
      register uint32_t k = db->services[j].x.longrun.pipeline[1] ;
      if (k >= db->nlong) break ;
      if (k == i || bitarray_peek(black, k))
      {
        problem->left = i ;
        problem->right = k ;
        return 1 + (k == i) ;
      }
      j = k ;
    }
    for (j = start ; j > db->nlong ; j = db->services[j].x.longrun.pipeline[1])
      bitarray_set(black, j) ;
  }
  return 0 ;
}