From 7595fed92d72496b5bb80eade886f3af5b8e7630 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 5 Oct 2023 09:46:40 +0200 Subject: [PATCH] pid1: allow creating scope units based in pidfds instead of plain pids --- src/core/dbus-scope.c | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c index 97a8d277fb..78196a1a08 100644 --- a/src/core/dbus-scope.c +++ b/src/core/dbus-scope.c @@ -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 -- 2.25.1