machine: use the correct escaping calls for machine metadata

This commit is contained in:
Lennart Poettering
2025-05-27 10:23:36 +02:00
parent b8396f1102
commit 4b9c918431
2 changed files with 6 additions and 44 deletions
+1 -15
View 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) {
+5 -29
View File
@@ -180,36 +180,12 @@ int machine_save(Machine *m) {
"NAME=%s\n",
m->name);
if (m->unit) {
_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->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;
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));