#!/usr/sbin/dtrace -qws #pragma D option strsize=500 /* * Copyright 2005 Sun Microsystems, Inc. ALL RIGHTS RESERVED * Use of this software is authorized pursuant to the terms of the license found at * http://developers.sun.com/berkeley_license.html * * By Greg Nakhimovsky and Morgan Herrington, Sun MDE, April 2005. * * This DTrace script can be run as a daemon started by root * (perhaps on boot with an RC script like /etc/rc2.d/S97app_crash), * or it can be run by any user with appropriate DTrace permissions * (in which case it would work for that user's applications only). * * args[1]->pr_pid is the signal-receiving process id; * Only react if it is the same as the sending process id (pid). */ proc:::signal-send /(args[2] == SIGBUS || args[2] == SIGSEGV) && pid == args[1]->pr_pid/ { stop(); /* * If $ON_APP_CRASH_INVOKE is defined in pid space, * run user-provided script as $USER */ system( "%s=%d; %s=%d; %s=%d; %s=%s; %s %s %s %s %s %s %s %s %s", "CRASH_PID", pid, "CRASH_UID", uid, "DTRACE_UID", $uid, "PROG", execname, "SCRIPT=`/bin/pargs -e $CRASH_PID | ", " /bin/grep ON_APP_CRASH_INVOKE | /bin/cut -d= -f2`;", "[ -z \"$SCRIPT\" -o ! -x \"$SCRIPT\" ] && exit 0;", "if [ $DTRACE_UID -eq 0 -a $CRASH_UID -ne 0 ] ; then", " USER_NAME=`/bin/getent passwd $CRASH_UID|/bin/cut -d: -f1`;", " /bin/su $USER_NAME -c \"$SCRIPT $CRASH_PID $PROG\";", "else ", " $SCRIPT $CRASH_PID $PROG; ", "fi" ); /* Continue normal processing */ system("/bin/prun %d", pid); }