From 49a510eba29c78f4b7dc1c39391314a48eb8833b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 16 Oct 2023 11:31:38 +0200 Subject: [PATCH] run: pin the unit we invoke continously while we are running We read properties of the unit, hence it shouldn't be GC'ed as long as we run. Hence, let's just set AddRef unconditionally for the units we create. --- src/run/run.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index 58974370ef..edafd49567 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -653,6 +653,8 @@ static int parse_argv(int argc, char *argv[]) { static int transient_unit_set_properties(sd_bus_message *m, UnitType t, char **properties) { int r; + assert(m); + r = sd_bus_message_append(m, "(sv)", "Description", "s", arg_description); if (r < 0) return bus_log_create_error(r); @@ -663,6 +665,17 @@ static int transient_unit_set_properties(sd_bus_message *m, UnitType t, char **p return bus_log_create_error(r); } + r = sd_bus_is_bus_client(sd_bus_message_get_bus(m)); + if (r < 0) + return log_error_errno(r, "Can't determine if bus connection is direct or to broker: %m"); + if (r > 0) { + /* Pin the object as least as long as we are around. Note that AddRef (currently) only works + * if we talk via the bus though. */ + r = sd_bus_message_append(m, "(sv)", "AddRef", "b", 1); + if (r < 0) + return bus_log_create_error(r); + } + return bus_append_unit_property_assignment_many(m, t, properties); } @@ -754,12 +767,6 @@ static int transient_service_set_properties(sd_bus_message *m, const char *pty_p if (r < 0) return r; - if (arg_wait || arg_stdio != ARG_STDIO_NONE) { - r = sd_bus_message_append(m, "(sv)", "AddRef", "b", 1); - if (r < 0) - return bus_log_create_error(r); - } - if (arg_remain_after_exit) { r = sd_bus_message_append(m, "(sv)", "RemainAfterExit", "b", arg_remain_after_exit); if (r < 0)