This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Symlinks under /proc


On Tue, 1 Feb 2005, Corinna Vinschen wrote:

> On Jan 31 19:02, Igor Pechtchanski wrote:
> > On Mon, 31 Jan 2005, Corinna Vinschen wrote:
> > > Talking about experiments, did you also try it on Cygwin if it works or
> > > did you just look on Linux how it's implemented there?
> >
> > I tried it on the CVS HEAD.  Making /dev/stdin a symlink works wherever
> > /proc/self/fd/0 works (as expected).
> > Both work perfectly for programs invoked directly from the bash command
> > line.  Pipes are another story.  The following fails for me:
> >
> > $ echo "blaaah" | perl -pe 's/aaa/bbb/g' /proc/self/fd/0
> > Can't open /proc/self/fd/0: No such file or directory.
> >
> > This shows some more detail:
> >
> > $ echo "blaaah" | perl -e 'print `ls -l /proc/self/fd/0 2>&1`,`ls -lL /proc/self/fd/0 2>&1`'
> > lrwxrwxrwx    1 igor     root            0 Jan 31 18:54 /proc/self/fd/0 -> pipe:[1700]
> > ls: /proc/self/fd/0: No such file or directory
> >
> > Could it be that the pipe is closed before the child process completes?
> > But no, making the first process in the pipe longer-running doesn't help:
> >
> > $ (echo "blaaah";sleep 10;echo "blaaarg") | perl -e 'print `ls -lL /proc/self/fd/0`'
> > $ (echo "blaaah";sleep 10;echo "blaaarg") | perl -e 'print `ls -l /proc/self/fd/0 2>&1`,`ls -lL /proc/self/fd/0 2>&1`'
> > lrwxrwxrwx    1 igor     root            0 Jan 31 18:54 /proc/self/fd/0 -> pipe:[1700]
> > ls: /proc/self/fd/0: No such file or directory
> >
> > Doesn't look like the symlink target is valid.
>
> Correct.  The name for pipes and, FWIW, AF_INET sockets, is generated
> following the Linux naming rules, but it's not possible to resolve it.
> I'm not sure how to implement that right now.

Looks like Linux resolves this at the kernel level, in the link processing
code.  The following (on Linux) shows that the link target is not resolved
outside of a link:

$ echo "blaaah" | perl -e 'print `ls -l /proc/self/fd/0 2>&1`,`ls -lL /proc/self/fd/0 2>&1`;$a=readlink("/proc/self/fd/0");print `ls -l $a 2>&1`,length($a),"\n"'
lr-x------    1 igor     igor           64 Feb  1 09:28 /proc/self/fd/0 -> pipe:[480743]
prw-------    1 igor     igor            0 Feb  1 09:28 /proc/self/fd/0
ls: pipe:[480743]: No such file or directory
13

Interestingly enough, when the "$a=readlink(...);print" part is removed
from the Perl script, the pipe has file length of 7.  With the readlink,
the pipe shows as empty.

I'm also unsure as to why the length of the symlink is 64 bytes, when
readlink returns only 13.  Looks like there are extra special characters
in the symlink name (that would enable the kernel to process the link
target as a pipe).
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]