From af39460a87749a87d3bf4ac36c8024b03fbebbd0 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 1 Sep 2004 07:22:19 +0000 Subject: [PATCH] 1709. [port] solaris: add SMF support from Sun. --- CHANGES | 2 + bin/named/main.c | 95 +++++++++++++++++++++++++++++++- config.h.in | 5 +- configure | 138 ++++++++++++++++++++++++++++++++++++----------- configure.in | 7 ++- 5 files changed, 214 insertions(+), 33 deletions(-) diff --git a/CHANGES b/CHANGES index b3b1793805..229402c9ad 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +1709. [port] solaris: add SMF support from Sun. + 1708. [cleanup] Replaced dns_fullname_hash() with dns_name_fullhash() for conformance to the name space convention. Binary backward compatibility to the old function name is diff --git a/bin/named/main.c b/bin/named/main.c index 87ce11f1cc..e6baf6323f 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.2 2004/07/01 02:02:24 marka Exp $ */ +/* $Id: main.c,v 1.136.18.3 2004/09/01 07:20:40 marka Exp $ */ #include @@ -47,6 +47,10 @@ #include +#ifdef HAVE_LIBSCF +#include +#endif + /* * Defining NS_MAIN provides storage declarations (rather than extern) * for variables in named/globals.h. @@ -684,6 +688,91 @@ ns_main_setmemstats(const char *filename) { strcpy(memstats, filename); } +#ifdef HAVE_LIBSCF +/* + * Get FMRI for the current named process + */ +static char * +scf_get_ins_name(void) { + scf_handle_t *h = NULL; + int namelen; + char *ins_name; + + if ((h = scf_handle_create(SCF_VERSION)) == NULL) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "scf_handle_create() failed: %s", + scf_strerror(scf_error())); + return (NULL); + } + + if (scf_handle_bind(h) == -1) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "scf_handle_bind() failed: %s", + scf_strerror(scf_error())); + scf_handle_destroy(h); + return (NULL); + } + + if ((namelen = scf_myname(h, NULL, 0)) == -1) { + isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, + NS_LOGMODULE_MAIN, ISC_LOG_INFO, + "scf_myname() failed: %s", + scf_strerror(scf_error())); + scf_handle_destroy(h); + return (NULL); + } + + if ((ins_name = malloc(namelen + 1)) == NULL) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "scf_get_ins_named() memory " + "allocation failed: %s", + isc_result_totext(ISC_R_NOMEMORY)); + scf_handle_destroy(h); + return (NULL); + } + + if (scf_myname(h, ins_name, namelen + 1) == -1) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "scf_myname() failed: %s", + scf_strerror(scf_error())); + scf_handle_destroy(h); + free(ins_name); + return (NULL); + } + + scf_handle_destroy(h); + isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, + ISC_LOG_INFO, "instance name:%s", ins_name); + + return (ins_name); +} + +static void +scf_cleanup(void) { + char *s; + char *ins_name; + + if ((ins_name = scf_get_ins_name()) != NULL) { + if ((s = smf_get_state(ins_name)) != NULL) { + if ((strcmp(SCF_STATE_STRING_ONLINE, s) == 0) || + (strcmp(SCF_STATE_STRING_DEGRADED, s) == 0)) { + if (smf_disable_instance(ins_name, 0) != 0) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "smf_disable_instance() failed: %s", + scf_strerror(scf_error())); + } + } + free(s); + } else { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "smf_get_state() failed: %s", + scf_strerror(scf_error())); + } + free(ins_name); + } +} +#endif + int main(int argc, char *argv[]) { isc_result_t result; @@ -762,6 +851,10 @@ main(int argc, char *argv[]) { } } while (result != ISC_R_SUCCESS); +#ifdef HAVE_LIBSCF + scf_cleanup(); +#endif + cleanup(); if (want_stats) { diff --git a/config.h.in b/config.h.in index 719fc43a68..c49ba2c52e 100644 --- a/config.h.in +++ b/config.h.in @@ -16,7 +16,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: config.h.in,v 1.60.18.1 2004/05/21 08:21:37 marka Exp $ */ +/* $Id: config.h.in,v 1.60.18.2 2004/09/01 07:22:18 marka Exp $ */ /*** *** This file is not to be included by any public header files, because @@ -161,6 +161,9 @@ int sigwait(const unsigned int *set, int *sig); /* Define to 1 if you have the `pthread' library (-lpthread). */ #undef HAVE_LIBPTHREAD +/* Define to 1 if you have the `scf' library (-lscf). */ +#undef HAVE_LIBSCF + /* Define to 1 if you have the `socket' library (-lsocket). */ #undef HAVE_LIBSOCKET diff --git a/configure b/configure index 28e4e97331..44f15b7b54 100755 --- a/configure +++ b/configure @@ -14,7 +14,7 @@ # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # -# $Id: configure,v 1.339.18.6 2004/08/28 06:21:10 marka Exp $ +# $Id: configure,v 1.339.18.7 2004/09/01 07:22:19 marka Exp $ # # Portions Copyright (C) 1996-2001 Nominum, Inc. # @@ -29,7 +29,7 @@ # 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. -# From configure.in Revision: 1.355.18.6 . +# From configure.in Revision: 1.355.18.7 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59. # @@ -6632,6 +6632,84 @@ fi ISC_THREAD_DIR=$thread_dir +# +# In solaris 10, SMF can manage named service +# + +echo "$as_me:$LINENO: checking for smf_enable_instance in -lscf" >&5 +echo $ECHO_N "checking for smf_enable_instance in -lscf... $ECHO_C" >&6 +if test "${ac_cv_lib_scf_smf_enable_instance+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lscf $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char smf_enable_instance (); +int +main () +{ +smf_enable_instance (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_scf_smf_enable_instance=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_scf_smf_enable_instance=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_scf_smf_enable_instance" >&5 +echo "${ECHO_T}$ac_cv_lib_scf_smf_enable_instance" >&6 +if test $ac_cv_lib_scf_smf_enable_instance = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBSCF 1 +_ACEOF + + LIBS="-lscf $LIBS" + +fi + + # # flockfile is usually provided by pthreads, but we may want to use it # even if compiled with --disable-threads. getc_unlocked might also not @@ -7842,7 +7920,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 7845 "configure"' > conftest.$ac_ext + echo '#line 7923 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -8832,7 +8910,7 @@ fi # Provide some information about the compiler. -echo "$as_me:8835:" \ +echo "$as_me:8913:" \ "checking for Fortran 77 compiler version" >&5 ac_compiler=`set X $ac_compile; echo $2` { (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 @@ -9870,11 +9948,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:9873: $lt_compile\"" >&5) + (eval echo "\"\$as_me:9951: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:9877: \$? = $ac_status" >&5 + echo "$as_me:9955: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -10103,11 +10181,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:10106: $lt_compile\"" >&5) + (eval echo "\"\$as_me:10184: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:10110: \$? = $ac_status" >&5 + echo "$as_me:10188: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -10163,11 +10241,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:10166: $lt_compile\"" >&5) + (eval echo "\"\$as_me:10244: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:10170: \$? = $ac_status" >&5 + echo "$as_me:10248: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -12347,7 +12425,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:14709: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:14635: \$? = $ac_status" >&5 + echo "$as_me:14713: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -14688,11 +14766,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14691: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14769: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:14695: \$? = $ac_status" >&5 + echo "$as_me:14773: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -16049,7 +16127,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:17055: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16981: \$? = $ac_status" >&5 + echo "$as_me:17059: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -17034,11 +17112,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:17037: $lt_compile\"" >&5) + (eval echo "\"\$as_me:17115: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:17041: \$? = $ac_status" >&5 + echo "$as_me:17119: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -19072,11 +19150,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:19075: $lt_compile\"" >&5) + (eval echo "\"\$as_me:19153: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:19079: \$? = $ac_status" >&5 + echo "$as_me:19157: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -19305,11 +19383,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:19308: $lt_compile\"" >&5) + (eval echo "\"\$as_me:19386: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:19312: \$? = $ac_status" >&5 + echo "$as_me:19390: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -19365,11 +19443,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:19368: $lt_compile\"" >&5) + (eval echo "\"\$as_me:19446: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:19372: \$? = $ac_status" >&5 + echo "$as_me:19450: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -21549,7 +21627,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <