]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: file-lock - Adjust API to allow EDEADLK to be used by application.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 20 Sep 2021 00:45:23 +0000 (02:45 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 23 Sep 2021 07:03:28 +0000 (07:03 +0000)
It always caused a Dovecot panic before when returned from kernel.

src/lib/file-lock.c
src/lib/file-lock.h

index 38ad23db0914ffe8ea4087e910acdbac6ea726a5..f17beea3bc368cdf4456e7ff503943162db798ed 100644 (file)
@@ -220,7 +220,7 @@ static int file_lock_do(int fd, const char *path, int lock_type,
                }
                *error_r = t_strdup_printf("fcntl(%s, %s, %s) locking failed: %m",
                        path, lock_type_str, timeout_secs == 0 ? "F_SETLK" : "F_SETLKW");
-               if (errno == EDEADLK) {
+               if (errno == EDEADLK && !set->allow_deadlock) {
                        i_panic("%s%s", *error_r,
                                file_lock_find(fd, set->lock_method,
                                               lock_type));
@@ -275,7 +275,7 @@ static int file_lock_do(int fd, const char *path, int lock_type,
                }
                *error_r = t_strdup_printf("flock(%s, %s) failed: %m",
                                           path, lock_type_str);
-               if (errno == EDEADLK) {
+               if (errno == EDEADLK && !set->allow_deadlock) {
                        i_panic("%s%s", *error_r,
                                file_lock_find(fd, set->lock_method,
                                               lock_type));
index 525c1d2be8e51fde0286cf509421d890aaef0a8e..0939adc69e3495206a6b8121524d386b4285662c 100644 (file)
@@ -25,6 +25,9 @@ struct file_lock_settings {
           processes are already waiting on the lock. This can be useful for
           files that are only created to exist as lock files. */
        bool close_on_free:1;
+       /* Do not panic when the kernel returns EDEADLK while acquiring the
+          lock. */
+       bool allow_deadlock:1;
 };
 
 /* Parse lock method from given string. Returns TRUE if ok,