From: Lennart Poettering Date: Wed, 28 Nov 2018 11:37:43 +0000 (+0100) Subject: mount: make sure mount_add_extras() is always invoked when we load a mount unit X-Git-Tag: v240~112^2~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=780ae0221a3ad8e149eb4397c0ea2a549557f064;p=thirdparty%2Fsystemd.git mount: make sure mount_add_extras() is always invoked when we load a mount unit We need to make sure that the slice property is initialized whenever mount_load() is invoked, even if we fail to load things properly off disk. This is important since we generally don't allow changing the slice after a unit has been started. But given that we must track the state of external objects with mount units we must hence initialize the property no matter what. --- diff --git a/src/core/mount.c b/src/core/mount.c index cfce01417e1..ce66c31a202 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -616,28 +616,33 @@ static int mount_load_root_mount(Unit *u) { static int mount_load(Unit *u) { Mount *m = MOUNT(u); - int r; + int r, q, w; assert(u); assert(u->load_state == UNIT_STUB); r = mount_load_root_mount(u); - if (r < 0) - return r; if (m->from_proc_self_mountinfo || u->perpetual) - r = unit_load_fragment_and_dropin_optional(u); + q = unit_load_fragment_and_dropin_optional(u); else - r = unit_load_fragment_and_dropin(u); + q = unit_load_fragment_and_dropin(u); + + /* 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; + if (r < 0) return r; - - /* This is a new unit? Then let's add in some extras */ - if (u->load_state == UNIT_LOADED) { - r = mount_add_extras(m); - if (r < 0) - return r; - } + if (q < 0) + return q; + if (w < 0) + return w; return mount_verify(m); }