int r;
assert(a);
-
- if (UNIT(a)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(a)->load_state == UNIT_LOADED);
if (path_equal(a->where, "/")) {
log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing.");
return 1;
}
+static int automount_add_extras(Automount *a) {
+ int r;
+
+ r = automount_set_where(a);
+ if (r < 0)
+ return r;
+
+ r = automount_add_trigger_dependencies(a);
+ if (r < 0)
+ return r;
+
+ r = automount_add_mount_dependencies(a);
+ if (r < 0)
+ return r;
+
+ return automount_add_default_dependencies(a);
+}
+
static int automount_load(Unit *u) {
Automount *a = AUTOMOUNT(u);
int r;
if (r < 0)
return r;
- if (u->load_state == UNIT_LOADED) {
- r = automount_set_where(a);
- if (r < 0)
- return r;
-
- r = automount_add_trigger_dependencies(a);
- if (r < 0)
- return r;
-
- r = automount_add_mount_dependencies(a);
- if (r < 0)
- return r;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- r = automount_add_default_dependencies(a);
- if (r < 0)
- return r;
- }
+ r = automount_add_extras(a);
+ if (r < 0)
+ return r;
return automount_verify(a);
}
int r;
assert(m);
-
- if (UNIT(m)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(m)->load_state == UNIT_LOADED);
if (!m->from_fragment && !m->from_proc_self_mountinfo && !UNIT(m)->perpetual)
return -ENOENT;
return 0;
}
-static int mount_load_root_mount(Unit *u) {
+static void mount_load_root_mount(Unit *u) {
assert(u);
if (!unit_has_name(u, SPECIAL_ROOT_MOUNT))
- return 0;
+ return;
u->perpetual = true;
u->default_dependencies = false;
if (!u->description)
u->description = strdup("Root Mount");
-
- return 1;
}
static int mount_load(Unit *u) {
Mount *m = MOUNT(u);
- int r, q, w;
+ int r, q = 0;
assert(u);
assert(u->load_state == UNIT_STUB);
- r = mount_load_root_mount(u);
+ mount_load_root_mount(u);
bool fragment_optional = m->from_proc_self_mountinfo || u->perpetual;
- q = unit_load_fragment_and_dropin(u, !fragment_optional);
+ r = unit_load_fragment_and_dropin(u, !fragment_optional);
/* Add in some extras. Note we do this in all cases (even if we failed to load the unit) when announced by the
* kernel, because we need some things to be set up no matter what when the kernel establishes a mount and thus
* we need to update the state in our unit to track it. After all, consider that we don't allow changing the
* 'slice' field for a unit once it is active. */
if (u->load_state == UNIT_LOADED || m->from_proc_self_mountinfo || u->perpetual)
- w = mount_add_extras(m);
- else
- w = 0;
+ q = mount_add_extras(m);
if (r < 0)
return r;
if (q < 0)
return q;
- if (w < 0)
- return w;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
return mount_verify(m);
}
static int path_verify(Path *p) {
assert(p);
-
- if (UNIT(p)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(p)->load_state == UNIT_LOADED);
if (!p->specs) {
log_unit_error(UNIT(p), "Path unit lacks path setting. Refusing.");
return unit_add_two_dependencies(UNIT(p), UNIT_BEFORE, UNIT_TRIGGERS, x, true, UNIT_DEPENDENCY_IMPLICIT);
}
+static int path_add_extras(Path *p) {
+ int r;
+
+ r = path_add_trigger_dependencies(p);
+ if (r < 0)
+ return r;
+
+ r = path_add_mount_dependencies(p);
+ if (r < 0)
+ return r;
+
+ return path_add_default_dependencies(p);
+}
+
static int path_load(Unit *u) {
Path *p = PATH(u);
int r;
if (r < 0)
return r;
- if (u->load_state == UNIT_LOADED) {
-
- r = path_add_trigger_dependencies(p);
- if (r < 0)
- return r;
-
- r = path_add_mount_dependencies(p);
- if (r < 0)
- return r;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- r = path_add_default_dependencies(p);
- if (r < 0)
- return r;
- }
+ r = path_add_extras(p);
+ if (r < 0)
+ return r;
return path_verify(p);
}
static int scope_verify(Scope *s) {
assert(s);
-
- if (UNIT(s)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(s)->load_state == UNIT_LOADED);
if (set_isempty(UNIT(s)->pids) &&
!MANAGER_IS_RELOADING(UNIT(s)->manager) &&
return 1;
}
+static int scope_add_extras(Scope *s) {
+ int r;
+
+ r = unit_patch_contexts(UNIT(s));
+ if (r < 0)
+ return r;
+
+ r = unit_set_default_slice(UNIT(s));
+ if (r < 0)
+ return r;
+
+ return scope_add_default_dependencies(s);
+}
+
static int scope_load(Unit *u) {
Scope *s = SCOPE(u);
int r;
if (r < 0)
return r;
- if (u->load_state == UNIT_LOADED) {
- r = unit_patch_contexts(u);
- if (r < 0)
- return r;
-
- r = unit_set_default_slice(u);
- if (r < 0)
- return r;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- r = scope_add_default_dependencies(s);
- if (r < 0)
- return r;
- }
+ r = scope_add_extras(s);
+ if (r < 0)
+ return r;
return scope_verify(s);
}
int r;
assert(s);
-
- if (UNIT(s)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(s)->load_state == UNIT_LOADED);
if (!slice_name_is_valid(UNIT(s)->id)) {
log_unit_error(UNIT(s), "Slice name %s is not valid. Refusing.", UNIT(s)->id);
if (r < 0)
return r;
- /* This is a new unit? Then let's add in some extras */
- if (u->load_state == UNIT_LOADED) {
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- r = unit_patch_contexts(u);
- if (r < 0)
- return r;
+ /* This is a new unit? Then let's add in some extras */
+ r = unit_patch_contexts(u);
+ if (r < 0)
+ return r;
- r = slice_add_parent_slice(s);
- if (r < 0)
- return r;
+ r = slice_add_parent_slice(s);
+ if (r < 0)
+ return r;
- r = slice_add_default_dependencies(s);
- if (r < 0)
- return r;
- }
+ r = slice_add_default_dependencies(s);
+ if (r < 0)
+ return r;
return slice_verify(s);
}
static int socket_verify(Socket *s) {
assert(s);
-
- if (UNIT(s)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(s)->load_state == UNIT_LOADED);
if (!s->ports) {
log_unit_error(UNIT(s), "Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.");
if (r < 0)
return r;
- if (u->load_state == UNIT_LOADED) {
- /* This is a new unit? Then let's add in some extras */
- r = socket_add_extras(s);
- if (r < 0)
- return r;
- }
+ if (u->load_state != UNIT_LOADED)
+ return 0;
+
+ /* This is a new unit? Then let's add in some extras */
+ r = socket_add_extras(s);
+ if (r < 0)
+ return r;
return socket_verify(s);
}
_cleanup_free_ char *e = NULL;
int r;
- if (UNIT(s)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(s)->load_state == UNIT_LOADED);
r = unit_name_from_path(s->what, ".swap", &e);
if (r < 0)
static int swap_load(Unit *u) {
Swap *s = SWAP(u);
- int r, q;
+ int r, q = 0;
assert(s);
assert(u->load_state == UNIT_STUB);
bool fragment_optional = s->from_proc_swaps;
r = unit_load_fragment_and_dropin(u, !fragment_optional);
- /* Add in some extras, and do so either when we successfully loaded something or when /proc/swaps is already
- * active. */
+ /* Add in some extras, and do so either when we successfully loaded something or when /proc/swaps is
+ * already active. */
if (u->load_state == UNIT_LOADED || s->from_proc_swaps)
q = swap_add_extras(s);
- else
- q = 0;
if (r < 0)
return r;
if (q < 0)
return q;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
return swap_verify(s);
}
if (r < 0)
return r;
- /* This is a new unit? Then let's add in some extras */
- if (u->load_state == UNIT_LOADED) {
- r = target_add_default_dependencies(t);
- if (r < 0)
- return r;
- }
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- return 0;
+ /* This is a new unit? Then let's add in some extras */
+ return target_add_default_dependencies(t);
}
static int target_coldplug(Unit *u) {
static int timer_verify(Timer *t) {
assert(t);
-
- if (UNIT(t)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(t)->load_state == UNIT_LOADED);
if (!t->values && !t->on_clock_change && !t->on_timezone_change) {
log_unit_error(UNIT(t), "Timer unit lacks value setting. Refusing.");
if (r < 0)
return r;
- if (u->load_state == UNIT_LOADED) {
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- r = timer_add_trigger_dependencies(t);
- if (r < 0)
- return r;
+ /* This is a new unit? Then let's add in some extras */
+ r = timer_add_trigger_dependencies(t);
+ if (r < 0)
+ return r;
- r = timer_setup_persistent(t);
- if (r < 0)
- return r;
+ r = timer_setup_persistent(t);
+ if (r < 0)
+ return r;
- r = timer_add_default_dependencies(t);
- if (r < 0)
- return r;
- }
+ r = timer_add_default_dependencies(t);
+ if (r < 0)
+ return r;
return timer_verify(t);
}