Merge branch '4387-lock-file-is-deleted-on-exit-even-if-lock-acquisition-failed' into 'main'

Resolve "lock file is deleted on exit even if lock acquisition failed"

Closes #4387

See merge request isc-projects/bind9!8422
This commit is contained in:
Mark Andrews 2023-10-26 07:02:01 +00:00
commit 17b0eff0cc
4 changed files with 21 additions and 10 deletions

View file

@ -1,3 +1,7 @@
6274. [bug] The 'lock-file' file was being removed when it
shouldn't have been making it ineffective if named was
started 3 or more times. [GL #4387]
6273. [bug] Don't reuse the existing TCP streams in dns_xfrin, so
parallel TCP transfers works again. [GL #4379]

View file

@ -706,17 +706,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;
@ -932,7 +934,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);
}
}
@ -944,7 +946,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);
}
@ -956,8 +958,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);
}
@ -968,7 +969,7 @@ void
named_os_shutdown(void) {
closelog();
cleanup_pidfile();
cleanup_lockfile();
cleanup_lockfile(true);
}
void

View file

@ -81,12 +81,14 @@ status=$((status+ret))
n=$((n+1))
echo_i "verifying that named checks for conflicting named processes ($n)"
ret=0
test -f ns2/named.lock || ret=1
testpid=$(run_named ns2 named$n.run -c named-alt2.conf -D runtime-ns2-extra-2 -X named.lock)
test -n "$testpid" || ret=1
retry_quiet 10 check_named_log "another named process" ns2/named$n.run || ret=1
test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
test -n "$testpid" && kill -15 $testpid > kill$n.out 2>&1 && ret=1
test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
test -f ns2/named.lock || ret=1
if [ $ret -ne 0 ]; then echo_i "failed"; fi
status=$((status+ret))

View file

@ -61,6 +61,10 @@ Bug Fixes
DNSSEC records, it was scheduled to be resigning. This unwanted behavior
has been fixed. :gl:`#4350`
- The :any:`lock-file` file was being removed when it shouldn't
have been making it ineffective if named was started 3 or more
times. :gl:`#4387`
Known Issues
~~~~~~~~~~~~