in reply to What is wrong in blocking?
The problem may stem from this attribute of dup(2):perl t50 </dev/tty perl t50 2>/dev/null
dup and dup2 create a copy of the file descriptor oldfd.I suspect this dup happens in your login program, such as ssh or /bin/login.After successful return of dup or dup2, the old and new descriptors may be used interchangeably. They share locks, file position pointers and flags; for example, if the file position is modified by using lseek on one of the descriptors, the position is also changed for the other.
Note that this behavior isn't perl-specific; I see the exact same thing with this C program:
#include <unistd.h> #include <stdio.h> #include <fcntl.h> void main() { char buf[8192]; int rr; fcntl(STDERR_FILENO,F_SETFL,O_NONBLOCK); while ( (rr = read(STDIN_FILENO,buf,8192)) > 0) { write(STDOUT_FILENO,buf,rr); } if (rr < 0) { perror("read error:"); exit(1); } exit(0); }
Whether or not this is a bug depends on POSIX, I suppose.
At any rate, hopefully one of the above workarounds will help. Good luck!
Update: It looks like this is How Things Have Always Worked. If you look at init.c from V7 Unix, the dfork function takes the tty on standard input and dup's it twice to create standard output and standard error. session.c from OpenSSH does essentially the same thing in its do_exec_pty function.
|
---|