Notify devd(8) when a process crashed.

This change implements a notification (via devctl) to userland when
the kernel produces coredumps after a process has crashed.
devd can then run a specific command to produce a human readable crash
report.  The command is most usually a helper that runs gdb/lldb
commands on the file/coredump pair.  It's possible to use this
functionality for implementing automatic generation of crash reports.

devd(8) will be notified of the full path of the binary that crashed and
the full path of the coredump file.
This commit is contained in:
Rui Paulo 2015-02-09 23:13:50 +00:00
parent a2e77dc906
commit 842ab62b05
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=278479
2 changed files with 43 additions and 0 deletions

View File

@ -325,4 +325,16 @@ notify 100 {
action "/usr/sbin/automount -c";
};
# Handle userland coredumps.
# This commented out handler makes it possible to run an
# automated debugging session after the core dump is generated.
# Replace action with a proper coredump handler, but be aware that
# it will run with elevated privileges.
notify 10 {
match "system" "kernel";
match "subsystem" "signal";
match "type" "coredump";
action "logger $comm $core";
};
*/

View File

@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include <sys/signalvar.h>
#include <sys/vnode.h>
#include <sys/acct.h>
#include <sys/bus.h>
#include <sys/capsicum.h>
#include <sys/condvar.h>
#include <sys/event.h>
@ -3237,6 +3238,9 @@ coredump(struct thread *td)
void *rl_cookie;
off_t limit;
int compress;
char *data = NULL;
size_t len;
char *fullpath, *freepath = NULL;
#ifdef COMPRESS_USER_CORES
compress = compress_user_cores;
@ -3322,9 +3326,36 @@ coredump(struct thread *td)
error1 = vn_close(vp, FWRITE, cred, td);
if (error == 0)
error = error1;
else
goto out;
/*
* Notify the userland helper that a process triggered a core dump.
* This allows the helper to run an automated debugging session.
*/
len = MAXPATHLEN * 2 + 5 /* comm= */ + 5 /* core= */ + 1;
data = malloc(len, M_TEMP, M_NOWAIT);
if (data == NULL)
goto out;
if (vn_fullpath_global(td, p->p_textvp, &fullpath, &freepath) != 0)
goto out;
snprintf(data, len, "comm=%s", fullpath);
if (freepath != NULL) {
free(freepath, M_TEMP);
freepath = NULL;
}
if (vn_fullpath_global(td, vp, &fullpath, &freepath) != 0)
goto out;
snprintf(data, len, "%s core=%s", data, fullpath);
devctl_notify("kernel", "signal", "coredump", data);
free(name, M_TEMP);
out:
#ifdef AUDIT
audit_proc_coredump(td, name, error);
#endif
if (freepath != NULL)
free(freepath, M_TEMP);
if (data != NULL)
free(data, M_TEMP);
free(name, M_TEMP);
return (error);
}