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.
Showing the changes to include/uapi (1 of 2 files). Show all
Unified · Split
| @@ -29,10 +29,12 @@ · 28 unmodified lines | ||
| 29 | 29 | #define PIDFD_INFO_COREDUMP (1UL << 4) /* Only returned if requested. */ |
| 30 | 30 | #define PIDFD_INFO_SUPPORTED_MASK (1UL << 5) /* Want/got supported mask flags */ |
| 31 | 31 | #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. */ | |
| 32 | 33 | |
| 33 | 34 | #define PIDFD_INFO_SIZE_VER0 64 /* sizeof first published struct */ |
| 34 | 35 | #define PIDFD_INFO_SIZE_VER1 72 /* sizeof second published struct */ |
| 35 | 36 | #define PIDFD_INFO_SIZE_VER2 80 /* sizeof third published struct */ |
| 37 | +#define PIDFD_INFO_SIZE_VER3 88 /* sizeof fourth published struct */ | |
| 36 | 38 | |
| 37 | 39 | /* |
| 38 | 40 | * Values for @coredump_mask in pidfd_info. |
| @@ -99,6 +101,8 @@ struct pidfd_info { · 60 unmodified lines | ||
| 99 | 101 | struct /* coredump info */ { |
| 100 | 102 | __u32 coredump_mask; |
| 101 | 103 | __u32 coredump_signal; |
| 104 | + __u32 coredump_code; | |
| 105 | + __u32 coredump_pad; /* align supported_mask to 8 bytes */ | |
| 102 | 106 | }; |
| 103 | 107 | __u64 supported_mask; /* Mask flags that this kernel supports */ |
| 104 | 108 | }; |