How very strange. For me, the problem only seems to happen when
STDIN and
STDERR are left at their defaults. For example, these work:
perl t50 </dev/tty
perl t50 2>/dev/null
The problem may stem from this attribute of
dup(2):
dup and dup2 create a copy of the file descriptor oldfd.
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.
I suspect this
dup happens in your login program, such as
ssh or
/bin/login.
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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.