From 0867a46534335cd160c13f9176a5ef283588b565 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 24 Mar 2023 16:33:20 +0100 Subject: [PATCH] lock-util: Add LOCK_NONE --- src/basic/fs-util.c | 2 +- src/basic/lock-util.c | 2 ++ src/basic/lock-util.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 1cf0f5b945e..94c0dfd3de5 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -1177,7 +1177,7 @@ int xopenat_lock( /* POSIX/UNPOSIX locks don't work on directories (errno is set to -EBADF so let's return early with * the same error here). */ - if (FLAGS_SET(open_flags, O_DIRECTORY) && locktype != LOCK_BSD) + if (FLAGS_SET(open_flags, O_DIRECTORY) && !IN_SET(locktype, LOCK_BSD, LOCK_NONE)) return -EBADF; for (;;) { diff --git a/src/basic/lock-util.c b/src/basic/lock-util.c index 3614fbe37cb..7e67c2d5838 100644 --- a/src/basic/lock-util.c +++ b/src/basic/lock-util.c @@ -174,6 +174,8 @@ int lock_generic(int fd, LockType type, int operation) { assert(fd >= 0); switch (type) { + case LOCK_NONE: + return 0; case LOCK_BSD: return RET_NERRNO(flock(fd, operation)); case LOCK_POSIX: diff --git a/src/basic/lock-util.h b/src/basic/lock-util.h index e7744476bbe..b96ad85e210 100644 --- a/src/basic/lock-util.h +++ b/src/basic/lock-util.h @@ -34,6 +34,7 @@ void unposix_unlockpp(int **fd); _cleanup_(unposix_unlockpp) _unused_ int *CONCATENATE(_cleanup_unposix_unlock_, UNIQ) = &(fd) typedef enum LockType { + LOCK_NONE, /* Don't lock the file descriptor. Useful if you need to conditionally lock a file. */ LOCK_BSD, LOCK_POSIX, LOCK_UNPOSIX,