Set configuration directory from the environment

This commit is contained in:
Michael Spang 2009-01-30 22:24:07 -05:00
parent 3c6c173424
commit cb8dd43d1d
2 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "config.h"
@ -28,6 +29,10 @@ static struct config_var config_vars[] = {
#undef CONFIG_STR
#undef CONFIG_INT
const char *default_config_dir = "/etc/csc";
const char *config_filename = "accounts.cf";
const char *config_dir;
void config_var(char *var, char *val) {
int i;
@ -51,8 +56,14 @@ void config_var(char *var, char *val) {
void configure() {
int i;
char conffile[1024];
config_parse(CONFIG_FILE);
config_dir = getenv("CEO_CONFIG_DIR") ?: default_config_dir;
if (snprintf(conffile, sizeof(conffile), "%s/%s", config_dir, config_filename) >= sizeof(conffile))
fatal("huge config path");
config_parse(conffile);
for (i = 0; i < sizeof(config_vars)/sizeof(*config_vars); i++) {
switch (config_vars[i].type) {

View File

@ -1,5 +1,3 @@
#define CONFIG_FILE "/etc/csc/accounts.cf"
#define CONFIG_STR(x) extern char *x;
#define CONFIG_INT(x) extern long x;
#include "config-vars.h"
@ -7,3 +5,5 @@
#undef CONFIG_INT
void configure();
extern const char *config_dir;