From 6bb442010046db0e4f18ee934d58496fdb0c51b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 27 Jun 2025 14:06:23 +0200 Subject: [PATCH] shared/bus-unit-util: define helper for StandardInputText= --- src/shared/bus-unit-util.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index fbf6e31a4ee..2a49d5717df 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1237,6 +1237,23 @@ static int bus_append_standard_inputs(sd_bus_message *m, const char *field, cons return 1; } +static int bus_append_standard_input_text(sd_bus_message *m, const char *field, const char *eq) { + _cleanup_free_ char *unescaped = NULL; + ssize_t l; + + l = cunescape(eq, 0, &unescaped); + if (l < 0) + return log_error_errno(l, "Failed to unescape text '%s': %m", eq); + + if (!strextend(&unescaped, "\n")) + return log_oom(); + + /* Note that we don't expand specifiers here, but that should be OK, as this is a + * programmatic interface anyway */ + + return bus_append_byte_array(m, field, unescaped, l + 1); +} + static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) { if (STR_IN_SET(field, "DevicePolicy", "Slice", @@ -1527,22 +1544,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con "StandardError")) return bus_append_standard_inputs(m, field, eq); - if (streq(field, "StandardInputText")) { - _cleanup_free_ char *unescaped = NULL; - ssize_t l; - - l = cunescape(eq, 0, &unescaped); - if (l < 0) - return log_error_errno(l, "Failed to unescape text '%s': %m", eq); - - if (!strextend(&unescaped, "\n")) - return log_oom(); - - /* Note that we don't expand specifiers here, but that should be OK, as this is a - * programmatic interface anyway */ - - return bus_append_byte_array(m, field, unescaped, l + 1); - } + if (streq(field, "StandardInputText")) + return bus_append_standard_input_text(m, field, eq); if (streq(field, "StandardInputData")) { _cleanup_free_ void *decoded = NULL; -- 2.47.3