Add kernel logging of processes which exit on signals which can

cause a core to drop, and whether the core dropped, or, if it did
not, why not (i.e. error number). Logs process ID, name, signal that
hit it, and whether the core dump was successful.

logging only happens if kern_logsigexit is non-zero, and it can be
changed by the new sysctl(3) value KERN_LOGSIGEXIT. The name of this
sysctl and its function are taken from FreeBSD, at the suggestion
of Greg Woods in PR 6224. Default behavior is zero for a normal
kernel, and one for a kernel compiled with DIAGNOSTIC.
This commit is contained in:
fair 2000-02-06 07:29:56 +00:00
parent a4746f91c3
commit c75556a12f
3 changed files with 35 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sig.c,v 1.95 1999/12/30 16:00:23 eeh Exp $ */
/* $NetBSD: kern_sig.c,v 1.96 2000/02/06 07:29:56 fair Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@ -1238,17 +1238,42 @@ killproc(p, why)
* If dumping core, save the signal number for the debugger. Calls exit and
* does not return.
*/
#if defined(DIAGNOSTIC) || defined(DEBUG)
int kern_logsigexit = 1; /* not static to make public for sysctl */
#else
int kern_logsigexit = 0; /* not static to make public for sysctl */
#endif
static char *logcoredump =
"pid %d (%s), uid %d: exited on signal %d (core dumped)\n";
static char *lognocoredump =
"pid %d (%s), uid %d: exited on signal %d (core not dumped, err = %d)\n";
void
sigexit(p, signum)
register struct proc *p;
int signum;
{
int error;
char *errmsg;
p->p_acflag |= AXSIG;
if (sigprop[signum] & SA_CORE) {
p->p_sigacts->ps_sig = signum;
if (coredump(p) == 0)
if ((error = coredump(p)) == 0) {
signum |= WCOREFLAG;
errmsg = logcoredump;
} else {
errmsg = lognocoredump;
}
if (kern_logsigexit)
log(LOG_INFO, errmsg, p->p_pid, p->p_comm,
p->p_cred && p->p_ucred ? p->p_ucred->cr_uid : -1,
signum &~ WCOREFLAG, error);
}
exit1(p, W_EXITCODE(0, signum));
/* NOTREACHED */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sysctl.c,v 1.56 2000/01/16 15:07:48 assar Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.57 2000/02/06 07:29:58 fair Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@ -233,6 +233,7 @@ int defcorenamelen = sizeof(DEFCORENAME);
char defcorename[MAXPATHLEN] = "%n.core";
int defcorenamelen = sizeof("%n.core");
#endif
extern int kern_logsigexit;
/*
* kernel related system variables.
@ -422,6 +423,8 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
return (sysctl_rdint(oldp, oldlenp, newp, 1));
case KERN_LOGIN_NAME_MAX:
return (sysctl_rdint(oldp, oldlenp, newp, LOGIN_NAME_MAX));
case KERN_LOGSIGEXIT:
return (sysctl_int(oldp, oldlenp, newp, newlen, &kern_logsigexit));
default:
return (EOPNOTSUPP);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysctl.h,v 1.39 1999/11/19 10:41:41 bouyer Exp $ */
/* $NetBSD: sysctl.h,v 1.40 2000/02/06 07:29:59 fair Exp $ */
/*
* Copyright (c) 1989, 1993
@ -157,7 +157,8 @@ struct ctlname {
#define KERN_MEMORY_PROTECTION 43 /* int: POSIX memory protections */
#define KERN_LOGIN_NAME_MAX 44 /* int: max length login name + NUL */
#define KERN_DEFCORENAME 45 /* old: sort core name format */
#define KERN_MAXID 46 /* number of valid kern ids */
#define KERN_LOGSIGEXIT 46 /* int: log signalled processes */
#define KERN_MAXID 47 /* number of valid kern ids */
#define CTL_KERN_NAMES { \
{ 0, 0 }, \
@ -206,6 +207,7 @@ struct ctlname {
{ "memory_protection", CTLTYPE_INT }, \
{ "login_name_max", CTLTYPE_INT }, \
{ "defcorename", CTLTYPE_STRING }, \
{ "logsigexit", CTLTYPE_INT }, \
}
/*