_ check

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
first I check if a file exists ( -f $file ) and then doing several tests  
using the _ for being fast.

I have serious problem because the _ checks e.g -z _ sometimes is giving  
wrong results. the code is multi thread . What is going wrong ?

Re: _ check

Quoted text here. Click to load it

Are you sure you are not running into race conditions?


Re: _ check

Στις 20/3/2014 23:12, ο/η Jürgen Exner έγραψε:
Quoted text here. Click to load it

do not know, I am bunging my head with this. It is an apache mod perl.  
Maybe it have to do with apache cache.
I do not know if _ is saying always the truth. I mean if between the -f  
and _ an other thread ask for -f what will happen

Re: _ check

Quoted text here. Click to load it

As a somewhat simplified statement: Perl doesn't really support
multi-threading, all it can do is have multiple perl processes (::=
interpreters) run in a shared address space (thus, elegantly combining
all disadvantages of either model with each other in order to provide
none of the advantages). For your case, this means that each thread has
its own 'stat buffer'.

What do you mean by "-z _ sometimes is giving wrong results"? All uses
of stat are prone to TOCTOU-races, meaning, -z file being true by the
time the test was made doesn't even imply that it's still true by the
time your code sees the result.

Re: _ check

El 20/03/14 21:43, George Mpouras escribió:
Quoted text here. Click to load it

The special filehandle '_' is different from using a normal variable.
So, if something is not working try a normal variable.

If that don't works, try something like this

             $can_perhaps_read = -r "file";      # use the mode bits
                use filetest 'access';          # intuit harder
                $can_really_read = -r "file";
            $can_perhaps_read = -r "file";      # use the mode bits again

Which is copyed from 'man filetest'


Re: _ check

Quoted text here. Click to load it

This depends on your definition of 'normal variable': perl keeps the
result of the last stat call in a 'normal variable' named PL_statbuf
(actually, this is a macro expanding to the 'normal variable' but that's
not really relevant here) and doing a filetest on _ examines the struct
stat available as/ via PL_statbuf.  

But this doesn't really matter: The state of 'filesystem objects' can
generally change at any time and this means the result of each stat call
is potentially outdated as soon as it becomes available. And the same is
true about checks done via access(2), as filetest does: No matter what
the call returned, it is potentially not correct anymore by the time the
result is available.

Site Timeline