parent
652125a269
commit
e327361844
|
@ -63,7 +63,7 @@ static const char *hostname = NULL;
|
||||||
|
|
||||||
static const char *efreet_dir_get(const char *key, const char *fallback);
|
static const char *efreet_dir_get(const char *key, const char *fallback);
|
||||||
static Eina_List *efreet_dirs_get(const char *key,
|
static Eina_List *efreet_dirs_get(const char *key,
|
||||||
const char *fallback);
|
const char *fallback);
|
||||||
static const char *efreet_user_dir_get(const char *key, const char *fallback);
|
static const char *efreet_user_dir_get(const char *key, const char *fallback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ int
|
||||||
efreet_base_init(void)
|
efreet_base_init(void)
|
||||||
{
|
{
|
||||||
_efreet_base_log_dom = eina_log_domain_register
|
_efreet_base_log_dom = eina_log_domain_register
|
||||||
("efreet_base", EFREET_DEFAULT_LOG_COLOR);
|
("efreet_base", EFREET_DEFAULT_LOG_COLOR);
|
||||||
if (_efreet_base_log_dom < 0)
|
if (_efreet_base_log_dom < 0)
|
||||||
{
|
{
|
||||||
EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_base.\n");
|
EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_base.\n");
|
||||||
|
@ -228,7 +228,7 @@ efreet_data_dirs_get(void)
|
||||||
xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", buf);
|
xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", buf);
|
||||||
#else
|
#else
|
||||||
xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS",
|
xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS",
|
||||||
PACKAGE_DATA_DIR ":/usr/share:/usr/local/share");
|
PACKAGE_DATA_DIR ":/usr/share:/usr/local/share");
|
||||||
#endif
|
#endif
|
||||||
return xdg_data_dirs;
|
return xdg_data_dirs;
|
||||||
}
|
}
|
||||||
|
@ -264,33 +264,33 @@ efreet_runtime_dir_get(void)
|
||||||
if (xdg_runtime_dir) return xdg_runtime_dir;
|
if (xdg_runtime_dir) return xdg_runtime_dir;
|
||||||
xdg_runtime_dir = efreet_dir_get("XDG_RUNTIME_DIR", "/tmp");
|
xdg_runtime_dir = efreet_dir_get("XDG_RUNTIME_DIR", "/tmp");
|
||||||
if (stat(xdg_runtime_dir, &st) == -1)
|
if (stat(xdg_runtime_dir, &st) == -1)
|
||||||
{
|
{
|
||||||
ERR("$XDG_RUNTIME_DIR did not exist, creating '%s' (breaks spec)",
|
ERR("$XDG_RUNTIME_DIR did not exist, creating '%s' (breaks spec)",
|
||||||
xdg_runtime_dir);
|
xdg_runtime_dir);
|
||||||
if (ecore_file_mkpath(xdg_runtime_dir))
|
if (ecore_file_mkpath(xdg_runtime_dir))
|
||||||
chmod(xdg_runtime_dir, 0700);
|
chmod(xdg_runtime_dir, 0700);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CRITICAL("Failed to create XDG_RUNTIME_DIR=%s", xdg_runtime_dir);
|
CRITICAL("Failed to create XDG_RUNTIME_DIR=%s", xdg_runtime_dir);
|
||||||
eina_stringshare_replace(&xdg_runtime_dir, NULL);
|
eina_stringshare_replace(&xdg_runtime_dir, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!S_ISDIR(st.st_mode))
|
else if (!S_ISDIR(st.st_mode))
|
||||||
{
|
{
|
||||||
CRITICAL("XDG_RUNTIME_DIR=%s is not a directory!", xdg_runtime_dir);
|
CRITICAL("XDG_RUNTIME_DIR=%s is not a directory!", xdg_runtime_dir);
|
||||||
eina_stringshare_replace(&xdg_runtime_dir, NULL);
|
eina_stringshare_replace(&xdg_runtime_dir, NULL);
|
||||||
}
|
}
|
||||||
else if ((st.st_mode & 0777) != 0700)
|
else if ((st.st_mode & 0777) != 0700)
|
||||||
{
|
{
|
||||||
ERR("XDG_RUNTIME_DIR=%s is mode %o, changing to 0700",
|
ERR("XDG_RUNTIME_DIR=%s is mode %o, changing to 0700",
|
||||||
xdg_runtime_dir, st.st_mode & 0777);
|
xdg_runtime_dir, st.st_mode & 0777);
|
||||||
if (chmod(xdg_runtime_dir, 0700) != 0)
|
if (chmod(xdg_runtime_dir, 0700) != 0)
|
||||||
{
|
{
|
||||||
CRITICAL("Cannot fix XDG_RUNTIME_DIR=%s incorrect mode %o: %s",
|
CRITICAL("Cannot fix XDG_RUNTIME_DIR=%s incorrect mode %o: %s",
|
||||||
xdg_runtime_dir, st.st_mode & 0777, strerror(errno));
|
xdg_runtime_dir, st.st_mode & 0777, strerror(errno));
|
||||||
eina_stringshare_replace(&xdg_runtime_dir, NULL);
|
eina_stringshare_replace(&xdg_runtime_dir, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return xdg_runtime_dir;
|
return xdg_runtime_dir;
|
||||||
}
|
}
|
||||||
|
@ -411,46 +411,46 @@ efreet_dirs_get(const char *key, const char *fallback)
|
||||||
static const char *
|
static const char *
|
||||||
efreet_env_expand(const char *in)
|
efreet_env_expand(const char *in)
|
||||||
{
|
{
|
||||||
Eina_Strbuf *sb;
|
Eina_Strbuf *sb;
|
||||||
const char *ret, *p, *e1 = NULL, *e2 = NULL, *val;
|
const char *ret, *p, *e1 = NULL, *e2 = NULL, *val;
|
||||||
char *env;
|
char *env;
|
||||||
|
|
||||||
if (!in) return NULL;
|
if (!in) return NULL;
|
||||||
sb = eina_strbuf_new();
|
sb = eina_strbuf_new();
|
||||||
if (!sb) return NULL;
|
if (!sb) return NULL;
|
||||||
|
|
||||||
/* maximum length of any env var is the input string */
|
/* maximum length of any env var is the input string */
|
||||||
env = alloca(strlen(in) + 1);
|
env = alloca(strlen(in) + 1);
|
||||||
for (p = in; *p; p++)
|
for (p = in; *p; p++)
|
||||||
{
|
{
|
||||||
if (!e1)
|
if (!e1)
|
||||||
{
|
{
|
||||||
if (*p == '$') e1 = p + 1;
|
if (*p == '$') e1 = p + 1;
|
||||||
else eina_strbuf_append_char(sb, *p);
|
else eina_strbuf_append_char(sb, *p);
|
||||||
}
|
}
|
||||||
else if (!(((*p >= 'a') && (*p <= 'z')) ||
|
else if (!(((*p >= 'a') && (*p <= 'z')) ||
|
||||||
((*p >= 'A') && (*p <= 'Z')) ||
|
((*p >= 'A') && (*p <= 'Z')) ||
|
||||||
((*p >= '0') && (*p <= '9')) ||
|
((*p >= '0') && (*p <= '9')) ||
|
||||||
(*p == '_')))
|
(*p == '_')))
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
e2 = p;
|
e2 = p;
|
||||||
len = (size_t)(e2 - e1);
|
len = (size_t)(e2 - e1);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
memcpy(env, e1, len);
|
memcpy(env, e1, len);
|
||||||
env[len] = 0;
|
env[len] = 0;
|
||||||
val = getenv(env);
|
val = getenv(env);
|
||||||
if (val) eina_strbuf_append(sb, val);
|
if (val) eina_strbuf_append(sb, val);
|
||||||
}
|
}
|
||||||
e1 = NULL;
|
e1 = NULL;
|
||||||
eina_strbuf_append_char(sb, *p);
|
eina_strbuf_append_char(sb, *p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = eina_stringshare_add(eina_strbuf_string_get(sb));
|
ret = eina_stringshare_add(eina_strbuf_string_get(sb));
|
||||||
eina_strbuf_free(sb);
|
eina_strbuf_free(sb);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -464,22 +464,22 @@ efreet_env_expand(const char *in)
|
||||||
static const char *
|
static const char *
|
||||||
efreet_user_dir_get(const char *key, const char *fallback)
|
efreet_user_dir_get(const char *key, const char *fallback)
|
||||||
{
|
{
|
||||||
Eina_File *file = NULL;
|
Eina_File *file = NULL;
|
||||||
Eina_File_Line *line;
|
Eina_File_Line *line;
|
||||||
Eina_Iterator *it = NULL;
|
Eina_Iterator *it = NULL;
|
||||||
const char *config_home;
|
const char *config_home;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
config_home = efreet_config_home_get();
|
config_home = efreet_config_home_get();
|
||||||
snprintf(path, sizeof(path), "%s/user-dirs.dirs", config_home);
|
snprintf(path, sizeof(path), "%s/user-dirs.dirs", config_home);
|
||||||
|
|
||||||
file = eina_file_open(path, EINA_FALSE);
|
file = eina_file_open(path, EINA_FALSE);
|
||||||
if (!file) goto fallback;
|
if (!file) goto fallback;
|
||||||
it = eina_file_map_lines(file);
|
it = eina_file_map_lines(file);
|
||||||
if (!it) goto fallback;
|
if (!it) goto fallback;
|
||||||
EINA_ITERATOR_FOREACH(it, line)
|
EINA_ITERATOR_FOREACH(it, line)
|
||||||
{
|
{
|
||||||
const char *eq, *end;
|
const char *eq, *end;
|
||||||
|
|
||||||
if (line->length < 3) continue;
|
if (line->length < 3) continue;
|
||||||
|
@ -497,16 +497,16 @@ efreet_user_dir_get(const char *key, const char *fallback)
|
||||||
memcpy(ret, eq, end - eq);
|
memcpy(ret, eq, end - eq);
|
||||||
ret[end - eq] = '\0';
|
ret[end - eq] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fallback:
|
fallback:
|
||||||
if (it) eina_iterator_free(it);
|
if (it) eina_iterator_free(it);
|
||||||
if (file) eina_file_close(file);
|
if (file) eina_file_close(file);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
const char *home;
|
const char *home;
|
||||||
home = efreet_home_dir_get();
|
home = efreet_home_dir_get();
|
||||||
ret = alloca(strlen(home) + strlen(fallback) + 2);
|
ret = alloca(strlen(home) + strlen(fallback) + 2);
|
||||||
sprintf(ret, "%s/%s", home, fallback);
|
sprintf(ret, "%s/%s", home, fallback);
|
||||||
}
|
}
|
||||||
return efreet_env_expand(ret);
|
return efreet_env_expand(ret);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue