aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-21 22:40:57 +0200
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-21 22:40:57 +0200
commit53de57ec2ee0af70ba59ec5fa4d30fc8a9102e9b (patch)
treec1a292c7298230988a2b5f7beccd4f3568226716
parentfdb1d0d676039bc6bc034c933204ba46283acc69 (diff)
openrc-run: chdir into HOME for user services.
some services might expect to be in home, and may behave unexpectedly for the user, e.g. any program started via dbus, and this matches systemd-user behaviour. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
-rw-r--r--src/openrc-run/openrc-run.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/openrc-run/openrc-run.c b/src/openrc-run/openrc-run.c
index 54745bf1..421715df 100644
--- a/src/openrc-run/openrc-run.c
+++ b/src/openrc-run/openrc-run.c
@@ -1164,6 +1164,7 @@ int main(int argc, char **argv)
char *path = NULL;
char *dir, *save = NULL;
char *pidstr = NULL;
+ const char *working_dir = "/";
size_t l = 0, ll;
struct stat stbuf;
@@ -1252,8 +1253,12 @@ int main(int argc, char **argv)
if (argc < 2)
usage(EXIT_FAILURE);
- /* Change dir to / to ensure all init scripts don't use stuff in pwd */
- if (chdir("/") == -1)
+ /* Change dir to / to ensure all init scripts don't use stuff in pwd
+ * For user services, change to the user HOME instead. */
+ if (rc_is_user() && !(working_dir = getenv("HOME")))
+ eerrorx("HOME unset in user mode.");
+
+ if (chdir(working_dir) == -1)
eerror("chdir: %s", strerror(errno));
if ((runlevel = xstrdup(getenv("RC_RUNLEVEL"))) == NULL) {