Re: flock: Allow lock directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 26, 2008 at 09:20:05AM -0800, H. Peter Anvin wrote:
> Karel Zak wrote:
> > Peter, your opinion? Please.
> >
> >    Karel
> >>-    fd = open(filename, O_RDONLY|O_CREAT, 0666);
> >>+#ifdef O_DIRECTORY
> >>+    if ((fd = open(filename, O_RDONLY|O_DIRECTORY)) < 0)
> >>+#endif
> >>+    fd = open(filename, O_RDONLY|O_NOCTTY|O_CREAT, 0666);
> >> 
> 
> This part is backwards.  Instead of doing the unlikely case first, one 
> should simply:
> 
> fd = open(filename, O_RDONLY|O_NOCTTY|O_CREAT, 0666);
> /* Linux doesn't like O_CREAT on a directory, even though it should be a
>    no-op */
> if (fd < 0 && errno == EISDIR)
> 	fd = open(filename, O_RDONLY|O_NOCTTY);
> 
> Note that the O_DIRECTORY is not necessary to the best of my knowledge.

O_DIRECTORY is used to cause the open to fail if filename is not a
directory.  In your edition of the change, it is not necessary.


-- 
ldv

Attachment: pgpDQp9Lac6p7.pgp
Description: PGP signature


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux