diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-07-09 08:13:55 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-07-09 08:13:55 +0000 |
| commit | 6209d961fd35c1d4e92d26c76a8ba0e98f1a6415 (patch) | |
| tree | c81dd76930b52f5010e1a55a7906b0f3b28bb662 /src/libs6rc | |
| parent | 50f4e65aa2776e0916ad90130dcd28043154dfd5 (diff) | |
| download | s6-rc-6209d961fd35c1d4e92d26c76a8ba0e98f1a6415.tar.gz | |
Add -c|--clean option to s6-rc (untested)
Diffstat (limited to 'src/libs6rc')
| -rw-r--r-- | src/libs6rc/deps-lib/s6rc | 1 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_graph_clean.c | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc index 9f677f7..f1a8370 100644 --- a/src/libs6rc/deps-lib/s6rc +++ b/src/libs6rc/deps-lib/s6rc @@ -5,6 +5,7 @@ s6rc_db_read.o s6rc_db_read_sizes.o s6rc_db_read_uint32.o s6rc_graph_closure.o +s6rc_graph_clean.o s6rc_live_state_size.o s6rc_live_state_read.o s6rc_livedir_canon.o diff --git a/src/libs6rc/s6rc_graph_clean.c b/src/libs6rc/s6rc_graph_clean.c new file mode 100644 index 0000000..d450d65 --- /dev/null +++ b/src/libs6rc/s6rc_graph_clean.c @@ -0,0 +1,42 @@ +/* ISC license. */ + +#include <stdint.h> + +#include <skalibs/bitarray.h> + +#include <s6-rc/s6rc-db.h> +#include <s6-rc/s6rc-utils.h> + +typedef struct recinfo_s recinfo_t, *recinfo_t_ref ; +struct recinfo_s +{ + s6rc_db_t const *db ; + unsigned char *bits ; + unsigned char statemask ; + unsigned char volmask ; + unsigned char resmask ; +} ; + +static void s6rc_graph_clean_rec (recinfo_t *info, uint32_t i) +{ + if (!(info->bits[i] & info->volmask)) + { + uint32_t j = 0 ; + for (; j < info->db->services[i].ndeps[0] ; j++) + if (info->bits[j] & info->statemask && !(info->bits[j] & info->resmask)) break ; + if (j >= info->db->services[i].ndeps[0]) + { + info->bits[i] |= info->resmask ; + for (j = 0 ; j < info->db->services[i].ndeps[1] ; j++) + s6rc_graph_clean_rec(info, info->db->deps[info->db->ndeps + info->db->services[i].deps[1] + j]) ; + } + } +} + +void s6rc_graph_clean (s6rc_db_t const *db, unsigned char *bits, unsigned int statebit, unsigned int volbit, unsigned int resbit) +{ + uint32_t n = db->nshort + db->nlong ; + recinfo_t info = { .db = db, .bits = bits, .statemask = 1 << statebit, .volmask = 1 << volbit, .resmask = 1 << resbit } ; + for (uint32_t i = 0 ; i < n ; i++) bits[i] &= ~info.resmask ; + for (uint32_t i = 0 ; i < n ; i++) if (bits[i] & info.statemask) s6rc_graph_clean_rec(&info, i) ; +} |
