in reply to File Locking in CGI programs

For one thing, you aren't checking for failures on commands like open(). Those may not succeed. You also don't need to actually flock the file if you open for append and are on a sane POSIX system. The seek will be done for you, and the writes will be atomic.

Replies are listed 'Best First'.
Re^2: File Locking in CGI programs
by enemyofthestate (Monk) on Jul 06, 2005 at 01:16 UTC
    I do check for a failure on open(); I just left that out as not relevant to the question. The code is running on a linux system (FC3) so is it sane enough so that I don't need to do the file locking? The string I write out may have embedded carriage returns if that makes a difference.
      You can check the open() man page on your system, but I believe it's safe if the data fits in one block, which typically means 4K or less on Linux.

      Whether you check return values is always relevant IMHO. You should at least include it to let us know you thought about and are doing it so as not cause someone to chase after a potential red herring in your code.

      See my earlier message in this thread. Were you checking the return value of close()? It's highly relevant.

        I'll be more careful in the future to make it clear if I'm checking returned values from system calls. And I am checking the return value from close() now. I wasn't before.