1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

lock-util: Add LOCK_NONE

This commit is contained in:
Daan De Meyer 2023-03-24 16:33:20 +01:00
parent 3bba91ef44
commit 0867a46534
3 changed files with 4 additions and 1 deletions

View 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 (;;) {

View 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:

View 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,