Merged branch configfile to trunk
authorocto <octo>
Sat, 17 Dec 2005 09:23:52 +0000 (09:23 +0000)
committerocto <octo>
Sat, 17 Dec 2005 09:23:52 +0000 (09:23 +0000)
Makefile.am
TODO
configure.in
src/Makefile.am
src/collectd.c
src/collectd.h
src/users.c
src/users.h
src/utils_debug.c
src/utils_debug.h

index d173ee7..30beb63 100644 (file)
@@ -7,6 +7,6 @@ dist-hook:
        find $(distdir) -type d -name '.svn' | xargs rm -rf
 
 install-exec-hook:
+       $(mkinstalldirs) $(DESTDIR)$(sysconfdir)
        $(mkinstalldirs) $(DESTDIR)$(localstatedir)/run
        $(mkinstalldirs) $(DESTDIR)$(localstatedir)/lib/$(PACKAGE_NAME)
-       $(mkinstalldirs) $(DESTDIR)$(sysconfdir)
diff --git a/TODO b/TODO
index edb073f..f98488f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,3 +3,4 @@ For version 3.*:
 * Port tape module to Linux
 * Maybe look into porting the serial module
 * Ping bug (disabled)
+* Handle sigterm
index 293fc6a..e5cf5cb 100644 (file)
@@ -37,6 +37,7 @@ AC_CHECK_HEADERS(sys/socket.h)
 AC_CHECK_HEADERS(sys/select.h)
 AC_CHECK_HEADERS(netdb.h)
 AC_CHECK_HEADERS(sys/resource.h)
+AC_CHECK_HEADERS(sys/param.h)
 AC_CHECK_HEADERS(errno.h)
 AC_CHECK_HEADERS(syslog.h)
 
@@ -100,6 +101,7 @@ AC_CHECK_FUNCS(socket, , AC_CHECK_LIB(socket, socket))
 AC_CHECK_FUNCS(gethostbyname, , AC_CHECK_LIB(nsl, gethostbyname))
 AC_CHECK_FUNCS(strchr memcpy strstr strcmp strncmp strncpy strlen)
 AC_CHECK_FUNCS(strncasecmp strcasecmp)
+AC_CHECK_FUNCS(openlog syslog closelog)
 
 # For cpu module
 AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
@@ -108,8 +110,7 @@ AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"]
 AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"])
 
 # For users module
-have_getutent="no"
-AC_CHECK_FUNCS(getutent getutxent, [have_getutent="yes"])
+AC_CHECK_FUNCS(getutent getutxent)
 
 # For quota module
 AC_CHECK_FUNCS(quotactl)
@@ -118,7 +119,7 @@ AC_CHECK_FUNCS(getgrgid getpwuid)
 # For mount interface
 AC_CHECK_FUNCS(getfsent getvfsent listmntent)
 AC_FUNC_GETMNTENT
-if test "x$ac_cv_func_getmntent" = 'xyes'; then
+if test "x$ac_cv_func_getmntent" = "xyes"; then
        saveCFLAGS="$CFLAGS"
        CFLAGS="-Wall -Werror $CFLAGS"
        AC_CACHE_CHECK([whether getmntent takes one argument],
@@ -132,7 +133,7 @@ if test "x$ac_cv_func_getmntent" = 'xyes'; then
                        [fu_cv_getmntent1=no]
                )
        )
