Skip to content

Commit

Permalink
Tidy up config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain M Conochie committed Apr 12, 2024
1 parent 16a9524 commit cd9e3a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 72 deletions.
2 changes: 0 additions & 2 deletions include/ailsacmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,6 @@ void
chomp(char *input);
void
display_type_error(short int type);
int
get_config_file_location(char *config);
char *
cmdb_get_uname(unsigned long int uid);
const char *
Expand Down
68 changes: 8 additions & 60 deletions lib/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,6 @@ parse_user_cmdb_config(ailsa_cmdb_s *cmdb);
static void
parse_cmdb_config_values(ailsa_cmdb_s *cmdb, FILE *conf);

int
get_config_file_location(char *config)
{
int retval = 0;
FILE *cnf;
const char *conf = config;

if (snprintf(config, CONFIG_LEN, "%s/cmdb/cmdb.conf", SYSCONFDIR) >= CONFIG_LEN)
return AILSA_BUFFER_TOO_SMALL;
if ((cnf = fopen(conf, "r"))) {
fclose(cnf);
} else {
if (snprintf(config, CONFIG_LEN, "%s/dnsa/dnsa.conf", SYSCONFDIR) >= CONFIG_LEN) {
ailsa_syslog(LOG_ERR, "Buffer too small to hold config file location");
retval = AILSA_BUFFER_TOO_SMALL;
}
if ((cnf = fopen(conf, "r")))
fclose(cnf);
else {
ailsa_syslog(LOG_ERR, "Cannot open config file %s", conf);
retval = AILSA_FILE_ERROR;
}
}
return retval;
}

void
parse_mkvm_config(ailsa_mkvm_s *vm)
{
Expand Down Expand Up @@ -183,7 +157,7 @@ parse_user_mkvm_config(ailsa_mkvm_s *vm)
#endif // HAVE_WORDEXP
}

/* Grab config values from confile file that uses NAME=value as configuration
/* Grab config values from conffile file that uses NAME=value as configuration
options */
#ifndef GET_CONFIG_OPTION
# define GET_CONFIG_OPTION(CONFIG, option) { \
Expand Down Expand Up @@ -334,14 +308,6 @@ display_mksp_usage(void)
printf("\t-p <path>: Specify the path to the storage directory\n");
}

#ifndef OPEN_CMDB_FILE
# define OPEN_CMDB_FILE { \
if ((conf = fopen(path, "r"))) { \
parse_cmdb_config_values(cmdb, conf); \
goto cleanup; \
} \
}
#endif

static void
parse_system_cmdb_config(ailsa_cmdb_s *cmdb)
Expand All @@ -351,19 +317,13 @@ parse_system_cmdb_config(ailsa_cmdb_s *cmdb)

memset(path, 0, FILE_LEN);
snprintf(path, FILE_LEN, "%s/cmdb/cmdb.conf", SYSCONFDIR);
OPEN_CMDB_FILE
memset(path, 0, FILE_LEN);
snprintf(path, FILE_LEN, "%s/cmdb/dnsa.conf", SYSCONFDIR);
OPEN_CMDB_FILE
memset(path, 0, FILE_LEN);
snprintf(path, FILE_LEN, "%s/dnsa/cmdb.conf", SYSCONFDIR);
OPEN_CMDB_FILE
memset(path, 0, FILE_LEN);
snprintf(path, FILE_LEN, "%s/dnsa/dnsa.conf", SYSCONFDIR);
OPEN_CMDB_FILE
cleanup:
if (conf)
fclose(conf);
if ((conf = fopen(path, "r"))) {
parse_cmdb_config_values(cmdb, conf);
fclose(conf);
} else {
ailsa_syslog(LOG_DAEMON, "Cannot open %s for config\n", path);
exit (1);
}
}

static void
Expand All @@ -383,17 +343,6 @@ parse_user_cmdb_config(ailsa_cmdb_s *cmdb)
#ifdef DEBUG
ailsa_syslog(LOG_DEBUG, "Cannot open file %s", *uconf);
#endif
upath = "~/.dnsa.conf";
wordexp_t r;
if ((retval = wordexp(upath, &r, 0)) == 0) {
uconf = r.we_wordv;
if (!(conf = fopen(*uconf, "r"))) {
#ifdef DEBUG
ailsa_syslog(LOG_DEBUG, "Cannot open file %s", *uconf);
#endif
}
wordfree(&r);
}
}
}
#endif // HAVE_WORDEXP
Expand Down Expand Up @@ -436,4 +385,3 @@ parse_user_cmdb_config(ailsa_cmdb_s *cmdb)

#undef GET_CONFIG_OPTION
#undef GET_CONFIG_INT
#undef OPEN_CMDB_FILE
11 changes: 1 addition & 10 deletions src/cmdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,12 @@ cmdb_hardware_type_actions(cmdb_comm_line_s *cm, ailsa_cmdb_s *cc)
static int
parse_cmdb_command_line(int argc, char **argv, cmdb_comm_line_s *comp)
{
const char *optstr = "c:i:k:n:x:y:A:B:C:D:E:H:I:L:M:N:O:P:S:T:U:V:Y:Z:adefghjlmorqstuvwz";
const char *optstr = "i:k:n:x:y:A:B:C:D:E:H:I:L:M:N:O:P:S:T:U:V:Y:Z:adefghjlmorqstuvwz";
int opt, retval;
#ifdef HAVE_GETOPT_H
int index;
struct option lopts[] = {
{"add", no_argument, NULL, 'a'},
{"config", required_argument, NULL, 'c'},
{"display", no_argument, NULL, 'd'},
{"service", no_argument, NULL, 'e'},
{"force", no_argument, NULL, 'f'},
Expand Down Expand Up @@ -369,11 +368,6 @@ parse_cmdb_command_line(int argc, char **argv, cmdb_comm_line_s *comp)
};
#endif // HAVE_GETOPT_H
retval = 0;
if (!(comp->config)) {
comp->config = ailsa_calloc(CONFIG_LEN, "comp->config in parse_cmdb_command_line");
if ((retval = get_config_file_location(comp->config)) != 0)
return retval;
}
#ifdef HAVE_GETOPT_H
while ((opt = getopt_long(argc, argv, optstr, lopts, &index)) != -1)
#else
Expand Down Expand Up @@ -434,9 +428,6 @@ parse_cmdb_command_line(int argc, char **argv, cmdb_comm_line_s *comp)
case 'f':
comp->force = 1;
break;
case 'c':
comp->config = strndup(optarg, CONFIG_LEN);
break;
case 'n':
comp->name = strndup(optarg, HOST_LEN);
break;
Expand Down

0 comments on commit cd9e3a1

Please sign in to comment.