* [PATCH lxc] d/patches: print a failing hook's last output along with its exit code
@ 2026-10-14 8:54 Hannes Laimer
0 siblings, 0 replies; only message in thread
From: Hannes Laimer @ 2026-10-14 8:54 UTC (permalink / raw)
To: pve-devel
This makes the output of a failed LXC start task way more useful when
diagnosing a problem. So far the reason a container could not start
was only in the lxc debug log, so one had to start it again with the
debug flag, which can't be done through the UI and dumps lxc's whole
debug output into the task log.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
some example outputs:
* typo in mp
```
run_buffer: 569 Script exited with status 2
lxc_init: 1037 Failed to run lxc.hook.pre-start for container "100"
__lxc_start: 2208 Failed to initialize container "100"
TASK ERROR: startup for container '100' failed
run_buffer: 580 Script output: directory '/mnt/nope' does not exist
run_buffer: 583 Script exited with status 2
lxc_init: 1037 Failed to run lxc.hook.pre-start for container "100"
__lxc_start: 2208 Failed to initialize container "100"
TASK ERROR: startup for container '100' failed
```
* problem with rootfs
```
run_buffer: 569 Script exited with status 32
lxc_init: 1037 Failed to run lxc.hook.pre-start for container "100"
__lxc_start: 2208 Failed to initialize container "100"
TASK ERROR: startup for container '100' failed
run_buffer: 580 Script output: command 'mount /dev/dm-6 /var/lib/lxc/.pve-staged-mounts/rootfs' failed: exit code 32
run_buffer: 583 Script exited with status 32
lxc_init: 1037 Failed to run lxc.hook.pre-start for container "100"
__lxc_start: 2208 Failed to initialize container "100"
TASK ERROR: startup for container '100' failed
```
...output-of-a-failing-hook-as-an-error.patch | 38 +++++++++++++++++++
debian/patches/series | 1 +
2 files changed, 39 insertions(+)
create mode 100644 debian/patches/pve/0004-utils-log-last-output-of-a-failing-hook-as-an-error.patch
diff --git a/debian/patches/pve/0004-utils-log-last-output-of-a-failing-hook-as-an-error.patch b/debian/patches/pve/0004-utils-log-last-output-of-a-failing-hook-as-an-error.patch
new file mode 100644
index 0000000..be72316
--- /dev/null
+++ b/debian/patches/pve/0004-utils-log-last-output-of-a-failing-hook-as-an-error.patch
@@ -0,0 +1,38 @@
+From eb3906204eb9ae822e6ab4d85f0d5e3dacc916d3 Mon Sep 17 00:00:00 2001
+From: Hannes Laimer <h.laimer@proxmox.com>
+Date: Wed, 14 Oct 2026 09:06:48 +0200
+Subject: [PATCH] utils: log last output of a failing hook as an error
+
+The exit code of a failing hook is logged as an error, and the code
+alone is usually not enough to locate the problem. Log the last output
+of the hook as an error as well.
+
+Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
+---
+ src/lxc/utils.c | 10 +++++++++-
+ 1 file changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/lxc/utils.c b/src/lxc/utils.c
+index cab8e893b..17249ab9f 100644
+--- a/src/lxc/utils.c
++++ b/src/lxc/utils.c
+@@ -565,7 +565,15 @@ static int run_buffer(char *buffer)
+ ret = lxc_pclose(move_ptr(f));
+ if (ret == -1)
+ return log_error_errno(-1, errno, "Script exited with error");
+- else if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0)
++
++ if (WIFEXITED(ret) && WEXITSTATUS(ret) == 0)
++ return 0;
++
++ remove_trailing_newlines(output);
++ if (*output)
++ ERROR("Script output: %s", output);
++
++ if (WIFEXITED(ret))
+ return log_error(-1, "Script exited with status %d", WEXITSTATUS(ret));
+ else if (WIFSIGNALED(ret))
+ return log_error(-1, "Script terminated by signal %d", WTERMSIG(ret));
+--
+2.47.3
+
diff --git a/debian/patches/series b/debian/patches/series
index 8a37d9b..8b9baac 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,5 +3,6 @@ apparmor/0002-apparmor-use-abi-directive-in-apparmor-profiles.patch
pve/0001-PVE-Config-deny-rw-mounting-of-sys-and-proc.patch
pve/0002-PVE-Config-attach-always-use-getent.patch
pve/0003-dhclient-script-set-RFC3442-classless-routes.patch
+pve/0004-utils-log-last-output-of-a-failing-hook-as-an-error.patch
cgroupv1-warnings/0001-PVE-Revert-lxc-conf-drop-cgroup1-config-options-lxc..patch
cgroupv1-warnings/0002-PVE-ignore-cgroupv1-settings-with-a-warning.patch
--
2.47.3
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-14 8:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 8:54 [PATCH lxc] d/patches: print a failing hook's last output along with its exit code Hannes Laimer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox