From: Stephan Bosch Date: Mon, 20 Sep 2021 00:45:23 +0000 (+0200) Subject: lib: file-lock - Adjust API to allow EDEADLK to be used by application. X-Git-Tag: 2.3.17~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c1cf82d614a4c390a336a6f4a6533cf5cdd65af;p=thirdparty%2Fdovecot%2Fcore.git lib: file-lock - Adjust API to allow EDEADLK to be used by application. It always caused a Dovecot panic before when returned from kernel. --- diff --git a/src/lib/file-lock.c b/src/lib/file-lock.c index 38ad23db09..f17beea3bc 100644 --- a/src/lib/file-lock.c +++ b/src/lib/file-lock.c @@ -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)); diff --git a/src/lib/file-lock.h b/src/lib/file-lock.h index 525c1d2be8..0939adc69e 100644 --- a/src/lib/file-lock.h +++ b/src/lib/file-lock.h @@ -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,