summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/bin/named/unix
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2004-09-28 17:14:10 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2004-09-28 17:14:10 +0000
commitff09ecf5e523f7c1678821dfc8753880775b9bc9 (patch)
treecfbc352a0605ad89a62d844079441dca80fca83d /usr.sbin/bind/bin/named/unix
parentae87190605c9d85eaf9ba7728034f343685da32a (diff)
resolve conflicts
Diffstat (limited to 'usr.sbin/bind/bin/named/unix')
-rw-r--r--usr.sbin/bind/bin/named/unix/include/named/os.h24
-rw-r--r--usr.sbin/bind/bin/named/unix/os.c105
2 files changed, 103 insertions, 26 deletions
diff --git a/usr.sbin/bind/bin/named/unix/include/named/os.h b/usr.sbin/bind/bin/named/unix/include/named/os.h
index db427bc99d3..91f2adea124 100644
--- a/usr.sbin/bind/bin/named/unix/include/named/os.h
+++ b/usr.sbin/bind/bin/named/unix/include/named/os.h
@@ -1,21 +1,21 @@
/*
+ * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2002 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
- * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
*/
-/* $ISC: os.h,v 1.14.2.2 2002/08/05 06:57:03 marka Exp $ */
+/* $ISC: os.h,v 1.14.2.2.8.8 2004/03/08 04:04:21 marka Exp $ */
#ifndef NS_OS_H
#define NS_OS_H 1
@@ -55,6 +55,12 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time);
void
ns_os_shutdown(void);
+isc_result_t
+ns_os_gethostname(char *buf, size_t len);
+
+void
+ns_os_shutdownmsg(char *command, isc_buffer_t *text);
+
void
ns_os_tzset(void);
diff --git a/usr.sbin/bind/bin/named/unix/os.c b/usr.sbin/bind/bin/named/unix/os.c
index 8f610ccf1f3..ddd339e8d17 100644
--- a/usr.sbin/bind/bin/named/unix/os.c
+++ b/usr.sbin/bind/bin/named/unix/os.c
@@ -1,26 +1,26 @@
/*
+ * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2002 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
- * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
*/
-/* $ISC: os.c,v 1.46.2.4 2002/08/05 06:57:03 marka Exp $ */
+/* $ISC: os.c,v 1.46.2.4.8.16 2004/05/04 03:19:42 marka Exp $ */
#include <config.h>
#include <stdarg.h>
-#include <sys/types.h> /* dev_t FreeBSD 2.1 */
+#include <sys/types.h> /* dev_t FreeBSD 2.1 */
#include <sys/stat.h>
#include <ctype.h>
@@ -30,9 +30,14 @@
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
#include <syslog.h>
+#ifdef HAVE_TZSET
+#include <time.h>
+#endif
#include <unistd.h>
+#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/print.h>
#include <isc/result.h>
@@ -45,8 +50,13 @@
static char *pidfile = NULL;
static int pidfilefd = -1;
static isc_boolean_t preopenpidfile = ISC_FALSE;
+
static int devnullfd = -1;
+#ifndef ISC_FACILITY
+#define ISC_FACILITY LOG_DAEMON
+#endif
+
/*
* If there's no <linux/capability.h>, we don't care about <sys/prctl.h>
*/
@@ -145,10 +155,10 @@ linux_setcaps(unsigned int caps) {
if ((getuid() != 0 && !non_root_caps) || non_root)
return;
- memset(&caphead, 0, sizeof caphead);
+ memset(&caphead, 0, sizeof(caphead));
caphead.version = _LINUX_CAPABILITY_VERSION;
caphead.pid = 0;
- memset(&cap, 0, sizeof cap);
+ memset(&cap, 0, sizeof(cap));
cap.effective = caps;
cap.permitted = caps;
cap.inheritable = caps;
@@ -273,8 +283,7 @@ setup_syslog(const char *progname) {
#ifdef LOG_NDELAY
options |= LOG_NDELAY;
#endif
-
- openlog(isc_file_basename(progname), options, LOG_DAEMON);
+ openlog(isc_file_basename(progname), options, ISC_FACILITY);
}
void
@@ -286,6 +295,9 @@ ns_os_init(const char *progname) {
#ifdef HAVE_LINUXTHREADS
mainpid = getpid();
#endif
+#ifdef SIGXFSZ
+ signal(SIGXFSZ, SIG_IGN);
+#endif
}
void
@@ -349,8 +361,10 @@ void
ns_os_closedevnull(void) {
if (devnullfd != STDIN_FILENO &&
devnullfd != STDOUT_FILENO &&
- devnullfd != STDERR_FILENO)
+ devnullfd != STDERR_FILENO) {
close(devnullfd);
+ devnullfd = -1;
+ }
}
static isc_boolean_t
@@ -495,8 +509,11 @@ open_pidfile(const char *filename, isc_boolean_t first_time) {
cleanup_pidfile();
- len = strlen(filename) + 1;
- pidfile = malloc(len);
+ if (filename == NULL)
+ return;
+
+ len = strlen(filename);
+ pidfile = malloc(len + 1);
if (pidfile == NULL) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("couldn't malloc '%s': %s", filename, strbuf);
@@ -579,6 +596,60 @@ ns_os_shutdown(void) {
if (preopenpidfile == ISC_FALSE) cleanup_pidfile();
}
+isc_result_t
+ns_os_gethostname(char *buf, size_t len) {
+ int n;
+
+ n = gethostname(buf, len);
+ return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
+}
+
+static char *
+next_token(char **stringp, const char *delim) {
+ char *res;
+
+ do {
+ res = strsep(stringp, delim);
+ if (res == NULL)
+ break;
+ } while (*res == '\0');
+ return (res);
+}
+
+void
+ns_os_shutdownmsg(char *command, isc_buffer_t *text) {
+ char *input, *ptr;
+ unsigned int n;
+ pid_t pid;
+
+ input = command;
+
+ /* Skip the command name. */
+ ptr = next_token(&input, " \t");
+ if (ptr == NULL)
+ return;
+
+ ptr = next_token(&input, " \t");
+ if (ptr == NULL)
+ return;
+
+ if (strcmp(ptr, "-p") != 0)
+ return;
+
+#ifdef HAVE_LINUXTHREADS
+ pid = mainpid;
+#else
+ pid = getpid();
+#endif
+
+ n = snprintf((char *)isc_buffer_used(text),
+ isc_buffer_availablelength(text),
+ "pid: %ld", (long)pid);
+ /* Only send a message if it is complete. */
+ if (n < isc_buffer_availablelength(text))
+ isc_buffer_add(text, n);
+}
+
void
ns_os_tzset(void) {
#ifdef HAVE_TZSET