diff options
author | Andrew J. Hesford <ajh@sideband.org> | 2022-02-14 14:25:22 -0500 |
---|---|---|
committer | Gerrit Pape <pape@smarden.org> | 2024-09-27 00:46:17 +0000 |
commit | a57a23bdd04c14600f82807ce96310a08ba90040 (patch) | |
tree | 9aad20b005b27c87443bccfe64fc8b7f34552c68 | |
parent | fc1d44f3f890ec219cdb87c1cd37ceb0360a165b (diff) | |
download | runit-a57a23bdd04c14600f82807ce96310a08ba90040.tar.gz runit-a57a23bdd04c14600f82807ce96310a08ba90040.tar.xz runit-a57a23bdd04c14600f82807ce96310a08ba90040.zip |
chpst: add -C to change working directory
-rw-r--r-- | man/chpst.8 | 8 | ||||
-rw-r--r-- | src/chpst.c | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/man/chpst.8 b/man/chpst.8 index 26c1a1d..57074d4 100644 --- a/man/chpst.8 +++ b/man/chpst.8 @@ -148,6 +148,14 @@ Change the root directory to before starting .IR prog . .TP +.B \-C \fIpwd +chdir. +Change the working directory to +.I pwd +before starting +.IR prog . +When combined with \-/, the working directory is changed after the chroot. +.TP .B \-n \fIinc nice. Add diff --git a/src/chpst.c b/src/chpst.c index d65e8fd..e46a054 100644 --- a/src/chpst.c +++ b/src/chpst.c @@ -20,7 +20,7 @@ #include "openreadclose.h" #include "direntry.h" -#define USAGE_MAIN " [-vVP012] [-u user[:group]] [-U user[:group]] [-b argv0] [-e dir] [-/ root] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] [-t n] prog" +#define USAGE_MAIN " [-vVP012] [-u user[:group]] [-U user[:group]] [-b argv0] [-e dir] [-/ root] [-C pwd] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] [-t n] prog" #define FATAL "chpst: fatal: " #define WARNING "chpst: warning: " @@ -60,6 +60,7 @@ long limitt =-2; long nicelvl =0; const char *lock =0; const char *root =0; +const char *pwd =0; unsigned int lockdelay; void suidgid(char *user, unsigned int ext) { @@ -286,7 +287,7 @@ int main(int argc, char **argv) { if (str_equal(progname, "setlock")) setlock(argc, argv); if (str_equal(progname, "softlimit")) softlimit(argc, argv); - while ((opt =getopt(argc, argv, "u:U:b:e:m:d:o:p:f:c:r:t:/:n:l:L:vP012V")) + while ((opt =getopt(argc, argv, "u:U:b:e:m:d:o:p:f:c:r:t:/:C:n:l:L:vP012V")) != opteof) switch(opt) { case 'u': set_user =(char*)optarg; break; @@ -305,6 +306,7 @@ int main(int argc, char **argv) { case 'r': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitr =ul; break; case 't': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitt =ul; break; case '/': root =optarg; break; + case 'C': pwd =optarg; break; case 'n': switch (*optarg) { case '-': @@ -337,6 +339,9 @@ int main(int argc, char **argv) { if (chdir(root) == -1) fatal2("unable to change directory", root); if (chroot(".") == -1) fatal("unable to change root directory"); } + if (pwd) { + if (chdir(pwd) == -1) fatal2("unable to change directory", pwd); + } if (nicelvl) { errno =0; if (nice(nicelvl) == -1) if (errno) fatal("unable to set nice level"); |