From 18f6c17b71061cdae467c7ce83b9ccedc8eb3c97 Mon Sep 17 00:00:00 2001 From: vangyzen Date: Tue, 16 Jul 2019 15:51:09 +0000 Subject: [PATCH] Adds signal number format to kern.corefile Add format capability to core file names to include signal that generated the core. This can help various validation workflows where all cores should not be considered equally (SIGQUIT is often intentional and not an error unlike SIGSEGV or SIGBUS) Submitted by: David Leimbach (leimy2k@gmail.com) Reviewed by: markj MFC after: 1 week Relnotes: sysctl kern.corefile can now include the signal number Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D20970 --- share/man/man5/core.5 | 2 ++ sys/kern/kern_sig.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/share/man/man5/core.5 b/share/man/man5/core.5 index e8c747ecd22b..c7449637b910 100644 --- a/share/man/man5/core.5 +++ b/share/man/man5/core.5 @@ -82,6 +82,8 @@ generated by a particular process. process name. .It Em \&%P processes PID. +.It Em \&%S +signal during core. .It Em \&%U process UID. .El diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index a3a05cef1038..0551f1c5e0b0 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -3433,7 +3433,7 @@ corefile_open_last(struct thread *td, char *name, int indexpos, */ static int corefile_open(const char *comm, uid_t uid, pid_t pid, struct thread *td, - int compress, struct vnode **vpp, char **namep) + int compress, int signum, struct vnode **vpp, char **namep) { struct sbuf sb; struct nameidata nd; @@ -3482,6 +3482,9 @@ corefile_open(const char *comm, uid_t uid, pid_t pid, struct thread *td, case 'P': /* process id */ sbuf_printf(&sb, "%u", pid); break; + case 'S': /* signal number */ + sbuf_printf(&sb, "%i", signum); + break; case 'U': /* user id */ sbuf_printf(&sb, "%u", uid); break; @@ -3599,7 +3602,7 @@ coredump(struct thread *td) PROC_UNLOCK(p); error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td, - compress_user_cores, &vp, &name); + compress_user_cores, p->p_sig, &vp, &name); if (error != 0) return (error);