From 34821f8dfa1bf0fd2c78a15b237bef3955c7ca01 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 18 Feb 2024 16:41:11 +0000 Subject: [PATCH] Adjust read only library check for Windows --- src/lib.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib.c b/src/lib.c index 6406be0a..6dd54797 100644 --- a/src/lib.c +++ b/src/lib.c @@ -222,17 +222,14 @@ static lib_t lib_init(const char *name, const char *rpath, int lock_fd) // Try to open the lock file read-write as this is required for // exlusive locking on some NFS implementations - int mode = O_RDWR; - if (access(tb_get(lock_path), mode) != 0) { - if (errno == EACCES || errno == EPERM || errno == EROFS) { - mode = O_RDONLY; - l->readonly = true; - } - else - fatal_errno("access: %s", tb_get(lock_path)); + if ((l->lock_fd = open(tb_get(lock_path), O_RDWR)) < 0 + && (errno == EACCES || errno == EPERM || errno == EROFS)) { + // Try again in read-only mode + l->lock_fd = open(tb_get(lock_path), O_RDONLY); + l->readonly = true; } - if ((l->lock_fd = open(tb_get(lock_path), mode)) < 0) + if (l->lock_fd < 0) fatal_errno("open: %s", tb_get(lock_path)); file_read_lock(l->lock_fd); -- 2.39.2