Commit 95ff121e authored by James Brister's avatar James Brister
Browse files

removed some platform specific code.

parent c14c6f86
......@@ -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 */
......@@ -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();
/*
......
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment