Skip to content

Commit

Permalink
openrc-run: Chdir into HOME for user services.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
navi-desu committed Oct 28, 2024
1 parent 74e9f17 commit 6d32d9d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/openrc-run/openrc-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ int main(int argc, char **argv)
char *path = NULL;
char *lnk = NULL;
char *dir, *save = NULL, *saveLnk = NULL;
const char *workingdir = "/";
char *pidstr = NULL;
size_t l = 0, ll;
const char *file;
Expand Down Expand Up @@ -1160,8 +1161,12 @@ int main(int argc, char **argv)
if (argc < 3)
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's HOME instead. */
if (rc_is_user() && !(workingdir = getenv("HOME")))
eerrorx("HOME is unset.");

if (chdir(workingdir) == -1)
eerror("chdir: %s", strerror(errno));

if ((runlevel = xstrdup(getenv("RC_RUNLEVEL"))) == NULL) {
Expand Down

0 comments on commit 6d32d9d

Please sign in to comment.