lock-util: Add CLEANUP_UNPOSIX_UNLOCK()

Also migrate the logic in dynamic-user.c to use the new cleanup
macro.
This commit is contained in:
Daan De Meyer
2023-03-10 11:57:43 +01:00
parent 663fd3e103
commit b4cbfa5f1b
3 changed files with 29 additions and 22 deletions
+10
View File
@@ -149,3 +149,13 @@ int unposix_lock(int fd, int operation) {
return r;
}
void unposix_unlockpp(int **fd) {
assert(fd);
if (!*fd || **fd < 0)
return;
(void) unposix_lock(**fd, LOCK_UN);
*fd = NULL;
}
+5
View File
@@ -15,3 +15,8 @@ void release_lock_file(LockFile *f);
/* 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) \
_cleanup_(unposix_unlockpp) _unused_ int *CONCATENATE(_cleanup_unposix_unlock_, UNIQ) = &(fd)