chiark / gitweb /
core: rearrange if blocks a bit
[elogind.git] / src / core / main.c
index 1d188e0bfe349a4b35952b38e80bdb0ef2af894e..749397578abd2be949ed30503c20f5546ad8dc47 100644 (file)
@@ -1055,15 +1055,16 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
         assert(_f);
         assert(_fds);
 
-        /* Make sure nothing is really destructed when we shut down */
-        m->n_reloading ++;
-
         r = manager_open_serialization(m, &f);
         if (r < 0) {
                 log_error("Failed to create serialization file: %s", strerror(-r));
                 goto fail;
         }
 
+        /* Make sure nothing is really destructed when we shut down */
+        m->n_reloading ++;
+        bus_broadcast_reloading(m, true);
+
         fds = fdset_new();
         if (!fds) {
                 r = -ENOMEM;
@@ -1514,12 +1515,7 @@ int main(int argc, char *argv[]) {
 
                 /* All other variables are left as is, so that clients
                  * can still read them via /proc/1/environ */
-        }
 
-        /* Move out of the way, so that we won't block unmounts */
-        assert_se(chdir("/")  == 0);
-
-        if (arg_running_as == SYSTEMD_SYSTEM) {
                 /* Become a session leader if we aren't one yet. */
                 setsid();
 
@@ -1527,6 +1523,9 @@ int main(int argc, char *argv[]) {
                 umask(0);
         }
 
+        /* Move out of the way, so that we won't block unmounts */
+        assert_se(chdir("/")  == 0);
+
         /* Make sure D-Bus doesn't fiddle with the SIGPIPE handlers */
         dbus_connection_set_change_sigpipe(FALSE);
 
@@ -1942,9 +1941,11 @@ finish:
                         watchdog_close(true);
                 }
 
-                /* avoid the creation of new processes forked by the kernel; at this
-                 * point, we will not listen to the signals anyway */
-                cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER);
+                /* Avoid the creation of new processes forked by the
+                 * kernel; at this point, we will not listen to the
+                 * signals anyway */
+                if (detect_container(NULL) <= 0)
+                        cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER);
 
                 execve(SYSTEMD_SHUTDOWN_BINARY_PATH, (char **) command_line, env_block);
                 free(env_block);