aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2011-01-17 19:22:53 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2011-01-17 19:29:45 +0000
commit2b7c2b8cf1248c5cea7c56ad1a3141973a34fe0a (patch)
treed06954d40aa8a2f2aefba84c9767f54cff98f2ce
parent6e876bca1313d0cc2ef576da15124a9082f404db (diff)
Bug #351570: Hidden function fixes: rc_conf_value.
Refactor rc_conf_value into librc for use in library context. Also requires moving: - rc_conf internal static - Defines: PROFILE_ENV, SYS_WHITELIST, USR_WHITELIST, RC_PATH_PREFIX moved to rc.h with new RC_ prefix added. - Defines: RC_CONF, RC_CONF_OLD moved to rc.h. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r--src/librc/librc-misc.c51
-rw-r--r--src/librc/librc.h1
-rw-r--r--src/librc/rc.h.in11
-rw-r--r--src/librc/rc.map1
-rw-r--r--src/rc/rc-misc.c66
-rw-r--r--src/test/librc.funcs.hidden.list1
-rw-r--r--src/test/rc.funcs.list2
7 files changed, 73 insertions, 60 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;
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index a7b4e2d8..64edf688 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -52,62 +52,8 @@
#include "rc-misc.h"
#include "version.h"
-#define PROFILE_ENV RC_SYSCONFDIR "/profile.env"
-#define SYS_WHITELIST RC_LIBEXECDIR "/conf.d/env_whitelist"
-#define 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 PATH_PREFIX RC_LIBEXECDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin"
-
-static RC_STRINGLIST *rc_conf = NULL;
-
extern char **environ;
-#ifdef DEBUG_MEMORY
-static void
-_free_rc_conf(void)
-{
- rc_stringlist_free(rc_conf);
-}
-#endif
-
-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);
-}
-
bool
rc_conf_yesno(const char *setting)
{
@@ -135,7 +81,7 @@ env_filter(void)
/* Add the user defined list of vars */
env_allow = rc_stringlist_split(rc_conf_value("rc_env_allow"), " ");
- profile = rc_config_load(PROFILE_ENV);
+ profile = rc_config_load(RC_PROFILE_ENV);
/* Copy the env and work from this so we can manipulate it safely */
env_list = rc_stringlist_new();
@@ -181,7 +127,7 @@ env_filter(void)
void
env_config(void)
{
- size_t pplen = strlen(PATH_PREFIX);
+ size_t pplen = strlen(RC_PATH_PREFIX);
char *path;
char *p;
char *e;
@@ -199,16 +145,16 @@ env_config(void)
for a little extra security */
path = getenv("PATH");
if (! path)
- setenv("PATH", PATH_PREFIX, 1);
- else if (strncmp (PATH_PREFIX, path, pplen) != 0) {
+ setenv("PATH", RC_PATH_PREFIX, 1);
+ else if (strncmp (RC_PATH_PREFIX, path, pplen) != 0) {
l = strlen(path) + pplen + 3;
e = p = xmalloc(sizeof(char) * l);
- p += snprintf(p, l, "%s", PATH_PREFIX);
+ p += snprintf(p, l, "%s", RC_PATH_PREFIX);
/* Now go through the env var and only add bits not in our
* PREFIX */
while ((token = strsep(&path, ":"))) {
- np = npp = xstrdup(PATH_PREFIX);
+ np = npp = xstrdup(RC_PATH_PREFIX);
while ((tok = strsep(&npp, ":")))
if (strcmp(tok, token) == 0)
break;
diff --git a/src/test/librc.funcs.hidden.list b/src/test/librc.funcs.hidden.list
index ffacf57f..1bc49a04 100644
--- a/src/test/librc.funcs.hidden.list
+++ b/src/test/librc.funcs.hidden.list
@@ -1,3 +1,4 @@
+rc_conf_value
rc_config_list
rc_config_load
rc_config_value
diff --git a/src/test/rc.funcs.list b/src/test/rc.funcs.list
index b01ddf60..a8b011ff 100644
--- a/src/test/rc.funcs.list
+++ b/src/test/rc.funcs.list
@@ -1,3 +1,5 @@
+rc_conf_value
+rc_conf_value@@RC_1.0
rc_config_list
rc_config_list@@RC_1.0
rc_config_load