diff options
Diffstat (limited to 'src/librc')
-rw-r--r-- | src/librc/librc-misc.c | 51 | ||||
-rw-r--r-- | src/librc/librc.h | 1 | ||||
-rw-r--r-- | src/librc/rc.h.in | 11 | ||||
-rw-r--r-- | src/librc/rc.map | 1 |
4 files changed, 64 insertions, 0 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index f83745f2..b7c4108e 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -218,3 +218,54 @@ rc_config_value(RC_STRINGLIST *list, const char *entry) return NULL; } librc_hidden_def(rc_config_value) + +/* Global for caching the strings loaded from rc.conf to avoid reparsing for + * each rc_conf_value call */ +static RC_STRINGLIST *rc_conf = NULL; + +char * +rc_conf_value(const char *setting) +{ + RC_STRINGLIST *old; + RC_STRING *s; + char *p; + + if (! rc_conf) { + rc_conf = rc_config_load(RC_CONF); +#ifdef DEBUG_MEMORY + atexit(_free_rc_conf); +#endif + + /* Support old configs */ + if (exists(RC_CONF_OLD)) { + old = rc_config_load(RC_CONF_OLD); + TAILQ_CONCAT(rc_conf, old, entries); +#ifdef DEBUG_MEMORY + free(old); +#endif + } + + /* Convert old uppercase to lowercase */ + TAILQ_FOREACH(s, rc_conf, entries) { + p = s->value; + while (p && *p && *p != '=') { + if (isupper((unsigned char)*p)) + *p = tolower((unsigned char)*p); + p++; + } + } + } + + return rc_config_value(rc_conf, setting); +} +librc_hidden_def(rc_conf_value) + +#ifdef DEBUG_MEMORY +static void +_free_rc_conf(void) +{ + rc_stringlist_free(rc_conf); +} +#endif + + diff --git a/src/librc/librc.h b/src/librc/librc.h index dc97f1d3..aea362e8 100644 --- a/src/librc/librc.h +++ b/src/librc/librc.h @@ -72,6 +72,7 @@ #define librc_hidden_proto(x) hidden_proto(x) #define librc_hidden_def(x) hidden_def(x) +librc_hidden_proto(rc_conf_value) librc_hidden_proto(rc_config_list) librc_hidden_proto(rc_config_load) librc_hidden_proto(rc_config_value) diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 5aad1d55..5b06de2f 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -43,6 +43,14 @@ __BEGIN_DECLS #define RC_CONFDIR RC_SYSCONFDIR "/conf.d" #define RC_PLUGINDIR RC_LIBDIR "/plugins" +#define RC_PROFILE_ENV RC_SYSCONFDIR "/profile.env" +#define RC_SYS_WHITELIST RC_LIBEXECDIR "/conf.d/env_whitelist" +#define RC_USR_WHITELIST RC_SYSCONFDIR "/conf.d/env_whitelist" +#define RC_CONF RC_SYSCONFDIR "/rc.conf" +#define RC_CONF_OLD RC_SYSCONFDIR "/conf.d/rc" + +#define RC_PATH_PREFIX RC_LIBEXECDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin" + /* PKG_PREFIX is where packages are installed if different from the base OS * On Gentoo this is normally unset, on FreeBSD /usr/local and on NetBSD * /usr/pkg. */ @@ -462,6 +470,9 @@ RC_STRINGLIST *rc_config_load(const char *); /*! Return the value of the entry from a key=value list. */ char *rc_config_value(RC_STRINGLIST *, const char *); +/*! Return the value of the entry from rc.conf. */ +char *rc_conf_value(const char *); + /*! Check if a variable is a boolean and return its value. * If variable is not a boolean then we set errno to be ENOENT when it does * not exist or EINVAL if it's not a boolean. diff --git a/src/librc/rc.map b/src/librc/rc.map index d763bfeb..c5f10ade 100644 --- a/src/librc/rc.map +++ b/src/librc/rc.map @@ -1,5 +1,6 @@ RC_1.0 { global: + rc_conf_value; rc_config_list; rc_config_load; rc_config_value; |