Web lists-archives.com

Re: /dev/fd/N not synonymous with file descriptor N; it is on Linux




On Sun, 6 Jan 2019 21:19:50, Corinna Vinschen  wrote:
> 
> On Dec 16 17:31, Houder wrote:
> > L.S.,
> >
> > /dev/fd/N not synonymous with file descriptor N; it is on Linux
> >
> > 64-@@ cat /dev/fd/0 <<\EOF
> > > Hi
> > > EOF
> > cat: /dev/fd/0: No such file or directory
> >
> > fails on Cygwin; not on Linux.
> >
> > Also see:
> >
> >     https://cygwin.com/ml/cygwin/2018-12/msg00028.html
> >     ( Bash heredoc on FD 3 )
> >
> > Based on the output of strace on Linux, I composed an STC, that duplicates
> > the steps taken by bash (and cat).
> 
> This should work in the latest developer snapshot uploaded to
> https://cygwin.com/snapshots/  Please give it a try.
> 
> Thanks,
> Corinna

Nice!

This solves: <program> -i /dev/fd/N N<<EOF (i.e. Steven Penny's problem)

Howver ...
(and I sure that I am not telling you anything new)

it still not the same as Linux ...

So, for the record only:

 - suppose a hacker deletes the logfile, but the file is still "help open"
   by some program
 - the logfile can be rescued on Linux, but not on Cygwin

64-@@ echo aap > aap.txt
64-@@ tail -f aap.txt
aap

.. in another terminal
64-@@ ls -l /proc/4120/fd # 4120 is the procid of "tail"
total 0
lrwxrwxrwx 1 Henri None 0 Jan 22 09:25 0 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Jan 22 09:25 1 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Jan 22 09:25 2 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Jan 22 09:25 3 -> /home/Henri/redirect/aap.txt

64-@@ stat -L /proc/4120/fd/3 # shows a file of 4 bytes ...
  File: /proc/4120/fd/3
  Size: 4               Blocks: 1          IO Block: 65536  regular file
Device: 33d91880h/869865600d    Inode: 35747322042382612  Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   Henri)   Gid: (  513/    None)
Access: 2019-01-22 09:24:41.978178200 +0100
Modify: 2019-01-22 09:24:41.978178200 +0100
Change: 2019-01-22 09:24:41.978178200 +0100
 Birth: 2019-01-22 09:24:41.978178200 +0100

64-@@ rm aap.txt # hacker removing the logfile

64-@@ stat -L /proc/4120/fd/3
  File: /proc/4120/fd/3
  Size: 4               Blocks: 1          IO Block: 65536  regular file
Device: 33d91880h/869865600d    Inode: 35747322042382612  Links: 0
Access: (0644/-rw-r--r--)  Uid: ( 1000/   Henri)   Gid: (  513/    None)
Access: 2019-01-22 09:24:41.978178200 +0100
Modify: 2019-01-22 09:24:41.978178200 +0100
Change: 2019-01-22 09:26:25.021040800 +0100
 Birth: 2019-01-22 09:24:41.978178200 +0100

64-@@ cp /proc/4120/fd/3 noot.txt # logfile rescue
64-@@ cat noot.txt # empty! (however, this works on Linux)
64-@@ cat /proc/4120/fd/3 # indeed, does not show contents
64-@@

=====


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple