]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: introduce MANAGER_IS_SWITCHING_ROOT() helper function
authorFranck Bui <fbui@suse.com>
Thu, 5 May 2022 06:49:56 +0000 (08:49 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Aug 2022 13:13:43 +0000 (22:13 +0900)
Will be used by the following commit.

src/core/main.c
src/core/manager.c
src/core/manager.h

index fbbfd71ac8aacd82cc75de2ddc164609b677fd71..9ad3983b209b6e750ea749e9f876dafef8aafe0b 100644 (file)
@@ -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;
index 45f6dccf4a26201b0aa8938107f86976fdb8701a..1b59b0624d2dadf5af3c338e22f0f7b3d7d18dc8 100644 (file)
@@ -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;
 }
 
index 63cff7989d4380d4570e82d88aefb6b0395159ae..16d108c7ed50b463f641fd067c115e2b5b966516 100644 (file)
@@ -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);