|laziness, impatience, and hubris|
opening files: link checking and race conditionsby danderson (Beadle)
|on Aug 02, 2005 at 23:59 UTC||Need Help??|
danderson has asked for the wisdom of the Perl Monks concerning the following question:
Hello most esteemed monks,
I have a most harrowing situation. I need to write a suid script that appends to a file. It is not suid root or anything, but I don't want to give anyone access they don't deserve. Problematically, -l doesn't work on filehandles, which kind of makes sense I suppose.
So here's the problem: I can't use
open(">>foo") unless (-l "foo")
since there's a race condition between the check and the open. I can't open the file, and check to see if it's a link in retrospect, since one cannot check for linkness on filehandles, and if I just checked by the filename, then there's just a different race case.
I've SuperSearched, I've googled, I've asked a perl goddess, and despite the fact that I'm sure there's an easy solution I can't find it.
So: is there a way to ease my troubled soul? Can my script safely open files, knowing in it's heart of hearts that they are not links? Even if the answer is "no," it would at least quiet my tempestuous conscience.