Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_sig.c
Show First 20 Lines • Show All 3,592 Lines • ▼ Show 20 Lines | |||||
* signal state. Mark the accounting record with the signal termination. | * signal state. Mark the accounting record with the signal termination. | ||||
* If dumping core, save the signal number for the debugger. Calls exit and | * If dumping core, save the signal number for the debugger. Calls exit and | ||||
* does not return. | * does not return. | ||||
*/ | */ | ||||
void | void | ||||
sigexit(struct thread *td, int sig) | sigexit(struct thread *td, int sig) | ||||
{ | { | ||||
struct proc *p = td->td_proc; | struct proc *p = td->td_proc; | ||||
const char *coreinfo; | |||||
int rv; | |||||
PROC_LOCK_ASSERT(p, MA_OWNED); | PROC_LOCK_ASSERT(p, MA_OWNED); | ||||
proc_set_p2_wexit(p); | proc_set_p2_wexit(p); | ||||
p->p_acflag |= AXSIG; | p->p_acflag |= AXSIG; | ||||
/* | /* | ||||
* We must be single-threading to generate a core dump. This | * We must be single-threading to generate a core dump. This | ||||
* ensures that the registers in the core file are up-to-date. | * ensures that the registers in the core file are up-to-date. | ||||
* Also, the ELF dump handler assumes that the thread list doesn't | * Also, the ELF dump handler assumes that the thread list doesn't | ||||
* change out from under it. | * change out from under it. | ||||
* | * | ||||
* XXX If another thread attempts to single-thread before us | * XXX If another thread attempts to single-thread before us | ||||
* (e.g. via fork()), we won't get a dump at all. | * (e.g. via fork()), we won't get a dump at all. | ||||
*/ | */ | ||||
if ((sigprop(sig) & SIGPROP_CORE) && | if ((sigprop(sig) & SIGPROP_CORE) && | ||||
thread_single(p, SINGLE_NO_EXIT) == 0) { | thread_single(p, SINGLE_NO_EXIT) == 0) { | ||||
p->p_sig = sig; | p->p_sig = sig; | ||||
/* | /* | ||||
* Log signals which would cause core dumps | * Log signals which would cause core dumps | ||||
* (Log as LOG_INFO to appease those who don't want | * (Log as LOG_INFO to appease those who don't want | ||||
* these messages.) | * these messages.) | ||||
* XXX : Todo, as well as euid, write out ruid too | * XXX : Todo, as well as euid, write out ruid too | ||||
* Note that coredump() drops proc lock. | * Note that coredump() drops proc lock. | ||||
*/ | */ | ||||
if (coredump(td) == 0) | rv = coredump(td); | ||||
switch (rv) { | |||||
markj: Handle ENOSYS as well? | |||||
case 0: | |||||
sig |= WCOREFLAG; | 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: | |||||
Not Done Inline ActionsI believe coredump() will return ENOTCAPABLE if the program is in capability mode and kern.capmode_coredump=0. It would be useful to have a case here for that, with an error message that points users at the sysctl. markj: I believe coredump() will return ENOTCAPABLE if the program is in capability mode and kern. | |||||
coreinfo = " (no core dump - too large)"; | |||||
break; | |||||
default: | |||||
coreinfo = " (no core dump - other error)"; | |||||
Not Done Inline ActionsAdd a break here? markj: Add a `break` here? | |||||
} | |||||
if (kern_logsigexit) | if (kern_logsigexit) | ||||
log(LOG_INFO, | log(LOG_INFO, | ||||
"pid %d (%s), jid %d, uid %d: exited on " | "pid %d (%s), jid %d, uid %d: exited on " | ||||
"signal %d%s\n", p->p_pid, p->p_comm, | "signal %d%s\n", p->p_pid, p->p_comm, | ||||
p->p_ucred->cr_prison->pr_id, | p->p_ucred->cr_prison->pr_id, | ||||
td->td_ucred->cr_uid, | td->td_ucred->cr_uid, | ||||
sig &~ WCOREFLAG, | sig &~ WCOREFLAG, coreinfo); | ||||
sig & WCOREFLAG ? " (core dumped)" : ""); | |||||
} else | } else | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
exit1(td, 0, sig); | exit1(td, 0, sig); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
/* | /* | ||||
* Send queued SIGCHLD to parent when child process's state | * Send queued SIGCHLD to parent when child process's state | ||||
▲ Show 20 Lines • Show All 934 Lines • Show Last 20 Lines |
Handle ENOSYS as well?