From: octo Date: Mon, 16 Jan 2006 20:49:10 +0000 (+0000) Subject: Renamed `cf_get_mode_option' to `cf_get_option'. Added the `default' argument.. X-Git-Tag: collectd-3.6.0~10 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=423a501df6c60f85893b6ff2bcd93351bdf2fd52;p=collectd.git Renamed `cf_get_mode_option' to `cf_get_option'. Added the `default' argument.. Added config option `LogFile' Removed the config options `Client', `Server' and `Local' --- diff --git a/configure.in b/configure.in index 1ae7ec2a..fcc40551 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(collectd, 3.6.alpha1) +AC_INIT(collectd, 3.6.alpha2) AC_CONFIG_SRCDIR(src/collectd.c) AC_CONFIG_HEADERS(src/config.h) AM_INIT_AUTOMAKE(dist-bzip2) diff --git a/src/collectd.c b/src/collectd.c index 190e043a..aacc96e3 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -296,7 +296,7 @@ int main (int argc, char **argv) } /* while (1) */ #if COLLECT_DEBUG - if ((logfile = cf_get_mode_option ("LogFile")) != NULL) + if ((logfile = cf_get_option ("LogFile", LOGFILE)) != NULL) DBG_STARTFILE (logfile, "Debug file opened."); #endif @@ -317,7 +317,7 @@ int main (int argc, char **argv) * 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); @@ -335,7 +335,7 @@ int main (int argc, char **argv) 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); diff --git a/src/configfile.c b/src/configfile.c index 21fcc8d3..ed8cb77e 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -67,13 +67,13 @@ typedef struct cf_mode_item */ 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}, - {"LogFile", LOGFILE, MODE_SERVER | MODE_SERVER | MODE_LOCAL}, + {"Server", NULL, MODE_CLIENT }, + {"Port", NULL, MODE_CLIENT | MODE_SERVER }, + {"PIDFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}, + {"DataDir", NULL, MODE_SERVER | MODE_LOCAL}, + {"LogFile", NULL, MODE_SERVER | MODE_SERVER | MODE_LOCAL} }; -static int cf_mode_num = 4; +static int cf_mode_num = 5; static int nesting_depth = 0; static char *current_module = NULL; @@ -207,7 +207,7 @@ void cf_register (char *type, /* * Other query functions */ -char *cf_get_mode_option (const char *key) +char *cf_get_option (const char *key, char *def) { int i; @@ -216,8 +216,12 @@ char *cf_get_mode_option (const char *key) if ((cf_mode_list[i].mode & operating_mode) == 0) continue; - if (strcasecmp (cf_mode_list[i].key, key) == 0) + if (strcasecmp (cf_mode_list[i].key, key) != 0) + continue; + + if (cf_mode_list[i].value != NULL) return (cf_mode_list[i].value); + return (def); } return (NULL); @@ -470,13 +474,6 @@ void cf_init (void) return; run_once = 1; - lc_register_callback ("Client", SHORTOPT_NONE, LC_VAR_NONE, - cf_callback_mode_switch, NULL); - lc_register_callback ("Local", SHORTOPT_NONE, LC_VAR_NONE, - cf_callback_mode_switch, NULL); - lc_register_callback ("Server", SHORTOPT_NONE, LC_VAR_NONE, - cf_callback_mode_switch, NULL); - lc_register_callback ("Mode", SHORTOPT_NONE, LC_VAR_STRING, cf_callback_mode, NULL); lc_register_callback ("Plugin", SHORTOPT_NONE, LC_VAR_SECTION, @@ -489,15 +486,11 @@ void cf_init (void) for (i = 0; i < cf_mode_num; i++) { - char longvar[256]; cf_mode_item_t *item; item = &cf_mode_list[i]; - if (snprintf (longvar, 256, "Mode.%s", item->key) >= 256) - continue; - - lc_register_callback (longvar, SHORTOPT_NONE, LC_VAR_STRING, + lc_register_callback (item->key, SHORTOPT_NONE, LC_VAR_STRING, cf_callback_mode_option, (void *) item); } } diff --git a/src/configfile.h b/src/configfile.h index e9d31104..8a34e7e9 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -63,17 +63,18 @@ void cf_register (char *type, /* * DESCRIPTION - * `cf_get_mode_option' returns options from the section(s). + * `cf_get_option' returns various general options. * * PARAMETERS * `key' Name of the option to query. + * `def' Pointer to return as default value. * * RETURN VALUE * The pointer returned is part of an internal structure and may not be * changed. If the option is not found for whatever reason (wrong key, option * not allowed for currently selected mode, ...) `NULL' is returned. */ -char *cf_get_mode_option (const char *key); +char *cf_get_option (const char *key, char *def); /* * DESCRIPTION