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

incorrect $! from open ">&nr" with too many open files #7971

Closed
p5pRT opened this issue Jun 15, 2005 · 5 comments
Closed

incorrect $! from open ">&nr" with too many open files #7971

p5pRT opened this issue Jun 15, 2005 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 15, 2005

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

Searchable as RT36291$

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2005

From Peter.Dintelmann@dresdner-bank.com

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.35 running under perl v5.8.7.

When open() is used with ">&nr" to dup a file descriptor and
there are too many open files then $! ist set to EBADF instead
of EMFILE.

  $ ulimit -n
  9

  $ perl -MPOSIX -e 'system "truss -p $$ &"; dup 1 for 0..5; \
  > open $fh, ">&2" or warn $!'
  ... ... ...
  dup(1) = 3
  dup(1) = 4
  dup(1) = 5
  dup(1) = 6
  dup(1) = 7
  dup(1) = 8
  dup(2) Err#24 EMFILE
  close(-1) Err#9 EBADF
  fstat64(2, 0xFFBFF5A0) = 0
  Bad file number at -e line 1.
  write(2, " B a d f i l e n u m".., 30) = 30
  ... ... ...

On my system at least 9 fds are needed to run truss in this way
and POSIX​::dup() is used to eat them all up. Therefore the
following call to open()/dup() fails and the expected error is
EMFILE.

The close(-1) looks strange to me.


Flags​:
  category=core
  severity=low


Site configuration information for perl v5.8.7​:

Configured by p013176 at Wed Jun 1 15​:12​:46 MEST 2005.

Summary of my perl5 (revision 5 version 8 subversion 7) configuration​:
  Platform​:
  osname=solaris, osvers=2.9, archname=sun4-solaris-thread-multi-64int
  uname='sunos oikbm03 5.9 generic_112233-01 sun4u sparc sunw,ultra-5_10 '
  config_args='-Dprefix=/opt/perl32 -Uinstallusrbinperl -Dcc=gcc
-Doptimize=-O2 -Aldflags=-R/usr/local/lib -Duseshrplib -Duseperlio
-Dusethreads -Duselargefiles -Duse64bitint -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=define use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-D_REENTRANT -fno-strict-aliasing -pipe -I/usr/local/include'
  ccversion='', gccversion='3.4.2', gccosandvers='solaris2.9'
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='gcc', ldflags =' -R/usr/local/lib -L/usr/local/lib '
  libpth=/usr/local/lib /usr/lib /usr/ccs/lib
  libs=-lsocket -lnsl -lgdbm -ldl -lm -lpthread -lc
  perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
  libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -R
/opt/perl32/lib/5.8.7/sun4-solaris-thread-multi-64int/CORE'
  cccdlflags='-fPIC', lddlflags='-G -R/usr/local/lib -L/usr/local/lib'

Locally applied patches​:


@​INC for perl v5.8.7​:
  /opt/perl32/lib/5.8.7/sun4-solaris-thread-multi-64int
  /opt/perl32/lib/5.8.7
  /opt/perl32/lib/site_perl/5.8.7/sun4-solaris-thread-multi-64int
  /opt/perl32/lib/site_perl/5.8.7
  /opt/perl32/lib/site_perl
  .


Environment for perl v5.8.7​:
  HOME=/export/home/p013176
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin
  PERL_BADLANG (unset)
  SHELL=/usr/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 27, 2005

From Peter.Dintelmann@dresdner-bank.com

The proposed patch below fixes this bug and open(">&fd") sets
$! now correctly to EMFILE when there are too many open files.

  $ ulimit -n
  7
  $ ./perl -MPOSIX -e 'dup 1 for 0..3; open $fh, ">&2" or warn $!'
  Too many open files at -e line 1.

$ diff -ur doio.c doio.c.patch

Inline Patch
--- doio.c      Thu Apr  7 18:13:55 2005
+++ doio.c.patch        Tue Sep 27 12:54:57 2005
@@ -410,7 +410,7 @@
                        else
                            was_fdopen = TRUE;
                        if (!(fp = PerlIO_openn(aTHX_
type,mode,fd,0,0,NULL,num_svs,svp))) { \- if \(dodup\) \+ if \(dodup && fd >= 0\)   PerlLIO\_close\(fd\);   \}   \}

