]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: register_machine() and allocate_scope() bools to flags
authorLuke T. Shumaker <lukeshu@parabola.nu>
Thu, 29 Aug 2024 17:00:18 +0000 (11:00 -0600)
committerLuke T. Shumaker <lukeshu@parabola.nu>
Sat, 7 Sep 2024 00:33:50 +0000 (18:33 -0600)
src/nspawn/nspawn-register.c
src/nspawn/nspawn-register.h
src/nspawn/nspawn.c

index 9f2c1b8f4635722cf14447988b18e5f963f509d5..855172c09c3fed20a849af86397e1148bbad50f9 100644 (file)
@@ -140,16 +140,16 @@ int register_machine(
                 int kill_signal,
                 char **properties,
                 sd_bus_message *properties_message,
-                bool keep_unit,
                 const char *service,
-                StartMode start_mode) {
+                StartMode start_mode,
+                RegisterMachineFlags flags) {
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
 
         assert(bus);
 
-        if (keep_unit) {
+        if (FLAGS_SET(flags, REGISTER_MACHINE_KEEP_UNIT)) {
                 r = bus_call_method(
                                 bus,
                                 bus_machine_mgr,
@@ -255,8 +255,8 @@ int allocate_scope(
                 int kill_signal,
                 char **properties,
                 sd_bus_message *properties_message,
-                bool allow_pidfd,
-                StartMode start_mode) {
+                StartMode start_mode,
+                AllocateScopeFlags flags) {
 
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -295,7 +295,7 @@ int allocate_scope(
         if (r < 0)
                 return log_error_errno(r, "Failed to allocate PID reference: %m");
 
-        r = bus_append_scope_pidref(m, &pidref, allow_pidfd);
+        r = bus_append_scope_pidref(m, &pidref, FLAGS_SET(flags, ALLOCATE_SCOPE_ALLOW_PIDFD));
         if (r < 0)
                 return bus_log_create_error(r);
 
@@ -347,9 +347,20 @@ int allocate_scope(
         if (r < 0) {
                 /* If this failed with a property we couldn't write, this is quite likely because the server
                  * doesn't support PIDFDs yet, let's try without. */
-                if (allow_pidfd &&
+                if (FLAGS_SET(flags, ALLOCATE_SCOPE_ALLOW_PIDFD) &&
                     sd_bus_error_has_names(&error, SD_BUS_ERROR_UNKNOWN_PROPERTY, SD_BUS_ERROR_PROPERTY_READ_ONLY))
-                        return allocate_scope(bus, machine_name, pid, slice, mounts, n_mounts, kill_signal, properties, properties_message, /* allow_pidfd= */ false, start_mode);
+                        return allocate_scope(
+                                        bus,
+                                        machine_name,
+                                        pid,
+                                        slice,
+                                        mounts,
+                                        n_mounts,
+                                        kill_signal,
+                                        properties,
+                                        properties_message,
+                                        start_mode,
+                                        flags & ~ALLOCATE_SCOPE_ALLOW_PIDFD);
 
                 return log_error_errno(r, "Failed to allocate scope: %s", bus_error_message(&error, r));
         }
index 4d16ac20e2d35725bd538df00d52c374942fdc32..0effb40aa01d812e5a58cb414a213e5c0dd460b4 100644 (file)
@@ -8,8 +8,40 @@
 #include "nspawn-mount.h"
 #include "nspawn-settings.h"
 
-int register_machine(sd_bus *bus, const char *machine_name, pid_t pid, const char *directory, sd_id128_t uuid, int local_ifindex, const char *slice, CustomMount *mounts, unsigned n_mounts, int kill_signal, char **properties, sd_bus_message *properties_message, bool keep_unit, const char *service, StartMode start_mode);
+typedef enum RegisterMachineFlags {
+        REGISTER_MACHINE_KEEP_UNIT = 1 << 0,
+} RegisterMachineFlags;
+
+int register_machine(
+                sd_bus *bus,
+                const char *machine_name,
+                pid_t pid,
+                const char *directory,
+                sd_id128_t uuid,
+                int local_ifindex,
+                const char *slice,
+                CustomMount *mounts, unsigned n_mounts,
+                int kill_signal,
+                char **properties,
+                sd_bus_message *properties_message,
+                const char *service,
+                StartMode start_mode,
+                RegisterMachineFlags flags);
 int unregister_machine(sd_bus *bus, const char *machine_name);
 
-int allocate_scope(sd_bus *bus, const char *machine_name, pid_t pid, const char *slice, CustomMount *mounts, unsigned n_mounts, int kill_signal, char **properties, sd_bus_message *properties_message, bool allow_pidfds, StartMode start_mode);
+typedef enum AllocateScopeFlags {
+        ALLOCATE_SCOPE_ALLOW_PIDFD = 1 << 0,
+} AllocateScopeFlags;
+
+int allocate_scope(
+                sd_bus *bus,
+                const char *machine_name,
+                pid_t pid,
+                const char *slice,
+                CustomMount *mounts, unsigned n_mounts,
+                int kill_signal,
+                char **properties,
+                sd_bus_message *properties_message,
+                StartMode start_mode,
+                AllocateScopeFlags flags);
 int terminate_scope(sd_bus *bus, const char *machine_name);
index 0cb26cbc31232c0754ee5c16de9a21fdb61dd2d8..8a26333364c18f149ad218ec51bca913a08fa9f2 100644 (file)
@@ -5384,6 +5384,8 @@ static int run_container(
         }
 
         if (arg_register) {
+                RegisterMachineFlags flags = 0;
+                SET_FLAG(flags, REGISTER_MACHINE_KEEP_UNIT, arg_keep_unit);
                 r = register_machine(
                                 bus,
                                 arg_machine,
@@ -5396,13 +5398,14 @@ static int run_container(
                                 arg_kill_signal,
                                 arg_property,
                                 arg_property_message,
-                                arg_keep_unit,
                                 arg_container_service_name,
-                                arg_start_mode);
+                                arg_start_mode,
+                                flags);
                 if (r < 0)
                         return r;
 
         } else if (!arg_keep_unit) {
+                AllocateScopeFlags flags = ALLOCATE_SCOPE_ALLOW_PIDFD;
                 r = allocate_scope(
                                 bus,
                                 arg_machine,
@@ -5412,8 +5415,8 @@ static int run_container(
                                 arg_kill_signal,
                                 arg_property,
                                 arg_property_message,
-                                /* allow_pidfds= */ true,
-                                arg_start_mode);
+                                arg_start_mode,
+                                flags);
                 if (r < 0)
                         return r;