Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Testing for readdir failure (Perl-bug)

by Corion (Patriarch)
on May 25, 2013 at 08:07 UTC ( [id://1035243]=note: print w/replies, xml ) Need Help??


in reply to Re: Testing for readdir failure (Perl-bug)
in thread Testing for readdir failure

perlvar says in the second paragraph about $!:

Many system or library calls set errno if they fail, to indicate the cause of failure. They usually do not set errno to zero if they succeed. This means errno , hence $! , is meaningful only immediately after a failure:

Replies are listed 'Best First'.
Re^3: Testing for readdir failure (Perl-bug)
by LanX (Saint) on May 25, 2013 at 10:26 UTC
    yes, but did you notice:

    ------ Error: on --- Reset: off $! 17: File exists

    I included all cases for completeness and to make it easier to find the bug.

    Maybe this is clearer:

    DB<105> $!=666 => "Unknown error 666" DB<106> $!=666;scalar readdir X or warn "$!\n" Unknown error 666 DB<107> $!=undef;scalar readdir X or warn "$!\n" Bad file descriptor

    As you can see $! needs to be reset in advance "to be meaningful".

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      As you can see $! needs to be reset in advance "to be meaningful".

      Yup, logic bug is logic bug :)

      Compare Perl_do_close (called by pp_close ie close ) to pp_readdir

      pp_readdir test errno without localizing, do_close doesn't test errno at all

      closedir has this issue, and probably many others, maybe 40 others

      I wouldn't be surprised if other functions testing errno have this issue too -- this needs explicit testing / reviewing / patching

        > closedir has this issue, and probably many others, maybe 40 others

        well at least readline, but now setting to undef doesn't help here.

        Additionally I couldn't figure out why readdir sometimes throws warnings and sometimes not.

        I already prepared a bug report and will send it tomorrow.

        Cheers Rolf

        ( addicted to the Perl Programming Language)

        I have practically no knowledge of C nor Perl's C code, so could you describe the effect(s) of this logic bug at the Perl level?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1035243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found