[systemd-devel] [PATCH] Pass environment over daemon-reexec

Oleksii Shevchuk alxchk at gmail.com
Wed Feb 6 14:40:56 PST 2013


Fixes this bug:
alxchk > systemctl --user set-environment A=B
alxchk > systemctl --user show-environment | grep ^A=
A=B
alxchk > systemctl --user daemon-reexec
alxchk > systemctl --user show-environment | grep ^A=
alxchk >
---
 src/core/manager.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/core/manager.c b/src/core/manager.c
index b538a9a..edcf517 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1852,6 +1852,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) {
         Iterator i;
         Unit *u;
         const char *t;
+        char **e;
         int r;
 
         assert(m);
@@ -1875,6 +1876,10 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) {
                 dual_timestamp_serialize(f, "finish-timestamp", &m->finish_timestamp);
         }
 
+        STRV_FOREACH(e, m->environment) {
+                fprintf(f, "env=%s\n", *e);
+        }
+
         fputc('\n', f);
 
         HASHMAP_FOREACH_KEY(u, t, m->units, i) {
@@ -1975,6 +1980,19 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
                         dual_timestamp_deserialize(l+20, &m->userspace_timestamp);
                 else if (startswith(l, "finish-timestamp="))
                         dual_timestamp_deserialize(l+17, &m->finish_timestamp);
+                else if (startswith(l, "env="))
+                        {
+                                char ** e;
+
+                                e = strv_env_set(m->environment, l+4);
+                                if (! e) {
+                                        r = -ENOMEM;
+                                        goto finish;
+                                }
+
+                                strv_free(m->environment);
+                                m->environment = e;
+                        }
                 else
                         log_debug("Unknown serialization item '%s'", l);
         }
-- 
1.8.1.2



More information about the systemd-devel mailing list