-----Ursprüngliche Nachricht-----
Von​: Peter Dintelmann [mailto​:perlbug-followup@​perl.org]
Gesendet​: Mittwoch, 15. Juni 2005 08​:17
An​: perl5-porters@​perl.org
Betreff​: [perl #36291] incorrect $! from open ">&nr" with too
many open
files

# New Ticket Created by Peter Dintelmann
# Please include the string​: [perl #36291]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=36291 >

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.35 running under perl v5.8.7.

When open() is used with ">&nr" to dup a file descriptor and
there are too many open files then $! ist set to EBADF instead
of EMFILE.

$ ulimit \-n
9

$ perl \-MPOSIX \-e 'system "truss \-p $$ &"; dup 1 for 0\.\.5; \\
> open $fh\, ">&2" or warn $\!'
\.\.\. \.\.\. \.\.\.
dup\(1\)                                          = 3
dup\(1\)                                          = 4
dup\(1\)                                          = 5
dup\(1\)                                          = 6
dup\(1\)                                          = 7
dup\(1\)                                          = 8
dup\(2\)                                          Err\#24 EMFILE
close\(\-1\)                                       Err\#9 EBADF
fstat64\(2\, 0xFFBFF5A0\)                          = 0
Bad file number at \-e line 1\.
write\(2\, " B a d   f i l e   n u m"\.\.\, 30\)      = 30
\.\.\. \.\.\. \.\.\.

On my system at least 9 fds are needed to run truss in this way
and POSIX​::dup() is used to eat them all up. Therefore the
following call to open()/dup() fails and the expected error is
EMFILE.

The close(-1) looks strange to me.

---
Flags​:
category=core
severity=low
---
Site configuration information for perl v5.8.7​:

Configured by p013176 at Wed Jun 1 15​:12​:46 MEST 2005.

Summary of my perl5 (revision 5 version 8 subversion 7) configuration​:
Platform​:
osname=solaris, osvers=2.9,
archname=sun4-solaris-thread-multi-64int
uname='sunos oikbm03 5.9 generic_112233-01 sun4u sparc
sunw,ultra-5_10 '
config_args='-Dprefix=/opt/perl32 -Uinstallusrbinperl -Dcc=gcc
-Doptimize=-O2 -Aldflags=-R/usr/local/lib -Duseshrplib -Duseperlio
-Dusethreads -Duselargefiles -Duse64bitint -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=define use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -fno-strict-aliasing -pipe
-I/usr/local/include'
ccversion='', gccversion='3.4.2', gccosandvers='solaris2.9'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='gcc', ldflags =' -R/usr/local/lib -L/usr/local/lib '
libpth=/usr/local/lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -lgdbm -ldl -lm -lpthread -lc
perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -R
/opt/perl32/lib/5.8.7/sun4-solaris-thread-multi-64int/CORE'
cccdlflags='-fPIC', lddlflags='-G -R/usr/local/lib
-L/usr/local/lib'

Locally applied patches​:

---
@​INC for perl v5.8.7​:
/opt/perl32/lib/5.8.7/sun4-solaris-thread-multi-64int
/opt/perl32/lib/5.8.7
/opt/perl32/lib/site_perl/5.8.7/sun4-solaris-thread-multi-64int
/opt/perl32/lib/site_perl/5.8.7
/opt/perl32/lib/site_perl
.

---
Environment for perl v5.8.7​:
HOME=/export/home/p013176
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin
PERL_BADLANG (unset)
SHELL=/usr/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 27, 2005

From @smpeters

[dint - Tue Sep 27 06​:19​:12 2005]​:

The proposed patch below fixes this bug and open(">&fd") sets
$! now correctly to EMFILE when there are too many open files.

$ ulimit \-n
7
$ \./perl \-MPOSIX \-e 'dup 1 for 0\.\.3; open $fh\, ">&2" or warn $\!'
Too many open files at \-e line 1\.

$ diff -ur doio.c doio.c.patch
--- doio.c Thu Apr 7 18​:13​:55 2005
+++ doio.c.patch Tue Sep 27 12​:54​:57 2005
@​@​ -410,7 +410,7 @​@​
else
was_fdopen = TRUE;
if (!(fp = PerlIO_openn(aTHX_
type,mode,fd,0,0,NULL,num_svs,svp))) {
- if (dodup)
+ if (dodup && fd >= 0)
PerlLIO_close(fd);
}
}

-----Ursprüngliche Nachricht-----
Von​: Peter Dintelmann [mailto​:perlbug-followup@​perl.org]
Gesendet​: Mittwoch, 15. Juni 2005 08​:17
An​: perl5-porters@​perl.org
Betreff​: [perl #36291] incorrect $! from open ">&nr" with too
many open
files

# New Ticket Created by Peter Dintelmann
# Please include the string​: [perl #36291]
# in the subject line of all future correspondence about this
issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=36291 >

This is a bug report for perl from Peter.Dintelmann@​dresdner-
bank.com,
generated with the help of perlbug 1.35 running under perl v5.8.7.

When open() is used with ">&nr" to dup a file descriptor and
there are too many open files then $! ist set to EBADF instead
of EMFILE.

$ ulimit \-n
9

$ perl \-MPOSIX \-e 'system "truss \-p $$ &"; dup 1 for 0\.\.5; \\
> open $fh\, ">&2" or warn $\!'
\.\.\. \.\.\. \.\.\.
dup\(1\)                                          = 3
dup\(1\)                                          = 4
dup\(1\)                                          = 5
dup\(1\)                                          = 6
dup\(1\)                                          = 7
dup\(1\)                                          = 8
dup\(2\)                                          Err\#24 EMFILE
close\(\-1\)                                       Err\#9 EBADF
fstat64\(2\, 0xFFBFF5A0\)                          = 0
Bad file number at \-e line 1\.
write\(2\, " B a d   f i l e   n u m"\.\.\, 30\)      = 30
\.\.\. \.\.\. \.\.\.

On my system at least 9 fds are needed to run truss in this way
and POSIX​::dup() is used to eat them all up. Therefore the
following call to open()/dup() fails and the expected error is
EMFILE.

The close(-1) looks strange to me.

Thanks! This patch applied with change #25621.

@p5pRT
Copy link
Author

p5pRT commented Sep 27, 2005

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

@p5pRT
Copy link
Author

p5pRT commented Sep 27, 2005

@smpeters - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant