]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: allow creating scope units based in pidfds instead of plain pids
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Oct 2023 07:46:40 +0000 (09:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Oct 2023 15:07:06 +0000 (17:07 +0200)
src/core/dbus-scope.c

index 97a8d277fb6e63424209c5119bd3b9c3e586f7d2..78196a1a08c90cbf19289e3d6fa7b5831f2c1808 100644 (file)
@@ -136,12 +136,51 @@ static int bus_scope_set_transient_property(
                 if (r < 0)
                         return r;
 
-                if (n <= 0)
-                        return -EINVAL;
+                return n <= 0 ? -EINVAL : 1;
+        }
 
-                return 1;
+        if (streq(name, "PIDFDs")) {
+                unsigned n = 0;
+
+                r = sd_bus_message_enter_container(message, 'a', "h");
+                if (r < 0)
+                        return r;
+
+                for (;;) {
+                        _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+                        int fd;
+
+                        r = sd_bus_message_read(message, "h", &fd);
+                        if (r < 0)
+                                return r;
+                        if (r == 0)
+                                break;
+
+                        r = pidref_set_pidfd(&pidref, fd);
+                        if (r < 0)
+                                return r;
+
+                        r = unit_pid_attachable(u, &pidref, error);
+                        if (r < 0)
+                                return r;
+
+                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
+                                r = unit_watch_pidref(u, &pidref, /* exclusive= */ false);
+                                if (r < 0 && r != -EEXIST)
+                                        return r;
+                        }
+
+                        n++;
+                }
+
+                r = sd_bus_message_exit_container(message);
+                if (r < 0)
+                        return r;
+
+                return n <= 0 ? -EINVAL : 1;
+        }
 
-        } else if (streq(name, "Controller")) {
+        if (streq(name, "Controller")) {
                 const char *controller;
 
                 /* We can't support direct connections with this, as direct connections know no service or unique name