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

binding STDIN to scalar hides fd 0 forever #7879

Open
p5pRT opened this issue Apr 14, 2005 · 3 comments
Open

binding STDIN to scalar hides fd 0 forever #7879

p5pRT opened this issue Apr 14, 2005 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 14, 2005

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

Searchable as RT34981$

@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2005

From Steffen_Ullrich@genua.de

Created by Steffen_Ullrich@genua.de

Binding STDIN to a scalar, e.g. "open(STDIN,'<',\$x)" makes fd 0
inaccessable in the future. with lsof from perl it looks like that
the fd 0 is then bound to PerlIO.pm forever.
Even forking does not help.
The side effect is that children startet with IPC​::Open2 or
"open(X,'|prog')" cannot read from stdin, e.g. they try to read
from fd 0 which is bound to something else.

The following script shows the problem and a possible workaround
(line 9​: closing the fd 0 manually using POSIX​::close).

The problem exists at least with perl5.8.6 on OpenBSD3.7 and
perl5.8.4 an Linux (Kubuntu 5.04).

  1 use strict;
  2 use POSIX;
  3
  4 open( STDIN,'</dev/null') || die $!;
  5 p();
  6 my $content = 'bla';
  7 close(STDIN);
  8 open( STDIN,'<',\$content ) || die $!;
  9 ##### POSIX​::close(0); <<<<< workaround
  10 p();
  11 close(STDIN);
  12 open( STDIN,'</dev/null' ) || die $!;
  13 p();
  14 system( "fstat -p$$" );
  15
  16 sub p() { print "XXX fileno=".fileno(STDIN)."\n" }

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.6:

Configured by root at Thu Jan  1  0:00:00 UTC 1970.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=openbsd, osvers=3.7, archname=i386-openbsd
    uname='openbsd'
    config_args='-dsE -Dopenbsd_distribution=defined'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -I/usr/local/include',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -fno-delete-null-pointer-checks -pipe -I/usr/local/include'
    ccversion='', gccversion='3.3.5 (propolice)', gccosandvers='openbsd3.7'
    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 ='-Wl,-E '
    libpth=/usr/lib
    libs=-lm -lutil -lc
    perllibs=-lm -lutil -lc
    libc=/usr/lib/libc.so.34.2, so=so, useshrplib=true, libperl=libperl.so.10.0
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-R/usr/libdata/perl5/i386-openbsd/5.8.6/CORE'
    cccdlflags='-DPIC -fPIC ', lddlflags='-shared -fPIC '

Locally applied patches:
    SUIDPERLIO1 - fix PERLIO_DEBUG buffer overflow (CAN-2005-0156)


@INC for perl v5.8.6:
    /usr/libdata/perl5/i386-openbsd/5.8.6
    /usr/local/libdata/perl5/i386-openbsd/5.8.6
    /usr/libdata/perl5
    /usr/local/libdata/perl5
    /usr/local/libdata/perl5/site_perl/i386-openbsd
    /usr/libdata/perl5/site_perl/i386-openbsd
    /usr/local/libdata/perl5/site_perl
    /usr/libdata/perl5/site_perl
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.8.6:
    HOME=/home/steffen
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/steffen/bin:/home/steffen/bin/OpenBSD.bin:/mount/share/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 17, 2006

From guest@guest.guest.xxxxxxxx

still unresolved in perl5.8.7

@p5pRT
Copy link
Author

p5pRT commented Mar 17, 2006

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

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