From 7edbc1a683dbe12db6de3b27a32b1f75838bd6ba Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 3 Jan 2007 10:42:32 +0000 Subject: [PATCH] A main program is compiled. git-svn-id: file:///svn/unbound/trunk@5 be551aaa-1e26-0410-a405-d3ace91eadb9 --- Makefile.in | 51 ++++++++++++++++++++++++++++++++++----------- configure.ac | 17 +++++++++++++++ daemon/unbound.c | 24 +++++++++++++++++++++ doc/Changelog | 2 ++ testcode/unitmain.c | 21 +++++++++++++++++++ util/log.c | 38 +++++++++++++++++++++++++++++++++ util/log.h | 33 +++++++++++++++++++++++++++++ 7 files changed, 174 insertions(+), 12 deletions(-) create mode 100644 daemon/unbound.c create mode 100644 testcode/unitmain.c create mode 100644 util/log.c create mode 100644 util/log.h diff --git a/Makefile.in b/Makefile.in index 9978f8929..199af4ac0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,17 @@ -# Standard installation pathnames +# Copyright 2007 NLnet Labs # See the file LICENSE for the license +# +# Standard installation pathnames + +QUIET=yes +ifeq "$(QUIET)" "yes" + Q=@ + INFO=@echo +else + Q= + INFO=@: +endif + SHELL=@SHELL@ VERSION=@PACKAGE_VERSION@ srcdir=@srcdir@ @@ -21,6 +33,9 @@ LIBOBJS=@LIBOBJS@ RUNTIME_PATH=@RUNTIME_PATH@ DATE=$(shell date +%Y%m%d) LIBTOOL=$(libtool) +ifeq "$(QUIET)" "yes" + LIBTOOL+=--quiet +endif BUILD=build/ LINT=splint @@ -28,24 +43,35 @@ LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned INSTALL=$(srcdir)/install-sh -COMMON_SRC=$(wildcard *.c) +COMMON_SRC=$(wildcard services/*.c util/*.c) COMMON_OBJ=$(addprefix $(BUILD),$(COMMON_SRC:.c=.o) $(LIBOBJS)) -ALL_SOURCES=$(COMMON_SRC) +UNITTEST_SRC=$(wildcard testcode/*.c) +UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o)) +DAEMON_SRC=$(wildcard daemon/*.c) +DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o)) +ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) +ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) $(LIBOBJS)) COMPILE=$(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) LINK=$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) LINK_LIB=$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -release $(VERSION) $(BUILD)%.o: $(srcdir)/%.c - @if test ! -d $(BUILD); then mkdir $(BUILD); fi - $(COMPILE) -c $< -o $@ + $(INFO) Build $< + @if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi + $Q$(COMPILE) -c $< -o $@ .PHONY: clean realclean doc lint all -all: $(COMMON_OBJ) main +all: $(COMMON_OBJ) unbound unittest + +unbound: $(COMMON_OBJ) $(DAEMON_OBJ) + $(INFO) Link $@ + $Q$(LINK) -o $@ $^ -main: $(COMMON_OBJ) - $(LINK) -o $@ $< +unittest: $(COMMON_OBJ) $(UNITTEST_OBJ) + $(INFO) Link $@ + $Q$(LINK) -o $@ $^ clean: rm -f *.o *.d *.lo *~ tags @@ -57,7 +83,7 @@ realclean: clean rm -f Makefile lint: - for i in $(SOURCES); do \ + for i in $(ALL_SRC); do \ $(LINT) $(LINTFLAGS) -I. -I$(srcdir) $(srcdir)/$$i ; \ if [ $$? -ne 0 ] ; then exit 1 ; fi ; \ done @@ -67,9 +93,10 @@ tags: $(srcdir)/*.c ldns/*.[ch] # Automatic dependencies. $(BUILD)%.d: $(srcdir)/%.c - @if test ! -d $(BUILD); then mkdir $(BUILD); fi - $(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \ + $(INFO) Depend $< + @if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi + $Q$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \ | sed '\''s!\(.*\)\.o[ :]*!$(dir $@)\1.o $@ : !g'\'' > $@; \ [ -s $@ ] || rm -f $@' --include $(addprefix $(BUILD),$(ALL_SOURCES:.c=.d)) +-include $(addprefix $(BUILD),$(ALL_SRC:.c=.d)) diff --git a/configure.ac b/configure.ac index 3f7ae0380..a75d21292 100644 --- a/configure.ac +++ b/configure.ac @@ -208,6 +208,8 @@ AC_ARG_WITH(ldns, AC_CHECK_LIB(ldns, ldns_rr_new,, [AC_MSG_ERROR([Can't find ldns library])]) +AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [512], [Define to the maximum message length to pass to syslog.]) + AH_BOTTOM([ #include #include @@ -238,6 +240,21 @@ AH_BOTTOM([ #ifdef HAVE_ARPA_INET_H #include #endif + +#ifdef HAVE_ATTR_FORMAT +# define ATTR_FORMAT(archetype, string_index, first_to_check) \ + __attribute__ ((format (archetype, string_index, first_to_check))) +#else /* !HAVE_ATTR_FORMAT */ +# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ +#endif /* !HAVE_ATTR_FORMAT */ +#if defined(__cplusplus) +# define ATTR_UNUSED(x) +#elif defined(HAVE_ATTR_UNUSED) +# define ATTR_UNUSED(x) x __attribute__((unused)) +#else /* !HAVE_ATTR_UNUSED */ +# define ATTR_UNUSED(x) x +#endif /* !HAVE_ATTR_UNUSED */ + ]) AC_CONFIG_FILES([Makefile]) diff --git a/daemon/unbound.c b/daemon/unbound.c new file mode 100644 index 000000000..aafb0ad67 --- /dev/null +++ b/daemon/unbound.c @@ -0,0 +1,24 @@ +/* + * daemon/unbound.c - main program for unbound DNS resolver daemon. + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * See LICENSE for the license. + * + */ + +#include "config.h" +#include "util/log.h" + +int +main(int argc, char* argv[]) +{ + if(argc != 1) { + printf("usage: %s\n", argv[0]); + printf("\tstart unbound daemon DNS resolver.\n"); + return 1; + } + log_init(); + log_info("Start of %s.", PACKAGE_STRING); + return 0; +} diff --git a/doc/Changelog b/doc/Changelog index 00bf99ae5..753c850ca 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,8 @@ You need a ssh login. There is no https access yet. - Added LICENSE, the BSD license. - Added doc/README with compile help. + - main program stub and quiet makefile. + - minimal logging service (to stderr). 15 December 2006: Wouter - Created Makefile.in and configure.ac. diff --git a/testcode/unitmain.c b/testcode/unitmain.c new file mode 100644 index 000000000..da04f2629 --- /dev/null +++ b/testcode/unitmain.c @@ -0,0 +1,21 @@ +/* + * testcode/unitmain.c - unit test main program for unbound. + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * See LICENSE for the license. + * + */ + +#include "config.h" + +int main(int argc, char* argv[]) +{ + if(argc != 1) { + printf("usage: %s\n", argv[0]); + printf("\tperforms unit tests.\n"); + return 1; + } + printf("Start of %s unit test.\n", PACKAGE_STRING); + return 0; +} diff --git a/util/log.c b/util/log.c new file mode 100644 index 000000000..56718be8c --- /dev/null +++ b/util/log.c @@ -0,0 +1,38 @@ +/* + * util/log.c - implementation of the log code + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * See LICENSE for the license. + * + */ + +#include "config.h" +#include "util/log.h" +#ifdef HAVE_TIME_H +#include +#endif + +void +log_init() +{ +} + +void +log_vmsg(const char *format, va_list args) +{ + char message[MAXSYSLOGMSGLEN]; + const char* ident="unbound"; + vsnprintf(message, sizeof(message), format, args); + fprintf(stderr, "[%d] %s[%d]: %s\n", + (int)time(NULL), ident, (int)getpid(), message); +} + +void +log_info(const char *format, ...) +{ + va_list args; + va_start(args, format); + log_vmsg(format, args); + va_end(args); +} diff --git a/util/log.h b/util/log.h new file mode 100644 index 000000000..4969ca21a --- /dev/null +++ b/util/log.h @@ -0,0 +1,33 @@ +/* + * util/log.h - logging service + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * See LICENSE for the license. + * + */ + +#ifndef UTIL_LOG_H +#define UTIL_LOG_H + +#include "config.h" +#ifdef HAVE_STDARG_H +#include +#endif + +/** + * call this to initialize logging services + */ +void log_init(); + +/** + * Pass printf formatted arguments. No trailing newline is needed. + */ +void log_info(const char* format, ...) ATTR_FORMAT(printf, 1, 2); + +/** + * va_list argument version of log_info. + */ +void log_vmsg(const char *format, va_list args); + +#endif /* UTIL_LOG_H */ -- 2.47.2