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

harald at redhat.com harald at redhat.com
Tue Mar 12 05:00:49 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 +-
 src/core/unit.c    | 4 ++--
 src/core/unit.h    | 2 +-
 5 files changed, 14 insertions(+), 11 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..6e8e6a6 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);
 
diff --git a/src/core/unit.c b/src/core/unit.c
index a6cc3b6..4c1fc7e 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2320,7 +2320,7 @@ bool unit_can_serialize(Unit *u) {
         return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item;
 }
 
-int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) {
+int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool do_switch_root) {
         int r;
 
         assert(u);
@@ -2334,7 +2334,7 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) {
                 return r;
 
 
-        if (serialize_jobs) {
+        if (!do_switch_root) {
                 if (u->job) {
                         fprintf(f, "job\n");
                         job_serialize(u->job, f, fds);
diff --git a/src/core/unit.h b/src/core/unit.h
index 9029d62..aa87e86 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -511,7 +511,7 @@ int unit_load_related_unit(Unit *u, const char *type, Unit **_found);
 int unit_get_related_unit(Unit *u, const char *type, Unit **_found);
 
 bool unit_can_serialize(Unit *u);
-int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs);
+int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool do_switch_root);
 void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *value, ...) _printf_attr_(4,5);
 void unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value);
 int unit_deserialize(Unit *u, FILE *f, FDSet *fds);
-- 
1.8.1



More information about the systemd-devel mailing list