-       if test "x$fu_cv_getmntent1" = 'xno'; then
+       if test "x$fu_cv_getmntent1" = "xno"; then
                AC_CACHE_CHECK([whether getmntent takes two arguments],
                        [fu_cv_getmntent2],
                        AC_COMPILE_IFELSE(
@@ -148,7 +149,7 @@ if test "x$ac_cv_func_getmntent" = 'xyes'; then
        fi
        CFLAGS="$saveCFLAGS"
 fi
-if test "x$fu_cv_getmntent1" = 'xyes'; then
+if test "x$fu_cv_getmntent1" = "xyes"; then
        AC_DEFINE(HAVE_GETMNTENT1,
                1,
                [Define if there is a function named getmntent
@@ -157,7 +158,7 @@ if test "x$fu_cv_getmntent1" = 'xyes'; then
                        SunOS, HP-UX, Dynix, Irix, Linux)]
                )
 fi
-if test "x$fu_cv_getmntent2" = 'xyes'; then
+if test "x$fu_cv_getmntent2" = "xyes"; then
        AC_DEFINE(HAVE_GETMNTENT2,
                1,
                [Define if there is a function named getmntent
@@ -185,9 +186,12 @@ dnl Checks for libraries.
 AC_CHECK_LIB(socket, socket)
 AC_CHECK_LIB(resolv, res_search)
 
+m4_divert_once([HELP_WITH], [
+collectd additional packages:])
+
 # AC_ARG_WITH (package, help-string, [action-if-given], [action-if-not-given])
-AC_ARG_WITH(rrdtool, AC_HELP_STRING([--with-rrdtool=PFX], [Path to rrdtool.]),
-[      if test "x$withval" != "xno" -a "x$withval" != "xyes"
+AC_ARG_WITH(rrdtool, [AS_HELP_STRING([--with-rrdtool@<:@=PREFIX@:>@], [Path to rrdtool.])],
+[      if test "x$withval" != "xno" && test "x$withval" != "xyes"
        then
                LDFLAGS="$LDFLAGS -L$withval/lib"
                CPPFLAGS="$CPPFLAGS -I$withval/include"
@@ -196,16 +200,24 @@ AC_ARG_WITH(rrdtool, AC_HELP_STRING([--with-rrdtool=PFX], [Path to rrdtool.]),
 ], [with_rrdtool="yes"])
 if test "x$with_rrdtool" = "xyes"
 then
-       AC_CHECK_LIB(rrd, rrd_update,, [with_rrdtool="no"], [-lm])
+       AC_CHECK_LIB(rrd, rrd_update,, [with_rrdtool="no (librrd not found)"], [-lm])
 fi
 if test "x$with_rrdtool" = "xyes"
 then
-       AC_CHECK_HEADERS(rrd.h,, [with_rrdtool="no"])
+       AC_CHECK_HEADERS(rrd.h,, [with_rrdtool="no (rrd.h not found)"])
+fi
+if test "x$with_rrdtool" = "xyes"
+then
+       collect_rrdtool=1
+else
+       collect_rrdtool=0
 fi
+AC_DEFINE_UNQUOTED(COLLECT_RRDTOOL, [$collect_rrdtool],
+       [Wether or not to use rrdtool library])
 AM_CONDITIONAL(BUILD_WITH_RRDTOOL, test "x$with_rrdtool" = "xyes")
 
-#AC_ARG_WITH(pth, AC_HELP_STRING([--with-pth=PFX], [Path to pth (experimental).]),
-#[     if test "x$withval" != "xno" -a "x$withval" != "xyes"
+#AC_ARG_WITH(pth, [AS_HELP_STRING([--with-pth=@<:@=PREFIX@:>@], [Path to pth (experimental).]),
+#[     if test "x$withval" != "xno" && test "x$withval" != "xyes"
 #      then
 #              LDFLAGS="$LDFLAGS -L$withval/lib"
 #              CPPFLAGS="$CPPFLAGS -I$withval/include"
@@ -214,11 +226,11 @@ AM_CONDITIONAL(BUILD_WITH_RRDTOOL, test "x$with_rrdtool" = "xyes")
 #], [with_pth="no"])
 #if test "x$with_pth" = "xyes"
 #then
-#      AC_CHECK_LIB(pth, pth_init,, [with_pth="no"], [])
+#      AC_CHECK_LIB(pth, pth_init,, [with_pth="no (libpth not found)"], [])
 #fi
 #if test "x$with_pth" = "xyes"
 #then
-#      AC_CHECK_HEADERS(pth.h,, [with_pth="no"])
+#      AC_CHECK_HEADERS(pth.h,, [with_pth="no (pth.h not found)"])
 #fi
 #if test "x$with_pth" = "xyes"
 #then
@@ -233,58 +245,75 @@ AM_CONDITIONAL(BUILD_WITH_RRDTOOL, test "x$with_rrdtool" = "xyes")
 if test "$ac_system" = "Solaris"
 then
        with_kstat="yes"
-       AC_CHECK_LIB(kstat, kstat_open,, [with_kstat="no (not found)"])
+else
+       with_kstat="no (Solaris only)"
+fi
+if test "x$with_kstat" = "xyes"
+then
+       AC_CHECK_LIB(kstat, kstat_open,, [with_kstat="no (libkstat not found)"])
+fi
+if test "x$with_kstat" = "xyes"
+then
        AC_CHECK_LIB(devinfo, di_init)
        AC_CHECK_HEADERS(kstat.h,, [with_kstat="no (kstat.h not found)"])
+fi
+if test "x$with_kstat" = "xyes"
+then
+       collect_kstat=1
 else
-       with_kstat="no (Solaris only)"
+       collect_kstat=0
 fi
+AC_DEFINE_UNQUOTED(COLLECT_KSTAT, [$collect_kstat],
+       [Wether or not to use kstat library (Solaris)])
+AM_CONDITIONAL(BUILD_WITH_KSTAT, test "x$with_kstat" = "xyes")
 
-AC_ARG_WITH(libstatgrab, AC_HELP_STRING([--with-libstatgrab@<:@=PFX@:>@], [Path to libstatgrab.]),
+AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
 [
-       # given..
-       if test "x$withval" != "xno"
+       if test "x$withval" != "xno" && test "x$withval" != "xyes"
        then
-               if test "x$withval" != "xyes"
-               then
-                       LDFLAGS="$LDFLAGS -L$withval/lib"
-                       CPPFLAGS="$CPPFLAGS -I$withval/include"
-                       with_libstatgrab="yes"
-               fi
+               LDFLAGS="$LDFLAGS -L$withval/lib"
+               CPPFLAGS="$CPPFLAGS -I$withval/include"
+               with_libstatgrab="yes"
        fi
 ],
 [
-       # not given..
-       if test "x$ac_system" != "xunknown"
+       if test "x$ac_system" == "xunknown"
        then
-               with_libstatgrab="no"
-       else
                with_libstatgrab="yes"
+       else
+               with_libstatgrab="no"
        fi
 ])
 if test "x$with_libstatgrab" = "xyes"
 then
        AC_CHECK_LIB(devstat, getdevs)
        AC_CHECK_LIB(kvm, kvm_getargv)
-       AC_CHECK_LIB(statgrab, sg_init,, [with_libstatgrab="no (not found)"])
-       AC_CHECK_HEADERS(statgrab.h,,    [with_libstatgrab="no (not found)"])
+       AC_CHECK_LIB(statgrab, sg_init,, [with_libstatgrab="no (libstatgrab not found)"])
 fi
+if test "x$with_libstatgrab" = "xyes"
+then
+       AC_CHECK_HEADERS(statgrab.h,,    [with_libstatgrab="no (statgrab.h not found)"])
+fi
+if test "x$with_libstatgrab" = "xyes"
+then
+       collect_libstatgrab=1
+else
+       collect_libstatgrab=0
+fi
+AC_DEFINE_UNQUOTED(COLLECT_LIBSTATGRAB, [$collect_libstatgrab],
+       [Wether or not to use statgrab library])
+AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
 
-AC_ARG_WITH(lm-sensors, AC_HELP_STRING([--with-lm-sensors@<:@=PFX@:>@], [Path to lm_sensors.]),
+AC_ARG_WITH(lm-sensors, [AS_HELP_STRING([--with-lm-sensors@<:@=PREFIX@:>@], [Path to lm_sensors.])],
 [
-       # given..
-       if test "x$withval" != "xno"
+       if test "x$withval" != "xno" && test "x$withval" != "xyes"
        then
-               if test "x$withval" != "xyes"
-               then
-                       LDFLAGS="$LDFLAGS -L$withval/lib"
-                       CPPFLAGS="$CPPFLAGS -I$withval/include"
-                       with_lm_sensors="yes"
-               fi
+               LDFLAGS="$LDFLAGS -L$withval/lib"
+               CPPFLAGS="$CPPFLAGS -I$withval/include"
+               with_lm_sensors="yes"
        fi
 ],
 [
-       # not given..
        if test "x$ac_system" = "xLinux"
        then
                with_lm_sensors="yes"
@@ -296,64 +325,122 @@ if test "x$with_lm_sensors" = "xyes"
 then
        AC_CHECK_LIB(sensors, sensors_init,
        [
-               with_lm_sensors="yes"
                AC_DEFINE(HAVE_LIBSENSORS, 1, [Define to 1 if you have the sensors library (-lsensors).])
        ],
-       [with_lm_sensors="no (not found)"])
+       [with_lm_sensors="no (libsensors not found)"])
+fi
+if test "x$with_lm_sensors" = "xyes"
+then
        AC_CHECK_HEADERS(sensors/sensors.h,
        [
-               with_lm_sensors="yes"
                AC_DEFINE(HAVE_SENSORS_SENSORS_H, 1, [Define to 1 if you have the <sensors/sensors.h> header file.])
        ],
-       [with_lm_sensors="no (not found)"])
+       [with_lm_sensors="no (sensors/sensors.h not found)"])
 fi
+if test "x$with_lm_sensors" = "xyes"
+then
+       collect_lm_sensors=1
+else
+       collect_lm_sensors=0
+fi
+AC_DEFINE_UNQUOTED(COLLECT_LM_SENSORS, [$collect_lm_sensors],
+       [Wether or not to use sensors library])
+AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_lm_sensors" = "xyes")
 
 
 
 #
 # Check for enabled/disabled features
 #
-m4_divert_once([HELP_ENABLE], [
-collectd features:])
-AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
-       [Enable debugging (disabled by default)]),
-       [], [enable_debug="no"])
-if test "x$enable_debug" = "xno"
-then
-       collect_debug=0
-else
-       if test "x$enable_debug" = "xyes"
-       then
-               collect_debug=1
-       else
-               AC_MSG_NOTICE([Please specify either --enable-debug or --disable-debug; Enabling debugging.])
-               collect_debug=1
-               enable_debug="yes"
-       fi
-fi
-AC_DEFINE_UNQUOTED(COLLECT_DEBUG, [$collect_debug],
-       [Wether or not to enable debugging])
-AM_CONDITIONAL(BUILD_DEBUG, test "x$enable_debug" = "xyes")
 
-AC_ARG_ENABLE(daemon, AC_HELP_STRING([--disable-daemon],
-       [Disable daemon mode (enabled by default)]),
-       [], [enable_daemon="yes"])
-if test "x$enable_daemon" = "xno"
-then
-       collect_daemon=0
+# AC_COLLECTD(name, enable/disable, info-text, feature/module)
+# ------------------------------------------------------------
+dnl
+m4_define([my_toupper], [m4_translit([$1], m4_defn([m4_cr_letters]), m4_defn([m4_cr_LETTERS]))])
+dnl
+AC_DEFUN(
+       [AC_COLLECTD],
+       [
+       m4_if([$1], [], [AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 1st argument must not be empty])])dnl
+       m4_if(
+               [$2],
+               [enable],
+               [dnl
+               m4_define([EnDis],[disabled])dnl
+               m4_define([YesNo],[no])dnl
+               ],dnl
+               [m4_if(
+                       [$2],
+                       [disable],
+                       [dnl
+                       m4_define([EnDis],[enabled])dnl
+                       m4_define([YesNo],[yes])dnl
+                       ],
+                       [dnl
+                       AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 2nd argument must be either enable or disable])dnl
+                       ]dnl
+               )]dnl
+       )dnl
+       m4_if([$3], [feature], [],
+               [m4_if(
+                       [$3], [module], [],
+                       [dnl
+                       AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 3rd argument must be either feature or disable])dnl
+                       ]dnl
+               )]dnl
+       )dnl
+       AC_ARG_ENABLE(
+               [$1],
+               AS_HELP_STRING([--$2-$1], [$2 $4 (EnDis by def)]),
+               [],
+               enable_$1='[YesNo]'dnl
+       )# AC_ARG_ENABLE
+if test "x$enable_$1" = "xno"
+then
+       collectd_$1=0
 else
-       if test "x$enable_daemon" = "xyes"
+       if test "x$enable_$1" = "xyes"
        then
-               collect_daemon=1
+               collectd_$1=1
        else
-               AC_MSG_NOTICE([Please specify either --enable-daemon or --disable-daemon; Enabling daemon mode.])
-               collect_daemon=1
-               enable_daemon="yes"
+               AC_MSG_NOTICE([please specify either --enable-$1 or --disable-$1; enabling $1.])
+               collectd_$1=1
+               enable_$1='yes'
        fi
 fi
-AC_DEFINE_UNQUOTED(COLLECT_DAEMON, [$collect_daemon],
-       [Wether or not to enable daemon mode])
-AM_CONDITIONAL(BUILD_DAEMON, test "x$enable_daemon" = "xyes")
+       AC_DEFINE_UNQUOTED([COLLECT_]my_toupper([$1]), [$collectd_$1], [wether or not to enable $3 $4])
+       AM_CONDITIONAL([BUILD_]my_toupper([$3])[_]my_toupper([$1]), [test "x$enable_$1" = "xyes"])dnl
+       ]dnl
+)# AC_COLLECTD(name, enable/disable, info-text, feature/module)
+
+
+
+#m4_divert_once([HELP_ENABLE], [
+#collectd modules:])
+#AC_COLLECTD([cpu],       [disable], [module], [cpu usage statistics])
+#AC_COLLECTD([cpufreq],   [disable], [module], [system cpu frequency statistics])
+#AC_COLLECTD([disk],      [disable], [module], [disk/partition statistics])
+#AC_COLLECTD([quota],     [enable],  [module], [quota statistics (experimental)])
+#AC_COLLECTD([hddtemp],   [disable], [module], [hdd temperature statistics])
+#AC_COLLECTD([load],      [disable], [module], [system load statistics])
+#AC_COLLECTD([memory],    [disable], [module], [memory statistics])
+#AC_COLLECTD([nfs],       [disable], [module], [nfs statistics])
+#AC_COLLECTD([ping],      [disable], [module], [ping statistics])
+#AC_COLLECTD([processes], [disable], [module], [processes statistics])
+#AC_COLLECTD([sensors],   [disable], [module], [lm_sensors statistics])
+#AC_COLLECTD([serial],    [disable], [module], [serial statistics])
+#AC_COLLECTD([swap],      [disable], [module], [swap statistics])
+#AC_COLLECTD([tape],      [disable], [module], [tape statistics])
+#AC_COLLECTD([traffic],   [disable], [module], [system traffic statistics])
+#AC_COLLECTD([users],     [disable], [module], [user count statistics])
+
+
+
+m4_divert_once([HELP_ENABLE], [
+collectd features:])
+
+AC_COLLECTD([debug],     [enable],  [feature], [debugging])
+AC_COLLECTD([daemon],    [disable], [feature], [daemon mode])
 
 m4_divert_once([HELP_ENABLE], [
 collectd modules:])
