]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Add allow_pidfd argument to bus_append_scope_pidref() 31886/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 22 Mar 2024 16:03:35 +0000 (17:03 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 22 Mar 2024 16:03:35 +0000 (17:03 +0100)
src/login/logind-dbus.c
src/machine/machine.c
src/nspawn/nspawn-register.c
src/run/run.c
src/shared/bus-unit-util.c
src/shared/bus-unit-util.h
src/vmspawn/vmspawn-scope.c

index 678e077d90e0bb673d7220c51c1135cd4395189f..5d27491af3a5fbec9dd0265e93912a8f1427a829 100644 (file)
@@ -4300,10 +4300,7 @@ int manager_start_scope(
         if (r < 0)
                 return r;
 
-        if (allow_pidfd)
-                r = bus_append_scope_pidref(m, pidref);
-        else
-                r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, (uint32_t) pidref->pid);
+        r = bus_append_scope_pidref(m, pidref, allow_pidfd);
         if (r < 0)
                 return r;
 
index af8a88f26caea134fd3a8f922092deeda7e7fb71..309bffa3c8075bbe0b0ccd5aa2008cf7cd7dedf5 100644 (file)
@@ -385,7 +385,7 @@ static int machine_start_scope(
         if (r < 0)
                 return r;
 
-        r = bus_append_scope_pidref(m, &machine->leader);
+        r = bus_append_scope_pidref(m, &machine->leader, /* allow_pidfd = */ true);
         if (r < 0)
                 return r;
 
index 358958b82b3d6f1b9d8e692591915e014edc2366..b63516d13efc0d87b34825e1ad518d64080c5623 100644 (file)
@@ -297,15 +297,12 @@ int allocate_scope(
 
         description = strjoina("Container ", machine_name);
 
-        if (allow_pidfd) {
-                _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
-                r = pidref_set_pid(&pidref, pid);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to allocate PID reference: %m");
+        _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+        r = pidref_set_pid(&pidref, pid);
+        if (r < 0)
+                return log_error_errno(r, "Failed to allocate PID reference: %m");
 
-                r = bus_append_scope_pidref(m, &pidref);
-        } else
-                r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, (uint32_t) pid);
+        r = bus_append_scope_pidref(m, &pidref, allow_pidfd);
         if (r < 0)
                 return bus_log_create_error(r);
 
index e8dc3388c05e9650c9ad9a456b66a85b27c08a27..93e061a3c311f2d1e9f84cec1750e6a914b34754 100644 (file)
@@ -1265,18 +1265,13 @@ static int transient_scope_set_properties(sd_bus_message *m, bool allow_pidfd) {
         if (r < 0)
                 return r;
 
-        if (allow_pidfd) {
-                _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+        _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
 
-                r = pidref_set_self(&pidref);
-                if (r < 0)
-                        return r;
+        r = pidref_set_self(&pidref);
+        if (r < 0)
+                return r;
 
-                r = bus_append_scope_pidref(m, &pidref);
-        } else
-                r = sd_bus_message_append(
-                                m, "(sv)",
-                                "PIDs", "au", 1, getpid_cached());
+        r = bus_append_scope_pidref(m, &pidref, allow_pidfd);
         if (r < 0)
                 return bus_log_create_error(r);
 
index 7d847b94252f79fd5324f166c60562aec11c5259..2fcfb1d3b96c9affc9f93dd4176c58f0e8713be5 100644 (file)
@@ -2821,13 +2821,13 @@ int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char
         return 0;
 }
 
-int bus_append_scope_pidref(sd_bus_message *m, const PidRef *pidref) {
+int bus_append_scope_pidref(sd_bus_message *m, const PidRef *pidref, bool allow_pidfd) {
         assert(m);
 
         if (!pidref_is_set(pidref))
                 return -ESRCH;
 
-        if (pidref->fd >= 0)
+        if (pidref->fd >= 0 && allow_pidfd)
                 return sd_bus_message_append(
                                 m, "(sv)",
                                 "PIDFDs", "ah", 1, pidref->fd);
index a1518158ff4691f8551064ea8a7db6151fc5eb6f..e4168a44254116ff24cc89f3a001db40afa3f5dc 100644 (file)
@@ -26,7 +26,7 @@ int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u);
 int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const char *assignment);
 int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char **l);
 
-int bus_append_scope_pidref(sd_bus_message *m, const PidRef *pidref);
+int bus_append_scope_pidref(sd_bus_message *m, const PidRef *pidref, bool allow_pidfd);
 
 int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet);
 
index ff986b09d65f94d55ae7d1d71f66bd9e3aa4ab48..a8d27afa113e50618a296d980cd3a54edaa17857 100644 (file)
@@ -61,15 +61,12 @@ int start_transient_scope(sd_bus *bus, const char *machine_name, bool allow_pidf
                                   "AddRef",      "b",  1,
                                   "CollectMode", "s",  "inactive-or-failed");
 
-        if (allow_pidfd) {
-                _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
-                r = pidref_set_pid(&pidref, getpid_cached());
-                if (r < 0)
-                        return log_error_errno(r, "Failed to allocate PID reference: %m");
+        _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+        r = pidref_set_self(&pidref);
+        if (r < 0)
+                return log_error_errno(r, "Failed to allocate PID reference: %m");
 
-                r = bus_append_scope_pidref(m, &pidref);
-        } else
-                r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, getpid_cached());
+        r = bus_append_scope_pidref(m, &pidref, allow_pidfd);
         if (r < 0)
                 return bus_log_create_error(r);