From 4cd765650776027d05fe7fca248478918e02e63b Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Fri, 22 Jun 2001 17:22:26 +0000 Subject: [PATCH] Split fatal(), notify() into util.c. Put DO() and the fatal()/notify() declarations in util.h. Makefile adjusted to build rndc with util.o, and to also build and install rndc-confgen. --- bin/rndc/Makefile.in | 40 +++++++++++++++++++++----------- bin/rndc/rndc.c | 45 ++++-------------------------------- bin/rndc/util.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ bin/rndc/util.h | 47 +++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 53 deletions(-) create mode 100644 bin/rndc/util.c create mode 100644 bin/rndc/util.h diff --git a/bin/rndc/Makefile.in b/bin/rndc/Makefile.in index 87ed65f215..53bfd1e44b 100644 --- a/bin/rndc/Makefile.in +++ b/bin/rndc/Makefile.in @@ -13,7 +13,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: Makefile.in,v 1.25 2001/06/01 00:45:03 bwelling Exp $ +# $Id: Makefile.in,v 1.26 2001/06/22 17:22:24 tale Exp $ srcdir = @srcdir@ VPATH = @srcdir@ @@ -23,8 +23,11 @@ top_srcdir = @top_srcdir@ @BIND9_INCLUDES@ -CINCLUDES = -I${top_srcdir}/bin/named/include \ - ${ISC_INCLUDES} ${ISCCC_INCLUDES} ${ISCCFG_INCLUDES} +CINCLUDES = ${ISC_INCLUDES} + +RNDCINCLUDES = ${CINCLUDES} ${ISCCC_INCLUDES} ${ISCCFG_INCLUDES} + +CONFINCLUDES = ${CINCLUDES} ${DNS_INCLUDES} CDEFINES = CWARNINGS = @@ -32,20 +35,20 @@ CWARNINGS = ISCCFGLIBS = ../../lib/isccfg/libisccfg.@A@ ISCCCLIBS = ../../lib/isccc/libisccc.@A@ ISCLIBS = ../../lib/isc/libisc.@A@ +DNSLIBS = ../../lib/dns/libdns.@A@ ISCCFGDEPLIBS = ../../lib/isccfg/libisccfg.@A@ ISCCCDEPLIBS = ../../lib/isccc/libisccc.@A@ ISCDEPLIBS = ../../lib/isc/libisc.@A@ +DNSDEPLIBS = ../../lib/dns/libdns.@A@ -DEPLIBS = ${ISCCFGDEPLIBS} ${ISCCCDEPLIBS} ${ISCDEPLIBS} +RNDCLIBS = ${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} @LIBS@ +RNDCDEPLIBS = ${ISCCFGDEPLIBS} ${ISCCCDEPLIBS} ${ISCDEPLIBS} -LIBS = ${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} @LIBS@ +CONFLIBS = ${DNSLIBS} ${ISCLIBS} @LIBS@ +CONFDEPLIBS = ${DNSLIBS} ${ISCLIBS} -TARGETS = rndc - -OBJS = rndc.@O@ - -SRCS = rndc.c +TARGETS = rndc rndc-confgen MANPAGES = rndc.8 rndc.conf.5 @@ -56,12 +59,22 @@ MANOBJS = ${MANPAGES} ${HTMLPAGES} @BIND9_MAKE_RULES@ rndc.@O@: rndc.c - ${LIBTOOL} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \ + ${LIBTOOL} ${CC} ${ALL_CFLAGS} ${RNDCINCLUDES} \ + -DVERSION=\"${VERSION}\" \ -DRNDC_SYSCONFDIR=\"${sysconfdir}\" \ -DNS_LOCALSTATEDIR=\"${localstatedir}\" -c ${srcdir}/rndc.c -rndc: ${OBJS} ${DEPLIBS} - ${LIBTOOL} ${PURIFY} ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} +rndc-confgen.@O@: rndc-confgen.c + ${LIBTOOL} ${CC} ${ALL_CFLAGS} ${CONFINCLUDES} \ + -DRNDC_SYSCONFDIR=\"${sysconfdir}\" -c ${srcdir}/rndc-confgen.c + +rndc: rndc.@O@ util.@O@ ${RNDCDEPLIBS} + ${LIBTOOL} ${PURIFY} ${CC} ${CFLAGS} -o $@ rndc.@O@ util.@O@ \ + ${RNDCLIBS} + +rndc-confgen: rndc-confgen.@O@ util.@O@ ${CONFDEPLIBS} + ${LIBTOOL} ${PURIFY} ${CC} ${CFLAGS} -o $@ rndc-confgen.@O@ util.@O@ \ + ${CONFLIBS} doc man:: ${MANOBJS} @@ -75,6 +88,7 @@ installdirs: install:: rndc installdirs ${LIBTOOL} ${INSTALL_PROGRAM} rndc ${DESTDIR}${sbindir} + ${LIBTOOL} ${INSTALL_PROGRAM} rndc-confgen ${DESTDIR}${sbindir} ${INSTALL_DATA} ${srcdir}/rndc.8 ${DESTDIR}${mandir}/man8 ${INSTALL_DATA} ${srcdir}/rndc.conf.5 ${DESTDIR}${mandir}/man5 diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 70875da62e..8fee8f4a4b 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rndc.c,v 1.64 2001/06/15 01:20:09 gson Exp $ */ +/* $Id: rndc.c,v 1.65 2001/06/22 17:22:25 tale Exp $ */ /* * Principal Author: DCL @@ -50,7 +50,7 @@ #include #include -#define NS_CONTROL_PORT 953 +#include "util.h" #ifdef HAVE_ADDRINFO #ifdef HAVE_GETADDRINFO @@ -64,6 +64,9 @@ extern int h_errno; #endif +char progname[256]; +isc_boolean_t verbose; + static const char *admin_conffile = RNDC_SYSCONFDIR "/rndc.conf"; static const char *auto_conffile = NS_LOCALSTATEDIR "/run/named.key"; static const char *version = VERSION; @@ -71,28 +74,14 @@ static const char *servername = NULL; static unsigned int remoteport = NS_CONTROL_PORT; static isc_socketmgr_t *socketmgr = NULL; static unsigned char databuf[2048]; -static char progname[256]; static isccc_ccmsg_t ccmsg; static isccc_region_t secret; -static isc_boolean_t verbose; static isc_boolean_t failed = ISC_FALSE; static isc_mem_t *mctx; static int sends, recvs, connects; static char *command; static char *args; -static void -notify(const char *fmt, ...) { - va_list ap; - - if (verbose) { - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fputs("\n", stderr); - } -} - static void usage(int status) { fprintf(stderr, "\ @@ -126,30 +115,6 @@ Version: %s\n", exit(status); } -static void -fatal(const char *format, ...) { - va_list args; - - fprintf(stderr, "%s: ", progname); - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fprintf(stderr, "\n"); - exit(1); -} - - -#undef DO -#define DO(name, function) \ - do { \ - result = function; \ - if (result != ISC_R_SUCCESS) \ - fatal("%s: %s", name, isc_result_totext(result)); \ - else \ - notify(name); \ - } while (0) - - static void get_address(const char *host, in_port_t port, isc_sockaddr_t *sockaddr) { struct in_addr in4; diff --git a/bin/rndc/util.c b/bin/rndc/util.c new file mode 100644 index 0000000000..98d52e5e29 --- /dev/null +++ b/bin/rndc/util.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 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. + */ + +/* $Id: util.c,v 1.1 2001/06/22 17:22:26 tale Exp $ */ + +#include + +#include +#include +#include + +#include + +#include "util.h" + +extern isc_boolean_t verbose; +extern const char *progname; + +void +notify(const char *fmt, ...) { + va_list ap; + + if (verbose) { + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputs("\n", stderr); + } +} + +void +fatal(const char *format, ...) { + va_list args; + + fprintf(stderr, "%s: ", progname); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + fprintf(stderr, "\n"); + exit(1); +} diff --git a/bin/rndc/util.h b/bin/rndc/util.h new file mode 100644 index 0000000000..005e452c99 --- /dev/null +++ b/bin/rndc/util.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 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. + */ + +/* $Id: util.h,v 1.1 2001/06/22 17:22:26 tale Exp $ */ + +#ifndef RNDC_UTIL_H +#define RNDC_UTIL_H 1 + +#include + +#define NS_CONTROL_PORT 953 + +#undef DO +#define DO(name, function) \ + do { \ + result = function; \ + if (result != ISC_R_SUCCESS) \ + fatal("%s: %s", name, isc_result_totext(result)); \ + else \ + notify(name); \ + } while (0) + +ISC_LANG_BEGINDECLS + +void +notify(const char *fmt, ...); + +void +fatal(const char *format, ...); + +ISC_LANG_ENDDECLS + +#endif /* RNDC_UTIL_H */