Skip to content

Commit 96569bd

Browse files
committed
libsemanage: open lock_file with O_RDWR
man 2 flock: Since Linux 2.6.12, NFS clients support flock() locks by emulating them as fcntl(2) byte-range locks on the entire file. This means that fcntl(2) and flock() locks do interact with one another over NFS. It also means that in order to place an exclusive lock, the file must be opened for writing. Fixes: # semanage fcontext -d -e /home /tmp/testdir libsemanage.semanage_get_lock: Error obtaining direct transaction lock at /var/lib/selinux/targeted/semanage.trans.LOCK. (Bad file descriptor). OSError: Bad file descriptor Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
1 parent 69350fc commit 96569bd

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

libsemanage/src/semanage_store.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,14 +1899,12 @@ static int semanage_get_lock(semanage_handle_t * sh,
18991899
struct timeval origtime, curtime;
19001900
int got_lock = 0;
19011901

1902-
if ((fd = open(lock_file, O_RDONLY)) == -1) {
1903-
if ((fd =
1904-
open(lock_file, O_RDWR | O_CREAT | O_TRUNC,
1905-
S_IRUSR | S_IWUSR)) == -1) {
1906-
ERR(sh, "Could not open direct %s at %s.", lock_name,
1907-
lock_file);
1908-
return -1;
1909-
}
1902+
if ((fd =
1903+
open(lock_file, O_RDWR | O_CREAT | O_TRUNC,
1904+
S_IRUSR | S_IWUSR)) == -1) {
1905+
ERR(sh, "Could not open direct %s at %s.", lock_name,
1906+
lock_file);
1907+
return -1;
19101908
}
19111909
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
19121910
ERR(sh, "Could not set close-on-exec for %s at %s.", lock_name,

0 commit comments

Comments
 (0)