summaryrefslogtreecommitdiff
path: root/bin/named/unix/os.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/named/unix/os.c')
-rw-r--r--bin/named/unix/os.c71
1 files changed, 49 insertions, 22 deletions
diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c
index bde3edf3..10fb5872 100644
--- a/bin/named/unix/os.c
+++ b/bin/named/unix/os.c
@@ -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.
*/
-/* $Id: os.c,v 1.46.2.4 2002/08/05 06:57:03 marka Exp $ */
+/* $Id: os.c,v 1.46.2.8 2004/03/09 06:09:23 marka Exp $ */
#include <config.h>
#include <stdarg.h>
@@ -30,6 +30,7 @@
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
#include <syslog.h>
#include <unistd.h>
@@ -43,6 +44,7 @@
#include <named/os.h>
static char *pidfile = NULL;
+static int devnullfd = -1;
/*
* If there's no <linux/capability.h>, we don't care about <sys/prctl.h>
@@ -283,12 +285,14 @@ ns_os_init(const char *progname) {
#ifdef HAVE_LINUXTHREADS
mainpid = getpid();
#endif
+#ifdef SIGXFSZ
+ signal(SIGXFSZ, SIG_IGN);
+#endif
}
void
ns_os_daemonize(void) {
pid_t pid;
- int fd;
char strbuf[ISC_STRERRORSIZE];
pid = fork();
@@ -322,18 +326,34 @@ ns_os_daemonize(void) {
* and will end up closing the wrong FD. This will be fixed eventually,
* and these calls will be removed.
*/
- fd = open("/dev/null", O_RDWR, 0);
- if (fd != -1) {
- close(STDIN_FILENO);
- (void)dup2(fd, STDIN_FILENO);
- close(STDOUT_FILENO);
- (void)dup2(fd, STDOUT_FILENO);
- close(STDERR_FILENO);
- (void)dup2(fd, STDERR_FILENO);
- if (fd != STDIN_FILENO &&
- fd != STDOUT_FILENO &&
- fd != STDERR_FILENO)
- (void)close(fd);
+ if (devnullfd != -1) {
+ if (devnullfd != STDIN_FILENO) {
+ (void)close(STDIN_FILENO);
+ (void)dup2(devnullfd, STDIN_FILENO);
+ }
+ if (devnullfd != STDOUT_FILENO) {
+ (void)close(STDOUT_FILENO);
+ (void)dup2(devnullfd, STDOUT_FILENO);
+ }
+ if (devnullfd != STDERR_FILENO) {
+ (void)close(STDERR_FILENO);
+ (void)dup2(devnullfd, STDERR_FILENO);
+ }
+ }
+}
+
+void
+ns_os_opendevnull(void) {
+ devnullfd = open("/dev/null", O_RDWR, 0);
+}
+
+void
+ns_os_closedevnull(void) {
+ if (devnullfd != STDIN_FILENO &&
+ devnullfd != STDOUT_FILENO &&
+ devnullfd != STDERR_FILENO) {
+ close(devnullfd);
+ devnullfd = -1;
}
}
@@ -537,3 +557,10 @@ ns_os_shutdown(void) {
closelog();
cleanup_pidfile();
}
+
+void
+ns_os_tzset(void) {
+#ifdef HAVE_TZSET
+ tzset();
+#endif
+}