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

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

int s6rc_db_check_revdeps (s6rc_db_t const *db)
{
  unsigned int n = db->nshort + db->nlong ;
  unsigned int m = bitarray_div8(n) ;
  unsigned char matrix[n * m] ;
  register unsigned int i = n ;
  register unsigned char const *p = matrix ;
  byte_zero(matrix, n * m) ;
  while (i--)
  {
    register unsigned int j = db->services[i].ndeps[1] ;
    while (j--) bitarray_not(matrix + m * i, db->deps[db->ndeps + db->services[i].deps[1] + j], 1) ;
  }
  i = n ;
  while (i--)
  {
    register unsigned int j = db->services[i].ndeps[0] ;
    while (j--) bitarray_not(matrix + m * db->deps[db->services[i].deps[0] + j], i, 1) ;
  }
  i = n * m ;
  while (i--) if (*p++) return 0 ;
  return 1 ;
}