From: Zbigniew Jędrzejewski-Szmek Date: Wed, 18 Jun 2025 14:55:34 +0000 (+0200) Subject: shared/bus-unit-util: define helper functions for StandardInput/Output/Error= X-Git-Tag: v258-rc1~183^2~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=375351d0039a91417458ec14046ab4d8ee62248b;p=thirdparty%2Fsystemd.git shared/bus-unit-util: define helper functions for StandardInput/Output/Error= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 74448a96fd9..fbf6e31a4ee 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1213,6 +1213,30 @@ static int bus_append_log_filter_patterns(sd_bus_message *m, const char *field, return 1; } +static int bus_append_standard_inputs(sd_bus_message *m, const char *field, const char *eq) { + const char *n, *appended; + int r; + + if ((n = startswith(eq, "fd:"))) { + appended = strjoina(field, "FileDescriptorName"); + r = sd_bus_message_append(m, "(sv)", appended, "s", n); + } else if ((n = startswith(eq, "file:"))) { + appended = strjoina(field, "File"); + r = sd_bus_message_append(m, "(sv)", appended, "s", n); + } else if ((n = startswith(eq, "append:"))) { + appended = strjoina(field, "FileToAppend"); + r = sd_bus_message_append(m, "(sv)", appended, "s", n); + } else if ((n = startswith(eq, "truncate:"))) { + appended = strjoina(field, "FileToTruncate"); + r = sd_bus_message_append(m, "(sv)", appended, "s", n); + } else + r = sd_bus_message_append(m, "(sv)", field, "s", eq); + if (r < 0) + return bus_log_create_error(r); + + return 1; +} + static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) { if (STR_IN_SET(field, "DevicePolicy", "Slice", @@ -1500,28 +1524,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con if (STR_IN_SET(field, "StandardInput", "StandardOutput", - "StandardError")) { - const char *n, *appended; - - if ((n = startswith(eq, "fd:"))) { - appended = strjoina(field, "FileDescriptorName"); - r = sd_bus_message_append(m, "(sv)", appended, "s", n); - } else if ((n = startswith(eq, "file:"))) { - appended = strjoina(field, "File"); - r = sd_bus_message_append(m, "(sv)", appended, "s", n); - } else if ((n = startswith(eq, "append:"))) { - appended = strjoina(field, "FileToAppend"); - r = sd_bus_message_append(m, "(sv)", appended, "s", n); - } else if ((n = startswith(eq, "truncate:"))) { - appended = strjoina(field, "FileToTruncate"); - r = sd_bus_message_append(m, "(sv)", appended, "s", n); - } else - r = sd_bus_message_append(m, "(sv)", field, "s", eq); - if (r < 0) - return bus_log_create_error(r); - - return 1; - } + "StandardError")) + return bus_append_standard_inputs(m, field, eq); if (streq(field, "StandardInputText")) { _cleanup_free_ char *unescaped = NULL;