diff --git a/src/collectd.c b/src/collectd.c
index 71c1167775b92172765fc3454eb70656a95a1194..aacc96e3d1de6c1f9b254454c90d9de7043e516f 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
} /* 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_option ("LogFile", 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");
* Change directory. We do this _after_ reading the config and loading
* modules to relative paths work as expected.
*/
- if ((datadir = cf_get_mode_option ("DataDir")) == NULL)
+ if ((datadir = cf_get_option ("DataDir", PKGLOCALSTATEDIR)) == NULL)
{
fprintf (stderr, "Don't have a datadir to use. This should not happen. Ever.");
return (1);
sigChldAction.sa_handler = SIG_IGN;
sigaction (SIGCHLD, &sigChldAction, NULL);
- if ((pidfile = cf_get_mode_option ("PIDFile")) == NULL)
+ if ((pidfile = cf_get_option ("PIDFile", PIDFILE)) == NULL)
{
fprintf (stderr, "Cannot obtain pidfile. This shoud not happen. Ever.");
return (1);
#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");