aboutsummaryrefslogtreecommitdiff
path: root/src/openrc/rc-logger.c
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-06-09 20:46:47 -0300
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-10-19 10:56:54 +0200
commit5a1cd9545164d978ded996ac6d673fd6d480a2fe (patch)
tree1002f7bdfb5b823aa8cdbe4502ebcb61bba97e7e /src/openrc/rc-logger.c
parentb8613baa85965cbdf5fbe262b9464d5c0d98614f (diff)
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 <navi@vlhl.dev>
Diffstat (limited to 'src/openrc/rc-logger.c')
-rw-r--r--src/openrc/rc-logger.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/openrc/rc-logger.c b/src/openrc/rc-logger.c
index ae1a9666..005b20c5 100644
--- a/src/openrc/rc-logger.c
+++ b/src/openrc/rc-logger.c
@@ -148,12 +148,10 @@ rc_logger_open(const char *level)
FILE *plog = NULL;
const char *logfile;
int log_error = 0;
- char *tmplog = TMPLOG;
- char *defaultlog = DEFAULTLOG;
-#ifdef RC_USER_SERVICES
- char *user_svcdir;
- char *user_datadir;
-#endif
+ char *tmplog = NULL;
+ char *defaultlog = NULL;
+ char *svcdir;
+ char *cachedir;
if (!rc_conf_yesno("rc_logger"))
return;
@@ -180,17 +178,17 @@ rc_logger_open(const char *level)
if ((s = fcntl(slave_tty, F_GETFD, 0)) == 0)
fcntl(slave_tty, F_SETFD, s | FD_CLOEXEC);
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- user_svcdir = rc_user_svcdir();
- xasprintf(&tmplog, "%s/%s", user_svcdir, LOGFILE);
- free(user_svcdir);
+ svcdir = rc_svcdir();
+ xasprintf(&tmplog, "%s/%s", svcdir, LOGFILE);
+ free(svcdir);
- user_datadir = rc_user_datadir();
- xasprintf(&defaultlog, "%s/%s", user_datadir, LOGFILE);
- free(user_datadir);
- }
-#endif
+ cachedir = rc_cachedir();
+ if (cachedir)
+ xasprintf(&defaultlog, "%s/%s", cachedir, LOGFILE);
+ else
+ defaultlog = xstrdup(DEFAULTLOG);
+
+ free(cachedir);
rc_logger_pid = fork();
switch (rc_logger_pid) {
@@ -331,11 +329,7 @@ rc_logger_open(const char *level)
break;
}
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- free(tmplog);
- free(defaultlog);
- }
-#endif
+ free(tmplog);
+ free(defaultlog);
}