mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 16:15:27 +00:00
1277. [bug] Failure to write pid-file should not be fatal on
reload. [RT #2861]
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
|||||||
|
1277. [bug] Failure to write pid-file should not be fatal on
|
||||||
|
reload. [RT #2861]
|
||||||
|
|
||||||
1276. [contrib] 'queryperf' now has EDNS (-e) + DNSSEC DO (-D) support.
|
1276. [contrib] 'queryperf' now has EDNS (-e) + DNSSEC DO (-D) support.
|
||||||
|
|
||||||
1275. [bug] When verifying that an NXT proves nonexistence, check
|
1275. [bug] When verifying that an NXT proves nonexistence, check
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: main.h,v 1.9 2001/09/07 00:36:55 marka Exp $ */
|
/* $Id: main.h,v 1.10 2002/05/03 05:28:23 marka Exp $ */
|
||||||
|
|
||||||
#ifndef NAMED_MAIN_H
|
#ifndef NAMED_MAIN_H
|
||||||
#define NAMED_MAIN_H 1
|
#define NAMED_MAIN_H 1
|
||||||
@@ -23,6 +23,9 @@
|
|||||||
void
|
void
|
||||||
ns_main_earlyfatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
ns_main_earlyfatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
||||||
|
|
||||||
|
void
|
||||||
|
ns_main_earlywarning(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_main_setmemstats(const char *);
|
ns_main_setmemstats(const char *);
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: main.c,v 1.127 2002/03/13 23:36:14 bwelling Exp $ */
|
/* $Id: main.c,v 1.128 2002/05/03 05:28:19 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -70,10 +70,7 @@ static char program_name[ISC_DIR_NAMEMAX] = "named";
|
|||||||
static char absolute_conffile[ISC_DIR_PATHMAX];
|
static char absolute_conffile[ISC_DIR_PATHMAX];
|
||||||
static char saved_command_line[512];
|
static char saved_command_line[512];
|
||||||
|
|
||||||
static void
|
void
|
||||||
ns_main_earlywarning(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
|
||||||
|
|
||||||
static void
|
|
||||||
ns_main_earlywarning(const char *format, ...) {
|
ns_main_earlywarning(const char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: server.c,v 1.374 2002/04/26 00:40:24 marka Exp $ */
|
/* $Id: server.c,v 1.375 2002/05/03 05:28:21 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -1966,13 +1966,13 @@ load_configuration(const char *filename, ns_server_t *server,
|
|||||||
obj = NULL;
|
obj = NULL;
|
||||||
if (ns_config_get(maps, "pid-file", &obj) == ISC_R_SUCCESS)
|
if (ns_config_get(maps, "pid-file", &obj) == ISC_R_SUCCESS)
|
||||||
if (cfg_obj_isvoid(obj))
|
if (cfg_obj_isvoid(obj))
|
||||||
ns_os_writepidfile(NULL);
|
ns_os_writepidfile(NULL, first_time);
|
||||||
else
|
else
|
||||||
ns_os_writepidfile(cfg_obj_asstring(obj));
|
ns_os_writepidfile(cfg_obj_asstring(obj), first_time);
|
||||||
else if (ns_g_lwresdonly)
|
else if (ns_g_lwresdonly)
|
||||||
ns_os_writepidfile(lwresd_g_defaultpidfile);
|
ns_os_writepidfile(lwresd_g_defaultpidfile, first_time);
|
||||||
else
|
else
|
||||||
ns_os_writepidfile(ns_g_defaultpidfile);
|
ns_os_writepidfile(ns_g_defaultpidfile, first_time);
|
||||||
|
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
if (options != NULL &&
|
if (options != NULL &&
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: os.h,v 1.18 2001/12/01 00:34:24 marka Exp $ */
|
/* $Id: os.h,v 1.19 2002/05/03 05:28:26 marka Exp $ */
|
||||||
|
|
||||||
#ifndef NS_OS_H
|
#ifndef NS_OS_H
|
||||||
#define NS_OS_H 1
|
#define NS_OS_H 1
|
||||||
@@ -41,7 +41,7 @@ void
|
|||||||
ns_os_minprivs(void);
|
ns_os_minprivs(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_writepidfile(const char *filename);
|
ns_os_writepidfile(const char *filename, isc_boolean_t first_time);
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_shutdown(void);
|
ns_os_shutdown(void);
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: os.c,v 1.57 2001/12/01 00:34:23 marka Exp $ */
|
/* $Id: os.c,v 1.58 2002/05/03 05:28:25 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -470,17 +470,20 @@ cleanup_pidfile(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_writepidfile(const char *filename) {
|
ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
|
||||||
int fd;
|
int fd;
|
||||||
FILE *lockfile;
|
FILE *lockfile;
|
||||||
size_t len;
|
size_t len;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char strbuf[ISC_STRERRORSIZE];
|
char strbuf[ISC_STRERRORSIZE];
|
||||||
|
void (*report)(const char *, ...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The caller must ensure any required synchronization.
|
* The caller must ensure any required synchronization.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
report = first_time ? ns_main_earlyfatal : ns_main_earlywarning;
|
||||||
|
|
||||||
cleanup_pidfile();
|
cleanup_pidfile();
|
||||||
|
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
@@ -490,8 +493,8 @@ ns_os_writepidfile(const char *filename) {
|
|||||||
pidfile = malloc(len + 1);
|
pidfile = malloc(len + 1);
|
||||||
if (pidfile == NULL) {
|
if (pidfile == NULL) {
|
||||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||||
ns_main_earlyfatal("couldn't malloc '%s': %s",
|
(*report)("couldn't malloc '%s': %s", filename, strbuf);
|
||||||
filename, strbuf);
|
return;
|
||||||
}
|
}
|
||||||
/* This is safe. */
|
/* This is safe. */
|
||||||
strcpy(pidfile, filename);
|
strcpy(pidfile, filename);
|
||||||
@@ -499,26 +502,37 @@ ns_os_writepidfile(const char *filename) {
|
|||||||
fd = safe_open(filename, ISC_FALSE);
|
fd = safe_open(filename, ISC_FALSE);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||||
ns_main_earlyfatal("couldn't open pid file '%s': %s",
|
(*report)("couldn't open pid file '%s': %s", filename, strbuf);
|
||||||
filename, strbuf);
|
free(pidfile);
|
||||||
|
pidfile = NULL;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
lockfile = fdopen(fd, "w");
|
lockfile = fdopen(fd, "w");
|
||||||
if (lockfile == NULL) {
|
if (lockfile == NULL) {
|
||||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||||
ns_main_earlyfatal("could not fdopen() pid file '%s': %s",
|
(*report)("could not fdopen() pid file '%s': %s",
|
||||||
filename, strbuf);
|
filename, strbuf);
|
||||||
|
(void)close(fd);
|
||||||
|
cleanup_pidfile();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_LINUXTHREADS
|
#ifdef HAVE_LINUXTHREADS
|
||||||
pid = mainpid;
|
pid = mainpid;
|
||||||
#else
|
#else
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
#endif
|
#endif
|
||||||
if (fprintf(lockfile, "%ld\n", (long)pid) < 0)
|
if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
|
||||||
ns_main_earlyfatal("fprintf() to pid file '%s' failed",
|
(*report)("fprintf() to pid file '%s' failed", filename);
|
||||||
filename);
|
(void)fclose(lockfile);
|
||||||
if (fflush(lockfile) == EOF)
|
cleanup_pidfile();
|
||||||
ns_main_earlyfatal("fflush() to pid file '%s' failed",
|
return;
|
||||||
filename);
|
}
|
||||||
|
if (fflush(lockfile) == EOF) {
|
||||||
|
(*report)("fflush() to pid file '%s' failed", filename);
|
||||||
|
(void)fclose(lockfile);
|
||||||
|
cleanup_pidfile();
|
||||||
|
return;
|
||||||
|
}
|
||||||
(void)fclose(lockfile);
|
(void)fclose(lockfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: os.h,v 1.5 2001/12/01 00:34:27 marka Exp $ */
|
/* $Id: os.h,v 1.6 2002/05/03 05:28:29 marka Exp $ */
|
||||||
|
|
||||||
#ifndef NS_OS_H
|
#ifndef NS_OS_H
|
||||||
#define NS_OS_H 1
|
#define NS_OS_H 1
|
||||||
@@ -41,7 +41,7 @@ void
|
|||||||
ns_os_minprivs(void);
|
ns_os_minprivs(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_writepidfile(const char *filename);
|
ns_os_writepidfile(const char *filename, isc_boolean_t first_time);
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_shutdown(void);
|
ns_os_shutdown(void);
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: os.c,v 1.13 2001/12/01 00:34:26 marka Exp $ */
|
/* $Id: os.c,v 1.14 2002/05/03 05:28:27 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -160,17 +160,20 @@ cleanup_pidfile(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_writepidfile(const char *filename) {
|
ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
|
||||||
int fd;
|
int fd;
|
||||||
FILE *lockfile;
|
FILE *lockfile;
|
||||||
size_t len;
|
size_t len;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char strbuf[ISC_STRERRORSIZE];
|
char strbuf[ISC_STRERRORSIZE];
|
||||||
|
void (*report)(const char *, ...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The caller must ensure any required synchronization.
|
* The caller must ensure any required synchronization.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
report = first_time ? ns_main_earlyfatal : ns_main_earlywarning;
|
||||||
|
|
||||||
cleanup_pidfile();
|
cleanup_pidfile();
|
||||||
|
|
||||||
if (strcmp(filename, "none") == 0)
|
if (strcmp(filename, "none") == 0)
|
||||||
@@ -179,8 +182,8 @@ ns_os_writepidfile(const char *filename) {
|
|||||||
pidfile = malloc(len + 1);
|
pidfile = malloc(len + 1);
|
||||||
if (pidfile == NULL) {
|
if (pidfile == NULL) {
|
||||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||||
ns_main_earlyfatal("couldn't malloc '%s': %s",
|
(*report)("couldn't malloc '%s': %s", filename, strbuf);
|
||||||
filename, strbuf);
|
return;
|
||||||
}
|
}
|
||||||
/* This is safe. */
|
/* This is safe. */
|
||||||
strcpy(pidfile, filename);
|
strcpy(pidfile, filename);
|
||||||
@@ -188,23 +191,35 @@ ns_os_writepidfile(const char *filename) {
|
|||||||
fd = safe_open(filename, ISC_FALSE);
|
fd = safe_open(filename, ISC_FALSE);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||||
ns_main_earlyfatal("couldn't open pid file '%s': %s",
|
(*report)("couldn't open pid file '%s': %s", filename, strbuf);
|
||||||
filename, strbuf);
|
free(pidfile);
|
||||||
|
pidfile = NULL;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
lockfile = fdopen(fd, "w");
|
lockfile = fdopen(fd, "w");
|
||||||
if (lockfile == NULL) {
|
if (lockfile == NULL) {
|
||||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||||
ns_main_earlyfatal("could not fdopen() pid file '%s': %s",
|
(*report)("could not fdopen() pid file '%s': %s",
|
||||||
filename, strbuf);
|
filename, strbuf);
|
||||||
|
(void)close(fd);
|
||||||
|
cleanup_pidfile();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
if (fprintf(lockfile, "%ld\n", (long)pid) < 0)
|
|
||||||
ns_main_earlyfatal("fprintf() to pid file '%s' failed",
|
if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
|
||||||
filename);
|
(*report)("fprintf() to pid file '%s' failed", filename);
|
||||||
if (fflush(lockfile) == EOF)
|
(void)fclose(fd);
|
||||||
ns_main_earlyfatal("fflush() to pid file '%s' failed",
|
cleanup_pidfile();
|
||||||
filename);
|
return;
|
||||||
|
}
|
||||||
|
if (fflush(lockfile) == EOF) {
|
||||||
|
(*report)("fflush() to pid file '%s' failed", filename);
|
||||||
|
(void)fclose(fd);
|
||||||
|
cleanup_pidfile();
|
||||||
|
return;
|
||||||
|
}
|
||||||
(void)fclose(lockfile);
|
(void)fclose(lockfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user