From: Bradley Morgan <include@grrlz.net>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Bradley Morgan <include@grrlz.net>
Subject: [PATCH] reboot: log the task that requested a reboot or shutdown
Date: Sun, 19 Jul 2026 15:29:09 +0000 [thread overview]
Message-ID: <20260719152909.3133-1-include@grrlz.net> (raw)
When a machine reboots or powers off, the kernel log records what
happened but not who asked for it. The reboot syscall throws the
caller identity away, and reconstructing it afterwards from userspace
logs is unreliable and more likely than not impossible.
"What made this reboot?" is a question every fleet operator has had to
answer with guesswork.
log the comm and pid of the calling task once at the syscall boundary,
before the requested command is carried out, e.g:
reboot: initiated by systemd-shutdow[1]
reboot: Restarting system
The existing "Restarting system", "System halted" and "Power down"
lines are left untouched, so anything parsing dmesg today keeps
working. The two ctrl alt del toggle commands are excluded so init
setting the mode does not add a line to dmesg on every boot.
Signed-off-by: Bradley Morgan <include@grrlz.net>
---
kernel/reboot.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/reboot.c b/kernel/reboot.c
index c10ac6a0200d..8ac96c527a4e 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -754,6 +754,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
if (ret)
return ret;
+ if (cmd != LINUX_REBOOT_CMD_CAD_ON && cmd != LINUX_REBOOT_CMD_CAD_OFF)
+ pr_info("initiated by %s[%d]\n",
+ current->comm, task_pid_nr(current));
+
/* Instead of trying to make the power_off code look like
* halt when pm_power_off is not set do it the easy way.
*/
--
2.53.0
next reply other threads:[~2026-07-19 15:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 15:29 Bradley Morgan [this message]
2026-07-19 15:56 ` [PATCH] reboot: log the task that requested a reboot or shutdown Bradley Morgan
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=20260719152909.3133-1-include@grrlz.net \
--to=include@grrlz.net \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/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