From 5a1cd9545164d978ded996ac6d673fd6d480a2fe Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Fri, 9 Jun 2023 20:46:47 -0300 Subject: openrc: rework pathing functions this simplifies the allocation of path string. also fixes some memory leaks from the ealier commit also changes the log path for users to XDG_CACHE_HOME, default ~/.cache/openrc Signed-off-by: Anna (navi) Figueiredo Gomes --- src/shared/misc.c | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) (limited to 'src/shared') diff --git a/src/shared/misc.c b/src/shared/misc.c index 9b40ce36..fbb50b59 100644 --- a/src/shared/misc.c +++ b/src/shared/misc.c @@ -259,21 +259,11 @@ svc_lock(const char *applet, bool ignore_lock_failure) { char *file = NULL; int fd; - char *svcdir = RC_SVCDIR; - -#ifdef RC_USER_SERVICES - if (rc_is_user()) { - svcdir = rc_user_svcdir(); - } -#endif + char *svcdir = rc_svcdir(); xasprintf(&file, "%s/exclusive/%s", svcdir, applet); -#ifdef RC_USER_SERVICES - if (rc_is_user()) { - free(svcdir); - } -#endif + free(svcdir); fd = open(file, O_WRONLY | O_CREAT | O_NONBLOCK, 0664); free(file); @@ -299,21 +289,11 @@ int svc_unlock(const char *applet, int fd) { char *file = NULL; - char *svcdir = RC_SVCDIR; - -#ifdef RC_USER_SERVICES - if (rc_is_user()) { - svcdir = rc_user_svcdir(); - } -#endif + char *svcdir = rc_svcdir(); xasprintf(&file, "%s/exclusive/%s", svcdir, applet); -#ifdef RC_USER_SERVICES - if (rc_is_user()) { - free(svcdir); - } -#endif + free(svcdir); close(fd); unlink(file); @@ -425,17 +405,14 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen) struct stat st; struct utimbuf ut; FILE *fp; - char *cache = RC_DEPTREE_CACHE; - char *skew = RC_DEPTREE_SKEWED; -#ifdef RC_USER_SERVICES - char *user_svcdir; - if (rc_is_user()) { - user_svcdir = rc_user_svcdir(); - xasprintf(&cache, "%s%s", user_svcdir, RC_DEPTREE_CACHE_FILE); - xasprintf(&skew, "%s%s", user_svcdir, RC_DEPTREE_SKEWED_FILE); - free(user_svcdir); - } -#endif + char *cache = NULL; + char *skew = NULL; + char *svcdir = rc_svcdir(); + + xasprintf(&cache, "%s%s", svcdir, RC_DEPTREE_CACHE_FILE); + xasprintf(&skew, "%s%s", svcdir, RC_DEPTREE_SKEWED_FILE); + + free(svcdir); t = 0; if (rc_deptree_update_needed(&t, file) || force != 0) { -- cgit v1.2.3