From 27237763df0803ddfb3377df1472af102c07effb Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 29 Apr 2005 00:55:53 +0000 Subject: [PATCH] further changes for 1848. [bug] Improve SMF integration. [RT #13238] --- bin/named/control.c | 30 +++++------------------- bin/named/include/named/ns_smf_globals.h | 4 ++-- bin/named/main.c | 21 ++++++++++++++++- bin/named/server.c | 16 +------------ 4 files changed, 29 insertions(+), 42 deletions(-) diff --git a/bin/named/control.c b/bin/named/control.c index 4ec7c1f6e8..9c5bbcd560 100644 --- a/bin/named/control.c +++ b/bin/named/control.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: control.c,v 1.20.10.5 2005/04/27 05:00:30 sra Exp $ */ +/* $Id: control.c,v 1.20.10.6 2005/04/29 00:55:52 marka Exp $ */ /*! \file */ @@ -64,7 +64,7 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { char *command; isc_result_t result; #ifdef HAVE_LIBSCF - char *instance = NULL; + ns_smf_want_disable = 0; #endif data = isccc_alist_lookup(message, "_data"); @@ -114,17 +114,8 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { * If we are managed by smf(5) but not in chroot, * try to disable ourselves the smf way. */ - if (ns_smf_got_instance == 1 && ns_smf_chroot == 0) { - result = ns_smf_get_instance(&instance, 1, ns_g_mctx); - if (result == ISC_R_SUCCESS && instance != NULL) { - ns_server_flushonshutdown(ns_g_server, - ISC_FALSE); - result = ns_smf_disable(instance); - } - if (instance != NULL) - isc_mem_free(ns_g_mctx, instance); - return (result); - } + if (ns_smf_got_instance == 1 && ns_smf_chroot == 0) + ns_smf_want_disable = 1; /* * If ns_smf_got_instance = 0, ns_smf_chroot * is not relevant and we fall through to @@ -141,17 +132,8 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { result = ns_smf_add_message(text); return (result); } - if (ns_smf_got_instance == 1 && ns_smf_chroot == 0) { - result = ns_smf_get_instance(&instance, 1, ns_g_mctx); - if (result == ISC_R_SUCCESS && instance != NULL) { - ns_server_flushonshutdown(ns_g_server, - ISC_TRUE); - result = ns_smf_disable(instance); - } - if (instance != NULL) - isc_mem_free(ns_g_mctx, instance); - return (result); - } + if (ns_smf_got_instance == 1 && ns_smf_chroot == 0) + ns_smf_want_disable = 1; #endif ns_server_flushonshutdown(ns_g_server, ISC_TRUE); ns_os_shutdownmsg(command, text); diff --git a/bin/named/include/named/ns_smf_globals.h b/bin/named/include/named/ns_smf_globals.h index a0d3ccf974..5389e08c7a 100644 --- a/bin/named/include/named/ns_smf_globals.h +++ b/bin/named/include/named/ns_smf_globals.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: ns_smf_globals.h,v 1.2.2.2 2005/04/07 04:08:45 marka Exp $ */ +/* $Id: ns_smf_globals.h,v 1.2.2.3 2005/04/29 00:55:53 marka Exp $ */ #ifndef NS_SMF_GLOBALS_H #define NS_SMF_GLOBALS_H 1 @@ -33,10 +33,10 @@ EXTERN unsigned int ns_smf_got_instance INIT(0); EXTERN unsigned int ns_smf_chroot INIT(0); +EXTERN unsigned int ns_smf_want_disable INIT(0); isc_result_t ns_smf_add_message(isc_buffer_t *text); isc_result_t ns_smf_get_instance(char **name, int debug, isc_mem_t *mctx); -isc_result_t ns_smf_disable(const char *name); #undef EXTERN #undef INIT diff --git a/bin/named/main.c b/bin/named/main.c index 0f6cec66a2..556ea78a15 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.c,v 1.136.18.9 2005/04/27 05:00:32 sra Exp $ */ +/* $Id: main.c,v 1.136.18.10 2005/04/29 00:55:52 marka Exp $ */ /*! \file */ @@ -779,6 +779,9 @@ ns_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) { int main(int argc, char *argv[]) { isc_result_t result; +#ifdef HAVE_LIBSCF + char *instance = NULL; +#endif /* * Record version in core image. @@ -849,6 +852,22 @@ main(int argc, char *argv[]) { } } while (result != ISC_R_SUCCESS); +#ifdef HAVE_LIBSCF + if (ns_smf_want_disable == 1) { + result = ns_smf_get_instance(&instance, 1, ns_g_mctx); + if (result == ISC_R_SUCCESS && instance != NULL) { + if (smf_disable_instance(instance, 0) != 0) + UNEXPECTED_ERROR(__FILE__, __LINE__, + "smf_disable_instance() ", + "failed for %s : %s", + instance, + scf_strerror(scf_error())); + } + if (instance != NULL) + isc_mem_free(ns_g_mctx, instance); + } +#endif /* HAVE_LIBSCF */ + cleanup(); if (want_stats) { diff --git a/bin/named/server.c b/bin/named/server.c index 9af8253a31..f8c0facb46 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.419.18.22 2005/04/27 05:00:33 sra Exp $ */ +/* $Id: server.c,v 1.419.18.23 2005/04/29 00:55:53 marka Exp $ */ /*! \file */ @@ -4240,18 +4240,4 @@ ns_smf_add_message(isc_buffer_t *text) { isc_buffer_add(text, n); return (ISC_R_SUCCESS); } - -isc_result_t -ns_smf_disable(const char *ins_name) { - - if (ins_name == NULL) - return (ISC_R_UNEXPECTED); - if (smf_disable_instance(ins_name, 0) != 0) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "smf_disable_instance() failed: %s", - scf_strerror(scf_error())); - return (ISC_R_FAILURE); - } - return (ISC_R_SUCCESS); -} #endif /* HAVE_LIBSCF */