develooper Front page | perl.perl5.porters | Postings from September 2000

[ID 20000913.003] Closing STDERR leaves fd(2) marked w/o?

Thread Next
September 13, 2000 14:02
[ID 20000913.003] Closing STDERR leaves fd(2) marked w/o?
Message ID:

This is a bug report for perl from,
generated with the help of perlbug 1.28 running under perl v5.6.0.

[Please enter your report here]

With warnings enabled (via '-w' or $^W=1), perl always assumes that
file descriptors #1 and #2 will be opened on STDOUT and STDERR, and
furthermore that they will be write-only.

If the user closes either STDOUT or STDERR, then re-openes them for
reading on a file or pipe, it causes a warning to be generated and
this warning is sent to file descriptor #2 even if STDERR had been
previously closed.

Now, if descriptor #2 is a readable pipe, it has the effect of killing
the pipe which clobbers any input it had to be read (since the warning
could not be sent to the pipe).

Once STDERR is closed, it should disable any warnings from being generated
in the first place because, obviously, there is nowhere left to send them.
Continuing to send them to file descriptor #2 is just plain bad, because
Perl has no control over what is opened on that file descriptor.

This bug only affects perl5.6.0 and no previous versions (of Perl 5).
I have verified this assertion with the following perl versions:
    PASS perl5.002
    PASS perl5.003
    PASS perl5.004
    PASS perl5.00502
    PASS perl5.00503
    FAIL perl5.6.0

Here is the code which will illustrate the bug, with the specific example
of showing how once STDOUT is closed, you cannot assume that file descriptor
#1 should be write-only:



# First, close STDOUT, which should free up file descriptor #1
close STDOUT;

# Select STDERR as default destination for print statements.
select STDERR;

# Next, open a file for reading which inherits file descriptor #1
open FOOBAR, "</etc/motd";

# Read from and exhaust the file
print (<FOOBAR>);
print "#### END\n";
close FOOBAR;

# Now, enable WARNINGS and do it all again
# Open another file for reading which inherits file descriptor #1
open FOOBAR, "</etc/motd";

# Read from and exhaust the file
print "#### BEGIN WITH WARNINGS\n";
print (<FOOBAR>);
print "#### END\n";
close FOOBAR;


[Please do not change anything below this line]
Site configuration information for perl v5.6.0:

Configured by whyde at Wed Apr 19 10:49:42 CDT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos beecave 5.6 generic_105181-16 sun4u sparc '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
    cc='gcc', optimize='-O', gccversion=2.95.2 19991024 (release)
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldb -ldl -lm -lc -lcrypt -lsec
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.6.0:

Environment for perl v5.6.0:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About