diff options
| author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-03-21 20:52:53 -0300 | 
|---|---|---|
| committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-10-19 10:56:54 +0200 | 
| commit | 8bb28cb0279f5cd93c0acbf36aa3f8ab3c01d6b1 (patch) | |
| tree | 561e92b796629473d5754b1430d2954ad48754c0 /src | |
| parent | c4b7a25b3781dd6ac645fef5cf8e0262d077da26 (diff) | |
| download | openrc-8bb28cb0279f5cd93c0acbf36aa3f8ab3c01d6b1.tar.xz | |
librc: Move sysconf dir to ~/.config/openrc/...
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 <navi@vlhl.dev>
Diffstat (limited to 'src')
| -rw-r--r-- | src/librc/librc.c | 56 | ||||
| -rw-r--r-- | src/librc/rc.h.in | 2 | 
2 files changed, 44 insertions, 14 deletions
diff --git a/src/librc/librc.c b/src/librc/librc.c index b05483d9..598207cc 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -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)); @@ -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)); @@ -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;  } @@ -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;  } diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 1ffeba5a..d177ee4b 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -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"  | 
