Dtrace notes and scripts
File Descriptors
Tracking down leaking file descriptors is a real pain. While far from perfect, here's what I used to track down the latest bug I had. This was a bug in lighttpd so if you're using it to debug something else replace mod_webdav_subrequest_handler with your suspect function.#!/usr/sbin/dtrace -s
#pragma D option flowindent
pid$target::mod_webdav_subrequest_handler:entry
{
self->follow = 1;
}
pid$target:::entry,
pid$target:::return
/self->follow/
{
}
syscall::open*:entry
/self->follow/
{
self->fh = arg0;
}
syscall::open*:return
/self->follow && self->fh/
{
printf("open: %d: %s\n", arg1, copyinstr(self->fh));
}
syscall::close*:entry
/self->follow/
{
printf("close: %d\n", arg0);
}
pid$target::mod_webdav_subrequest_handler:return
/self->follow/
{
self->follow = 0;
}
on 2012-01-10 at 03:30