Permalink
Browse files

clusternetd: add basic stuff

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information...
0 parents commit 99afbd6e87d182067efa3e39f46f90e77a233de0 @fabbione fabbione committed Aug 13, 2010
Showing with 648 additions and 0 deletions.
  1. +21 −0 .gitignore
  2. +29 −0 Makefile.am
  3. +4 −0 autogen.sh
  4. +21 −0 conf.c
  5. +12 −0 conf.h
  6. +176 −0 configure.ac
  7. +33 −0 logging.c
  8. +9 −0 logging.h
  9. +268 −0 main.c
  10. +64 −0 tun.c
  11. +11 −0 tun.h
@@ -0,0 +1,21 @@
+*.o
+stamp-h1
+Makefile.in
+Makefile
+.deps
+.libs
+aclocal.m4
+autoconf
+autoheader
+autom4te.cache
+automake
+compile
+config.*
+configure
+depcomp
+install-sh
+libtoolize
+ltmain.sh
+m4
+missing
+libtool
@@ -0,0 +1,29 @@
+MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure depcomp \
+ config.guess config.sub missing install-sh \
+ ltmain.sh compile config.h.in config.h.in~
+
+AUTOMAKE_OPTIONS = foreign
+
+ACLOCAL_AMFLAGS = -I m4
+
+noinst_HEADERS = \
+ conf.h logging.h \
+ tun.h
+
+sbin_PROGRAMS = clusternetd
+
+clusternetd_SOURCES = main.c \
+ conf.c logging.c \
+ tun.c
+
+clusternetd_CPPFLAGS =
+
+clusternetd_CFLAGS = -fPIC \
+ $(logt_CFLAGS)
+
+clusternetd_LDFLAGS = $(logt_LIBS)
+
+clusternetd_LDADD =
+
+maintainer-clean-local:
+ rm -rf m4
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Run this to generate all the initial makefiles, etc.
+mkdir -p m4
+autoreconf -i -v && echo Now run ./configure and make
21 conf.c
@@ -0,0 +1,21 @@
+#include "conf.h"
+
+#include <stdlib.h>
+
+int readconf(char *conffile, struct peer **head)
+{
+ return 0;
+}
+
+void freeconf(struct peer *head)
+{
+ struct peer *next;
+
+ while(head) {
+ next = head->next;
+ free(head);
+ head = next;
+ }
+
+ return;
+}
12 conf.h
@@ -0,0 +1,12 @@
+#ifndef __CONF_H__
+#define __CONF_H__
+
+struct peer {
+ struct peer *next;
+ struct peer *tail;
+};
+
+int readconf(char *conffile, struct peer **head);
+void freeconf(struct peer *head);
+
+#endif
@@ -0,0 +1,176 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.63])
+AC_INIT([clusternetd], [0.1], [fdinitto@redhat.com])
+AM_INIT_AUTOMAKE([-Wno-portability])
+LT_PREREQ([2.2.6])
+LT_INIT
+
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SRCDIR([main.c])
+AC_CONFIG_HEADERS([config.h])
+
+AC_CANONICAL_HOST
+AC_PROG_LIBTOOL
+
+AC_LANG([C])
+
+if test "$prefix" = "NONE"; then
+ prefix="/usr"
+ if test "$localstatedir" = "\${prefix}/var"; then
+ localstatedir="/var"
+ fi
+ if test "$sysconfdir" = "\${prefix}/etc"; then
+ sysconfdir="/etc"
+ fi
+fi
+
+# Checks for programs.
+if ! ${MAKE-make} --version /cannot/make/this >/dev/null 2>&1; then
+ AC_MSG_ERROR([you don't seem to have GNU make; it is required])
+fi
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_LN_S
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+AC_PROG_CXX
+AC_PROG_RANLIB
+AC_CHECK_PROGS([PKGCONFIG], [pkg-config])
+
+## local helper functions
+# this function checks if CC support options passed as
+# args. Global CFLAGS are ignored during this test.
+cc_supports_flag() {
+ local CFLAGS="$@"
+ AC_MSG_CHECKING([whether $CC supports "$@"])
+ AC_COMPILE_IFELSE([int main(){return 0;}] ,
+ [RC=0; AC_MSG_RESULT([yes])],
+ [RC=1; AC_MSG_RESULT([no])])
+ return $RC
+}
+
+# helper macro to check libs without adding them to LIBS
+check_lib_no_libs() {
+ lib_no_libs_arg1=$1
+ shift
+ lib_no_libs_arg2=$1
+ shift
+ lib_no_libs_args=$@
+ AC_CHECK_LIB([$lib_no_libs_arg1],
+ [$lib_no_libs_arg2],,,
+ [$lib_no_libs_args])
+ LIBS=$ac_check_lib_save_LIBS
+}
+
+# Checks for libraries.
+PKG_CHECK_MODULES([logt],[liblogthread])
+
+# Checks for header files.
+AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h sys/ioctl.h sys/socket.h unistd.h netinet/in.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_SIZE_T
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([atexit ftruncate memset strdup strtol])
+
+# local options
+AC_ARG_ENABLE([debug],
+ [ --enable-debug enable debug build. ],
+ [ default="no" ])
+
+AC_ARG_WITH([syslogfacility],
+ [ --syslogfacility=FACILITY
+ default syslog facility. ],
+ [ SYSLOGFACILITY="$withval" ],
+ [ SYSLOGFACILITY="LOG_LOCAL4" ])
+
+AC_ARG_WITH([sysloglevel],
+ [ --sysloglevel=LEVEL
+ default syslog level. ],
+ [ SYSLOGLEVEL="$withval" ],
+ [ SYSLOGLEVEL="LOG_INFO" ])
+
+## random vars
+LOGDIR=${localstatedir}/log/
+RUNDIR=${localstatedir}/run/
+
+## do subst
+
+AC_DEFINE_UNQUOTED([CONFFILE], "$(eval echo ${sysconfdir}/clusternetd.conf)",
+ [Default config file])
+
+AC_DEFINE_UNQUOTED([LOGDIR], "$(eval echo ${LOGDIR})",
+ [Default logging directory])
+
+AC_DEFINE_UNQUOTED([RUNDIR], "$(eval echo ${RUNDIR})",
+ [Default run directory])
+
+AC_DEFINE_UNQUOTED([SYSLOGFACILITY], $(eval echo ${SYSLOGFACILITY}),
+ [Default syslog facility])
+
+AC_DEFINE_UNQUOTED([SYSLOGLEVEL], $(eval echo ${SYSLOGLEVEL}),
+ [Default syslog level])
+
+## *FLAGS handling
+ENV_CFLAGS="$CFLAGS"
+ENV_CPPFLAGS="$CPPFLAGS"
+ENV_LDFLAGS="$LDFLAGS"
+
+# debug build stuff
+if test "x${enable_debug}" = xyes; then
+ AC_DEFINE_UNQUOTED([DEBUG], [1], [Compiling Debugging code])
+ OPT_CFLAGS="-O0"
+else
+ OPT_CFLAGS="-O3"
+fi
+
+# gdb flags
+if test "x${GCC}" = xyes; then
+ GDB_FLAGS="-ggdb3"
+else
+ GDB_FLAGS="-g"
+fi
+
+# extra warnings
+EXTRA_WARNINGS=""
+
+WARNLIST="
+ all
+ shadow
+ missing-prototypes
+ missing-declarations
+ strict-prototypes
+ declaration-after-statement
+ pointer-arith
+ write-strings
+ cast-align
+ bad-function-cast
+ missing-format-attribute
+ format=2
+ format-security
+ format-nonliteral
+ no-long-long
+ unsigned-char
+ gnu89-inline
+ no-strict-aliasing
+ error
+ "
+
+for j in $WARNLIST; do
+ if cc_supports_flag -W$j; then
+ EXTRA_WARNINGS="$EXTRA_WARNINGS -W$j";
+ fi
+done
+
+CFLAGS="$ENV_CFLAGS $OPT_CFLAGS $GDB_FLAGS \
+ $EXTRA_WARNINGS $WERROR_CFLAGS"
+CPPFLAGS="$ENV_CPPFLAGS"
+LDFLAGS="$ENV_LDFLAGS"
+
+AC_CONFIG_FILES([Makefile])
+
+AC_OUTPUT
@@ -0,0 +1,33 @@
+#include "config.h"
+
+#include <limits.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "logging.h"
+
+int init_logging(int debug, int daemonize)
+{
+ int mode = LOG_MODE_OUTPUT_FILE | LOG_MODE_OUTPUT_SYSLOG;
+ int syslog_facility = SYSLOGFACILITY;
+ int syslog_priority = SYSLOGLEVEL;
+ char logfile[PATH_MAX];
+ int logfile_priority = SYSLOGLEVEL;
+
+ memset(logfile, 0, PATH_MAX);
+ sprintf(logfile, LOGDIR "/" PACKAGE ".log");
+
+ if (!daemonize)
+ mode |= LOG_MODE_OUTPUT_STDERR;
+
+ if (debug)
+ logfile_priority = LOG_DEBUG;
+
+ return logt_init(PACKAGE, mode, syslog_facility, syslog_priority,
+ logfile_priority, logfile);
+}
+
+void close_logging(void)
+{
+ logt_exit();
+}
@@ -0,0 +1,9 @@
+#ifndef __LOGGING_H__
+#define __LOGGING_H__
+
+#include <liblogthread.h>
+
+int init_logging(int debug, int daemonize);
+void close_logging(void);
+
+#endif
Oops, something went wrong.

0 comments on commit 99afbd6

Please sign in to comment.