To find out the names of open files in a process

Steven Sargent sarge at sting.Berkeley.EDU
Thu Feb 4 22:34:05 AEST 1988


You can (with fair effort) discover the names of many (not all)
disk files by fstat'ing the descriptor, then rooting around in
directories to find the <name,inumber> translation, then winding
up to the root.  (getwd(3), or pwd(1) for usg'ers, does something
like this, but it depends on being able to start from "."  This is
somewhat more complicated).  You can read the disk -- write a
separate program that has readonly permissions for the disk --
being sure that you turn off close-on-exec flags for your fd's
before running it.  Note:
	- fails for non-disk files (e.g., pipes); restarting your
		process in mid-IPC is problematical, anyway;
	- fails if your process has created, then unlinked, a file
		(standard trick for creating temp files; on last
		close, the bits are reclaimed);
You may not need read-disk permission (I'm too fuzzy right now
to be sure), and just replicate what getwd does; in which case
	- fails if you don't have read permission on any of the
		intermediate directories.

Salting away the names of files opened by open(2), &c. is ineffective
since you can't know the names of files inherited by I/O redirection.

I know of at least one implementation in which the full path name
associated with u.u_cdir is maintained by the operating system
(chdir(), &c. are never "fooled" by symbolic links).  I suppose
you could do the same thing with filenames ... but that way leads
VMS.


S.



More information about the Comp.unix.wizards mailing list