From: Lennart Poettering Date: Mon, 16 Oct 2023 09:31:38 +0000 (+0200) Subject: run: pin the unit we invoke continously while we are running X-Git-Tag: v255-rc1~230^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=49a510eba29c78f4b7dc1c39391314a48eb8833b;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/run/run.c b/src/run/run.c index 58974370ef2..edafd495673 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)