aboutsummaryrefslogtreecommitdiff
path: root/src/openrc
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
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')
-rw-r--r--src/openrc/rc-logger.c38
-rw-r--r--src/openrc/rc.c100
2 files changed, 48 insertions, 90 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);
}
diff --git a/src/openrc/rc.c b/src/openrc/rc.c
index 366ceca2..819f6d73 100644
--- a/src/openrc/rc.c
+++ b/src/openrc/rc.c
@@ -108,13 +108,9 @@ clean_failed(void)
DIR *dp;
struct dirent *d;
char *path;
- char *svcdir = RC_SVCDIR;
+ char *svcdir = rc_svcdir();
char *failed_path;
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- svcdir = rc_user_svcdir();
- }
-#endif
+
xasprintf(&failed_path, "%s/%s", svcdir, "/failed");
/* Clean the failed services state dir now */
@@ -134,23 +130,16 @@ clean_failed(void)
closedir(dp);
}
free(failed_path);
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- free(svcdir);
- }
-#endif
+ free(svcdir);
}
static void
cleanup(void)
{
RC_PID *p, *tmp;
- char *rc_starting = RC_STARTING;
- char *rc_stopping = RC_STOPPING;
-
-#ifdef RC_USER_SERVICES
- char *user_svcdir;
-#endif
+ char *rc_starting = NULL;
+ char *rc_stopping = NULL;
+ char *svcdir = rc_svcdir();
if (!rc_in_logger && !rc_in_plugin &&
applet && (strcmp(applet, "rc") == 0 || strcmp(applet, "openrc") == 0))
@@ -165,14 +154,10 @@ cleanup(void)
free(termios_orig);
}
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- user_svcdir = rc_user_svcdir();
- xasprintf(&rc_starting, "%s/%s", user_svcdir, RC_STARTING_FOLDER);
- xasprintf(&rc_stopping, "%s/%s", user_svcdir, RC_STOPPING_FOLDER);
- free(user_svcdir);
- }
-#endif
+ xasprintf(&rc_starting, "%s/%s", svcdir, RC_STARTING_FOLDER);
+ xasprintf(&rc_stopping, "%s/%s", svcdir, RC_STOPPING_FOLDER);
+
+ free(svcdir);
/* Clean runlevel start, stop markers */
rmdir(rc_starting);
@@ -180,12 +165,8 @@ cleanup(void)
clean_failed();
rc_logger_close();
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- free(rc_starting);
- free(rc_stopping);
- }
-#endif
+ free(rc_starting);
+ free(rc_stopping);
}
LIST_FOREACH_SAFE(p, &service_pids, entries, tmp) {
@@ -261,23 +242,15 @@ static void
mark_interactive(void)
{
FILE *fp;
- char *interactive_path = INTERACTIVE;
-#ifdef RC_USER_SERVICES
- char *svcdir;
- if (rc_is_user()) {
- svcdir = rc_user_svcdir();
- xasprintf(&interactive_path, "%s/%s", svcdir, INTERACTIVE_FILE);
- free(svcdir);
- }
-#endif
+ char *interactive_path = NULL;
+ char *svcdir = rc_svcdir();
+ xasprintf(&interactive_path, "%s/%s", svcdir, INTERACTIVE_FILE);
+ free(svcdir);
+
fp = fopen(interactive_path, "w");
if (fp)
fclose(fp);
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- free(interactive_path);
- }
-#endif
+ free(interactive_path);
}
static void
@@ -713,15 +686,10 @@ do_start_services(const RC_STRINGLIST *start_services, bool parallel)
bool interactive = false;
RC_SERVICE state;
bool crashed = false;
- char *interactive_path = INTERACTIVE;
-#ifdef RC_USER_SERVICES
- char *svcdir;
- if (rc_is_user()) {
- svcdir = rc_user_svcdir();
- xasprintf(&interactive_path, "%s/%s", svcdir, INTERACTIVE_FILE);
- free(svcdir);
- }
-#endif
+ char *interactive_path = NULL;
+ char *svcdir = rc_svcdir();
+ xasprintf(&interactive_path, "%s/%s", svcdir, INTERACTIVE_FILE);
+ free(svcdir);
if (!rc_yesno(getenv("EINFO_QUIET")))
interactive = exists(interactive_path);
@@ -787,11 +755,7 @@ do_start_services(const RC_STRINGLIST *start_services, bool parallel)
unlink(interactive_path);
}
-#ifdef RC_USER_SERVICES
- if (rc_is_user()) {
- free(interactive_path);
- }
-#endif
+ free(interactive_path);
}
#ifdef RC_DEBUG
@@ -833,7 +797,7 @@ inc_dec_lockfile(int val)
einfov("locking lockfile");
- svcdir = rc_user_svcdir();
+ svcdir = rc_svcdir();
if (mkdir(svcdir, 0700) != 0 && errno != EEXIST)
eerrorx("mkdir: %s, %s", svcdir, strerror(errno));
@@ -886,14 +850,14 @@ int main(int argc, char **argv)
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
char *krunlevel = NULL;
char *pidstr = NULL;
- char *rc_starting = RC_STARTING;
- char *rc_stopping = RC_STOPPING;
+ char *rc_starting = NULL;
+ char *rc_stopping = NULL;
int opt;
bool parallel;
int regen = 0;
bool nostop = false;
+ char *svcdir = NULL;
#ifdef RC_USER_SERVICES
- char *user_svcdir = NULL;
int locknum = 0;
#endif
#ifdef __linux__
@@ -1012,14 +976,14 @@ int main(int argc, char **argv)
einfov("lock set, skipping");
return EXIT_SUCCESS;
}
-
- user_svcdir = rc_user_svcdir();
- xasprintf(&rc_stopping, "%s/%s", user_svcdir, RC_STOPPING_FOLDER);
- xasprintf(&rc_starting, "%s/%s", user_svcdir, RC_STARTING_FOLDER);
- free(user_svcdir);
}
#endif
+ svcdir = rc_svcdir();
+ xasprintf(&rc_stopping, "%s/%s", svcdir, RC_STOPPING_FOLDER);
+ xasprintf(&rc_starting, "%s/%s", svcdir, RC_STARTING_FOLDER);
+ free(svcdir);
+
/* Create a list of all services which should be started for the new or
* current runlevel including those in boot, sysinit and hotplugged
* runlevels. Clearly, some of these will already be started so we