Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

close(PIPE) doesn't set $? if pipe opened by "open2(\*PIPE, ..." #9245

Open p5pRT opened 16 years ago

p5pRT commented 16 years ago

Migrated from rt.perl.org#51548 (status was 'stalled')

Searchable as RT51548$

p5pRT commented 16 years ago

From kanda@tortrade.ru

According to "perlfunc/close"​: --- If the file handle came from a piped open\, "close" ... waits for the process executing on the pipe to complete\, ... and implicitly puts the exit status value of that command into $?. ---

That's true while pipe is opened like "open( PIPE\, '-|' );". But if pipe is opened by "open2(\*PIPE\, ..." the "close" does not set $?. Here is a testcase​:

---( testcase begins )---------- #!/usr/bin/perl -w use strict; use IPC​::Open2;

my $chld_pid = open2( \*PIPE\, '\<&STDIN'\, '/bin/bash'\, '-c'\, 'exit 2' );

while(\) { print $_; } close( PIPE );

print "Chld exit status is $? after close(PIPE).\n"; # this prints​: # Chld exit status is 0 after close(PIPE).

# ***** WRONG EXIT STATUS IS REPORTED ABOVE THIS LINE ******

waitpid( $chld_pid\, 0 ); print "Chld exit status is $? after waitpid($chld_pid).\n"; # this prints like​: # Chld exit status is 512 after waitpid(29779). ---( testcase ends )----------

The same incorrect behaviour is also demonstrated by Perl 5.8.0 for Linux\, by ActiveState perl 5.10.0\, 5.8.0 for windows.

We expect "close( PIPE )" should always set $?\, as documented.

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl 5.10.0: Configured by instaler at Sun Mar 9 01:51:26 MSK 2008. Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Platform: osname=linux, osvers=2.6.17.6lf39, archname=i586-linux-thread-multi-64int uname='linux life 2.6.17.6lf39 #5 preempt thu jul 20 15:47:40 msd 2006 i686 i686 i386 gnulinux ' config_args='-des -Dprefix=/usr -Dinstallprefix=/var/tmp/perl-5.10.0-root/usr -Dnoextensions=GDBM_File SDBM_File -Dcc=gcc -Uusenm -Dusemultiplicity -Duseithreads -Dlibpth=/lib /usr/lib -Dlibs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -Doptimize=-O2 -Os -frename-registers -march=i586 -mtune=i686 -Duse64bitint -Darchname=i586-linux -Dbin=/usr/perl/5.10.0/bin -Dprivlib=/usr/perl/5.10.0 -Dsitelib=/usr/perl/site/5.10.0 -Dinc_version_list=none -Uinstallusrbinperl -Duseshrplib=true -Dlibperl=libperl.so.5.10.0 -Dman1dir=/usr/perl/5.10.0/man/man1 -Dcf_email=none -Dstartperl=#!/usr/bin/perl -Dsitebin=/usr/perl/addon -Dusefaststdio -Duselargefiles -Dyacc=/usr/bin/bison -y -Accflags=-DNO_MATHOMS' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DNO_MATHOMS -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -Os -frename-registers -march=i586 -mtune=i686', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DNO_MATHOMS -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='4.1.2', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags ='' libpth=/lib /usr/lib libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0 gnulibc_version='2.3.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/perl/5.10.0/i586-linux-thread-multi-64int/CORE' cccdlflags='-fPIC', lddlflags='-shared -O2 -Os -frename-registers -march=i586 -mtune=i686' Locally applied patches: @INC for perl 5.10.0: /usr/perl/5.10.0/i586-linux-thread-multi-64int /usr/perl/5.10.0 /usr/perl/site/5.10.0/i586-linux-thread-multi-64int /usr/perl/site/5.10.0 . Environment for perl 5.10.0: HOME=/home/instaler LANG=ru_RU.CP1251 LANGUAGE (unset) LC_MESSAGES=POSIX LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/j2sdk/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/perl/5.10.0/bin:/usr/share/ghostscript/script:~/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 8 years ago

From @dcollinsn

The behavior described by the requestor is still present in blead (5.25.2).

-- Respectfully\, Dan Collins

p5pRT commented 8 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 8 years ago

@dcollinsn - Status changed from 'open' to 'stalled'