From 6edbe5616c761bff9e570d9c77db0644a9487174 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 27 Oct 2017 10:26:03 -0400 Subject: [PATCH] Provide some more information for userland core dumps Previously the log message indicated only "(core dumped)" if a core was successfully created, or nothing if it was not. This provides insufficient information to faciliate debugging. Dtrace is no help as coredump() is static and we cannot find the return value via fbt. Expand the log message to include error return value information. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39942 --- sys/kern/kern_sig.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 5876e2e9392..df3ebc0103c 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -3598,6 +3598,8 @@ void sigexit(struct thread *td, int sig) { struct proc *p = td->td_proc; + const char *coreinfo; + int rv; PROC_LOCK_ASSERT(p, MA_OWNED); proc_set_p2_wexit(p); @@ -3622,16 +3624,31 @@ sigexit(struct thread *td, int sig) * XXX : Todo, as well as euid, write out ruid too * Note that coredump() drops proc lock. */ - if (coredump(td) == 0) + rv = coredump(td); + switch (rv) { + case 0: sig |= WCOREFLAG; + coreinfo = " (core dumped)"; + break; + case EFAULT: + coreinfo = " (no core dump - bad address)"; + break; + case EINVAL: + coreinfo = " (no core dump - invalid argument)"; + break; + case EFBIG: + coreinfo = " (no core dump - too large)"; + break; + default: + coreinfo = " (no core dump - other error)"; + } if (kern_logsigexit) log(LOG_INFO, "pid %d (%s), jid %d, uid %d: exited on " "signal %d%s\n", p->p_pid, p->p_comm, p->p_ucred->cr_prison->pr_id, td->td_ucred->cr_uid, - sig &~ WCOREFLAG, - sig & WCOREFLAG ? " (core dumped)" : ""); + sig &~ WCOREFLAG, coreinfo); } else PROC_UNLOCK(p); exit1(td, 0, sig);