summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-05-22 10:26:23 +0900
committerLennart Poettering <lennart@poettering.net>2014-05-22 10:36:16 +0900
commitca5405bb4fb1fabd1fe43e4ee23edf58914bdfae (patch)
treee664f85c331146edc4f798aad661f2374c4cbb8a
parent5052e3996d11033413372ee9d95df7f7a72b08a2 (diff)
downloadsystemd-ca5405bb4fb1fabd1fe43e4ee23edf58914bdfae.tar.gz
machine: escape fields we store in /run, so that they can be properly unescaped by parse_env_file()
-rw-r--r--src/machine/machine.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c
index 1164ce8f3d..a49cf81906 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -123,17 +123,42 @@ int machine_save(Machine *m) {
"NAME=%s\n",
m->name);
- if (m->unit)
- fprintf(f, "SCOPE=%s\n", m->unit); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */
+ if (m->unit) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(m->unit);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ fprintf(f, "SCOPE=%s\n", escaped); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */
+ }
if (m->scope_job)
fprintf(f, "SCOPE_JOB=%s\n", m->scope_job);
- if (m->service)
- fprintf(f, "SERVICE=%s\n", m->service);
+ if (m->service) {
+ _cleanup_free_ char *escaped;
- if (m->root_directory)
- fprintf(f, "ROOT=%s\n", m->root_directory);
+ escaped = cescape(m->service);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ fprintf(f, "SERVICE=%s\n", escaped);
+ }
+
+ if (m->root_directory) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(m->root_directory);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ fprintf(f, "ROOT=%s\n", escaped);
+ }
if (!sd_id128_equal(m->id, SD_ID128_NULL))
fprintf(f, "ID=" SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(m->id));