Automatic backtrace [Was: Re: NetAPP/Samba 3.0/plugs]

Esh, Andrew AEsh at
Wed Mar 13 13:36:02 GMT 2002

Can the smbd process pid be passed to a panic action?

#!/bin/bash -norc
# bt - backtrace a process, given its PID
# Copyright (c) 2002 Andrew C. Esh
# License: Forceless - You can use it any way
# you like, as long as you don't use it to force
# anyone else to do anything they don't want to.
# Log:
#     3/13/2002 ACE Initial development. Works with Redhat 7.1.

# Find the process's command
cmd=`/bin/ps --no-heading -p $1 -o cmd | cut -f1 -d' ' 2>/dev/null`

# Leave if process not found
if [ $? -eq 1 ] ; then
    echo Process not found
    exit 1

# Leave if command not found
if [ X${cmd}X == XX ] ; then
    echo Command not found
    exit 2

# Strip decorating braces on swapped processes
cmd=`echo $cmd | sed 's/\[//g' | sed 's/\]//g'`

# Find the process's state
state=`/bin/ps -p $1 -o stat --no-heading`

# Leave if gdb won't be able to trace it
if [ X${state}X == XTX ] ; then
    echo Process is being traced already
    exit 3

# Find the executable, if the ps listing didn't
if [ ! -f ${cmd} -o ! -x ${cmd} ] ; then
    cmd2=`which $cmd 2>/dev/null`
    if [ $? -eq 0 ] ; then
	echo Executable not found
	exit 4

# Backtrace it
echo "bt" >/tmp/backtrace$$.txt
echo "q" >>/tmp/backtrace$$.txt
echo "Backtrace of process $1 '$cmd'"
gdb $cmd $1 -x /tmp/backtrace$$.txt -batch 2>/dev/null
rm /tmp/backtrace$$.txt

-----Original Message-----
From: Mike Gerdts [mailto:Michael.Gerdts at]
Sent: Wednesday, March 13, 2002 6:19 AM
To: Andrew Bartlett
Cc: Scott Gifford; David Lee; Samba Technical Mailing List
Subject: Re: Automatic backtrace [Was: Re: NetAPP/Samba 3.0/plugs]

On Wed, 2002-03-13 at 03:56, Andrew Bartlett wrote:
> Scott Gifford wrote:

> > Perhaps I'm missing something obvious, but why not just let Samba dump
> > core?...It's straightforward to provide a backtrace from a core file.
> Where?  Under what uid?  Following what symlinks?  
> Dumping core just has 'bad idea' written all over it.  Plus the people
> who know how to use gdb on a core file would already have a magic 'panic
> action' already setup.

Most systems will not dump core if real, effective, and saved (if it
exists) do not match.

Solaris 7 with the right patches and later allows you to get core dumps
in a defined location, even for setuid programs.  See coreadm(1) or
for details.  I have used this quit successfully with a variety of programs
(including samba) to cause core dumps to be put in /var/cores, which I
create as owned by root and mode 700.

I have seen mention of a similar patch for Linux mentioned.  I first saw
it mentioned at , the kernel
mailing list message is .


-------------- next part --------------
HTML attachment scrubbed and removed

More information about the samba-technical mailing list