]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add file_lock_set_close_on_free()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 21 Jun 2017 22:52:29 +0000 (01:52 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 3 Jul 2017 12:13:24 +0000 (15:13 +0300)
src/lib/file-lock.c
src/lib/file-lock.h

index bef1548c09a02212eb23bd79b240cb36252cfe8e..4f5ad49d892f9a6184aeb086ace6aff10b9b1435 100644 (file)
@@ -19,6 +19,7 @@ struct file_lock {
        int lock_type;
        enum file_lock_method lock_method;
        bool unlink_on_free;
+       bool close_on_free;
 };
 
 static struct timeval lock_wait_start;
@@ -346,6 +347,11 @@ void file_lock_set_unlink_on_free(struct file_lock *lock, bool set)
        lock->unlink_on_free = set;
 }
 
+void file_lock_set_close_on_free(struct file_lock *lock, bool set)
+{
+       lock->close_on_free = set;
+}
+
 void file_unlock(struct file_lock **_lock)
 {
        struct file_lock *lock = *_lock;
@@ -375,6 +381,8 @@ void file_lock_free(struct file_lock **_lock)
 
        if (lock->unlink_on_free)
                i_unlink(lock->path);
+       if (lock->close_on_free)
+               i_close_fd(&lock->fd);
 
        file_lock_log_warning_if_slow(lock);
        i_free(lock->path);
index 377abdbf8cf8997c8131443a09b033e9f136a8b3..022210600a0b0c7f7948792adbc2674c415a9936 100644 (file)
@@ -48,6 +48,9 @@ int file_lock_try_update(struct file_lock *lock, int lock_type);
 /* When the lock is freed, unlink() the file automatically. This can be useful
    for files that are only created to exist as lock files. */
 void file_lock_set_unlink_on_free(struct file_lock *lock, bool set);
+/* When the lock is freed, close the fd automatically. This can
+   be useful for files that are only created to exist as lock files. */
+void file_lock_set_close_on_free(struct file_lock *lock, bool set);
 
 /* Unlock and free the lock. */
 void file_unlock(struct file_lock **lock);