} /* static void update_kstat (void) */
#endif /* HAVE_LIBKSTAT */
+/* TODO
+ * Remove all settings but `-f' and `-C'
+ */
+static void exit_usage (char *name)
+{
+ printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
+
+ "Available options:\n"
+ " General:\n"
+ " -C <file> Configuration file.\n"
+ " Default: "CONFIGFILE"\n"
+#if COLLECT_DAEMON
+ " -f Don't fork to the background.\n"
+#endif
+ "\n"PACKAGE" "VERSION", http://verplant.org/collectd/\n"
+ "by Florian octo Forster <octo@verplant.org>\n"
+ "for contributions see `AUTHORS'\n");
+ exit (0);
+} /* static void exit_usage (char *name) */
+
static int start_client (void)
{
int sleepingtime;
int main (int argc, char **argv)
{
-#if COLLECT_DAEMON
- struct sigaction sigChldAction;
-#endif
struct sigaction sigIntAction;
struct sigaction sigTermAction;
- char *datadir;
+ char *datadir = PKGLOCALSTATEDIR;
+ char *configfile = CONFIGFILE;
#if COLLECT_DAEMON
+ struct sigaction sigChldAction;
char *pidfile = PIDFILE;
pid_t pid;
int daemonize = 1;
/* open syslog */
openlog (PACKAGE, LOG_CONS | LOG_PID, LOG_DAEMON);
- DBG_STARTFILE(logfile, "Debug file opened.");
+ /* read options */
+ while (1)
+ {
+ int c;
+
+ /* FIXME */
+ c = getopt (argc, argv, "C:"
+#if COLLECT_DAEMON
+ "f"
+#endif
+ );
+
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 'C':
+ configfile = optarg;
+ break;
+#if COLLECT_DAEMON
+ case 'f':
+ daemonize = 0;
+ break;
+#endif /* COLLECT_DAEMON */
+ case 'h':
+ default:
+ exit_usage (argv[0]);
+ } /* switch (c) */
+ } /* while (1) */
+
+#if COLLECT_DEBUG
+ if ((logfile = cf_get_mode_option ("LogFile")) != NULL)
+ DBG_STARTFILE (logfile, "Debug file opened.");
+#endif
/*
* Read options from the config file, the environment and the command
* general).
* Also, this will automatically load modules.
*/
- if (cf_read (argc, argv, CONFIGFILE))
+ if (cf_read (configfile))
{
fprintf (stderr, "Error: Reading the config file failed!\n"
"Read the syslog for details.\n");
#endif
start_client ();
- DBG_STOPFILE("debug file closed.");
+#if COLLECT_DEBUG
+ if (logfile != NULL)
+ DBG_STOPFILE("debug file closed.");
+#endif
/* close syslog */
syslog (LOG_INFO, "Exiting normally");
* Florian octo Forster <octo at verplant.org>
**/
+/* TODO
+ * make internal-only functions `static' */
+
#include "collectd.h"
#include "libconfig/libconfig.h"
/* TODO
* - LogFile
- * - DontFork
*/
static cf_mode_item_t cf_mode_list[] =
{
{"Server", NULL, MODE_CLIENT },
{"Port", NULL, MODE_CLIENT | MODE_SERVER },
{"PIDFile", PIDFILE, MODE_CLIENT | MODE_SERVER | MODE_LOCAL},
- {"DataDir", PKGLOCALSTATEDIR, MODE_SERVER | MODE_LOCAL}
+ {"DataDir", PKGLOCALSTATEDIR, MODE_SERVER | MODE_LOCAL},
+ {"LogFile", LOGFILE, MODE_SERVER | MODE_SERVER | MODE_LOCAL},
};
static int cf_mode_num = 4;
return (NULL);
}
-int cf_callback_usage (const char *shortvar, const char *var,
- const char *arguments, const char *value, lc_flags_t flags,
- void *extra)
-{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
-
- printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
-
- "Available options:\n"
-#if COLLECT_DAEMON
- " -P <file> PID file.\n"
- " Default: "PIDFILE"\n"
-#endif
- " -M <dir> Module/Plugin directory.\n"
- " Default: "PLUGINDIR"\n"
- " -D <dir> Data storage directory.\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"
-#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"
-#endif /* HAVE_LIBRRD */
-#if COLLECT_PING
- " Ping:\n"
- " -p <host> Host to ping periodically, may be repeated to ping\n"
- " more than one host.\n"
-#endif /* COLLECT_PING */
- "\n"PACKAGE" "VERSION", http://verplant.org/collectd/\n"
- "by Florian octo Forster <octo@verplant.org>\n"
- "for contributions see `AUTHORS'\n");
- exit (0);
-} /* exit_usage */
-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Functions for the actual parsing *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* `cf_callback_mode'
- * Start/end the `mode' section
+ * Chose the `operating_mode'
*
- * <Mode `arguments'>
- * ...
- * </Mode>
+ * Mode `value'
*/
int cf_callback_mode (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
shortvar, var, arguments, value);
- if (flags == LC_FLAGS_SECTIONSTART)
- {
- if (nesting_depth != 0)
- {
- fprintf (stderr, ERR_NOT_NESTED);
- return (LC_CBRET_ERROR);
- }
-
- if (arguments == NULL)
- {
- fprintf (stderr, ERR_NEEDS_ARG, shortvar);
- return (LC_CBRET_ERROR);
- }
-
- nesting_depth++;
-
- if (((operating_mode == MODE_CLIENT)
- && (strcasecmp (arguments, "Client") == 0))
- || ((operating_mode == MODE_SERVER)
- && (strcasecmp (arguments, "Server") == 0))
- || ((operating_mode == MODE_LOCAL)
- && (strcasecmp (arguments, "Local") == 0)))
- {
- return (LC_CBRET_OKAY);
- }
- else
- {
- return (LC_CBRET_IGNORESECTION);
- }
- }
- else if (flags == LC_FLAGS_SECTIONEND)
- {
- nesting_depth--;
-
- return (LC_CBRET_OKAY);
- }
+ if (strcasecmp (value, "Client") == 0)
+ operating_mode = MODE_CLIENT;
+ else if (strcasecmp (value, "Server") == 0)
+ operating_mode = MODE_SERVER;
+ else if (strcasecmp (value, "Local") == 0)
+ operating_mode = MODE_LOCAL;
else
{
- fprintf (stderr, ERR_SECTION_ONLY, shortvar);
+ syslog (LOG_ERR, "Invalid value for config option `Mode': `%s'", value);
return (LC_CBRET_ERROR);
}
+ return (LC_CBRET_OKAY);
}
/*
DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
shortvar, var, arguments, value);
- if (nesting_depth == 0)
- {
- fprintf (stderr, ERR_NEEDS_SECTION, shortvar);
- return (LC_CBRET_ERROR);
- }
-
if (plugin_load (value))
syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", value);
return;
run_once = 1;
- lc_register_callback ("Help", 'h', LC_VAR_NONE,
- cf_callback_usage, NULL);
-
- lc_register_callback ("Client", 'c', LC_VAR_NONE,
+ lc_register_callback ("Client", SHORTOPT_NONE, LC_VAR_NONE,
cf_callback_mode_switch, NULL);
- lc_register_callback ("Local", 'l', LC_VAR_NONE,
+ lc_register_callback ("Local", SHORTOPT_NONE, LC_VAR_NONE,
cf_callback_mode_switch, NULL);
- lc_register_callback ("Server", 's', LC_VAR_NONE,
+ lc_register_callback ("Server", SHORTOPT_NONE, LC_VAR_NONE,
cf_callback_mode_switch, NULL);
- lc_register_callback ("Mode", SHORTOPT_NONE, LC_VAR_SECTION,
+ lc_register_callback ("Mode", SHORTOPT_NONE, LC_VAR_STRING,
cf_callback_mode, NULL);
lc_register_callback ("Plugin", SHORTOPT_NONE, LC_VAR_SECTION,
cf_callback_plugin, NULL);
- lc_register_callback ("Mode.PluginDir", 'P',
+ lc_register_callback ("PluginDir", SHORTOPT_NONE,
LC_VAR_STRING, cf_callback_mode_plugindir, NULL);
- lc_register_callback ("Mode.LoadPlugin", SHORTOPT_NONE,
+ lc_register_callback ("LoadPlugin", SHORTOPT_NONE,
LC_VAR_STRING, cf_callback_mode_loadmodule, NULL);
for (i = 0; i < cf_mode_num; i++)
}
}
-int cf_read (int argc, char **argv, char *filename)
+int cf_read (char *filename)
{
cf_init ();
if (filename == NULL)
filename = CONFIGFILE;
- if (lc_process (argc, argv, "collectd", LC_CONF_APACHE, filename))
+ DBG ("Starting to parse file `%s'", filename);
+
+ /* int lc_process_file(const char *appname, const char *pathname, lc_conf_type_t type); */
+ if (lc_process_file ("collectd", filename, LC_CONF_APACHE))
{
syslog (LOG_ERR, "lc_process_file (%s): %s", filename, lc_geterrstr ());
return (-1);
}
+ DBG ("Done parsing file `%s'", filename);
+
/* free memory and stuff */
lc_cleanup ();