r1557: Add sigchld handling to winbindd. Next step is to have the child restarted if
[Samba/gebeck_regimport.git] / examples / scripts / backtrace
blob2ea6a4d00a1d3f587f240a026981a7c80c1bb0ec
1 #! /bin/sh
3 # Author: Andrew Tridgell <tridge at samba dot org>
5 # we want everything on stderr, so the program is not disturbed
6 exec 1>&2
8 BASENAME=$( basename $0)
10 test -z ${GDB_BIN} && GDB_BIN=$( type -p gdb)
11 if [ -z ${GDB_BIN} ]; then
12 echo "ERROR: ${BASENAME} needs an installed gdb. "
13 exit 1
16 if [ -z $1 ]; then
17 echo "ERROR: ${BASENAME} needs a PID. "
18 exit 1
20 PID=$1
22 # use /dev/shm as default temp directory
23 test -d /dev/shm && \
24 TMP_BASE_DIR=/dev/shm || \
25 TMP_BASE_DIR=/var/tmp
26 TMPFILE=$( mktemp -p ${TMP_BASE_DIR} backtrace.XXXXXX)
27 if [ $? -ne 0 ]; then
28 echo "ERROR: ${basename} can't create temp file in ${TMP_BASE_DIR}. "
29 exit 1
32 cat << EOF > "${TMPFILE}"
33 set height 0
34 up 8
35 bt full
36 quit
37 EOF
39 ${GDB_BIN} -x "${TMPFILE}" "/proc/${PID}/exe" "${PID}"
41 /bin/rm -f "${TMPFILE}"