1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 16:21:26 +03:00

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.
This commit is contained in:
Lennart Poettering 2015-04-30 01:29:00 +02:00
parent 524d896ac1
commit 1c2e9646e4
7 changed files with 26 additions and 12 deletions

View File

@ -1012,11 +1012,9 @@ static void automount_reset_failed(Unit *u) {
a->result = AUTOMOUNT_SUCCESS;
}
static bool automount_supported(Manager *m) {
static bool automount_supported(void) {
static int supported = -1;
assert(m);
if (supported < 0)
supported = access("/dev/autofs", F_OK) >= 0;

View File

@ -984,9 +984,8 @@ static int busname_get_timeout(Unit *u, uint64_t *timeout) {
return 1;
}
static bool busname_supported(Manager *m) {
static bool busname_supported(void) {
static int supported = -1;
assert(m);
if (supported < 0)
supported = access("/sys/fs/kdbus", F_OK) >= 0;

View File

@ -750,9 +750,8 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
return 0;
}
static bool device_supported(Manager *m) {
static bool device_supported(void) {
static int read_only = -1;
assert(m);
/* If /sys is read-only we don't support device units, and any
* attempts to start one should fail immediately. */

View File

@ -975,7 +975,7 @@ int manager_enumerate(Manager *m) {
for (c = 0; c < _UNIT_TYPE_MAX; c++) {
int q;
if (unit_vtable[c]->supported && !unit_vtable[c]->supported(m)) {
if (!unit_type_supported(c)) {
log_debug("Unit type .%s is not supported on this system.", unit_type_to_string(c));
continue;
}

View File

@ -1407,7 +1407,7 @@ static int swap_get_timeout(Unit *u, uint64_t *timeout) {
return 1;
}
static bool swap_supported(Manager *m) {
static bool swap_supported(void) {
static int supported = -1;
/* If swap support is not available in the kernel, or we are

View File

@ -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",

View File

@ -402,7 +402,7 @@ struct UnitVTable {
/* If this function is set and return false all jobs for units
* of this type will immediately fail. */
bool (*supported)(Manager *m);
bool (*supported)(void);
/* The interface name */
const char *bus_interface;
@ -601,6 +601,12 @@ int unit_make_transient(Unit *u);
int unit_require_mounts_for(Unit *u, const char *path);
bool unit_type_supported(UnitType t);
static inline bool unit_supported(Unit *u) {
return unit_type_supported(u->type);
}
const char *unit_active_state_to_string(UnitActiveState i) _const_;
UnitActiveState unit_active_state_from_string(const char *s) _pure_;