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

IPC::Open3 fails in mod_perl (tie bug) #7199

Closed
p5pRT opened this issue Mar 26, 2004 · 10 comments
Closed

IPC::Open3 fails in mod_perl (tie bug) #7199

p5pRT opened this issue Mar 26, 2004 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 26, 2004

Migrated from rt.perl.org#27986 (status was 'resolved')

Searchable as RT27986$

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2004

From ben_tilly@operamail.com

Created by ben_tilly@operamail.com

It appears that if STDIN is tied when you call open3 from
IPC​::Open3, directly or through the IPC​::Open2 wrapper, you
get a silent failure. The result is that the child process
will get no input. This happens under mod_perl. (At least
with Apache 1.3.) Looking at source-code, it looks like a tie on
STDOUT will also be a problem.

The following function shows that data does to a child process
offline, but in mod_perl will return nothing​:

  use File​::Temp 'tempfile';
  use IPC​::Open2 'open2';

  sub demonstrate_subprocess {
  my $out_fh = tempfile();
  my $in_fh;
  open2($out_fh, $in_fh, "perl", "-e", "print <>")
  or die "Cannot run perl​: $!";
  print $in_fh @​_ or die "Error​: $!";;
  close($in_fh);
  return join '', <$out_fh>;
  }

Here is a patch that fixes the bug​:

