From 95ff121ebd392ee9745d6ebfde4fc7fe4aea5208 Mon Sep 17 00:00:00 2001 From: James Brister Date: Wed, 26 Jan 2000 19:36:18 +0000 Subject: [PATCH] removed some platform specific code. --- bin/named/include/named/server.h | 5 -- bin/named/main.c | 40 -------------- bin/named/server.c | 90 -------------------------------- 3 files changed, 135 deletions(-) diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index ef6c17e9b3..552f8b2399 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -87,10 +87,5 @@ ns_server_reloadwanted(ns_server_t *server); * is ignored. */ -void -ns_update_pidfile(const char *filename); -/* - * Save the pid to the given file - */ #endif /* NS_SERVER_H */ diff --git a/bin/named/main.c b/bin/named/main.c index 020ed84c64..7ea8d81974 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -263,29 +263,16 @@ cleanup() { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_NOTICE, "exiting"); ns_log_shutdown(); - - if (ns_g_pidfile != NULL) { - (void)unlink(ns_g_pidfile); - isc_mem_free(ns_g_mctx, ns_g_pidfile); - } } int main(int argc, char *argv[]) { isc_result_t result; - int n; program_name = argv[0]; isc_assertion_setcallback(assertion_failed); isc_error_setfatal(library_fatal_error); - for (n = sysconf(_SC_OPEN_MAX) - 1; n >= 0; n--) - if (n != STDIN_FILENO && - n != STDOUT_FILENO && - n != STDERR_FILENO) - (void) close(n); - - result = ns_os_init(); if (result != ISC_R_SUCCESS) ns_main_earlyfatal("ns_os_init() failed: %s", @@ -306,33 +293,6 @@ main(int argc, char *argv[]) { parse_command_line(argc, argv); - if (ns_g_chrootdir != NULL) { -#ifdef HAVE_CHROOT - if (chroot(ns_g_chrootdir) < 0) { - ns_main_earlyfatal("chroot %s failed: %s\n", - ns_g_chrootdir, strerror(errno)); - exit(1); - } - if (chdir("/") < 0) { - ns_main_earlyfatal("chdir(\"/\") failed: %s\n", - strerror(errno)); - exit(1); - } -#else - fprintf(stderr, "warning: chroot() not available\n"); -#endif - } - - /* - * deamon() must be called before any threads are created - * (fork() is deadly to threads). Threads get created in setup(). - */ - if (ns_g_foreground == ISC_FALSE) { - if (daemon(1, 0) != 0) { - ns_main_earlyfatal("daemon(): %s", strerror(errno)); - } - } - setup(); /* diff --git a/bin/named/server.c b/bin/named/server.c index 22b8525443..df67892aad 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -105,7 +105,6 @@ typedef struct { static void fatal(char *msg, isc_result_t result); static void ns_server_reload(isc_task_t *task, isc_event_t *event); -static FILE *write_open(char *filename); static isc_result_t ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx, @@ -527,7 +526,6 @@ load_configuration(const char *filename, ns_server_t *server) { dns_view_t *view, *view_next; dns_viewlist_t tmpviewlist; dns_aclconfctx_t aclconfctx; - char *pidfile; dns_dispatch_t *dispatch; dns_aclconfctx_init(&aclconfctx); @@ -672,14 +670,6 @@ load_configuration(const char *filename, ns_server_t *server) { } - if (dns_c_ctx_getpidfilename(configctx, &pidfile) == ISC_R_SUCCESS) { - ns_update_pidfile(pidfile); - } else { - ns_update_pidfile(ns_g_defaultpidfile); - } - - - /* * Swap our new view list with the production one. */ @@ -1017,83 +1007,3 @@ ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx, return (ISC_R_SUCCESS); } -void -ns_update_pidfile(const char *pidfile) -{ - FILE *fp; - - INSIST(pidfile != NULL); - INSIST(strlen(pidfile) > 0); - - if (ns_g_pidfile != NULL) { - (void)unlink(ns_g_pidfile); - isc_mem_free(ns_g_mctx, ns_g_pidfile); - } - - ns_g_pidfile = isc_mem_strdup(ns_g_mctx, (char *) pidfile); - if (ns_g_pidfile == NULL) { - fatal("failed to isc_mem_strdup() the pidfile", - ISC_R_NOMEMORY); - } - - /* Not sure why I'm doing it this way, but bind8 did */ - fp = write_open(ns_g_pidfile); - if (fp != NULL) { - fprintf(fp, "%ld\n", (long)getpid()); - (void)fclose(fp); - } else { - isc_log_write(ns_g_lctx, - NS_LOGCATEGORY_GENERAL, - NS_LOGMODULE_SERVER, - ISC_LOG_ERROR, - "couldn't create pid file '%s'", - ns_g_pidfile); - } -} - - - -static FILE * -write_open(char *filename) -{ - FILE *stream; - int fd; - struct stat sb; - int regular; - - if (stat(filename, &sb) < 0) { - if (errno != ENOENT) { - isc_log_write(ns_g_lctx, - NS_LOGCATEGORY_GENERAL, - NS_LOGMODULE_SERVER, - ISC_LOG_ERROR, - "write_open: stat of %s failed: %s", - filename, strerror(errno)); - return (NULL); - } - regular = 1; - } else - regular = (sb.st_mode & S_IFREG); - - if (!regular) { - isc_log_write(ns_g_lctx, - NS_LOGCATEGORY_GENERAL, - NS_LOGMODULE_SERVER, - ISC_LOG_ERROR, - "write_open: %s isn't a regular file", - filename); - return (NULL); - } - - (void)unlink(filename); - fd = open(filename, O_WRONLY|O_CREAT|O_EXCL, - S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); - if (fd < 0) - return (NULL); - stream = fdopen(fd, "w"); - if (stream == NULL) - (void)close(fd); - return (stream); -} - -