summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2015-01-29 16:01:25 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2015-01-29 16:01:25 -0500
commit4aa4c64508a6ffe8bedfc0fa7cec41f2f0817b38 (patch)
tree125ceab51933421dc11166c3c105dae708723022
parentfbde0824d1960f890550d816ac9d21c0459ff984 (diff)
downloadenlightenment-4aa4c64508a6ffe8bedfc0fa7cec41f2f0817b38.tar.gz
ensure no duplicate XDG paths are prepended during startup
the previous patch(es) had a number of issues which made them unsuitable for general use: * only checking "/usr" and "/usr/local" paths, despite this only being accurate if e was installed into /usr or /usr/local * only checking if the paths were at the beginning of the string, when it's possible that they could be anywhere * failure to also check XDG_CONFIG_DIRS * improper formatting: this is a bit of a nitpick, but there are no correct instances of 'strcmp(a, b) == 0' in the e codebase.
-rw-r--r--src/bin/e_main.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/bin/e_main.c b/src/bin/e_main.c
index 733219d98a..375238ffb1 100644
--- a/src/bin/e_main.c
+++ b/src/bin/e_main.c
@@ -116,6 +116,20 @@ EAPI Eina_Bool e_nopause = EINA_FALSE;
EINTERN const char *e_first_frame = NULL;
EINTERN double e_first_frame_start_time = -1;
+static Eina_Bool
+_xdg_check_str(const char *env, const char *str)
+{
+ const char *p;
+ size_t len;
+
+ len = strlen(str);
+ for (p = strstr(env, str); p; p++, p = strstr(p, str))
+ {
+ if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
+ }
+ return EINA_FALSE;
+}
+
static void
_xdg_data_dirs_augment(void)
{
@@ -126,18 +140,27 @@ _xdg_data_dirs_augment(void)
if (!p) return;
s = getenv("XDG_DATA_DIRS");
- snprintf(newpath, sizeof(newpath), "%s:%s/share", e_prefix_data_get(), p);
if (s)
{
- if (strncmp(s, newpath, strlen(newpath)))
+ Eina_Bool pfxdata, pfx;
+
+ pfxdata = !_xdg_check_str(s, e_prefix_data_get());
+ snprintf(newpath, sizeof(newpath), "%s/share", p);
+ pfx = !_xdg_check_str(s, newpath);
+ if (pfxdata || pfx)
{
- snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
+ snprintf(buf, sizeof(buf), "%s%s%s%s%s",
+ pfxdata ? e_prefix_data_get() : "",
+ pfxdata ? ":" : "",
+ pfx ? newpath : "",
+ pfx ? ":" : "",
+ s);
e_util_env_set("XDG_DATA_DIRS", buf);
}
}
else
{
- snprintf(buf, sizeof(buf), "%s:/usr/local/share:/usr/share", newpath);
+ snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
e_util_env_set("XDG_DATA_DIRS", buf);
}
@@ -145,7 +168,7 @@ _xdg_data_dirs_augment(void)
snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
if (s)
{
- if (strncmp(s, newpath, strlen(newpath)))
+ if (!_xdg_check_str(s, newpath))
{
snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
e_util_env_set("XDG_CONFIG_DIRS", buf);