X

Debugging smf(5)-managed processes

Recently, I've seen a couple questions (internally and externally) about the best way to debug something controlled by smf(5); since the process isn't started up directly, the usual ways of running things under a debugger aren't effective. If you don't need to debug the initialization process, it's also easy; just attach the debugger after the daemon is running.

If you need to debug the initialization, however, you need some way to stop the process before it does so. The easiest way is to use dtrace(1M). The following script:

# cat > stop_daemon.d <<\\EOF
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option destructive
BEGIN
{
printf("READY\\n");
}
proc:::start
/execname == $$1/
{
stop();
printf("stopped %d\\n", pid);
exit(0);
}
EOF
# chmod +x stop_daemon.d

Will let you grab the \*daemon\* process (i.e. at the time of the second fork()). If you need to grab the parent process, change
proc:::start to proc:::exec-success. It takes the "execname" of the daemon (i.e. the first 16 characters of the executable name, which you can get using "pgrep -l daemon") as its argument. For example, if you wanted to debug the fault manager, you can do:
# ./stop_daemon fmd &
# READY
svcadm restart fmd
# stopped 5678
mdb -p 5678
Loading modules: [ fmd ld.so.1 ... ]
>

Any debugger which can attach to processes will work; mdb(1), dbx(1), gdb(1), etc.

Technorati Tag:

Technorati Tag:

Join the discussion

Comments ( 1 )
  • UX-admin Wednesday, July 16, 2014

    Wow; this is super-useful information. There were so many times I was stuck debugging SMF, if I only knew this earlier...


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.