tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: procfs files vs symlink
In article <Yd1XkIokEY/jX/7O%mail.soc.lip6.fr@localhost>,
Manuel Bouyer <bouyer%antioche.eu.org@localhost> wrote:
>-=-=-=-=-=-
>
>On Fri, Jan 07, 2022 at 03:20:04PM +0100, Manuel Bouyer wrote:
>> Hello
>> I'm trying to get a linux binary to run on NetBSD, as stated in this thread
>> http://mail-index.netbsd.org/current-users/2022/01/06/msg041891.html
>>
>> Now I hit an issue where the linux process does a readlink() on a procfs
>> file and gets EINVAL.
>> It seems that this is because, on linux all files in /proc/<pid>/fd/ are
>> symlinks, while on NetBSD they are some kind of hard links.
>> E.g. on linux:
>> bip:/dsk/l1/misc/bouyer/HEAD/clean/src>ls -l /proc/$$/fd/
>> total 0
>> lr-x------ 1 bouyer ita-iatos 64 Jan 7 14:13 0 -> /dev/null
>> lr-x------ 1 bouyer ita-iatos 64 Jan 7 14:13 1 -> /dev/null
>> lrwx------ 1 bouyer ita-iatos 64 Jan 7 15:16 15 -> /dev/pts/11
>> lrwx------ 1 bouyer ita-iatos 64 Jan 7 14:13 16 -> /dev/pts/11
>> lrwx------ 1 bouyer ita-iatos 64 Jan 7 15:16 17 -> /dev/pts/11
>> lrwx------ 1 bouyer ita-iatos 64 Jan 7 15:16 18 -> /dev/pts/11
>> lrwx------ 1 bouyer ita-iatos 64 Jan 7 15:16 19 -> /dev/pts/11
>> lr-x------ 1 bouyer ita-iatos 64 Jan 7 14:13 2 -> /dev/null
>>
>> On NetBSD:
>> armandeche:/local/armandeche1/bouyer>/emul/linux/bin/ls -l /proc/$$/fd/
>> total 0
>> crw--w---- 1 bouyer tty 3, 13 Jan 7 15:19 15
>> crw--w---- 1 bouyer tty 3, 13 Jan 7 15:19 16
>> crw--w---- 1 bouyer tty 3, 13 Jan 7 15:19 17
>>
>> Any idea on how to properly fix it ?
>
>The attached diff changes the procfs behavior to match the linux one, for
>linux processes:
>comore:/home/bouyer>ls -l /proc/self/fd/
>total 1
>crw--w---- 1 bouyer tty 5, 0 Jan 11 11:08 0
>crw--w---- 1 bouyer tty 5, 0 Jan 11 11:08 1
>crw--w---- 1 bouyer tty 5, 0 Jan 11 11:08 2
>lr-xr-xr-x 1 bouyer staff 512 Jan 11 11:08 3 -> /home/bouyer
>
>ls: /proc/self/fd//4: Invalid argument
>lr-xr-xr-x 1 bouyer staff 0 Jan 11 11:08 4
>comore:/home/bouyer>/emul/linux/bin/ls -l /proc/self/fd/
>total 0
>lr-xr-xr-x 1 root wheel 0 Jan 11 11:08 0 -> /dev/ttyp0
>lr-xr-xr-x 1 root wheel 0 Jan 11 11:08 1 -> /dev/ttyp0
>lr-xr-xr-x 1 root wheel 0 Jan 11 11:08 2 -> /dev/ttyp0
>lr-xr-xr-x 1 bouyer staff 0 Jan 11 11:08 3 -> /
>
>and my linux binaries seems to work properly now
>
>would it be OK to commit ?
Err, no :-) The previous behavior uses the original inode from the filesystem.
This means that you can undelete files:
[7:39am] 1978>cat > removeme
23423234234324
^Z
[1] + 21532 Suspended cat > removeme
[7:39am] 1979>bg
[1] cat > removeme &
[2] + Suspended (tty input) cat > removeme
[7:39am] 1980>rm removeme
[7:39am] 1981>cd /proc/21532/fd
[7:39am] 1982>ls -l
total 2
crw--w---- 1 christos tty 5, 2 Jan 12 07:39 0
-rw-rw-r-- 0 christos christos 15 Jan 12 07:39 1
crw--w---- 1 christos tty 5, 2 Jan 12 07:39 2
[7:39am] 1983>ln 1 ~christos/unremove
[7:40am] 1984>fg
cat > removeme (wd: ~)
(wd now: /proc/21532/fd)
[7:40am] 1985>cat ~christos/unremove
23423234234324
Yes, this is a stupid example, but consider doing the same to recover
the log from a long running daemon that was accidentally removed.
christos
Home |
Main Index |
Thread Index |
Old Index