2020#include "openreadclose.h"
2121#include "direntry.h"
2222
23- #define USAGE_MAIN " [-vP012] [-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] prog"
23+ #define USAGE_MAIN " [-vP012] [-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] prog"
2424#define FATAL "chpst: fatal: "
2525#define WARNING "chpst: warning: "
2626
@@ -60,6 +60,7 @@ long limitt =-2;
6060long nicelvl = 0 ;
6161const char * lock = 0 ;
6262const char * root = 0 ;
63+ const char * pwd = 0 ;
6364unsigned int lockdelay ;
6465
6566void suidgid (char * user , unsigned int ext ) {
@@ -286,7 +287,7 @@ int main(int argc, const char **argv) {
286287 if (str_equal (progname , "setlock" )) setlock (argc , argv );
287288 if (str_equal (progname , "softlimit" )) softlimit (argc , argv );
288289
289- while ((opt = getopt (argc , argv , "u:U:b:e:m:d:o:p:f:c:r:t:/:n:l:L:vP012V" ))
290+ while ((opt = getopt (argc , argv , "u:U:b:e:m:d:o:p:f:c:r:t:/:C: n:l:L:vP012V" ))
290291 != opteof )
291292 switch (opt ) {
292293 case 'u' : set_user = (char * )optarg ; break ;
@@ -305,6 +306,7 @@ int main(int argc, const char **argv) {
305306 case 'r' : if (optarg [scan_ulong (optarg , & ul )]) usage (); limitr = ul ; break ;
306307 case 't' : if (optarg [scan_ulong (optarg , & ul )]) usage (); limitt = ul ; break ;
307308 case '/' : root = optarg ; break ;
309+ case 'C' : pwd = optarg ; break ;
308310 case 'n' :
309311 switch (* optarg ) {
310312 case '-' :
@@ -337,6 +339,9 @@ int main(int argc, const char **argv) {
337339 if (chdir (root ) == -1 ) fatal2 ("unable to change directory" , root );
338340 if (chroot ("." ) == -1 ) fatal ("unable to change root directory" );
339341 }
342+ if (pwd ) {
343+ if (chdir (pwd ) == -1 ) fatal2 ("unable to change directory" , pwd );
344+ }
340345 if (nicelvl ) {
341346 errno = 0 ;
342347 if (nice (nicelvl ) == -1 ) if (errno ) fatal ("unable to set nice level" );
0 commit comments