} /* 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
* 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);
*/
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;
/*
* Other query functions
*/
-char *cf_get_mode_option (const char *key)
+char *cf_get_option (const char *key, char *def)
{
int i;
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);
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,
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);
}
}