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

[perl #33831] [PATCH] EMFILE misinterpretation

Thread Next
From:
Steve Peters via RT
Date:
September 27, 2005 19:40
Subject:
[perl #33831] [PATCH] EMFILE misinterpretation
Message ID:
rt-3.0.11-33831-121710.14.261981590682@perl.org
> [rainer.weikusat@sncag.com - Tue Jan 18 03:34:25 2005]:
> 
> This is a bug report for perl from rainer.weikusat@sncag.com,
> generated with the help of perlbug 1.35 running under perl v5.8.5.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> If perl gets an EMFILE while trying to load a module,
> it will report that as "Can't locate ... in @INC', which
> can be somewhat confusing if the file is known to exist.
> 
> 

This problem has come up before with the solution being to simply
increase the max open filehandles.  This error message, however, is very
confusing.  I'm suggesting something like the following patch to clarify
the situation.  Not knowing Perl's internals that well, can someone
please look this over before I apply it?  Also, I'm simply using
strerror(errno) to get the error message.  Any other suggestions?
I tested the patch with and without threads and it worked fine.  Here's
a quick test showing the difference.

steve@kirk:~/perl-current$ ulimit -n
4
steve@kirk:~/perl-current$ perl5.8.7 -MCarp -e1
Can't locate Carp.pm in @INC (@INC contains: /etc/perl
/usr/local/lib/perl/5.8.7 /usr/local/share/perl/5.8.7 /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.4
/usr/local/share/perl/5.8.4 .).
BEGIN failed--compilation aborted.

... now the new version ...

steve@kirk:~/perl-current$ ./perl -I lib -MCarp -e1
Too many open files.
BEGIN failed--compilation aborted.

And now, the patch:

--- pp_ctl.c.old        2005-09-27 03:12:28.000000000 -0500
+++ pp_ctl.c    2005-09-27 20:05:12.000000000 -0500
@@ -3337,28 +3337,33 @@
     SvREFCNT_dec(namesv);
     if (!tryrsfp) {
        if (PL_op->op_type == OP_REQUIRE) {
-           const char *msgstr = name;
-           if (namesv) {                       /* did we lookup @INC? */
-               SV *msg = sv_2mortal(newSVpv(msgstr,0));
-               SV *dirmsgsv = NEWSV(0, 0);
-               AV *ar = GvAVn(PL_incgv);
-               I32 i;
-               sv_catpvn(msg, " in @INC", 8);
-               if (instr(SvPVX_const(msg), ".h "))
-                   sv_catpv(msg, " (change .h to .ph maybe?)");
-               if (instr(SvPVX_const(msg), ".ph "))
-                   sv_catpv(msg, " (did you run h2ph?)");
-               sv_catpv(msg, " (@INC contains:");
-               for (i = 0; i <= AvFILL(ar); i++) {
-                   const char *dir = SvPVx_nolen_const(*av_fetch(ar, i,
TRUE
-                   Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
-                   sv_catsv(msg, dirmsgsv);
-               }
-               sv_catpvn(msg, ")", 1);
-               SvREFCNT_dec(dirmsgsv);
-               msgstr = SvPV_nolen_const(msg);
+           if(errno == EMFILE) {
+               DIE(aTHX_ strerror(errno));
+           } else {
+               const char *msgstr = name;
+               if (namesv) {                   /* did we lookup @INC? */
+                   SV *msg = sv_2mortal(newSVpv(msgstr,0));
+                   SV *dirmsgsv = NEWSV(0, 0);
+                   AV *ar = GvAVn(PL_incgv);
+                   I32 i;
+                   sv_catpvn(msg, " in @INC", 8);
+                   if (instr(SvPVX_const(msg), ".h "))
+                       sv_catpv(msg, " (change .h to .ph maybe?)");
+                   if (instr(SvPVX_const(msg), ".ph "))
+                       sv_catpv(msg, " (did you run h2ph?)");
+                   sv_catpv(msg, " (@INC contains:");
+                   for (i = 0; i <= AvFILL(ar); i++) {
+                       const char *dir =
SvPVx_nolen_const(*av_fetch(ar, i, E));
+                       Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
+                       sv_catsv(msg, dirmsgsv);
+                   }
+                   sv_catpvn(msg, ")", 1);
+                   SvREFCNT_dec(dirmsgsv);
+                   msgstr = SvPV_nolen_const(msg);
+               }    
+           
+               DIE(aTHX_ "Can't locate %s", msgstr);
            }
-           DIE(aTHX_ "Can't locate %s", msgstr);
        }
 
        RETPUSHUNDEF;


Thread Next


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