diff options
Diffstat (limited to '')
-rw-r--r-- | libblkid/src/config.c | 107 |
1 files changed, 100 insertions, 7 deletions
diff --git a/libblkid/src/config.c b/libblkid/src/config.c index d3f5eea..7b8b04f 100644 --- a/libblkid/src/config.c +++ b/libblkid/src/config.c @@ -22,6 +22,9 @@ #endif #include <stdint.h> #include <stdarg.h> +#if defined (HAVE_LIBECONF) +#include <libeconf.h> +#endif #include "blkidP.h" #include "env.h" @@ -55,6 +58,7 @@ err: return -1; } +#ifndef HAVE_LIBECONF static int parse_next(FILE *fd, struct blkid_config *conf) { char buf[BUFSIZ]; @@ -111,25 +115,29 @@ static int parse_next(FILE *fd, struct blkid_config *conf) } return 0; } +#endif /* !HAVE_LIBECONF */ /* return real config data or built-in default */ struct blkid_config *blkid_read_config(const char *filename) { struct blkid_config *conf; - FILE *f; - - if (!filename) - filename = safe_getenv("BLKID_CONF"); - if (!filename) - filename = BLKID_CONFIG_FILE; conf = calloc(1, sizeof(*conf)); if (!conf) return NULL; conf->uevent = -1; - DBG(CONFIG, ul_debug("reading config file: %s.", filename)); + if (!filename) + filename = safe_getenv("BLKID_CONF"); + +#ifndef HAVE_LIBECONF + + FILE *f; + if (!filename) + filename = BLKID_CONFIG_FILE; + + DBG(CONFIG, ul_debug("reading config file: %s.", filename)); f = fopen(filename, "r" UL_CLOEXECSTR); if (!f) { DBG(CONFIG, ul_debug("%s: does not exist, using built-in default", filename)); @@ -141,6 +149,81 @@ struct blkid_config *blkid_read_config(const char *filename) goto err; } } + +#else /* !HAVE_LIBECONF */ + + static econf_file *file = NULL; + econf_err error; + + if (filename) { + DBG(CONFIG, ul_debug("reading config file: %s.", filename)); + error = econf_readFile(&file, filename, "= \t", "#"); + } else { + error = econf_readDirs(&file, +#if USE_VENDORDIR + _PATH_VENDORDIR, +#else + NULL, +#endif + "/etc", "blkid", "conf", "= \t", "#"); + } + + if (error) { + if (error == ECONF_NOFILE) { + if (filename) + DBG(CONFIG, + ul_debug("%s: does not exist, using built-in default", filename)); + else + DBG(CONFIG, + ul_debug("No configuration file blkid.conf found, using built-in default ")); + goto dflt; + } else { + if (filename) + DBG(CONFIG, ul_debug("%s: parse error:%s", filename, econf_errString(error))); + else + DBG(CONFIG, ul_debug("parse error:%s", econf_errString(error))); + + goto err; + } + } + + bool uevent = false; + if ((error = econf_getBoolValue(file, NULL, "SEND_UEVENT", &uevent))) { + if (error != ECONF_NOKEY) { + DBG(CONFIG, ul_debug("couldn't fetch SEND_UEVENT corrently: %s", econf_errString(error))); + goto err; + } else { + DBG(CONFIG, ul_debug("key SEND_UEVENT not found, using built-in default ")); + } + } else { + conf->uevent = uevent ? TRUE : FALSE; + } + + if ((error = econf_getStringValue(file, NULL, "CACHE_FILE", &(conf->cachefile)))) { + conf->cachefile = NULL; + if (error != ECONF_NOKEY) { + DBG(CONFIG, ul_debug("couldn't fetch CACHE_FILE correctly: %s", econf_errString(error))); + goto err; + } else { + DBG(CONFIG, ul_debug("key CACHE_FILE not found, using built-in default ")); + } + } + + char *line = NULL; + if ((error = econf_getStringValue(file, NULL, "EVALUATE", &line))) { + conf->nevals = 0; + if (error != ECONF_NOKEY) { + DBG(CONFIG, ul_debug("couldn't fetch EVALUATE correctly: %s", econf_errString(error))); + goto err; + } else { + DBG(CONFIG, ul_debug("key CACHE_FILE not found, using built-in default ")); + } + } else { + if (*line && parse_evaluate(conf, line) == -1) + goto err; + } + +#endif /* HAVE_LIBECONF */ dflt: if (!conf->nevals) { conf->eval[0] = BLKID_EVAL_UDEV; @@ -151,13 +234,23 @@ dflt: conf->cachefile = strdup(BLKID_CACHE_FILE); if (conf->uevent == -1) conf->uevent = TRUE; +#ifndef HAVE_LIBECONF if (f) fclose(f); +#else + econf_free (file); + free (line); +#endif return conf; err: free(conf->cachefile); free(conf); +#ifndef HAVE_LIBECONF fclose(f); +#else + econf_free (file); + free (line); +#endif return NULL; } |