diff options
author | ejaaskel <esa.jaaskela@suomi24.fi> | 2023-11-07 07:12:40 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-11-07 07:12:40 +0100 |
commit | 73f28134fc0987474384fde345559d4b34bf5385 (patch) | |
tree | d3439e5c69e79c940bfac38a773d24d9d1b78183 /debianutils | |
parent | 0c71497e654fb5e9a9272f81ddb5d994d2839df4 (diff) | |
download | busybox-w32-73f28134fc0987474384fde345559d4b34bf5385.tar.gz busybox-w32-73f28134fc0987474384fde345559d4b34bf5385.tar.bz2 busybox-w32-73f28134fc0987474384fde345559d4b34bf5385.zip |
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 16df67b3e..750167349 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -11,7 +11,7 @@ | |||
11 | /* | 11 | /* |
12 | This is how it is supposed to work: | 12 | This is how it is supposed to work: |
13 | 13 | ||
14 | start-stop-daemon [OPTIONS] [--start|--stop] [[--] ARGS...] | 14 | start-stop-daemon [OPTIONS] [--start|--stop] [[--] ARGS] |
15 | 15 | ||
16 | One (only) of these must be given: | 16 | One (only) of these must be given: |
17 | -S,--start Start | 17 | -S,--start Start |
@@ -58,13 +58,14 @@ Options which are valid for --start only: | |||
58 | priority can be optionally specified by appending a : | 58 | priority can be optionally specified by appending a : |
59 | followed by the value. The default priority is 0. The | 59 | followed by the value. The default priority is 0. The |
60 | currently supported policy values are other, fifo and rr. | 60 | currently supported policy values are other, fifo and rr. |
61 | -r,--chroot root Change directory and chroot to root before starting the | 61 | -r,--chroot DIR Change directory and chroot to DIR before starting the |
62 | process. Please note that the pidfile is also written after | 62 | process. Please note that the pidfile is also written after |
63 | the chroot. | 63 | the chroot. |
64 | -d,--chdir path Change directory to path before starting the process. This is | 64 | -d,--chdir DIR Change directory to DIR before starting the process. This is |
65 | done after the chroot if the -r|--chroot option is set. When | 65 | done after the chroot if the -r|--chroot option is set. |
66 | not specified, start-stop-daemon will change directory to the | 66 | When not specified, start-stop-daemon will change directory to the |
67 | root directory before starting the process. | 67 | root directory before starting the process. |
68 | ^^^^ Seems to be false, no default "/" chdir is done. | ||
68 | 69 | ||
69 | Options which are valid for --stop only: | 70 | Options which are valid for --stop only: |
70 | -s,--signal SIG Signal to send (default:TERM) | 71 | -s,--signal SIG Signal to send (default:TERM) |
@@ -106,7 +107,7 @@ Misc options: | |||
106 | //kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o | 107 | //kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o |
107 | 108 | ||
108 | //usage:#define start_stop_daemon_trivial_usage | 109 | //usage:#define start_stop_daemon_trivial_usage |
109 | //usage: "-S|-K [OPTIONS] [-- ARGS...]" | 110 | //usage: "-S|-K [OPTIONS] [-- ARGS]" |
110 | //usage:#define start_stop_daemon_full_usage "\n\n" | 111 | //usage:#define start_stop_daemon_full_usage "\n\n" |
111 | //usage: "Search for matching processes, and then\n" | 112 | //usage: "Search for matching processes, and then\n" |
112 | //usage: "-S: start a process unless a matching process is found\n" | 113 | //usage: "-S: start a process unless a matching process is found\n" |
@@ -127,6 +128,7 @@ Misc options: | |||
127 | //usage: "\n -N N Change nice level" | 128 | //usage: "\n -N N Change nice level" |
128 | //usage: ) | 129 | //usage: ) |
129 | //usage: "\n -c USER[:[GRP]] Change user/group" | 130 | //usage: "\n -c USER[:[GRP]] Change user/group" |
131 | //usage: "\n -d DIR Change to DIR" | ||
130 | //usage: "\n -m Write PID to pidfile specified by -p" | 132 | //usage: "\n -m Write PID to pidfile specified by -p" |
131 | //usage: "\n-K only:" | 133 | //usage: "\n-K only:" |
132 | //usage: "\n -s SIG Signal to send" | 134 | //usage: "\n -s SIG Signal to send" |
@@ -160,11 +162,12 @@ enum { | |||
160 | OPT_s = (1 << 8), // -s | 162 | OPT_s = (1 << 8), // -s |
161 | OPT_u = (1 << 9), // -u | 163 | OPT_u = (1 << 9), // -u |
162 | OPT_c = (1 << 10), // -c | 164 | OPT_c = (1 << 10), // -c |
163 | OPT_x = (1 << 11), // -x | 165 | OPT_d = (1 << 11), // -d |
164 | OPT_p = (1 << 12), // -p | 166 | OPT_x = (1 << 12), // -x |
165 | OPT_OKNODO = (1 << 13) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o | 167 | OPT_p = (1 << 13), // -p |
166 | OPT_VERBOSE = (1 << 14) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v | 168 | OPT_OKNODO = (1 << 14) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o |
167 | OPT_NICELEVEL = (1 << 15) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N | 169 | OPT_VERBOSE = (1 << 15) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v |
170 | OPT_NICELEVEL = (1 << 16) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N | ||
168 | }; | 171 | }; |
169 | #define QUIET (option_mask32 & OPT_QUIET) | 172 | #define QUIET (option_mask32 & OPT_QUIET) |
170 | #define TEST (option_mask32 & OPT_TEST) | 173 | #define TEST (option_mask32 & OPT_TEST) |
@@ -413,6 +416,7 @@ static const char start_stop_daemon_longopts[] ALIGN1 = | |||
413 | "signal\0" Required_argument "s" | 416 | "signal\0" Required_argument "s" |
414 | "user\0" Required_argument "u" | 417 | "user\0" Required_argument "u" |
415 | "chuid\0" Required_argument "c" | 418 | "chuid\0" Required_argument "c" |
419 | "chdir\0" Required_argument "d" | ||
416 | "exec\0" Required_argument "x" | 420 | "exec\0" Required_argument "x" |
417 | "pidfile\0" Required_argument "p" | 421 | "pidfile\0" Required_argument "p" |
418 | # if ENABLE_FEATURE_START_STOP_DAEMON_FANCY | 422 | # if ENABLE_FEATURE_START_STOP_DAEMON_FANCY |
@@ -433,6 +437,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
433 | char *signame; | 437 | char *signame; |
434 | char *startas = NULL; | 438 | char *startas = NULL; |
435 | char *chuid; | 439 | char *chuid; |
440 | char *chdir; | ||
436 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY | 441 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY |
437 | // char *retry_arg = NULL; | 442 | // char *retry_arg = NULL; |
438 | // int retries = -1; | 443 | // int retries = -1; |
@@ -442,7 +447,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
442 | INIT_G(); | 447 | INIT_G(); |
443 | 448 | ||
444 | opt = GETOPT32(argv, "^" | 449 | opt = GETOPT32(argv, "^" |
445 | "KSbqtma:n:s:u:c:x:p:" | 450 | "KSbqtma:n:s:u:c:d:x:p:" |
446 | IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:") | 451 | IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:") |
447 | "\0" | 452 | "\0" |
448 | "K:S:K--S:S--K" | 453 | "K:S:K--S:S--K" |
@@ -458,7 +463,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
458 | IF_FEATURE_START_STOP_DAEMON_FANCY(":q-v") /* -q turns off -v */ | 463 | IF_FEATURE_START_STOP_DAEMON_FANCY(":q-v") /* -q turns off -v */ |
459 | , | 464 | , |
460 | LONGOPTS | 465 | LONGOPTS |
461 | &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile | 466 | &startas, &cmdname, &signame, &userspec, &chuid, &chdir, &execname, &pidfile |
462 | IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) | 467 | IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) |
463 | /* We accept and ignore -R <param> / --retry <param> */ | 468 | /* We accept and ignore -R <param> / --retry <param> */ |
464 | IF_FEATURE_START_STOP_DAEMON_FANCY(,NULL) | 469 | IF_FEATURE_START_STOP_DAEMON_FANCY(,NULL) |
@@ -586,6 +591,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
586 | setgroups(1, &ugid.gid); | 591 | setgroups(1, &ugid.gid); |
587 | } | 592 | } |
588 | } | 593 | } |
594 | if (opt & OPT_d) { | ||
595 | xchdir(chdir); | ||
596 | } | ||
589 | /* Try: | 597 | /* Try: |
590 | * strace -oLOG start-stop-daemon -S -x /bin/usleep -a qwerty 500000 | 598 | * strace -oLOG start-stop-daemon -S -x /bin/usleep -a qwerty 500000 |
591 | * should exec "/bin/usleep", but argv[0] should be "qwerty": | 599 | * should exec "/bin/usleep", but argv[0] should be "qwerty": |