From f14bf013126ebcdc689995234cb15fc0b605a262 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 27 Nov 2019 12:05:38 +0100 Subject: [PATCH 1/2] core: write out correct field name when creating transient service units --- src/core/dbus-execute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 13ff6f489a..c35b486408 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1095,7 +1095,7 @@ int bus_set_transient_exec_command( if (!f) return -ENOMEM; - fputs("ExecStart=\n", f); + fprintf(f, "%s=\n", name); LIST_FOREACH(command, c, *exec_command) { _cleanup_free_ char *a = NULL, *t = NULL, *exec_chars = NULL; From 540ac9338ea6c8fc57f99384d19bf8da4f615cd4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 27 Nov 2019 12:05:57 +0100 Subject: [PATCH 2/2] core: prefer non-@ syntax for ExecStart= If the zeroth and first argv[] element on the same we don't need to generate the "@" syntax for ExecStart= and friends. --- src/core/dbus-execute.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index c35b486408..1d0bc1ede3 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1098,22 +1098,28 @@ int bus_set_transient_exec_command( fprintf(f, "%s=\n", name); LIST_FOREACH(command, c, *exec_command) { - _cleanup_free_ char *a = NULL, *t = NULL, *exec_chars = NULL; - const char *p; + _cleanup_free_ char *a = NULL, *exec_chars = NULL; - p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); - if (!p) + exec_chars = exec_command_flags_to_exec_chars(c->flags); + if (!exec_chars) return -ENOMEM; a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS); if (!a) return -ENOMEM; - exec_chars = exec_command_flags_to_exec_chars(c->flags); - if (!exec_chars) - return -ENOMEM; + if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL)) + fprintf(f, "%s=%s%s\n", name, exec_chars, a); + else { + _cleanup_free_ char *t = NULL; + const char *p; - fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a); + p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); + if (!p) + return -ENOMEM; + + fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a); + } } r = fflush_and_check(f);