diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-30 01:29:00 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-30 01:29:00 +0200 |
commit | 1c2e9646e4a1720fc8ad35c705c195ae1a2c5ce0 (patch) | |
tree | 3d7f61210c0b45fb1f1fa61629c2b5825a0c43e9 /src/core/unit.c | |
parent | 524d896ac17518b824b2c94b3b0b2a23c23da08f (diff) |
core: simplify unit type detection logic
Introduce a new call unit_type_supported() and make use of it
everywhere.
Also, drop Manager parameter from per-type supported method prototype.
Diffstat (limited to 'src/core/unit.c')
-rw-r--r-- | src/core/unit.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/core/unit.c b/src/core/unit.c index 7ef8dbbf48..6071bd51b1 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1448,7 +1448,7 @@ int unit_start(Unit *u) { return unit_start(following); } - if (UNIT_VTABLE(u)->supported && !UNIT_VTABLE(u)->supported(u->manager)) + if (!unit_supported(u)) return -EOPNOTSUPP; /* If it is stopped, but we cannot start it, then fail */ @@ -2855,7 +2855,7 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) { /* When device units aren't supported (such as in a * container), don't create dependencies on them. */ - if (unit_vtable[UNIT_DEVICE]->supported && !unit_vtable[UNIT_DEVICE]->supported(u->manager)) + if (!unit_type_supported(UNIT_DEVICE)) return 0; e = unit_name_from_path(what, ".device"); @@ -3690,6 +3690,18 @@ int unit_setup_exec_runtime(Unit *u) { return exec_runtime_make(rt, unit_get_exec_context(u), u->id); } +bool unit_type_supported(UnitType t) { + if (_unlikely_(t < 0)) + return false; + if (_unlikely_(t >= _UNIT_TYPE_MAX)) + return false; + + if (!unit_vtable[t]->supported) + return true; + + return unit_vtable[t]->supported(); +} + static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = { [UNIT_ACTIVE] = "active", [UNIT_RELOADING] = "reloading", |