Skip to content

Commit

Permalink
librc: Move sysconf dir to ~/.config/openrc/...
Browse files Browse the repository at this point in the history
Also add ~/.local/share/openrc for data files (like logs)

This is done to help avoid name conflictions for anything else that
might create/user files in .config/

Signed-off-by: Anna (navi) Figueiredo Gomes <[email protected]>
  • Loading branch information
navi-desu committed Mar 22, 2023
1 parent 7da8435 commit 563832c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sh/gendepends.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dirs="
if [ "${RC_USER_SERVICES}" = "YES" ]; then
dirs="
@SYSCONFDIR@/init.d/user.d
${XDG_CONFIG_HOME:-HOME/.config}/init.d
${XDG_CONFIG_HOME:-HOME/.config}/openrc/init.d
"
fi

Expand Down
56 changes: 42 additions & 14 deletions src/librc/librc.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ rc_set_user(void)
char *path, *tmp;

/* Setting the sysconf path to XDG_CONFIG_HOME, or ~/.config/, so subdirectories would go:
* ~/.config/init.d
* ~/.config/conf.d
* ~/.config/runlevels
* ~/.config/rc.conf */
* ~/.config/openrc/init.d
* ~/.config/openrc/conf.d
* ~/.config/openrc/runlevels
* ~/.config/openrc/rc.conf
* ~/.lcaol/share/openrc/
* */
path = rc_user_sysconfdir();
if (mkdir(path, 0700) != 0 && errno != EEXIST) {
eerrorx("mkdir: %s", strerror(errno));
Expand All @@ -400,6 +402,12 @@ rc_set_user(void)
free(tmp);
free(path);

path = rc_user_datadir();
if (mkdir(path, 0700) != 0 && errno != EEXIST) {
eerrorx("mkdir: %s", strerror(errno));
}
free(path);

path = rc_user_svcdir();
if (mkdir(path, 0700) != 0 && errno != EEXIST) {
eerrorx("mkdir: %s", strerror(errno));
Expand All @@ -409,21 +417,41 @@ rc_set_user(void)
setenv("RC_USER_SERVICES", "YES", 1);
}

const char *
rc_user_home(void)
{
struct passwd *user_passwd;

errno = 0;
user_passwd = getpwuid(getuid());
if (!user_passwd) {
eerrorx("getpwuid: Failed to get user's passwd: %s", strerror(errno));
}
return user_passwd->pw_dir;
}

char *
rc_user_sysconfdir(void)
{
char *env, *path = NULL;
struct passwd *user_passwd = NULL;

if ((env = getenv("XDG_CONFIG_HOME"))) {
xasprintf(&path, "%s", env);
xasprintf(&path, "%s/openrc", env);
} else {
errno = 0;
user_passwd = getpwuid(getuid());
if (!user_passwd) {
eerrorx("getpwuid: Failed to get user's passwd: %s", strerror(errno));
}
xasprintf(&path, "%s/.config/", user_passwd->pw_dir);
xasprintf(&path, "%s/.config/openrc", rc_user_home());
}
return path;
}

char *
rc_user_datadir(void)
{
char *env, *path = NULL;

if ((env = getenv("XDG_DATA_HOME"))) {
xasprintf(&path, "%s/openrc", env);
} else {
xasprintf(&path, "%s/.local/share/openrc", rc_user_home());
}
return path;
}
Expand All @@ -433,9 +461,9 @@ rc_user_svcdir(void)
{
char *env, *path = NULL;
if ((env = getenv("XDG_RUNTIME_DIR"))) {
xasprintf(&path, "%s%s", env, RC_USER_RUNTIME_FOLDER);
xasprintf(&path, "%s/%s", env, RC_USER_RUNTIME_FOLDER);
} else {
xasprintf(&path, "/tmp%s/%d/", RC_USER_RUNTIME_FOLDER, getuid());
xasprintf(&path, "/tmp/%s/%d/", RC_USER_RUNTIME_FOLDER, getuid());
}
return path;
}
Expand Down
2 changes: 2 additions & 0 deletions src/librc/rc.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ bool rc_is_user(void);

void rc_set_user(void);

const char *rc_user_home(void);
char *rc_user_sysconfdir(void);
char *rc_user_svcdir(void);
char *rc_user_datadir(void);
#endif

#define RC_PATH_PREFIX RC_LIBEXECDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin"
Expand Down

0 comments on commit 563832c

Please sign in to comment.