This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: Get filename from fd
On Tue, 2010-09-07 at 11:50 +0200, Andi Kleen wrote:
> "Rob Donovan" <rob@proivrc.com> writes:
> > Is it possible to get from $fd to a filename in some way, in probes like
> > syscall.fcntl etc?
> >
> > I know I can probe syscall.open() and then keep an array of FD / filenames,
> > but this doesn't help me when I need to trace a process that has already
> > been started some time ago, and already has opened files.
>
> There's a undocumented internal utility function for this in vfs.stp:
> __file_filename()
>
> I agree it would make sense to export it. I have been using it too.
And it is a "pure" stap function, so should be safe to export.
You do need to convert from file descriptor (fd) to file first though.
Which is a little tricky, but can be done with something like:
$ stap -e 'probe syscall.fcntl
{ file = @cast(task_current(), "task_struct")->files->fdt->fd[fd];
printf("%s:%s (%s)\n",
execname(), __file_filename(file), argstr); }'
This will not work 100% since you aren't supposed to access the
files_fdtable (fdt) directly. But stap will catch any bad references.
Cheers,
Mark