Re: [PATCH v3] pidfds: add coredump_code field to pidfd_info

From: Christian Brauner

Date: Mon Mar 23 2026 - 08:04:03 EST


On Sun, Mar 22, 2026 at 09:31:11PM +0100, Emanuele Rocca wrote:
> The struct pidfd_info currently exposes in a field called coredump_signal the
> signal number (si_signo) that triggered the dump (for example, 11 for SIGSEGV).
> However, it is also valuable to understand the reason why that signal was sent.
> This additional context is provided by the signal code (si_code), such as 2 for
> SEGV_ACCERR.
>
> Add a new field to struct pidfd_info called coredump_code with the value of
> si_code for the benefit of sysadmins who pipe core dumps to user-space programs
> for later analysis. The following snippet illustrates a simplified C program
> that consumes coredump_signal and coredump_code, and then logs core dump
> signals and codes to a file:
>
> int pidfd = (int)atoi(argv[1]);
>
> struct pidfd_info info = {
> .mask = PIDFD_INFO_EXIT | PIDFD_INFO_COREDUMP,
> };
>
> if (ioctl(pidfd, PIDFD_GET_INFO, &info) == 0)
> if (info.mask & PIDFD_INFO_COREDUMP)
> fprintf(f, "PID=%d, si_signo: %d si_code: %d\n",
> info.pid, info.coredump_signal, info.coredump_code);
>
> Assuming the program is installed under /usr/local/bin/core-logger, core dump
> processing can be enabled by setting /proc/sys/kernel/core_pattern to
> '|/usr/local/bin/dumpstuff %F'.
>
> systemd-coredump(8) already uses pidfds to process core dumps, and it could be
> extended to include the values of coredump_code too.
>
> Signed-off-by: Emanuele Rocca <emanuele.rocca@xxxxxxx>
> ---
> Resending as a new thread, apologies for sending v2 as a follow-up to
> the kernel test robot instead!
>
> V1 -> V2: Add coredump_pad to struct pidfd_info to ensure the struct has
> the same size on both 64 bit and 32 bit systems. The issue was spotted
> by the kernel test robot.
> v1: https://lore.kernel.org/lkml/ab29J6KsQm8Xg3LR@NH27D9T0LF/
> Link: https://lore.kernel.org/lkml/202603211842.JCwUVYTI-lkp@xxxxxxxxx/
>
> V2 -> V3: Sending as a new thread, same as v2 otherwise.
> v2: https://lore.kernel.org/lkml/ab68fUmCK4An1UH-@NH27D9T0LF/
>
> fs/pidfs.c | 12 ++++---
> include/uapi/linux/pidfd.h | 4 +++
> .../coredump/coredump_socket_protocol_test.c | 26 +++++++++++++++
> .../selftests/coredump/coredump_socket_test.c | 32 +++++++++++++++++++
> .../coredump/coredump_test_helpers.c | 4 +--
> tools/testing/selftests/pidfd/pidfd.h | 5 +++
> .../testing/selftests/pidfd/pidfd_info_test.c | 1 +
> 7 files changed, 78 insertions(+), 6 deletions(-)

Please split the kernel code from the selftest code into separate
commits. Thanks!