[systemd-devel] [PATCH V3] core: do not serialize targets on switch-root

harald at redhat.com harald at redhat.com
Tue Mar 12 05:04:05 PDT 2013


From: Harald Hoyer <harald at redhat.com>

Targets in the initrd can differ from targets on the switched root.

Do not assume these targets are active.
---
 src/core/main.c    | 8 ++++----
 src/core/manager.c | 9 ++++++---
 src/core/manager.h | 2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/core/main.c b/src/core/main.c
index 7b03983..b67ef79 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1091,7 +1091,7 @@ static int version(void) {
         return 0;
 }
 
-static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize_jobs) {
+static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool do_switch_root) {
         FILE *f = NULL;
         FDSet *fds = NULL;
         int r;
@@ -1116,7 +1116,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize
                 goto fail;
         }
 
-        r = manager_serialize(m, f, fds, serialize_jobs);
+        r = manager_serialize(m, f, fds, do_switch_root);
         if (r < 0) {
                 log_error("Failed to serialize state: %s", strerror(-r));
                 goto fail;
@@ -1790,7 +1790,7 @@ int main(int argc, char *argv[]) {
 
                 case MANAGER_REEXECUTE:
 
-                        if (prepare_reexecute(m, &serialization, &fds, true) < 0)
+                        if (prepare_reexecute(m, &serialization, &fds, false) < 0)
                                 goto finish;
 
                         reexecute = true;
@@ -1804,7 +1804,7 @@ int main(int argc, char *argv[]) {
                         m->switch_root = m->switch_root_init = NULL;
 
                         if (!switch_root_init)
-                                if (prepare_reexecute(m, &serialization, &fds, false) < 0)
+                                if (prepare_reexecute(m, &serialization, &fds, true) < 0)
                                         goto finish;
 
                         reexecute = true;
diff --git a/src/core/manager.c b/src/core/manager.c
index c261b25..661534a 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2025,7 +2025,7 @@ int manager_open_serialization(Manager *m, FILE **_f) {
         return 0;
 }
 
-int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) {
+int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root) {
         Iterator i;
         Unit *u;
         const char *t;
@@ -2064,6 +2064,9 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) {
         fputc('\n', f);
 
         HASHMAP_FOREACH_KEY(u, t, m->units, i) {
+                if (do_switch_root && u->type == UNIT_TARGET)
+                        return 0;
+
                 if (u->id != t)
                         continue;
 
@@ -2074,7 +2077,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) {
                 fputs(u->id, f);
                 fputc('\n', f);
 
-                if ((r = unit_serialize(u, f, fds, serialize_jobs)) < 0) {
+                if ((r = unit_serialize(u, f, fds, !do_switch_root)) < 0) {
                         m->n_reloading --;
                         return r;
                 }
@@ -2262,7 +2265,7 @@ int manager_reload(Manager *m) {
                 goto finish;
         }
 
-        r = manager_serialize(m, f, fds, true);
+        r = manager_serialize(m, f, fds, false);
         if (r < 0) {
                 m->n_reloading --;
                 goto finish;
diff --git a/src/core/manager.h b/src/core/manager.h
index c486a16..262f390 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -277,7 +277,7 @@ void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid
 
 int manager_open_serialization(Manager *m, FILE **_f);
 
-int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs);
+int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root);
 int manager_deserialize(Manager *m, FILE *f, FDSet *fds);
 int manager_distribute_fds(Manager *m, FDSet *fds);
 
-- 
1.8.1



More information about the systemd-devel mailing list