summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_db_check_pipelines.c
blob: d3d1bd9c26b595d26b6487e08dc755bb82d7b386 (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
/* ISC license. */

#include <string.h>
#include <stdint.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)] ;
  memset(black, 0, bitarray_div8(db->nlong)) ;
  while (i--) if (!bitarray_peek(black, i))
  {
    uint32_t j = i ;
    uint32_t start ;
    for (;;)
    {
      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 (;;)
    {
      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 ;
}