From: Franck Bui Date: Thu, 5 May 2022 06:49:56 +0000 (+0200) Subject: core: introduce MANAGER_IS_SWITCHING_ROOT() helper function X-Git-Tag: v252-rc1~506^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d35fe8c0afaa55441608cb7bbfa4af908e1ea8e3;p=thirdparty%2Fsystemd.git core: introduce MANAGER_IS_SWITCHING_ROOT() helper function Will be used by the following commit. --- diff --git a/src/core/main.c b/src/core/main.c index fbbfd71ac8a..9ad3983b209 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1966,6 +1966,8 @@ static int invoke_main_loop( return objective; case MANAGER_SWITCH_ROOT: + manager_set_switching_root(m, true); + if (!m->switch_root_init) { r = prepare_reexecute(m, &arg_serialization, ret_fds, true); if (r < 0) { @@ -2943,6 +2945,7 @@ int main(int argc, char *argv[]) { set_manager_defaults(m); set_manager_settings(m); manager_set_first_boot(m, first_boot); + manager_set_switching_root(m, arg_switched_root); /* Remember whether we should queue the default job */ queue_default_job = !arg_serialization || arg_switched_root; diff --git a/src/core/manager.c b/src/core/manager.c index 45f6dccf4a2..1b59b0624d2 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -807,6 +807,10 @@ static int manager_find_credentials_dirs(Manager *m) { return 0; } +void manager_set_switching_root(Manager *m, bool switching_root) { + m->switching_root = MANAGER_IS_SYSTEM(m) && switching_root; +} + int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager **_m) { _cleanup_(manager_freep) Manager *m = NULL; int r; @@ -1872,6 +1876,8 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds, const char *roo manager_ready(m); + manager_set_switching_root(m, false); + return 0; } diff --git a/src/core/manager.h b/src/core/manager.h index 63cff7989d4..16d108c7ed5 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -406,6 +406,9 @@ struct Manager { char *switch_root; char *switch_root_init; + /* This is true before and after switching root. */ + bool switching_root; + /* This maps all possible path prefixes to the units needing * them. It's a hashmap with a path string as key and a Set as * value where Unit objects are contained. */ @@ -476,6 +479,8 @@ static inline usec_t manager_default_timeout_abort_usec(Manager *m) { /* The objective is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */ #define MANAGER_IS_RUNNING(m) ((m)->objective == MANAGER_OK) +#define MANAGER_IS_SWITCHING_ROOT(m) ((m)->switching_root) + #define MANAGER_IS_TEST_RUN(m) ((m)->test_run_flags != 0) int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager **m); @@ -541,6 +546,7 @@ void manager_set_show_status(Manager *m, ShowStatus mode, const char *reason); void manager_override_show_status(Manager *m, ShowStatus mode, const char *reason); void manager_set_first_boot(Manager *m, bool b); +void manager_set_switching_root(Manager *m, bool switching_root); void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) _printf_(4,5);