@@ -487,25 +574,7 @@ then
 fi
 AM_CONDITIONAL(BUILD_MODULE_PROCESSES, test "x$enable_processes" = "xyes")
 
-#AC_ARG_ENABLE(quota, AC_HELP_STRING([--enable-quota],
-#      [Enable quota statistics (experimental, disabled by default)]),
-#      [], [enable_quota="no"])
-#if test "x$enable_quota" = "xno"
-#then
-#      collect_quota=0
-#else
-#      if test "x$enable_quota" = "xyes"
-#      then
-#              collect_quota=1
-#      else
-#              AC_MSG_NOTICE([Please specify either --enable-quota or --disable-quota; Enabling quota statistics.])
-#              collect_quota=1
-#              enable_quota="yes"
-#      fi
-#fi
-#AC_DEFINE_UNQUOTED(COLLECT_QUOTA, [$collect_quota],
-#      [Wether or not to collect quota statistics])
-#AM_CONDITIONAL(BUILD_MODULE_QUOTA, test "x$enable_quota" = "xyes")
+#AC_COLLECTD([quota],     [enable],  [module], [quota statistics (experimental)])
 
 AC_ARG_ENABLE(sensors, AC_HELP_STRING([--disable-sensors], [Disable lm_sensors statistics]),, [enable_sensors=$with_lm_sensors])
 if test "x$enable_sensors" != "xno"
