flock != O_EXCL ?

sky on 2003-01-21T07:37:41

Reading the journal of brain d foy I noticed his filecounter entry where talks about using O_EXCL instead of flock. However I was under the impression O_EXCL is related to O_CREAT when the file exists, and should be used when you use rename() to get atomic operation at the filesystem level. In fact quoted fom perldoc -f open is the following.

In many systems the "O_EXCL" flag is available for opening files in exclusive mode. This is not locking: exclusiveness means here that if the file already exists, sysopen() fails. The "O_EXCL" wins "O_TRUNC".

So what is correct?

sky


flock != O_EXCL

jhi on 2003-01-21T14:29:41

You're right: O_EXCL only matters with O_CREAT. It guarantees (on a local filesystem, at least, don't expect anything on networked filesystems) that the open(2) fails (with errno == EEXIST) if a file by the specified name already exists. Nothing to do with locking, only to do with EXCLusive CREATion.

No, its me.

brian_d_foy on 2003-01-21T17:11:50

Yes, I am wrong.

Thanks :)