summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/nspawn/nspawn-register.c27
-rw-r--r--src/nspawn/nspawn-register.h36
-rw-r--r--src/nspawn/nspawn.c11
3 files changed, 60 insertions, 14 deletions
diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c
index 9f2c1b8f46..855172c09c 100644
--- a/src/nspawn/nspawn-register.c
+++ b/src/nspawn/nspawn-register.c
@@ -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));
}
diff --git a/src/nspawn/nspawn-register.h b/src/nspawn/nspawn-register.h
index 4d16ac20e2..0effb40aa0 100644
--- a/src/nspawn/nspawn-register.h
+++ b/src/nspawn/nspawn-register.h
@@ -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);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 0cb26cbc31..8a26333364 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -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;