From e2fc8e037ea6bb5de92b25ec9c12a624737ac5ca Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 8 Apr 2024 18:41:29 +0200 Subject: Merging upstream version 1:9.18.24. Signed-off-by: Daniel Baumann --- bin/named/os.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'bin/named/os.c') diff --git a/bin/named/os.c b/bin/named/os.c index 7af4729..0222abb 100644 --- a/bin/named/os.c +++ b/bin/named/os.c @@ -552,17 +552,19 @@ cleanup_pidfile(void) { } static void -cleanup_lockfile(void) { +cleanup_lockfile(bool unlink_lockfile) { if (singletonfd != -1) { close(singletonfd); singletonfd = -1; } if (lockfile != NULL) { - int n = unlink(lockfile); - if (n == -1 && errno != ENOENT) { - named_main_earlywarning("unlink '%s': failed", - lockfile); + if (unlink_lockfile) { + int n = unlink(lockfile); + if (n == -1 && errno != ENOENT) { + named_main_earlywarning("unlink '%s': failed", + lockfile); + } } free(lockfile); lockfile = NULL; @@ -830,7 +832,7 @@ named_os_issingleton(const char *filename) { if (ret == -1) { named_main_earlywarning("couldn't create '%s'", filename); - cleanup_lockfile(); + cleanup_lockfile(false); return (false); } } @@ -842,7 +844,7 @@ named_os_issingleton(const char *filename) { singletonfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (singletonfd == -1) { - cleanup_lockfile(); + cleanup_lockfile(false); return (false); } @@ -854,8 +856,7 @@ named_os_issingleton(const char *filename) { /* Non-blocking (does not wait for lock) */ if (fcntl(singletonfd, F_SETLK, &lock) == -1) { - close(singletonfd); - singletonfd = -1; + cleanup_lockfile(false); return (false); } @@ -866,7 +867,7 @@ void named_os_shutdown(void) { closelog(); cleanup_pidfile(); - cleanup_lockfile(); + cleanup_lockfile(true); } void -- cgit v1.2.3