Inline Patch
--- Open3.pm.bak	2004-03-26 12:40:49.000000000 -0800
+++ Open3.pm	2004-03-26 12:46:28.000000000 -0800
@@ -121,6 +121,9 @@
 
     $kidpid = $do_spawn ? -1 : xfork;
     if ($kidpid == 0) {		# Kid
+	# A tie in the parent should not be allowed to cause problems.
+	untie *STDIN;
+	untie *STDOUT;
 	# If she wants to dup the kid's stderr onto her stdout I need to
 	# save a copy of her stdout before I put something else there.
 	if ($dad_rdr ne $dad_err && $dup_err
Perl Info

Flags:
    category=library
    severity=medium

Site configuration information for perl v5.8.3:

Configured by Debian Project at Sun Feb 15 17:22:09 EST 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.4.22-xfs+ti1211, archname=i386-linux-thread-multi
    uname='linux kosh 2.4.22-xfs+ti1211 #1 sat oct 25 10:11:37 est 2003 i686 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.3 -Dsitearch=/usr/local/lib/perl/5.8.3 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.3 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.3.3 20040125 (prerelease) (Debian)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so.5.8.3
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.3:
    /etc/perl
    /usr/local/lib/perl/5.8.3
    /usr/local/share/perl/5.8.3
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.8
    /usr/share/perl/5.8
    /usr/local/lib/site_perl
    /usr/local/lib/perl/5.8.2
    /usr/local/share/perl/5.8.2
    /usr/local/lib/perl/5.8.1
    /usr/local/share/perl/5.8.1
    /usr/local/lib/perl/5.8.0
    /usr/local/share/perl/5.8.0
    .


Environment for perl v5.8.3:
    HOME=/home/btilly
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/local/oracle/lib
    LOGDIR (unset)
    PATH=/home/btilly/cvs/bin:/home/btilly/cvs/lib/oracle/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/share/games:~/cvs/bin:/usr/local/oracle/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2004

From stas@stason.org

Benjamin J. Tilly (via RT) wrote​:

# New Ticket Created by "Benjamin J. Tilly"
# Please include the string​: [perl #27986]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=27986 >

This is a bug report for perl from ben_tilly@​operamail.com,
generated with the help of perlbug 1.34 running under perl v5.8.3.

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

It appears that if STDIN is tied when you call open3 from
IPC​::Open3, directly or through the IPC​::Open2 wrapper, you
get a silent failure. The result is that the child process
will get no input. This happens under mod_perl. (At least
with Apache 1.3.) Looking at source-code, it looks like a tie on
STDOUT will also be a problem.

The following function shows that data does to a child process
offline, but in mod_perl will return nothing​:

use File​::Temp 'tempfile';
use IPC​::Open2 'open2';

sub demonstrate_subprocess {
my $out_fh = tempfile();
my $in_fh;
open2($out_fh, $in_fh, "perl", "-e", "print <>")
or die "Cannot run perl​: $!";
print $in_fh @​_ or die "Error​: $!";;
close($in_fh);
return join '', <$out_fh>;
}

Here is a patch that fixes the bug​:

--- Open3.pm.bak 2004-03-26 12​:40​:49.000000000 -0800
+++ Open3.pm 2004-03-26 12​:46​:28.000000000 -0800
@​@​ -121,6 +121,9 @​@​

 $kidpid = $do\_spawn ? \-1 : xfork;
 if \($kidpid == 0\) \{        \# Kid

+ # A tie in the parent should not be allowed to cause problems.
+ untie *STDIN;
+ untie *STDOUT;
# If she wants to dup the kid's stderr onto her stdout I need to
# save a copy of her stdout before I put something else there.
if ($dad_rdr ne $dad_err && $dup_err

Excellent work, Benjamin! It's been a long long outstanding bug.

Nick, it'd be great to integrate it in 5.8.4. Thanks.

__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http​://stason.org/ mod_perl Guide ---> http​://perl.apache.org
mailto​:stas@​stason.org http​://use.perl.org http​://apacheweek.com
http​://modperlbook.org http​://apache.org http​://ticketmaster.com

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2004

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

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2004

From @iabyn

On Fri, Mar 26, 2004 at 09​:02​:19PM -0000, Benjamin J. Tilly wrote​:

It appears that if STDIN is tied when you call open3 from
IPC​::Open3, directly or through the IPC​::Open2 wrapper, you
get a silent failure. The result is that the child process
will get no input. This happens under mod_perl. (At least
with Apache 1.3.) Looking at source-code, it looks like a tie on
STDOUT will also be a problem.

Thanks, I've applied your patch to bleedperl as change #22609.

The following function shows that data does to a child process
offline, but in mod_perl will return nothing​:

use File​::Temp 'tempfile';
use IPC​::Open2 'open2';

sub demonstrate_subprocess {
my $out_fh = tempfile();
my $in_fh;
open2($out_fh, $in_fh, "perl", "-e", "print <>")
or die "Cannot run perl​: $!";
print $in_fh @​_ or die "Error​: $!";;
close($in_fh);
return join '', <$out_fh>;
}

Is it possible to rework this into a test that could be added to
lib/IPC/Open3.t?

Dave.

--
Red sky at night - gerroff my land!
Red sky at morning - gerroff my land!
  -- old farmers' sayings #14

@p5pRT
Copy link
Author

p5pRT commented Mar 30, 2004

From ben_tilly@operamail.com

"Dave Mitchell via RT" <perlbug-followup@​perl.org> wrote​:

On Fri, Mar 26, 2004 at 09​:02​:19PM -0000, Benjamin J. Tilly wrote​:

It appears that if STDIN is tied when you call open3 from
IPC​::Open3, directly or through the IPC​::Open2 wrapper, you
get a silent failure. The result is that the child process
will get no input. This happens under mod_perl. (At least
with Apache 1.3.) Looking at source-code, it looks like a tie on
STDOUT will also be a problem.

Thanks, I've applied your patch to bleedperl as change #22609.

Good. :-)

The following function shows that data does to a child process
offline, but in mod_perl will return nothing​:

use File​::Temp 'tempfile';
use IPC​::Open2 'open2';

sub demonstrate_subprocess {
my $out_fh = tempfile();
my $in_fh;
open2($out_fh, $in_fh, "perl", "-e", "print <>")
or die "Cannot run perl​: $!";
print $in_fh @​_ or die "Error​: $!";;
close($in_fh);
return join '', <$out_fh>;
}

Is it possible to rework this into a test that could be added to
lib/IPC/Open3.t?

I tried to duplicate the exact mod_perl behaviour, but didn't have
a convenient tie class with enough functionality.

Do you mind a test that crashes without the patch?

Thanks,
Ben

@p5pRT
Copy link
Author

p5pRT commented Apr 1, 2004

From @iabyn

On Tue, Mar 30, 2004 at 05​:33​:12AM +0800, Benjamin J. Tilly wrote​:

The following function shows that data does to a child process
offline, but in mod_perl will return nothing​:

use File​::Temp 'tempfile';
use IPC​::Open2 'open2';

sub demonstrate_subprocess {
my $out_fh = tempfile();
my $in_fh;
open2($out_fh, $in_fh, "perl", "-e", "print <>")
or die "Cannot run perl​: $!";
print $in_fh @​_ or die "Error​: $!";;
close($in_fh);
return join '', <$out_fh>;
}

Is it possible to rework this into a test that could be added to
lib/IPC/Open3.t?

I tried to duplicate the exact mod_perl behaviour, but didn't have
a convenient tie class with enough functionality.

Do you mind a test that crashes without the patch?

I'd prefer not. In that case the whole test would have to be run in a
sub-process. If you don't feel confident doing this I'll have a go myself.

Dave.

--
Red sky at night - gerroff my land!
Red sky at morning - gerroff my land!
  -- old farmers' sayings #14

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2004

From ben_tilly@operamail.com

Dave Mitchell <davem@​fdisolutions.com> wrote​:

On Tue, Mar 30, 2004 at 05​:33​:12AM +0800, Benjamin J. Tilly wrote​:

The following function shows that data does to a child process
offline, but in mod_perl will return nothing​:

use File​::Temp 'tempfile';
use IPC​::Open2 'open2';

sub demonstrate_subprocess {
my $out_fh = tempfile();
my $in_fh;
open2($out_fh, $in_fh, "perl", "-e", "print <>")
or die "Cannot run perl​: $!";
print $in_fh @​_ or die "Error​: $!";;
close($in_fh);
return join '', <$out_fh>;
}

Is it possible to rework this into a test that could be added to
lib/IPC/Open3.t?

I tried to duplicate the exact mod_perl behaviour, but didn't have
a convenient tie class with enough functionality.

Do you mind a test that crashes without the patch?

I'd prefer not. In that case the whole test would have to be run in a
sub-process. If you don't feel confident doing this I'll have a go myself.

I can do it, but I'm not sure when I'll get around to it.

Keeping it from crashing is probably as simple as using eval{}. The
crash happens when it tries to call open or fileno on the handle,
and IO​::Scalar doesn't provide OPEN or FILENO for the tie to go to.

Ben

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2004

From @nwc10

On Fri, Apr 02, 2004 at 09​:06​:44AM +0800, Benjamin J. Tilly wrote​:

I can do it, but I'm not sure when I'll get around to it.

Aha. So I made the right decision not to wait for a test before integrating
the fix? :-)

http​://public.activestate.com/cgi-bin/perlbrowse?patch=22623

(That was Wednesday. What I'd actually said about "code freeze" was that
patches had to be in blead by then. I'm allowing myself a few days to
integrate stuff to maint, and sit and watch the smokes)

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Apr 12, 2005

From @smpeters

[nicholas - Fri Apr 02 02​:53​:09 2004]​:

On Fri, Apr 02, 2004 at 09​:06​:44AM +0800, Benjamin J. Tilly wrote​:

I can do it, but I'm not sure when I'll get around to it.

Aha. So I made the right decision not to wait for a test before
integrating
the fix? :-)

http​://public.activestate.com/cgi-bin/perlbrowse?patch=22623

(That was Wednesday. What I'd actually said about "code freeze" was that
patches had to be in blead by then. I'm allowing myself a few days to
integrate stuff to maint, and sit and watch the smokes)

Nicholas Clark

This ticket is resolved (actually patched in 5.8.3).

Does anyone know of any other open issues between IPC​::Open3 and mod_perl?

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

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

1 participant