Merge pull request #26749 from DaanDeMeyer/more-cleanups

execute: Some modernizations
This commit is contained in:
Yu Watanabe
2023-03-14 03:34:37 +09:00
committed by GitHub
6 changed files with 107 additions and 96 deletions
+24 -3
View File
@@ -109,12 +109,15 @@ void release_lock_file(LockFile *f) {
f->operation = 0;
}
int unposix_lock(int fd, int operation) {
static int fcntl_lock(int fd, int operation, bool ofd) {
int cmd, type, r;
assert(fd >= 0);
cmd = (operation & LOCK_NB) ? F_OFD_SETLK : F_OFD_SETLKW;
if (ofd)
cmd = (operation & LOCK_NB) ? F_OFD_SETLK : F_OFD_SETLKW;
else
cmd = (operation & LOCK_NB) ? F_SETLK : F_SETLKW;
switch (operation & ~LOCK_NB) {
case LOCK_EX:
@@ -143,12 +146,30 @@ int unposix_lock(int fd, int operation) {
return r;
}
int posix_lock(int fd, int operation) {
return fcntl_lock(fd, operation, /*ofd=*/ false);
}
int unposix_lock(int fd, int operation) {
return fcntl_lock(fd, operation, /*ofd=*/ true);
}
void posix_unlockpp(int **fd) {
assert(fd);
if (!*fd || **fd < 0)
return;
(void) fcntl_lock(**fd, LOCK_UN, /*ofd=*/ false);
*fd = NULL;
}
void unposix_unlockpp(int **fd) {
assert(fd);
if (!*fd || **fd < 0)
return;
(void) unposix_lock(**fd, LOCK_UN);
(void) fcntl_lock(**fd, LOCK_UN, /*ofd=*/ true);
*fd = NULL;
}
+7 -1
View File
@@ -13,9 +13,15 @@ void release_lock_file(LockFile *f);
#define LOCK_FILE_INIT { .fd = -EBADF, .path = NULL }
/* POSIX locks with the same interface as flock(). */
int posix_lock(int fd, int operation);
void posix_unlockpp(int **fd);
#define CLEANUP_POSIX_UNLOCK(fd) \
_cleanup_(posix_unlockpp) _unused_ int *CONCATENATE(_cleanup_posix_unlock_, UNIQ) = &(fd)
/* Open File Description locks with the same interface as flock(). */
int unposix_lock(int fd, int operation);
void unposix_unlockpp(int **fd);
#define CLEANUP_UNPOSIX_UNLOCK(fd) \