]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: set CoredumpReceive=yes on container's scope when --boot is set 29272/head
authorNick Rosbrook <enr0n@ubuntu.com>
Thu, 12 Oct 2023 17:39:56 +0000 (13:39 -0400)
committerNick Rosbrook <enr0n@ubuntu.com>
Fri, 13 Oct 2023 19:28:50 +0000 (15:28 -0400)
When --boot is set, and --keep-unit is not, set CoredumpReceive=yes on
the scope allocated for the container. When --keep-unit is set, nspawn
does not allocate the container's unit, so the existing unit needs to
configure this setting itself.

Since systemd-nspawn@.service sets --boot and --keep-unit, add
CoredumpReceives=yes to that unit.

src/nspawn/nspawn-register.c
src/nspawn/nspawn-register.h
src/nspawn/nspawn.c
units/systemd-nspawn@.service.in

index 2c9ebda61a1dc3114ee28e1dc379d7f3f44d84a6..f8f82e91b1bbb26545b2a3951204fd2192dfc942 100644 (file)
@@ -8,6 +8,7 @@
 #include "bus-util.h"
 #include "bus-wait-for-jobs.h"
 #include "nspawn-register.h"
+#include "nspawn-settings.h"
 #include "special.h"
 #include "stat-util.h"
 #include "strv.h"
@@ -16,7 +17,8 @@ static int append_machine_properties(
                 sd_bus_message *m,
                 CustomMount *mounts,
                 unsigned n_mounts,
-                int kill_signal) {
+                int kill_signal,
+                bool coredump_receive) {
 
         unsigned j;
         int r;
@@ -79,6 +81,12 @@ static int append_machine_properties(
                         return bus_log_create_error(r);
         }
 
+        if (coredump_receive) {
+                r = sd_bus_message_append(m, "(sv)", "CoredumpReceive", "b", true);
+                if (r < 0)
+                        return bus_log_create_error(r);
+        }
+
         return 0;
 }
 
@@ -114,7 +122,8 @@ int register_machine(
                 char **properties,
                 sd_bus_message *properties_message,
                 bool keep_unit,
-                const char *service) {
+                const char *service,
+                StartMode start_mode) {
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
@@ -174,7 +183,8 @@ int register_machine(
                                 m,
                                 mounts,
                                 n_mounts,
-                                kill_signal);
+                                kill_signal,
+                                start_mode == START_BOOT);
                 if (r < 0)
                         return r;
 
@@ -226,7 +236,8 @@ int allocate_scope(
                 int kill_signal,
                 char **properties,
                 sd_bus_message *properties_message,
-                bool allow_pidfd) {
+                bool allow_pidfd,
+                StartMode start_mode) {
 
         _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 +306,8 @@ int allocate_scope(
                         m,
                         mounts,
                         n_mounts,
-                        kill_signal);
+                        kill_signal,
+                        start_mode == START_BOOT);
         if (r < 0)
                 return r;
 
@@ -321,7 +333,7 @@ int allocate_scope(
                  * doesn't support PIDFDs yet, let's try without. */
                 if (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);
+                        return allocate_scope(bus, machine_name, pid, slice, mounts, n_mounts, kill_signal, properties, properties_message, /* allow_pidfd= */ false, start_mode);
 
                 return log_error_errno(r, "Failed to allocate scope: %s", bus_error_message(&error, r));
         }
index be65d2b2300cd41416737e7d32013b03b3cf7217..4d16ac20e2d35725bd538df00d52c374942fdc32 100644 (file)
@@ -6,9 +6,10 @@
 #include "sd-id128.h"
 
 #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);
+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);
 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);
+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);
 int terminate_scope(sd_bus *bus, const char *machine_name);
index 07234df85b22ac9a203e3c8214b0527297cd4119..de76b88c2788392082b850cab1e6c7eaf47b91ff 100644 (file)
@@ -5061,7 +5061,8 @@ static int run_container(
                                 arg_property,
                                 arg_property_message,
                                 arg_keep_unit,
-                                arg_container_service_name);
+                                arg_container_service_name,
+                                arg_start_mode);
                 if (r < 0)
                         return r;
 
@@ -5075,7 +5076,8 @@ static int run_container(
                                 arg_kill_signal,
                                 arg_property,
                                 arg_property_message,
-                                /* allow_pidfds= */ true);
+                                /* allow_pidfds= */ true,
+                                arg_start_mode);
                 if (r < 0)
                         return r;
 
index 079d6064f631e69e2c37a60f610d5dae98ee8939..ff66d4090acb3b4ec1b3160b3bf2e76d14d7e0b5 100644 (file)
@@ -26,6 +26,7 @@ SuccessExitStatus=133
 Slice=machine.slice
 Delegate=yes
 DelegateSubgroup=supervisor
+CoredumpReceive=yes
 TasksMax=16384
 {{SERVICE_WATCHDOG}}