diff options
-rw-r--r-- | src/librc/librc.c | 2 | ||||
-rw-r--r-- | src/librc/rc.h.in | 2 | ||||
-rw-r--r-- | src/openrc-run/openrc-run.c | 9 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/librc/librc.c b/src/librc/librc.c index 0a42e2c0..58219b40 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -454,7 +454,7 @@ rc_set_user(void) free(path); } -static const char * +const char * rc_user_home(void) { struct passwd *user_passwd; diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index f35c9110..8b1c705a 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -66,6 +66,8 @@ extern "C" { bool rc_is_user(void); void rc_set_user(void); + +const char *rc_user_home(void); #endif #define RC_PATH_PREFIX RC_LIBEXECDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin" diff --git a/src/openrc-run/openrc-run.c b/src/openrc-run/openrc-run.c index ac2b498f..daece676 100644 --- a/src/openrc-run/openrc-run.c +++ b/src/openrc-run/openrc-run.c @@ -1123,6 +1123,7 @@ int main(int argc, char **argv) char *pidstr = NULL; size_t l = 0, ll; const char *file; + const char *changedir = "/"; struct stat stbuf; /* Show help if insufficient args */ @@ -1183,8 +1184,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 + * In user scripts mode, we change to the homefolder of the user instead */ + if (rc_is_user()) + changedir = rc_user_home(); + + if (chdir(changedir) == -1) eerror("chdir: %s", strerror(errno)); if ((runlevel = xstrdup(getenv("RC_RUNLEVEL"))) == NULL) { |