Perl / perl5

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

getpwuid seems to leave file descriptors open #7415

Closed p5pRT closed 20 years ago

p5pRT commented 20 years ago

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

Searchable as RT30654$

p5pRT commented 20 years ago

From bplatz@acm.org

Created by bplatz@acm.org

This is a bug report for perl from bplatz@​acm.org\, generated with the help of perlbug 1.34 running under perl v5.8.0.

-----------------------------------------------------------------

As demonstrated by the example below\, getpwuid seems to leave file descriptors open.

Example​:

#!/opt/perl58/bin/perl -w

my @​userInfoArray;

open TMP\, "\< /dev/null"; print "before getpwuid fileno(TMP) = "\, fileno(TMP)\, "\n"; close TMP;

@​userInfoArray = getpwuid $\<;

open TMP\, "\< /dev/null"; print "after getpwuid fileno(TMP) = "\, fileno(TMP)\, "\n"; close TMP;

open TMP\, "\< /dev/null"; print "after open/close above fileno(TMP) = "\, fileno(TMP)\, "\n"; close TMP;

Output from Perl 5.8.0​:

before getpwuid fileno(TMP) = 4 after getpwuid fileno(TMP) = 6 after open/close above fileno(TMP) = 6

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.8.0: Configured by lstreet at Tue Mar 4 13:54:18 EST 2003. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=solaris, osvers=2.8, archname=sun4-solaris uname='sunos meappdevnew.agere.com 5.8 generic_108528-18 sun4u sparc sunw,ultra-enterprise-10000 ' config_args='-Dcc=gcc -B/usr/ccs/bin/' 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='gcc -B/usr/ccs/bin/', ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O', cppflags='-fno-strict-aliasing' ccversion='', gccversion='3.2', gccosandvers='solaris2.8' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='gcc -B/usr/ccs/bin/', ldflags =' -L/usr/local/lib ' libpth=/usr/local/lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc perllibs=-lsocket -lnsl -ldl -lm -lc libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.0: /opt/perl58/lib/5.8.0/sun4-solaris /opt/perl58/lib/5.8.0 /opt/perl58/lib/site_perl/5.8.0/sun4-solaris /opt/perl58/lib/site_perl/5.8.0 /opt/perl58/lib/site_perl . Environment for perl v5.8.0: HOME=/home/aldrsh LANG=C LANGUAGE (unset) LD_LIBRARY_PATH=/opt/SUNWspro6/SUNWspro/WS6/lib:/opt/SUNWspro6/SUNWspro/lib:/usr/openwin/lib:/usr/lib:/oracle/product/8.1.7/lib:/usr/dt/lib:/jdbc/lib:/opt/EMCpower/lib:/opt/VRTSvcs/EMC/lib:/usr/dt/lib:/usr/dt/lib LOGDIR (unset) PATH=/usr/openwin/bin:/usr/dt/bin:/usr/openwin/lib/X11:/usr/openwin/bin:/oracle/product/8.1.7/bin:/usr/ccs/bin:/opt/SUNWspro6/SUNWspro/bin:/opt/netscape/netscape7/SUNWns:/home/aldrsh/bin:/opt/addpath/bin:/usr/ccs/bin:/usr/bin:/usr/ucb:/usr/openv/netbackup/bin:/opt/VRTSvmsa/bin:/opt/sudo/bin:/opt/local/bin:/usr/openv/netbackup/bin:/usr/lib:/sopt/dazel/local/bin::/opt/dcs/bin:/opt/dcs/adm:/opt/local/bin:/usr/local/bin:/etc:/opt/EMCpower/bin/sparcv9:/opt/VRTSvcs/EMC/bin:/etc/emc/bin::/usr/dt/bin:/opt/smradmin/scheduler/dcssrv15eP:/opt/smradmin/bin:/home/unidats/UNI_DEVTOOLS/bin:/opt/oracle/local/bin:/bin:/usr/ccs/bin PERL_BADLANG (unset) SHELL=/bin/ksh ```
p5pRT commented 20 years ago

@rspier - Status changed from 'new' to 'resolved'

p5pRT commented 20 years ago

From @rspier

As demonstrated by the example below\, getpwuid seems to leave file descriptors open. osname=solaris\, osvers=2.8\, archname=sun4-solaris

I can't replicate this on Linux.

I suspect this a because of​:

  Calls to getpwnam() and getpwuid() leave the enumeration position   in an indeterminate state.

(from Solaris' man page.)

That implies to me that the handle to the nsswitch provider (generally /etc/passwd) is kept open.

You'll probably see this in the C version too..

#include \<stdio.h> #include \<pwd.h> void main() {   FILE *f;   struct passwd *p;

  f = fopen("/dev/null"\,"r");   printf("fileno is​: %d\n"\, fileno(f));   fclose(f);

  p = getpwuid(0);

  f = fopen("/dev/null"\,"r");   printf("fileno is​: %d\n"\, fileno(f));   fclose(f);

  f = fopen("/dev/null"\,"r");   printf("fileno is​: %d\n"\, fileno(f));   fclose(f); }

And you do...

fileno is​: 3 fileno is​: 4 fileno is​: 4

-R