summaryrefslogtreecommitdiff
path: root/src/server/deps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/deps.c')
-rw-r--r--src/server/deps.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/src/server/deps.c b/src/server/deps.c
index 12e0fb6..b1a1fd4 100644
--- a/src/server/deps.c
+++ b/src/server/deps.c
@@ -15,7 +15,7 @@ static int state_allownext (sstate_t const *st, uint8_t deptype, uint8_t subtype
|| (s6rc_deptype_loose(deptype) && !(st->bits & SSTATE_TRANSITIONING))
}
-static int instances_alldown (mstate_t const *m, uint8_t deptype, uint8_t type, uint32_t num)
+static int instances_testalldown (mstate_t const *m, uint8_t deptype, uint8_t type, uint32_t num)
{
instance_t const *ins = genalloc_s(instance_t, m->dyn[type] + num) ;
size_t n = genalloc_len(instance_t, m->dyn[type] + num) ;
@@ -38,7 +38,7 @@ int deps_fulfilled (s6rc_db_t const *db, mstate_t const *m, uint32_t id, char co
uint8_t deptype = db->deptypes[h][common->deps[h] + i] ;
s6rc_service_typenum(db->n, db->deps[h][common->deps[h] + i], &subtype, &subnum) ;
if (!h && type < S6RC_STYPE_N && subtype >= S6RC_STYPE_N)
- return instances_alldown(m, deptype, subtype, subnum) ;
+ return instances_testalldown(m, deptype, subtype, subnum) ;
if (h && type >= S6RC_STYPE_N && subtype < S6RC_STYPE_N)
param = 0 ;
if (!state_allownext(sstate_tn(m, subtype, subnum, param), deptype, subtype, h))
@@ -47,18 +47,6 @@ int deps_fulfilled (s6rc_db_t const *db, mstate_t const *m, uint32_t id, char co
return 1 ;
}
-static int sstate_zerotmp (sstate_t *st, void *arg)
-{
- st->tmp = 0 ;
- (void)arg ;
- return 1 ;
-}
-
-static int instance_zerotmp (instance_t *ins, void *arg)
-{
- return sstate_zerotmp(&ins->sstate) ;
-}
-
typedef struct recinfo_s recinfo_t, *recinfo_t_ref ;
struct recinfo_s
{
@@ -66,37 +54,70 @@ struct recinfo_s
mstate_t *m ;
char const *param ;
uint8_t h : 1 ;
+ uint8_t force : 1 ;
}
-static int mstate_dep_closure_rec (recinfo_t *recinfo, uint32_t id)
+static int mstate_dep_closure_rec (recinfo_t *recinfo, uint32_t id, char const *param)
{
- sstate_t *st = sstate(recinfo->db, recinfo->m, id, recinfo->param) ;
+ sstate_t *st ;
+ st = sstate(recinfo->db, recinfo->m, id, param) ;
if (!st)
{
- st = instance_create(recinfo->m, id, recinfo->param) ;
+ if (!recinfo->h) return 1 ;
+ st = instance_create(recinfo->m, id, param) ;
if (!st) return 0 ;
}
- if (!(st->tmp & SSTATE_GRAY))
+ if (!(st->tmp & SSTATE_TRANSITIONING))
{
- uint32_t ndeps = re
+ s6rc_common_t const *common ;
+ uint32_t num ;
+ uint8_t type ;
+ st->tmp |= SSTATE_TRANSITIONING ;
+ s6rc_service_typenum(recinfo->db->n, id, &type, &num) ;
+ common = s6rc_service_common_tn(recinfo->db, type, num) ;
+ if (!recinfo->h && !recinfo->force && common->flags & S6RC_DB_FLAG_ESSENTIAL) return (errno = EPERM, 0) ;
+ for (uint32_t i = 0 ; i < common->ndeps[recinfo->h] ; i++)
+ {
+ uint32_t subid = recinfo->db->deps[recinfo->h][common->deps[recinfo->h] + i] ;
+ uint32_t subnum ;
+ uint8_t subtype ;
+ if (s6rc_service_recheck_instance(recinfo->db, &subid, &param) < 0) return (errno = EPROTO, 0) ;
+ if (deptype_passive(recinfo->db->deptypes[recinfo->h][common->deps[recinfo->h] + i])) continue ;
+ s6rc_service_typenum(recinfo->db->n, subid, &subtype, &subnum) ;
+ if (!recinfo->h && type < S6RC_STYPE_N && subtype >= S6RC_STYPE_N)
+ {
+ instance_t const *ins = genalloc_s(instance_t, recinfo->m->dyn[subtype] + subnum) ;
+ size_t n = genalloc_len(instance_t, recinfo->m->dyn[subtype] + subnum) ;
+ for (size_t j = 0 ; j < n ; j++)
+ if (!mstate_dep_closure_rec(recinfo, subid, ins[j].param)) return 0 ;
+ }
+ else
+ {
+ if (recinfo->h && type >= S6RC_STYPE_N && subtype < S6RC_STYPE_N)
+ param = 0 ;
+ if (!mstate_dep_closure_rec(recinfo, subid, param))
+ return 0 ;
+ }
+ }
+ st->tmp |= SSTATE_WANTED ;
}
}
-static void mstate_dep_closure (s6rc_db_t const *db, mstate_t *m, sstate_t *st, char const *param, int h)
+static void mstate_dep_closure (s6rc_db_t const *db, mstate_t *m, sstate_t *st, char const *param, int h, int force)
{
- recinfo_t recinfo = { .db = db, .m = m, .param = param, .h = !!h } ;
+ recinfo_t recinfo = { .db = db, .m = m, .param = param, .h = !!h, .force = !!force } ;
mstate_dep_closure_rec(&recinfo, st) ;
}
-int mstate_change_wanted (s6rc_db_t const *db, cdb_t *c, mstate_t *m, char const *const *args, size_t n, int h)
+int mstate_change_wanted (s6rc_db_t const *db, mstate_t *m, char const *const *args, size_t n, int h, int force)
{
- mstate_iterate(m, db->n, &sstate_zerotmp, &instancelen_nop, &instance_zerotmp, 0) ;
+ mstate_zerotmp(m, db->n) ;
for (size_t i = 0 ; i < n ; n++)
{
sstate_t *st ;
uint32_t id ;
char const *param ;
- int r = s6rc_service_resolve(c, args[i], &id, &param) ;
+ int r = s6rc_service_resolve(&db->resolve, args[i], &id, &param) ;
if (r < 0) return -1 ;
if (!r) return 1 + i ;
st = sstate(db, m, id, param) ;
@@ -105,7 +126,7 @@ int mstate_change_wanted (s6rc_db_t const *db, cdb_t *c, mstate_t *m, char const
st = instance_create(m, id, param) ;
if (!st) return -1 ;
}
- st->tmp |= SSTATE_MARK | SSTATE_EXPLICIT ;
+ st->tmp |= SSTATE_WANTED | SSTATE_EXPLICIT ;
mstate_dep_closure(db, m, st, param, h) ;
}
}