]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine: use the correct escaping calls for machine metadata
authorLennart Poettering <lennart@poettering.net>
Mon, 19 May 2025 09:07:53 +0000 (11:07 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 May 2025 08:23:36 +0000 (10:23 +0200)
src/libsystemd/sd-login/sd-login.c
src/machine/machine.c

index efe40c70f5b6db7236b79c2cec4f2db01be76aa0..f49713597a878ea42217a2a6d40922ae68ebee48 100644 (file)
@@ -10,7 +10,6 @@
 #include "cgroup-util.h"
 #include "dirent-util.h"
 #include "env-file.h"
-#include "escape.h"
 #include "extract-word.h"
 #include "fd-util.h"
 #include "format-util.h"
@@ -837,20 +836,7 @@ _public_ int sd_session_get_class(const char *session, char **class) {
 }
 
 _public_ int sd_session_get_desktop(const char *session, char **desktop) {
-        _cleanup_free_ char *escaped = NULL;
-        int r;
-        ssize_t l;
-
-        assert_return(desktop, -EINVAL);
-
-        r = session_get_string(session, "DESKTOP", &escaped);
-        if (r < 0)
-                return r;
-
-        l = cunescape(escaped, 0, desktop);
-        if (l < 0)
-                return l;
-        return 0;
+        return session_get_string(session, "DESKTOP", desktop);
 }
 
 _public_ int sd_session_get_display(const char *session, char **display) {
index fb397362b15142d99dd181d09135b3b168be0d38..0d5818439d1d3ee6d3d66d456bb8bd84989e01e4 100644 (file)
@@ -180,36 +180,12 @@ int machine_save(Machine *m) {
                 "NAME=%s\n",
                 m->name);
 
-        if (m->unit) {
-                _cleanup_free_ char *escaped = NULL;
-
-                escaped = cescape(m->unit);
-                if (!escaped)
-                        return log_oom();
-
-                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) {
-                _cleanup_free_ char *escaped = NULL;
+        /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */
+        env_file_fputs_assignment(f, "SCOPE=", m->unit);
+        env_file_fputs_assignment(f, "SCOPE_JOB=", m->scope_job);
 
-                escaped = cescape(m->service);
-                if (!escaped)
-                        return log_oom();
-                fprintf(f, "SERVICE=%s\n", escaped);
-        }
-
-        if (m->root_directory) {
-                _cleanup_free_ char *escaped = NULL;
-
-                escaped = cescape(m->root_directory);
-                if (!escaped)
-                        return log_oom();
-                fprintf(f, "ROOT=%s\n", escaped);
-        }
+        env_file_fputs_assignment(f, "SERVICE=", m->service);
+        env_file_fputs_assignment(f, "ROOT=", m->root_directory);
 
         if (!sd_id128_is_null(m->id))
                 fprintf(f, "ID=" SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(m->id));