@@ -587,21 +656,7 @@ then
 fi
 AM_CONDITIONAL(BUILD_MODULE_TRAFFIC, test "x$enable_traffic" = "xyes")
 
-AC_ARG_ENABLE(users, AC_HELP_STRING([--disable-users], [Disable user count statistics]),, [enable_users="yes"])
-if test "x$enable_users" != "xno"
-then
-       if test "x$have_getutent" = "xyes"
-       then
-               enable_users="yes"
-       else
-               enable_users="no"
-       fi
-fi
-if test "x$enable_users" = "xno"
-then
-       AC_DEFINE(COLLECT_USERS, 0, [Wether or not to collect user count statistics])
-fi
-AM_CONDITIONAL(BUILD_MODULE_USERS, test "x$enable_users" = "xyes")
+AC_COLLECTD([users],     [disable], [module], [user count statistics])
 
 AC_OUTPUT(Makefile src/libconfig/Makefile src/libping/Makefile src/Makefile)
 
index 4f21f1c..11e34a9 100644 (file)
@@ -2,7 +2,6 @@ SUBDIRS = libconfig
 if BUILD_MODULE_PING
 SUBDIRS += libping
 endif
-#SUBDIRS += .
 
 sbin_PROGRAMS = collectd
 
@@ -17,15 +16,17 @@ collectd_SOURCES = collectd.c collectd.h \
 collectd_CPPFLAGS = $(LTDLINCL)
 collectd_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"'
 collectd_CPPFLAGS += -DPKGLOCALSTATEDIR='"${localstatedir}/lib/${PACKAGE_NAME}"'
+if BUILD_FEATURE_DAEMON
 collectd_CPPFLAGS += -DPIDFILE='"${localstatedir}/run/${PACKAGE_NAME}.pid"'
+endif
 collectd_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"'
+if BUILD_FEATURE_DEBUG
+collectd_CPPFLAGS += -DLOGFILE='"${localstatedir}/log/${PACKAGE_NAME}/collectd.log"'
+endif
 collectd_LDFLAGS = -export-dynamic
