summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ecf283d)
raw | patch | inline | side by side (parent: ecf283d)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 5 Jun 2016 22:03:39 +0000 (00:03 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 5 Jun 2016 22:03:39 +0000 (00:03 +0200) |
This replaces 09fb81e130ad70bf0547cec3d3c349ce8cb092cf which provided a
specific solution for the `PIDFile' option. The new solution is generic and
more nicely abstracted without the need for global variables across multiple
modules.
Fixes #366
specific solution for the `PIDFile' option. The new solution is generic and
more nicely abstracted without the need for global variables across multiple
modules.
Fixes #366
src/daemon/collectd.c | patch | blob | history | |
src/daemon/collectd.h | patch | blob | history | |
src/daemon/configfile.c | patch | blob | history | |
src/daemon/configfile.h | patch | blob | history |
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
index a72ff35f2fc21ec042e809d64967100f35f5a9fd..ce4922d602ec2d5aa4bbd4f81a3e9856b3e995a4 100644 (file)
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
*/
char hostname_g[DATA_MAX_NAME_LEN];
cdtime_t interval_g;
-int pidfile_from_cli = 0;
int timeout_g;
#if HAVE_LIBKSTAT
kstat_ctl_t *kc;
break;
case 'T':
test_readall = 1;
- global_option_set ("ReadThreads", "-1");
+ global_option_set ("ReadThreads", "-1", 1);
#if COLLECT_DAEMON
daemonize = 0;
#endif /* COLLECT_DAEMON */
break;
#if COLLECT_DAEMON
case 'P':
- global_option_set ("PIDFile", optarg);
- pidfile_from_cli = 1;
+ global_option_set ("PIDFile", optarg, 1);
break;
case 'f':
daemonize = 0;
diff --git a/src/daemon/collectd.h b/src/daemon/collectd.h
index 8fb29455d55798fbc6bd0d832dd6f54b3961845d..500bba2658ed62831603ffad5960123fbc19086d 100644 (file)
--- a/src/daemon/collectd.h
+++ b/src/daemon/collectd.h
extern char hostname_g[];
extern cdtime_t interval_g;
-extern int pidfile_from_cli;
extern int timeout_g;
#endif /* COLLECTD_H */
index 34c23cdfad3b24c408269ae60f834aa90e18f8f4..93e90e3b14442199f3600547d5084beef065a83c 100644 (file)
--- a/src/daemon/configfile.c
+++ b/src/daemon/configfile.c
{
const char *key;
char *value;
+ _Bool from_cli; /* value set from CLI */
const char *def;
} cf_global_option_t;
static cf_global_option_t cf_global_options[] =
{
- {"BaseDir", NULL, PKGLOCALSTATEDIR},
- {"PIDFile", NULL, PIDFILE},
- {"Hostname", NULL, NULL},
- {"FQDNLookup", NULL, "true"},
- {"Interval", NULL, NULL},
- {"ReadThreads", NULL, "5"},
- {"WriteThreads", NULL, "5"},
- {"WriteQueueLimitHigh", NULL, NULL},
- {"WriteQueueLimitLow", NULL, NULL},
- {"Timeout", NULL, "2"},
- {"AutoLoadPlugin", NULL, "false"},
- {"CollectInternalStats", NULL, "false"},
- {"PreCacheChain", NULL, "PreCache"},
- {"PostCacheChain", NULL, "PostCache"},
- {"MaxReadInterval", NULL, "86400"}
+ {"BaseDir", NULL, 0, PKGLOCALSTATEDIR},
+ {"PIDFile", NULL, 0, PIDFILE},
+ {"Hostname", NULL, 0, NULL},
+ {"FQDNLookup", NULL, 0, "true"},
+ {"Interval", NULL, 0, NULL},
+ {"ReadThreads", NULL, 0, "5"},
+ {"WriteThreads", NULL, 0, "5"},
+ {"WriteQueueLimitHigh", NULL, 0, NULL},
+ {"WriteQueueLimitLow", NULL, 0, NULL},
+ {"Timeout", NULL, 0, "2"},
+ {"AutoLoadPlugin", NULL, 0, "false"},
+ {"CollectInternalStats", NULL, 0, "false"},
+ {"PreCacheChain", NULL, 0, "PreCache"},
+ {"PostCacheChain", NULL, 0, "PostCache"},
+ {"MaxReadInterval", NULL, 0, "86400"}
};
static int cf_global_options_num = STATIC_ARRAY_SIZE (cf_global_options);
if (ci->values_num != 1)
return (-1);
if (ci->values[0].type == OCONFIG_TYPE_STRING)
- return (global_option_set (ci->key, ci->values[0].value.string));
+ return (global_option_set (ci->key, ci->values[0].value.string, 0));
else if (ci->values[0].type == OCONFIG_TYPE_NUMBER)
{
char tmp[128];
ssnprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
- return (global_option_set (ci->key, tmp));
+ return (global_option_set (ci->key, tmp, 0));
}
else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
{
if (ci->values[0].value.boolean)
- return (global_option_set (ci->key, "true"));
+ return (global_option_set (ci->key, "true", 0));
else
- return (global_option_set (ci->key, "false"));
+ return (global_option_set (ci->key, "false", 0));
}
return (-1);
/*
* Public functions
*/
-int global_option_set (const char *option, const char *value)
+int global_option_set (const char *option, const char *value, _Bool from_cli)
{
int i;
if (i >= cf_global_options_num)
return (-1);
- if (strcasecmp (option, "PIDFile") == 0 && pidfile_from_cli == 1)
+ if (cf_global_options[i].from_cli && (! from_cli))
{
- DEBUG ("Configfile: Ignoring `PIDFILE' option because "
- "command-line option `-P' take precedence.");
+ DEBUG ("Configfile: Ignoring %s `%s' option because "
+ "it was overriden by a command-line option.",
+ option, value);
return (0);
}
else
cf_global_options[i].value = NULL;
+ cf_global_options[i].from_cli = from_cli;
+
return (0);
}
index 09dbe58f827fa3cf7262817d9d1ad7f27161d4f9..924d97c5395b00ce3c373cf94c665c0c928b073d 100644 (file)
--- a/src/daemon/configfile.h
+++ b/src/daemon/configfile.h
*/
int cf_read (const char *filename);
-int global_option_set (const char *option, const char *value);
+int global_option_set (const char *option, const char *value, _Bool from_cli);
const char *global_option_get (const char *option);
long global_option_get_long (const char *option, long default_value);
long global_option_get_long_in_range (const char *option, long default_value, long min, long max);