]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: pin the unit we invoke continously while we are running
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Oct 2023 09:31:38 +0000 (11:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 16 Oct 2023 12:30:11 +0000 (14:30 +0200)
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

index 58974370ef2c2a9eae40917ff4a9c10a3ee98fa8..edafd4956734081095cb650778d1035003a64294 100644 (file)
@@ -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)