-collectd_CFLAGS = -Werror
+collectd_CFLAGS = -Wall -Werror
 collectd_LDADD = $(LIBLTDL) libconfig/libconfig.la "-dlopen" self
 collectd_DEPENDENCIES = $(LIBLTDL) libconfig/libconfig.la
-if BUILD_WITH_RRDTOOL
-collectd_LDADD += -lrrd
-endif
 
 pkglib_LTLIBRARIES = 
 
@@ -159,7 +160,7 @@ if BUILD_MODULE_USERS
 pkglib_LTLIBRARIES += users.la
 users_la_SOURCES = users.c users.h
 users_la_LDFLAGS = -module -avoid-version
-users_la_CFLAGS = -Werror
+users_la_CFLAGS = -Wall -Werror
 collectd_LDADD += "-dlopen" users.la
 collectd_DEPENDENCIES += users.la
 endif
index af6a93e..c86a678 100644 (file)
@@ -21,7 +21,8 @@
  *   Alvaro Barcellos <alvaro.barcellos at gmail.com>
  **/
 
-#include "collectd.h"
+#include "common.h"
+#include "utils_debug.h"
 
 #include "multicast.h"
 #include "plugin.h"
@@ -31,7 +32,7 @@
 
 static int loop = 0;
 
-#ifdef HAVE_LIBKSTAT
+#if HAVE_LIBKSTAT
 kstat_ctl_t *kc;
 #endif /* HAVE_LIBKSTAT */
 
@@ -45,16 +46,16 @@ int   num_pinghosts = 0;
  */
 time_t curtime;
 
-#ifdef HAVE_LIBRRD
+#if HAVE_LIBRRD
 int operating_mode;
 #endif
 
-void sigIntHandler (int signal)
+static void sigIntHandler (int signal)
 {
        loop++;
 }
 
-int change_basedir (char *dir)
+static int change_basedir (char *dir)
 {
        int dirlen = strlen (dir);
        
@@ -87,10 +88,10 @@ int change_basedir (char *dir)
        }
 
        return (0);
-}
+} /* static int change_basedir (char *dir) */
 
-#ifdef HAVE_LIBKSTAT
-void update_kstat (void)
+#if HAVE_LIBKSTAT
+static void update_kstat (void)
 {
        if (kc == NULL)
        {
@@ -112,25 +113,33 @@ void update_kstat (void)
        }
 
        return;
-}
+} /* static void update_kstat (void) */
 #endif /* HAVE_LIBKSTAT */
 
-void exit_usage (char *name)
+static void exit_usage (char *name)
 {
-       printf ("Usage: %s [OPTIONS]\n\n"
+       printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
                        
                        "Available options:\n"
                        "  General:\n"
-                       "    -C <dir>        Configuration file.\n"
-                       "                    Default: %s\n"
-                       "    -P <file>       PID File.\n"
-                       "                    Default: %s\n"
+                       "    -C <file>       Configuration file.\n"
+                       "                    Default: "CONFIGFILE"\n"
+#if COLLECT_DAEMON
+                       "    -P <file>       PID file.\n"
+                       "                    Default: "PIDFILE"\n"
+#endif
                        "    -M <dir>        Module/Plugin directory.\n"
-                       "                    Default: %s\n"
+                       "                    Default: "PLUGINDIR"\n"
                        "    -D <dir>        Data storage directory.\n"
-                       "                    Default: %s\n"
+                       "                    Default: "PKGLOCALSTATEDIR"\n"
+#if COLLECT_DEBUG
+                       "    -L <file>       Log file.\n"
+                       "                    Default: "LOGFILE"\n"
+#endif
+#if COLLECT_DAEMON
                        "    -f              Don't fork to the background.\n"
-#ifdef HAVE_LIBRRD
+#endif
+#if HAVE_LIBRRD
                        "    -l              Start in local mode (no network).\n"
                        "    -c              Start in client (sender) mode.\n"
                        "    -s              Start in server (listener) mode.\n"
@@ -140,23 +149,22 @@ void exit_usage (char *name)
                        "    -p <host>       Host to ping periodically, may be repeated to ping\n"
                        "                    more than one host.\n"
 #endif /* COLLECT_PING */
-                       "\n%s %s, http://verplant.org/collectd/\n"
+                       "\n"PACKAGE" "VERSION", http://verplant.org/collectd/\n"
                        "by Florian octo Forster <octo@verplant.org>\n"
-                       "for contributions see `AUTHORS'\n",
-                       PACKAGE, CONFIGFILE, PIDFILE, PLUGINDIR, PKGLOCALSTATEDIR, PACKAGE, VERSION);
+                       "for contributions see `AUTHORS'\n");
        exit (0);
-}
+} /* static void exit_usage (char *name) */
 
-int start_client (void)
+static int start_client (void)
 {
        int sleepingtime;
 
-#ifdef HAVE_LIBKSTAT
+#if HAVE_LIBKSTAT
        kc = NULL;
        update_kstat ();
 #endif
 
-#ifdef HAVE_LIBSTATGRAB
+#if HAVE_LIBSTATGRAB
        if (sg_init ())
        {
                syslog (LOG_ERR, "sg_init: %s", sg_str_error (sg_get_error ()));
@@ -175,7 +183,7 @@ int start_client (void)
        while (loop == 0)
        {
                curtime = time (NULL);
-#ifdef HAVE_LIBKSTAT
+#if HAVE_LIBKSTAT
                update_kstat ();
 #endif
                plugin_read_all ();
@@ -190,10 +198,10 @@ int start_client (void)
        }
 
        return (0);
-}
+} /* static int start_client (void) */
 
