diff options
author | ejaaskel | 2023-11-07 07:12:40 +0100 |
---|---|---|
committer | Denys Vlasenko | 2023-11-07 07:12:40 +0100 |
commit | 73f28134fc0987474384fde345559d4b34bf5385 (patch) | |
tree | d3439e5c69e79c940bfac38a773d24d9d1b78183 /debianutils | |
parent | 0c71497e654fb5e9a9272f81ddb5d994d2839df4 (diff) | |
download | busybox-73f28134fc0987474384fde345559d4b34bf5385.zip busybox-73f28134fc0987474384fde345559d4b34bf5385.tar.gz |
start-stop-daemon: add -d DIR chdir option
Add option to change the running directory before starting the process.
This can be done using -d or --chdir options. Add also test cases to
start-stop-daemon to test out the directory change option.
function old new delta
packed_usage 34602 34648 +46
start_stop_daemon_main 1107 1130 +23
start_stop_daemon_longopts 156 164 +8
.rodata 105382 105384 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 79/0) Total: 79 bytes
Signed-off-by: ejaaskel <esa.jaaskela@suomi24.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/start_stop_daemon.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 16df67b..7501673 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -11,7 +11,7 @@ /* This is how it is supposed to work: -start-stop-daemon [OPTIONS] [--start|--stop] [[--] ARGS...] +start-stop-daemon [OPTIONS] [--start|--stop] [[--] ARGS] One (only) of these must be given: -S,--start Start @@ -58,13 +58,14 @@ Options which are valid for --start only: priority can be optionally specified by appending a : followed by the value. The default priority is 0. The currently supported policy values are other, fifo and rr. - -r,--chroot root Change directory and chroot to root before starting the + -r,--chroot DIR Change directory and chroot to DIR before starting the process. Please note that the pidfile is also written after the chroot. - -d,--chdir path Change directory to path before starting the process. This is - done after the chroot if the -r|--chroot option is set. When - not specified, start-stop-daemon will change directory to the + -d,--chdir DIR Change directory to DIR before starting the process. This is + done after the chroot if the -r|--chroot option is set. + When not specified, start-stop-daemon will change directory to the root directory before starting the process. + ^^^^ Seems to be false, no default "/" chdir is done. Options which are valid for --stop only: -s,--signal SIG Signal to send (default:TERM) @@ -106,7 +107,7 @@ Misc options: //kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o //usage:#define start_stop_daemon_trivial_usage -//usage: "-S|-K [OPTIONS] [-- ARGS...]" +//usage: "-S|-K [OPTIONS] [-- ARGS]" //usage:#define start_stop_daemon_full_usage "\n\n" //usage: "Search for matching processes, and then\n" //usage: "-S: start a process unless a matching process is found\n" @@ -127,6 +128,7 @@ Misc options: //usage: "\n -N N Change nice level" //usage: ) //usage: "\n -c USER[:[GRP]] Change user/group" +//usage: "\n -d DIR Change to DIR" //usage: "\n -m Write PID to pidfile specified by -p" //usage: "\n-K only:" //usage: "\n -s SIG Signal to send" @@ -160,11 +162,12 @@ enum { OPT_s = (1 << 8), // -s OPT_u = (1 << 9), // -u OPT_c = (1 << 10), // -c - OPT_x = (1 << 11), // -x - OPT_p = (1 << 12), // -p - OPT_OKNODO = (1 << 13) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o - OPT_VERBOSE = (1 << 14) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v - OPT_NICELEVEL = (1 << 15) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N + OPT_d = (1 << 11), // -d + OPT_x = (1 << 12), // -x + OPT_p = (1 << 13), // -p + OPT_OKNODO = (1 << 14) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o + OPT_VERBOSE = (1 << 15) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v + OPT_NICELEVEL = (1 << 16) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N }; #define QUIET (option_mask32 & OPT_QUIET) #define TEST (option_mask32 & OPT_TEST) @@ -413,6 +416,7 @@ static const char start_stop_daemon_longopts[] ALIGN1 = "signal\0" Required_argument "s" "user\0" Required_argument "u" "chuid\0" Required_argument "c" + "chdir\0" Required_argument "d" "exec\0" Required_argument "x" "pidfile\0" Required_argument "p" # if ENABLE_FEATURE_START_STOP_DAEMON_FANCY @@ -433,6 +437,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) char *signame; char *startas = NULL; char *chuid; + char *chdir; #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY // char *retry_arg = NULL; // int retries = -1; @@ -442,7 +447,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) INIT_G(); opt = GETOPT32(argv, "^" - "KSbqtma:n:s:u:c:x:p:" + "KSbqtma:n:s:u:c:d:x:p:" IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:") "\0" "K:S:K--S:S--K" @@ -458,7 +463,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_START_STOP_DAEMON_FANCY(":q-v") /* -q turns off -v */ , LONGOPTS - &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile + &startas, &cmdname, &signame, &userspec, &chuid, &chdir, &execname, &pidfile IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) /* We accept and ignore -R <param> / --retry <param> */ IF_FEATURE_START_STOP_DAEMON_FANCY(,NULL) @@ -586,6 +591,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) setgroups(1, &ugid.gid); } } + if (opt & OPT_d) { + xchdir(chdir); + } /* Try: * strace -oLOG start-stop-daemon -S -x /bin/usleep -a qwerty 500000 * should exec "/bin/usleep", but argv[0] should be "qwerty": |