]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
lock-util: Add LOCK_NONE
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 24 Mar 2023 15:33:20 +0000 (16:33 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 15 Jun 2023 15:10:35 +0000 (17:10 +0200)
src/basic/fs-util.c
src/basic/lock-util.c
src/basic/lock-util.h

index 1cf0f5b945ee9a365efb8f8ee10dc3bff8529888..94c0dfd3de5b23f31613830a31e6d97bc6befce2 100644 (file)
@@ -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 (;;) {
index 3614fbe37cba9994cd206d30bf63c97a449e8ad5..7e67c2d583850ad61978533c42c94b2e7f2fccad 100644 (file)
@@ -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:
index e7744476bbeefadfdf95648ab84874fdedcc09c1..b96ad85e2106269ee74375305c3165348c6ae3d3 100644 (file)
@@ -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,