mwhuen
asked on
umask
I am new to PERL
I am learning CGI with source codes.
I don't understand what is umask even after reading some books.
sub lock
{
local ($oumask);
# create the lock file world-writable
$oumask = umask(0);
for($i = 0; !open(LOCK, ">$lockfile"); $i++) {
# wait a sec and try again
sleep 1;
# after 30 seconds, just unlock it
&unlock if ($i > 30);
}
close(LOCK);
umask($oumask);
}
why it uses umask?what is it doing?
umask(0) = ???
umask($oumask) ???
please help!!!
I am learning CGI with source codes.
I don't understand what is umask even after reading some books.
sub lock
{
local ($oumask);
# create the lock file world-writable
$oumask = umask(0);
for($i = 0; !open(LOCK, ">$lockfile"); $i++) {
# wait a sec and try again
sleep 1;
# after 30 seconds, just unlock it
&unlock if ($i > 30);
}
close(LOCK);
umask($oumask);
}
why it uses umask?what is it doing?
umask(0) = ???
umask($oumask) ???
please help!!!
ASKER
I still can't understand it all,
can you explain every lines of the above code?
umask(0) makes the file permission to 777?
can you explain every lines of the above code?
umask(0) makes the file permission to 777?
ASKER
what meant by !open()???
open returns true if it succeds, and false if it fails.
so !open would be true if it fails, and false if it succeeds.
But the above routine does not seem to be a reliable way of obtaining a lock
so !open would be true if it fails, and false if it succeeds.
But the above routine does not seem to be a reliable way of obtaining a lock
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
can you provide me a piece of good/typical locking source code?
please explain that is it that you are trying to do using file locking.
maybe then i could provide you wil a more precise code.
maybe then i could provide you wil a more precise code.
A) You can set the default file permissions for the news files that you create using the command umask.
This mask affects the initial value of
the file permission of subsequently created files
Q) what does umask(0) do?
A) Sets the umask for the process to EXPR (0 in this case) and returns the previous value
Here, $oumask=umask(0);, the previous value returned by umask is stored in the $oumask variable.
After the processing is done it just reset the umask back to its original value - umask($oumask).