changeset 22270:5b108ca20b05

lib: Add file_lock_set_close_on_free()
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 22 Jun 2017 01:52:29 +0300
parents b553f6960cb9
children 5c7987bec546
files src/lib/file-lock.c src/lib/file-lock.h
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/file-lock.c	Thu Jun 22 01:47:51 2017 +0300
+++ b/src/lib/file-lock.c	Thu Jun 22 01:52:29 2017 +0300
@@ -19,6 +19,7 @@
 	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 @@
 	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 @@
 
 	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);
--- a/src/lib/file-lock.h	Thu Jun 22 01:47:51 2017 +0300
+++ b/src/lib/file-lock.h	Thu Jun 22 01:52:29 2017 +0300
@@ -48,6 +48,9 @@
 /* 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);