]> git.ipfire.org Git - thirdparty/util-linux.git/commit
flock: use O_RDWR as fallback if O_RDONLY returns EIO
authorKarel Zak <kzak@redhat.com>
Mon, 21 Nov 2011 16:12:33 +0000 (17:12 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 21 Nov 2011 16:26:41 +0000 (17:26 +0100)
commiteb742a1f66d5e3a7c5b43efce741c113f51bef3b
tree0f81af233004f822e6eb424890d6eb771e7578b2
parentbc3ae4c6fc66bcfec3ed9933e698a5ede853869d
flock: use O_RDWR as fallback if O_RDONLY returns EIO

The commit 75aaee08f06b92d119ed827c53d1af5474eb16ff introduces
regression:

     $ echo '#!/bin/sh' > test.sh
     $ chmod a+rx test.sh
     $ flock -eon ./test.sh ./test.sh
     flock: ./test.sh: Text file busy

The lock file cannot be opened in read-write mode by default, because
then we cannot use flock(1) to lock executable files.

The read-write mode for lock files is necessary on NFSv4 where
flock(2) is emulated by by fcntl() -- this situation is possible to
detect by flock(2) EIO error.

This patch reverts the default to O_RDONLY and use O_RDWR only if EIO
error is detected.

Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/flock.c