public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH lxc] d/patches: print a failing hook's last output along with its exit code
Date: Wed, 14 Oct 2026 10:54:00 +0200	[thread overview]
Message-ID: <20261014085400.551471-1-h.laimer@proxmox.com> (raw)

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





                 reply	other threads:[~2026-10-14  8:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014085400.551471-1-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal