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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user