-#ifdef HAVE_LIBRRD
-int start_server (void)
+#if HAVE_LIBRRD
+static int start_server (void)
 {
        char *host;
        char *type;
@@ -212,10 +220,11 @@ int start_server (void)
        }
        
        return (0);
-}
+} /* static int start_server (void) */
 #endif /* HAVE_LIBRRD */
 
-int pidfile_create (char *file)
+#if COLLECT_DAEMON
+static int pidfile_create (const char *file)
 {
        FILE *fh;
 
@@ -232,31 +241,38 @@ int pidfile_create (char *file)
        fclose(fh);
 
        return (0);
-}
+} /* static int pidfile_create (const char *file) */
+#endif /* COLLECT_DAEMON */
 
-int pidfile_remove (void)
+#if COLLECT_DAEMON
+static int pidfile_remove (const char *file)
 {
-      return (unlink (PIDFILE));
-}
+       if (file == NULL) {
+               file = PIDFILE;
+       }
+       return (unlink (file));
+} /* static int pidfile_remove (const char *file) */
+#endif /* COLLECT_DAEMON */
 
 int main (int argc, char **argv)
 {
        struct sigaction sigIntAction, sigChldAction;
+       char *configfile = CONFIGFILE;
+       char *plugindir  = PLUGINDIR;
+       char *datadir    = PKGLOCALSTATEDIR;
 #if COLLECT_DAEMON
+       char *pidfile    = PIDFILE;
        pid_t pid;
+       int daemonize    = 1;
+#endif
+#if COLLECT_DEBUG
+       char *logfile    = LOGFILE;
 #endif
 
-       char *configfile = CONFIGFILE;
-       char *pidfile    = PIDFILE;
-       char *plugindir  = PLUGINDIR;
-       char *datadir    = PKGLOCALSTATEDIR;
-
-       int daemonize = 1;
-
-#ifdef HAVE_LIBRRD
+#if HAVE_LIBRRD
        operating_mode = MODE_LOCAL;
 #endif
-       
+
        /* open syslog */
        openlog (PACKAGE, LOG_CONS | LOG_PID, LOG_DAEMON);
 
@@ -265,7 +281,13 @@ int main (int argc, char **argv)
        {
                int c;
 
-               c = getopt (argc, argv, "C:P:M:D:fh"
+               c = getopt (argc, argv, "C:M:D:h"
+#if COLLECT_DAEMON
+                               "fP:"
+#endif
+#if COLLECT_DEBUG
+                               "L:"
+#endif
 #if HAVE_LIBRRD
                                "csl"
 #endif /* HAVE_LIBRRD */
@@ -279,7 +301,7 @@ int main (int argc, char **argv)
 
                switch (c)
                {
-#ifdef HAVE_LIBRRD
+#if HAVE_LIBRRD
                        case 'c':
                                operating_mode = MODE_CLIENT;
                                break;
@@ -295,18 +317,25 @@ int main (int argc, char **argv)
                        case 'C':
                                configfile = optarg;
                                break;
+#if COLLECT_DAEMON
                        case 'P':
                                pidfile = optarg;
                                break;
+                       case 'f':
+                               daemonize = 0;
+                               break;
+#endif /* COLLECT_DAEMON */
                        case 'M':
                                plugindir = optarg;
                                break;
                        case 'D':
                                datadir = optarg;
                                break;
-                       case 'f':
-                               daemonize = 0;
+#if COLLECT_DEBUG
+                       case 'L':
+                               logfile = optarg;
                                break;
+#endif
 #if COLLECT_PING
                        case 'p':
                                if (num_pinghosts < MAX_PINGHOSTS)
@@ -318,9 +347,10 @@ int main (int argc, char **argv)
                        case 'h':
                        default:
                                exit_usage (argv[0]);
-               }
-                               
-       }
+               } /* switch (c) */
+       } /* while (1) */
+
+       DBG_STARTFILE(logfile, "debug file opened.");
 
        /*
         * Read the config file. This will load any modules automagically.
@@ -405,19 +435,23 @@ int main (int argc, char **argv)
        /*
         * run the actual loops
         */
-#ifdef HAVE_LIBRRD
+#if HAVE_LIBRRD
        if (operating_mode == MODE_SERVER)
                start_server ();
        else /* if (operating_mode == MODE_CLIENT || operating_mode == MODE_LOCAL) */
 #endif
                start_client ();
 
+       DBG_STOPFILE("debug file closed.");
+
        /* close syslog */
        syslog (LOG_INFO, "Exiting normally");
        closelog ();
 
+#if COLLECT_DAEMON
        if (daemonize)
-               pidfile_remove();
+               pidfile_remove(pidfile);
+#endif /* COLLECT_DAEMON */
 
        return (0);
-}
+} /* int main (int argc, char **argv) */
index 7f163bd..f20a337 100644 (file)
@@ -35,8 +35,8 @@
 # include <sys/stat.h>
 #endif
 #if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
+# include <stdlib.h>
+# include <stddef.h>
 #else
 # if HAVE_STDLIB_H
 #  include <stdlib.h>
 #if HAVE_CTYPE_H
 # include <ctype.h>
 #endif
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
 
 #if HAVE_SYSLOG
 # define syslog(...) syslog(__VA_ARGS__)
 # define closelog(...) /**/
 #endif
 
-#ifndef HAVE_RRD_H
-#undef HAVE_LIBRRD
+#if HAVE_KSTAT_H
+# include <kstat.h>
 #endif
 
-#ifdef HAVE_LIBRRD
-#include <rrd.h>
-#endif /* HAVE_LIBRRD */
-
-/* Won't work without the header file */
-#ifndef HAVE_KSTAT_H
-#undef HAVE_LIBKSTAT
+#if HAVE_RRD_H
+# include <rrd.h>
 #endif
