From: Lennart Poettering Date: Thu, 5 Oct 2023 07:46:40 +0000 (+0200) Subject: pid1: allow creating scope units based in pidfds instead of plain pids X-Git-Tag: v255-rc1~321^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7595fed92d72496b5bb80eade886f3af5b8e7630;p=thirdparty%2Fsystemd.git pid1: allow creating scope units based in pidfds instead of plain pids --- diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c index 97a8d277fb6..78196a1a08c 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