diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-06-15 18:31:13 -0300 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-10-19 10:56:54 +0200 |
commit | 95e77e9a0bac0827e8b8efdb9565063566d22587 (patch) | |
tree | afe29bfd5049d5b63487af35c144247164a217ca | |
parent | f3ad53c0ce8676a075af23b108f430a035d78270 (diff) |
openrc-run: in user mode, change to homedir instead of /
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
-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) { |