History

pidfds: add coredump_code field to pidfd_info

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.

Emanuele Rocca committed 7 months ago

Commit 701f7f41 parent 3fc66a12 files · +12 −4Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/pidfd.h+4−0
@@ -29,10 +29,12 @@ · 28 unmodified lines
2929 #define PIDFD_INFO_COREDUMP (1UL << 4) /* Only returned if requested. */
3030 #define PIDFD_INFO_SUPPORTED_MASK (1UL << 5) /* Want/got supported mask flags */
3131 #define PIDFD_INFO_COREDUMP_SIGNAL (1UL << 6) /* Always returned if PIDFD_INFO_COREDUMP is requested. */
32+#define PIDFD_INFO_COREDUMP_CODE (1UL << 7) /* Always returned if PIDFD_INFO_COREDUMP is requested. */
3233
3334 #define PIDFD_INFO_SIZE_VER0 64 /* sizeof first published struct */
3435 #define PIDFD_INFO_SIZE_VER1 72 /* sizeof second published struct */
3536 #define PIDFD_INFO_SIZE_VER2 80 /* sizeof third published struct */
37+#define PIDFD_INFO_SIZE_VER3 88 /* sizeof fourth published struct */
3638
3739 /*
3840 * Values for @coredump_mask in pidfd_info.
@@ -99,6 +101,8 @@ struct pidfd_info { · 60 unmodified lines
99101 struct /* coredump info */ {
100102 __u32 coredump_mask;
101103 __u32 coredump_signal;
104+ __u32 coredump_code;
105+ __u32 coredump_pad; /* align supported_mask to 8 bytes */
102106 };
103107 __u64 supported_mask; /* Mask flags that this kernel supports */
104108 };