summaryrefslogtreecommitdiff
path: root/src/core/dbus-kill.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-11-22 15:03:51 +0100
committerLennart Poettering <lennart@poettering.net>2017-11-29 12:34:12 +0100
commit2e59b241ca86b8338c706a7a704d301fde908581 (patch)
tree4f83e31ad02c6c691ff712a8a4499533c63dd720 /src/core/dbus-kill.c
parentddd59d0c7ffc77158ab2d6f52f08812670bb9160 (diff)
downloadsystemd-2e59b241ca86b8338c706a7a704d301fde908581.tar.gz
core: add proper escaping to writing of drop-ins/transient unit files
This majorly refactors the transient unit file and drop-in writing logic, so that we properly C-escape and specifier-escape (% → %%) everything we write out, so that when we read it back again, specifiers are parsed that aren't supposed to be parsed. This renames unit_write_drop_in() and friends by unit_write_setting(). The name change is supposed to clarify that the functions are not only used to write drop-in files, but also transient unit files. The previous "mode" parameter to this function is replaced by a more generic "flags", which knows additional flags for implicit C-style and specifier escaping before writing things out. This can cover most properties where either form of escaping is defined. For the cases where this isn't sufficient, we add helpers unit_escape_setting() and unit_concat_strv() for escaping individual strings or strvs properly. While we are at it, we also prettify generation of transient unit files: we try to reduce the number of section headers written out: previously we'd write the right section header our for each setting. With this change we do so only if the setting lives in a different section than the one before. (This should also be considered preparation for when we add proper APIs to systemd to write normal, persistant unit files through the bus API)
Diffstat (limited to 'src/core/dbus-kill.c')
-rw-r--r--src/core/dbus-kill.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/core/dbus-kill.c b/src/core/dbus-kill.c
index 4ac9f363cc..bf3bbb2047 100644
--- a/src/core/dbus-kill.c
+++ b/src/core/dbus-kill.c
@@ -39,7 +39,7 @@ int bus_kill_context_set_transient_property(
KillContext *c,
const char *name,
sd_bus_message *message,
- UnitSetPropertiesMode mode,
+ UnitWriteFlags flags,
sd_bus_error *error) {
int r;
@@ -49,6 +49,8 @@ int bus_kill_context_set_transient_property(
assert(name);
assert(message);
+ flags |= UNIT_PRIVATE;
+
if (streq(name, "KillMode")) {
const char *m;
KillMode k;
@@ -61,10 +63,10 @@ int bus_kill_context_set_transient_property(
if (k < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
- if (mode != UNIT_CHECK) {
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->kill_mode = k;
- unit_write_drop_in_private_format(u, mode, name, "KillMode=%s", kill_mode_to_string(k));
+ unit_write_settingf(u, flags, name, "KillMode=%s", kill_mode_to_string(k));
}
return 1;
@@ -79,10 +81,10 @@ int bus_kill_context_set_transient_property(
if (!SIGNAL_VALID(sig))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
- if (mode != UNIT_CHECK) {
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->kill_signal = sig;
- unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s", signal_to_string(sig));
+ unit_write_settingf(u, flags, name, "KillSignal=%s", signal_to_string(sig));
}
return 1;
@@ -94,10 +96,10 @@ int bus_kill_context_set_transient_property(
if (r < 0)
return r;
- if (mode != UNIT_CHECK) {
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->send_sighup = b;
- unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s", yes_no(b));
+ unit_write_settingf(u, flags, name, "SendSIGHUP=%s", yes_no(b));
}
return 1;
@@ -109,10 +111,10 @@ int bus_kill_context_set_transient_property(
if (r < 0)
return r;
- if (mode != UNIT_CHECK) {
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->send_sigkill = b;
- unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s", yes_no(b));
+ unit_write_settingf(u, flags, name, "SendSIGKILL=%s", yes_no(b));
}
return 1;