further changes for

1848.   [bug]           Improve SMF integration. [RT #13238]
This commit is contained in:
Mark Andrews 2005-04-29 00:55:53 +00:00
parent e8f92bfe9c
commit 27237763df
4 changed files with 29 additions and 42 deletions

View file

@ -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);

View file

@ -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

View file

@ -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) {

View file

@ -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 */