core: enforce that scope units can be started only once
Scope units are populated from PIDs specified by the bus client. We do that when a scope is started. We really shouldn't allow scopes to be started multiple times, as the PIDs then might be heavily out of date. Moreover, clients should have the guarantee that any scope they allocate has a clear runtime cycle which is not repetitive.
This commit is contained in:
@@ -1753,6 +1753,7 @@ static bool unit_verify_deps(Unit *u) {
|
||||
* -EINVAL: Unit not loaded
|
||||
* -EOPNOTSUPP: Unit type not supported
|
||||
* -ENOLINK: The necessary dependencies are not fulfilled.
|
||||
* -ESTALE: This unit has been started before and can't be started a second time
|
||||
*/
|
||||
int unit_start(Unit *u) {
|
||||
UnitActiveState state;
|
||||
@@ -1772,6 +1773,10 @@ int unit_start(Unit *u) {
|
||||
if (u->load_state != UNIT_LOADED)
|
||||
return -EINVAL;
|
||||
|
||||
/* Refuse starting scope units more than once */
|
||||
if (UNIT_VTABLE(u)->once_only && dual_timestamp_is_set(&u->inactive_enter_timestamp))
|
||||
return -ESTALE;
|
||||
|
||||
/* If the conditions failed, don't do anything at all. If we
|
||||
* already are activating this call might still be useful to
|
||||
* speed up activation in case there is some hold-off time,
|
||||
@@ -1835,6 +1840,10 @@ bool unit_can_start(Unit *u) {
|
||||
if (!unit_supported(u))
|
||||
return false;
|
||||
|
||||
/* Scope units may be started only once */
|
||||
if (UNIT_VTABLE(u)->once_only && dual_timestamp_is_set(&u->inactive_exit_timestamp))
|
||||
return false;
|
||||
|
||||
return !!UNIT_VTABLE(u)->start;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user