-
-#ifdef HAVE_LIBKSTAT
-#include <kstat.h>
-#include <sys/param.h>
-#endif /* HAVE_LIBKSTAT */
-
-/* Won't work without the header file */
-#ifndef HAVE_STATGRAB_H
-#undef HAVE_LIBSTATGRAB
+#if HAVE_PTH_H
+# include <pth.h>
 #endif
-
-#ifdef HAVE_LIBSTATGRAB
-#include <statgrab.h>
+#if HAVE_STATGRAB_H
+# include <statgrab.h>
+#endif
+#if HAVE_SENSORS_SENSORS_H
+# include <sensors/sensors.h>
 #endif
 
 #ifndef PACKAGE_NAME
 extern time_t curtime;
 extern int operating_mode;
 
+/* int main (int argc, char **argv); */
+
 #endif /* COLLECTD_H */
index 31c936c..2739c2b 100644 (file)
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
+#include "common.h"
+#include "plugin.h"
 #include "users.h"
 
-#if COLLECT_USERS
-#define MODULE_NAME "users"
+#if HAVE_UTMPX_H
+# include <utmpx.h>
+#else /* !HAVE_UTMPX_H */
+# if HAVE_UTMP_H
+#  include <utmp.h>
+# endif /* HAVE_UTMP_H */
+#endif /* HAVE_UTMPX_H */
 
-#include "plugin.h"
-#include "common.h"
-
-#ifdef HAVE_UTMPX_H
-#include <utmpx.h>
-#elif defined(HAVE_UTMP_H)
-#include <utmp.h>
-#endif
+#define MODULE_NAME "users"
 
 static char *rrd_file = "users.rrd";
-
-static char *ds_def[] = {
-    "DS:users:GAUGE:25:0:65535",
-    NULL
+static char *ds_def[] =
+{
+       "DS:users:GAUGE:25:0:65535",
+       NULL
 };
 static int ds_num = 1;
 
-void users_init(void)
+static void users_init (void)
 {
-    /* we have nothing to do here :-) */
-    return;
-}
+       /* we have nothing to do here :-) */
+       return;
+} /* static void users_init(void) */
 
-void users_read(void)
+static void users_write (char *host, char *inst, char *val)
 {
-#ifdef HAVE_GETUTXENT
-    unsigned int users = 0;
-    struct utmpx *entry = NULL;
-
-    /* according to the *utent(3) man page none of the functions sets errno in
-     * case of an error, so we cannot do any error-checking here */
-    setutxent();
-
-    while (NULL != (entry = getutxent()))
-        if (USER_PROCESS == entry->ut_type)
-            ++users;
-    endutxent();
-
-    users_submit(users);
-/* #endif HAVE_GETUTXENT */
-
-#elif defined(HAVE_GETUTENT)
-    unsigned int users = 0;
-    struct utmp *entry = NULL;
-
-    /* according to the *utent(3) man page none of the functions sets errno in
-     * case of an error, so we cannot do any error-checking here */
-    setutent();
-
-    while (NULL != (entry = getutent()))
-        if (USER_PROCESS == entry->ut_type)
-            ++users;
-    endutent();
-
-    users_submit(users);
-#endif
-
+       rrd_update_file(host, rrd_file, val, ds_def, ds_num);
        return;
-}
+} /* static void users_write(char *host, char *inst, char *val) */
 
 /* I don't like this temporary macro definition - well it's used everywhere
* else in the collectd-sources, so I will just stick with it...  */
  else in the collectd-sources, so I will just stick with it...  */
 #define BUFSIZE 256
-void users_submit(users)
-    unsigned int users;
+static void users_submit (unsigned int users)
 {
-    char buf[BUFSIZE] = "";
+       char buf[BUFSIZE] = "";
 
-    if (snprintf(buf, BUFSIZE, "%u:%u", 
-                (unsigned int)curtime, 
-                users) >= BUFSIZE)
-        return;
+       if (snprintf(buf, BUFSIZE, "%u:%u", 
+               (unsigned int)curtime, users) >= BUFSIZE)
+       {
+               return;
+       }
 
-    plugin_submit(MODULE_NAME, NULL, buf);
-    return;
-}
+       plugin_submit(MODULE_NAME, NULL, buf);
+       return;
+} /* static void users_submit(unsigned int users) */
 #undef BUFSIZE
 
-void users_write(host, inst, val)
-    char *host;
-    char *inst;
-    char *val;
+static void users_read (void)
 {
-    rrd_update_file(host, rrd_file, val, ds_def, ds_num);
-    return;
-}
+#if HAVE_GETUTXENT
+       unsigned int users = 0;
+       struct utmpx *entry = NULL;
+
+       /* according to the *utent(3) man page none of the functions sets errno
+          in case of an error, so we cannot do any error-checking here */
+       setutxent();
+
+       while (NULL != (entry = getutxent())) {
+               if (USER_PROCESS == entry->ut_type) {
+                       ++users;
+               }
+       }
+       endutxent();
+
+       users_submit (users);
+/* #endif HAVE_GETUTXENT */
+       
+#elif HAVE_GETUTENT
+       unsigned int users = 0;
+       struct utmp *entry = NULL;
 
-void module_register(void)
-{
-    plugin_register(MODULE_NAME, users_init, users_read, users_write);
-    return;
-}
+       /* according to the *utent(3) man page none of the functions sets errno
+          in case of an error, so we cannot do any error-checking here */
+       setutent();
+
+       while (NULL != (entry = getutent())) {
+               if (USER_PROCESS == entry->ut_type) {
+                       ++users;
+               }
+       }
+       endutent();
+
+       users_submit(users);
+#endif /* HAVE_GETUTENT */
 
-#undef MODULE_NAME
-#endif /* COLLECT_USERS */
+       return;
+} /* static void users_read(void) */
 
+void module_register (void)
+{
+       plugin_register (MODULE_NAME, users_init, users_read, users_write);
+       return;
+} /* void module_register(void) */
index c250f6c..f67b83f 100644 (file)
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
-#ifndef USERS_H
-#define USERS_H 1
+#if !COLLECTD_USERS_H
+#define COLLECTD_USERS_H 1
 
-#include "config.h"
+void module_register(void);
 
-#if !defined(HAVE_UTMPX_H) || !defined(HAVE_GETUTXENT)
-#undef HAVE_UTMPX_H
-#undef HAVE_GETUTXENT
-#endif
-
-#if !defined(HAVE_UTMP_H) || !defined(HAVE_GETUTENT)
-#undef HAVE_UTMPX_H
-#undef HAVE_GETUTXENT
-#endif
-
-#ifndef COLLECT_USERS
-#if defined(HAVE_UTMPX_H) || defined(HAVE_UTMP_H)
-#define COLLECT_USERS 1
-#else
-#define COLLECT_USERS 0
-#endif
-#endif /* ! defined(COLLECT_USERS) */
-
-void users_init(void);
-void users_read(void);
-void users_submit(unsigned int);
-void users_write(char *, char *, char *);
-
-#endif /* ! defined(USERS_H) */
+#endif /* !COLLECTD_USERS_H) */
 
index db59525..9a6c1c5 100644 (file)
 #include "common.h"
 #include "utils_debug.h"
 
-/* *** *** ***   global variables   *** *** *** */
 #if COLLECT_DEBUG
 
-#define DEFAULT_FILENAME "collectd.log"
-
 static void cu_vdebug(const char *file, int line, const char *func,
        const char *format, va_list ap);
 
 /* if preemptive threads are used, these vars need some sort of locking! */
-/* pth is non-preemptive, so no locking is necessary (?) */
+/* pth is non-preemptive, so no locking is necessary */
 static FILE *cu_debug_file = NULL;
 static char *cu_debug_filename = NULL;
 
@@ -71,7 +68,7 @@ cu_debug(const char *file, int line, const char *func,
 
 int
 cu_debug_startfile(const char *file, int line, const char *func,
-       const char *format, ...)
+       const char *filename, const char *format, ...)
 {
        va_list ap;
 
@@ -82,7 +79,7 @@ cu_debug_startfile(const char *file, int line, const char *func,
        }
 
        if(cu_debug_filename == NULL) {
-               cu_debug_filename = sstrdup(DEFAULT_FILENAME);
+               cu_debug_filename = sstrdup(filename);
        }
 
        cu_debug_file = fopen(cu_debug_filename, "a");
@@ -169,27 +166,5 @@ cu_debug_resetfile(const char *file, int line, const char *func,
 } /* int cu_debug_resetfile(const char *file, int line, const char *func,
         const char *filename) */
 
-#else /* !COLLECT_DEBUG */
-
-void
-cu_debug(const char *file, int line, const char *func, const char *format, ...)
-{
-}
-int
-cu_debug_startfile(const char *file, int line, const char *func, const char *format, ...)
-{
-       return EXIT_SUCCESS;
-}
-int
-cu_debug_stopfile(const char *file, int line, const char *func, const char *format, ...)
-{
-       return EXIT_SUCCESS;
-}
-int
-cu_debug_resetfile(const char *file, int line, const char *func, const char *filename)
-{
-       return EXIT_SUCCESS;
-}
-
 #endif /* COLLECT_DEBUG */
 
index 247b141..561e6b1 100644 (file)
  *   Niki W. Waibel <niki.waibel@gmx.net>
 **/
 
+/* BUG: at the moment you can use DBG_STARTFILE only ONCE in
+   your program. more then one logfile is not supported. */
+
 #if !COLLECTD_UTILS_DEBUG_H
 #define COLLECTD_UTILS_DEBUG_H 1
 
+#if COLLECT_DEBUG
+
 #define DBG(...) cu_debug(__FILE__, __LINE__, __func__, \
        __VA_ARGS__)
 
-#define DBG_STARTFILE(...) cu_debug_startfile(__FILE__, __LINE__, \
-       __func__, __VA_ARGS__)
+#define DBG_STARTFILE(file, ...) cu_debug_startfile(__FILE__, __LINE__, \
+       __func__, file, __VA_ARGS__)
 #define DBG_STOPFILE(...) cu_debug_stopfile(__FILE__, __LINE__, \
        __func__, __VA_ARGS__)
 
@@ -39,12 +44,21 @@ void cu_debug(const char *file, int line, const char *func,
        const char *format, ...);
 
 int cu_debug_startfile(const char *file, int line, const char *func,
-       const char *format, ...);
+       const char *filename, const char *format, ...);
 int cu_debug_stopfile(const char *file, int line, const char *func,
        const char *format, ...);
 
 int cu_debug_resetfile(const char *file, int line, const char *func,
        const char *filename);
 
+#else /* !COLLECT_DEBUG */
+
+#define DBG(...)                   /* DBG(...) */
+#define DBG_STARTFILE(file, ...)   /* DBG_STARTFILE(file, ...) */
+#define DBG_STOPFILE(...)          /* DBG_STOPFILE(...) */
+#define DBG_RESETFILE(file)        /* DBG_RESETFILE(file) */
+
+#endif /* COLLECT_DEBUG */
+
 #endif /* !COLLECTD_UTILS_DEBUG_H */