develooper Front page | perl.perl5.porters | Postings from September 2005

AW: [perl #36291] incorrect $! from open ">&nr" with too many open files

Thread Previous
From:
Dintelmann, Peter
Date:
September 27, 2005 06:18
Subject:
AW: [perl #36291] incorrect $! from open ">&nr" with too many open files
Message ID:
E9A2605289D8D7468B1A21EC24E59D2101852606@naimucx5.muc.allianz
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.perl.org/rt3/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
> 

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About