Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle multiple XDG_CONFIG_DIRS elements correctly #405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions config.c
Expand Up @@ -152,7 +152,7 @@ int config_load(const char *path, config_cb_t *cb, void *data)
{
const char * const home = sys_getenv("HOME");
const char * const xdg_home = sys_getenv("XDG_CONFIG_HOME");
const char * const xdg_dirs = sys_getenv("XDG_CONFIG_DIRS");
const char * xdg_dirs = sys_getenv("XDG_CONFIG_DIRS");
struct config conf = {
.data = data,
.cb = cb,
Expand Down Expand Up @@ -182,13 +182,22 @@ int config_load(const char *path, config_cb_t *cb, void *data)
}

/* system config file? */
if (xdg_dirs)
snprintf(buf, sizeof(buf), "%s/i3blocks/config", xdg_dirs);
else
snprintf(buf, sizeof(buf), "%s/xdg/i3blocks/config", SYSCONFDIR);
err = config_open(&conf, buf);
if (err != -ENOENT)
return err;
if (!xdg_dirs) xdg_dirs = SYSCONFDIR "/xdg";
while (*xdg_dirs) {
const char * end = strchr(xdg_dirs, ':');

if (end != xdg_dirs) {
int len = end
? end - xdg_dirs
: sizeof(buf);
snprintf(buf, sizeof(buf), "%.*s/i3blocks/config", len, xdg_dirs);
err = config_open(&conf, buf);
if (err != -ENOENT) return err;
}

if (!end) break;
xdg_dirs = end + 1;
}

snprintf(buf, sizeof(buf), "%s/i3blocks.conf", SYSCONFDIR);
return config_open(&conf, buf);
Expand Down