From 0c0448c13167b6ef097473ef3a5d4321ebae50b0 Mon Sep 17 00:00:00 2001 From: octo Date: Fri, 16 Dec 2005 09:58:46 +0000 Subject: [PATCH] Merged changes from the quota-branch: - Changed command line options to be more consitent - Hopefully changed automake to it creates directories --- src/Makefile.am | 7 ++++++- src/collectd.c | 59 +++++++++++++++++++++++++++++++-------------------------- src/collectd.h | 34 +++++++++++++++++---------------- 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4f271bf2..ae7df9ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,7 +11,11 @@ collectd_SOURCES = collectd.c collectd.h \ multicast.c multicast.h \ plugin.c plugin.h #collectd_CFLAGS = -DPLUGINDIR='"$(pkglibdir)"' -collectd_CPPFLAGS = -DLOCALSTATEDIR='"$(localstatedir)"' -DPLUGINDIR='"$(pkglibdir)"' +collectd_CPPFLAGS = +collectd_CPPFLAGS += -DSYSCONFDIR='"${sysconfdir}"' +collectd_CPPFLAGS += -DPKGLOCALSTATEDIR='"${localstatedir}/${PACKAGE_NAME}"' +collectd_CPPFLAGS += -DPIDFILE='"${localstatedir}/run/${PACKAGE_NAME}.pid"' +collectd_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"' collectd_LDFLAGS = -export-dynamic collectd_CFLAGS = -Werror collectd_LDADD = $(LIBLTDL) "-dlopen" self @@ -152,6 +156,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 collectd_LDADD += "-dlopen" users.la collectd_DEPENDENCIES += users.la endif diff --git a/src/collectd.c b/src/collectd.c index 633d0230..9932fd90 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -120,15 +120,19 @@ void exit_usage (char *name) "Available options:\n" " General:\n" - " -d Base directory to use.\n" + " -C Configuration directory.\n" " Default: %s\n" - " -P Set the plugin-directory\n" + " -P PID File.\n" " Default: %s\n" - " -f Don't fork to the background\n" + " -M Module/Plugin directory.\n" + " Default: %s\n" + " -D Data storage directory.\n" + " Default: %s\n" + " -f Don't fork to the background.\n" #ifdef HAVE_LIBRRD - " -l Start in local mode (no network)\n" - " -c Start in client (sender) mode\n" - " -s Start in server (listener) mode\n" + " -l Start in local mode (no network).\n" + " -c Start in client (sender) mode.\n" + " -s Start in server (listener) mode.\n" #endif /* HAVE_LIBRRD */ #if COLLECT_PING " Ping:\n" @@ -138,7 +142,7 @@ void exit_usage (char *name) "\n%s %s, http://verplant.org/collectd/\n" "by Florian octo Forster \n" "for contributions see `AUTHORS'\n", - PACKAGE, DATADIR, PLUGINDIR, PACKAGE, VERSION); + PACKAGE, SYSCONFDIR, PIDFILE, PLUGINDIR, PKGLOCALSTATEDIR, PACKAGE, VERSION); exit (0); } @@ -238,8 +242,10 @@ int main (int argc, char **argv) pid_t pid; #endif - char *plugindir = NULL; - char *basedir = DATADIR; + char *confdir = SYSCONFDIR; + char *pidfile = PIDFILE; + char *plugindir = PLUGINDIR; + char *datadir = PKGLOCALSTATEDIR; int daemonize = 1; @@ -247,19 +253,15 @@ int main (int argc, char **argv) operating_mode = MODE_LOCAL; #endif - /* - * open syslog - */ + /* open syslog */ openlog (PACKAGE, LOG_CONS | LOG_PID, LOG_DAEMON); - /* - * read options - */ + /* read options */ while (1) { int c; - c = getopt (argc, argv, "d:fP:h" + c = getopt (argc, argv, "C:P:M:D:fh" #if HAVE_LIBRRD "csl" #endif /* HAVE_LIBRRD */ @@ -286,8 +288,17 @@ int main (int argc, char **argv) operating_mode = MODE_LOCAL; break; #endif /* HAVE_LIBRRD */ - case 'd': - basedir = optarg; + case 'C': + confdir = optarg; + break; + case 'P': + pidfile = optarg; + break; + case 'M': + plugindir = optarg; + break; + case 'D': + datadir = optarg; break; case 'f': daemonize = 0; @@ -300,10 +311,6 @@ int main (int argc, char **argv) fprintf (stderr, "Maximum of %i ping hosts reached.\n", MAX_PINGHOSTS); break; #endif /* COLLECT_PING */ - case 'P': - plugindir = optarg; - break; - case 'h': default: exit_usage (argv[0]); @@ -321,9 +328,9 @@ int main (int argc, char **argv) return (1); } - if (change_basedir (basedir)) + if (change_basedir (datadir)) { - fprintf (stderr, "Error: Unable to change to directory `%s'.\n", basedir); + fprintf (stderr, "Error: Unable to change to directory `%s'.\n", datadir); return (1); } @@ -395,9 +402,7 @@ int main (int argc, char **argv) #endif start_client (); - /* - * close syslog - */ + /* close syslog */ syslog (LOG_INFO, "Exiting normally"); closelog (); diff --git a/src/collectd.h b/src/collectd.h index c7aa925a..64fe463c 100644 --- a/src/collectd.h +++ b/src/collectd.h @@ -119,6 +119,24 @@ # include #endif +#if HAVE_SYSLOG +# define syslog(...) syslog(__VA_ARGS__) +# if HAVE_OPENLOG +# define openlog(...) openlog(__VA_ARGS__) +# else +# define openlog(...) /**/ +# endif +# if HAVE_CLOSELOG +# define closelog(...) closelog(__VA_ARGS__) +# else +# define closelog(...) /**/ +# endif +#else +# define syslog(...) /**/ +# define openlog(...) /**/ +# define closelog(...) /**/ +#endif + #ifndef HAVE_RRD_H #undef HAVE_LIBRRD #endif @@ -146,22 +164,6 @@ #include #endif -#ifndef LOCALSTATEDIR -#define LOCALSTATEDIR "/opt/collectd/var" -#endif - -#ifndef DATADIR -#define DATADIR LOCALSTATEDIR"/lib/collectd" -#endif - -#ifndef PLUGINDIR -#define PLUGINDIR "/opt/collectd/lib/collectd" -#endif - -#ifndef PIDFILE -#define PIDFILE LOCALSTATEDIR"/run/collectd.pid" -#endif - #define MODE_SERVER 0x01 #define MODE_CLIENT 0x02 #define MODE_LOCAL 0x03 -- 2.11.0