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.

Signed-off-by: Anna (navi) Figueiredo Gomes <[email protected]>
  • Loading branch information
navi-desu committed Jul 24, 2024
1 parent c4b1634 commit c26bc8a
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 @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c26bc8a

Please sign in to comment.