Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STDERR handle duplication issue #6037

Open
p5pRT opened this issue Oct 27, 2002 · 2 comments
Open

STDERR handle duplication issue #6037

p5pRT opened this issue Oct 27, 2002 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 27, 2002

Migrated from rt.perl.org#18099 (status was 'open')

Searchable as RT18099$

@p5pRT
Copy link
Author

p5pRT commented Oct 27, 2002

From mike@longenbach.com

Created by mike@longenbach.com

I have saved off STDERR to the file handle STDSAVE, and closed STDERR. Then
I open a new file handle (FILE) for output, which I believe receives file
handle 2. Then I have code which generates a runtime warning. The warning
text goes to the file handle FILE. This seems incorrect, as if the core is
hardcoded to send warning output to file handle 2 instead of STDERR. The
following is minimal code to generate the problem. Note the warning will
appear in the file "foo.file".

#!perl -w

open( STDSAVE, ">&STDERR" );
close STDERR;

open FILE, ">foo.file";

if( $foo eq '' ) { print "foo\n"; }; # this line generates a run time
warning

close FILE;

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.6.1:

Configured by ActiveState at Mon Jun 17 21:32:50 2002.

Summary of my perl5 (revision 5 version 6 subversion 1) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cl', ccflags
='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT 
 -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX',
    optimize='-O1 -MD -DNDEBUG',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags
'-nologo -nodefaultlib -release  -libpath:"C:/Perl\lib\CORE"  -machine:x86'
    libpth="C:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ',
ddlflags='-dll -nologo -nodefaultlib -release  -libpath:"C:/Perl\lib\CORE"  
-machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl v5.6.1:
    C:/Perl/lib
    C:/Perl/site/lib
    .


Environment for perl v5.6.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=C:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:
\PROGRA~1\ULTRAE~1
    PERL_BADLANG (unset)
    SHELL (unset)



@p5pRT
Copy link
Author

p5pRT commented Oct 29, 2002

From @eserte

"mike@​longenbach.com (via RT)" <perlbug@​perl.org> writes​:

# New Ticket Created by mike@​longenbach.com
# Please include the string​: [perl #18099]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt2/Ticket/Display.html?id=18099 >

This is a bug report for perl from mike@​longenbach.com,
generated with the help of perlbug 1.33 running under perl v5.6.1.

-----------------------------------------------------------------
[Please enter your report here]

I have saved off STDERR to the file handle STDSAVE, and closed STDERR. Then
I open a new file handle (FILE) for output, which I believe receives file
handle 2. Then I have code which generates a runtime warning. The warning
text goes to the file handle FILE. This seems incorrect, as if the core is
hardcoded to send warning output to file handle 2 instead of STDERR. The
following is minimal code to generate the problem. Note the warning will
appear in the file "foo.file".

#!perl -w

open( STDSAVE, ">&STDERR" );
close STDERR;

open FILE, ">foo.file";

if( $foo eq '' ) { print "foo\n"; }; # this line generates a run time
warning

close FILE;

The problem is still in 5.8.0. I guess the following define in perl.h​:

# define Perl_error_log (PL_stderrgv \
  && isGV(PL_stderrgv) \
  && GvIOp(PL_stderrgv) \
  && IoOFP(GvIOp(PL_stderrgv)) \
  ? IoOFP(GvIOp(PL_stderrgv)) \
  : PerlIO_stderr())

is responsible for this behavior​: if there is no valid STDERR, then
there is a fallback to PerlIO_stderr (always fd 2?). Possible
solutions​:

* Document this behavior. To workaround the problem, always reopen
  STDERR to /dev/null​:

  require File​::Spec;
  open(STDERR, ">" . File​::Spec->devnull);

* Instead of using PerlIO_stderr, use some magic filehandle which
  writes to /dev/null.

* Do not fallback but return NULL and change all occurrences (there
  are many) of Perl_error_log to check for the return value.

Regards,
  Slaven

--
Slaven Rezic - slaven.rezic@​berlin.de
  BBBike - route planner for cyclists in Berlin
  WWW version​: http​://www.bbbike.de
  Perl/Tk version for Unix and Windows​: http​://bbbike.sourceforge.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants