Re: New system call wanted: fdreopen

From: Theodore Ts'o
Date: Sun Dec 09 2012 - 11:27:39 EST


On Sun, Dec 09, 2012 at 03:03:30PM +0000, Tristan Wibberley wrote:
>
> - /proc/self/fd/* does not solve this problem because the file might no
> longer be available at the same place in the filesystem. In some
> otherwise simple message passing or ReSTful IPC a different file will
> be available at that path.

Actually, /proc/self/fd/* _will_ work. When you do a ls -l, it looks
like a symlink, but the files in /proc/self/fd (and /proc/<pid>/fd
more generally) are magic. If you open files in /proc/<pid>/fd/*, it
will do what you want.

See for yourself:

% cat > /tmp/foo.test
foo
bar
^Z
% jobs -l # (and note the pid, hereafter <pid>)
% ls -l /proc/<pid>/fd
% mv /tmp/foo.test /tmp/foo2.test
% ls -l /proc/<pid>/fd # note that the symlink now points at /tmp/foo2.test
% cat /proc/<pid>/fd/1 # note that it works!
% rm /tmp/foo2.test
% ls -l /proc/<pid>/fd # note that the symlink now has "(deleted)" at the end
% cat /proc/<pid>/fd/1 # note that it works!

This is of course horribly Linux-specific, but so would be a new
system call like your proposed fdrepon. Better yet, using
/proc/self/fd/* will work *now*. You don't have to wait for a new
system call in a future verison of the kernel to start shipping in new
distributions.

Regards,

- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/