From 279d81dd46ae5fc58d5466cdec3e6c59b79d0269 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Dec 2017 23:24:00 +0100 Subject: [PATCH 1/3] manager: split out code that sets up run_queue event source into function of its own Let's shorten manager_new() a bit. --- src/core/manager.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index be44ab3778..de0a719a65 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -603,6 +603,29 @@ static int manager_setup_prefix(Manager *m) { return 0; } +static int manager_setup_run_queue(Manager *m) { + int r; + + assert(m); + assert(!m->run_queue_event_source); + + r = sd_event_add_defer(m->event, &m->run_queue_event_source, manager_dispatch_run_queue, m); + if (r < 0) + return r; + + r = sd_event_source_set_priority(m->run_queue_event_source, SD_EVENT_PRIORITY_IDLE); + if (r < 0) + return r; + + r = sd_event_source_set_enabled(m->run_queue_event_source, SD_EVENT_OFF); + if (r < 0) + return r; + + (void) sd_event_source_set_description(m->run_queue_event_source, "manager-run-queue"); + + return 0; +} + int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { Manager *m; int r; @@ -687,20 +710,10 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { if (r < 0) goto fail; - r = sd_event_add_defer(m->event, &m->run_queue_event_source, manager_dispatch_run_queue, m); + r = manager_setup_run_queue(m); if (r < 0) goto fail; - r = sd_event_source_set_priority(m->run_queue_event_source, SD_EVENT_PRIORITY_IDLE); - if (r < 0) - goto fail; - - r = sd_event_source_set_enabled(m->run_queue_event_source, SD_EVENT_OFF); - if (r < 0) - goto fail; - - (void) sd_event_source_set_description(m->run_queue_event_source, "manager-run-queue"); - r = manager_setup_signals(m); if (r < 0) goto fail; From 5eb397cfad05382c282cef3470b55c23b6d3d27c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Dec 2017 23:24:29 +0100 Subject: [PATCH 2/3] manager: don't bother with creating /run/systemd/units/ in test mode This makes sure running "systemd --test" works again on systems running older systemd versions where the dir doesn't exist yet. --- src/core/manager.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index de0a719a65..3f92ac3948 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -732,7 +732,7 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { goto fail; } - if (MANAGER_IS_SYSTEM(m)) { + if (MANAGER_IS_SYSTEM(m) && test_run_flags == 0) { r = mkdir_label("/run/systemd/units", 0755); if (r < 0 && r != -EEXIST) goto fail; @@ -740,7 +740,6 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { /* Note that we do not set up the notify fd here. We do that after deserialization, * since they might have gotten serialized across the reexec. */ - m->taint_usr = dir_is_empty("/usr") > 0; r = manager_setup_prefix(m); From e27fe688f2d2dfa2ccc013d3ad0c7db53a97f142 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Dec 2017 11:09:09 +0100 Subject: [PATCH 3/3] manager: don't check /usr state of initrd to determine "taint-usr" taint --- src/core/manager.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index 3f92ac3948..063c04c3ff 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -732,19 +732,22 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { goto fail; } + r = manager_setup_prefix(m); + if (r < 0) + goto fail; + if (MANAGER_IS_SYSTEM(m) && test_run_flags == 0) { r = mkdir_label("/run/systemd/units", 0755); if (r < 0 && r != -EEXIST) goto fail; } + m->taint_usr = + !in_initrd() && + dir_is_empty("/usr") > 0; + /* Note that we do not set up the notify fd here. We do that after deserialization, * since they might have gotten serialized across the reexec. */ - m->taint_usr = dir_is_empty("/usr") > 0; - - r = manager_setup_prefix(m); - if (r < 0) - goto fail; *_m = m; return 0;