diff options
| author | Ron Yorston <rmy@pobox.com> | 2017-08-22 14:56:12 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2017-08-22 14:56:12 +0100 |
| commit | ce9af1cc5ea23f754587448cf35b5120c77bfeef (patch) | |
| tree | 69e5eaba5e75ab909ed92d5045393471b8ff3c13 /debianutils | |
| parent | c170026700eabb10147dd848c45c06995b43a32e (diff) | |
| parent | e837a0dbbebf4229306df98fe9ee3b9bb30630c4 (diff) | |
| download | busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.gz busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.bz2 busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/run_parts.c | 17 | ||||
| -rw-r--r-- | debianutils/start_stop_daemon.c | 94 | ||||
| -rw-r--r-- | debianutils/which.c | 7 |
3 files changed, 49 insertions, 69 deletions
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index c6a90a486..e4d61df35 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
| @@ -159,10 +159,15 @@ static const char runparts_longopts[] ALIGN1 = | |||
| 159 | "reverse\0" No_argument "\xf0" | 159 | "reverse\0" No_argument "\xf0" |
| 160 | "test\0" No_argument "\xf1" | 160 | "test\0" No_argument "\xf1" |
| 161 | "exit-on-error\0" No_argument "\xf2" | 161 | "exit-on-error\0" No_argument "\xf2" |
| 162 | #if ENABLE_FEATURE_RUN_PARTS_FANCY | 162 | # if ENABLE_FEATURE_RUN_PARTS_FANCY |
| 163 | "list\0" No_argument "\xf3" | 163 | "list\0" No_argument "\xf3" |
| 164 | #endif | 164 | # endif |
| 165 | ; | 165 | ; |
| 166 | # define GETOPT32 getopt32long | ||
| 167 | # define LONGOPTS ,runparts_longopts | ||
| 168 | #else | ||
| 169 | # define GETOPT32 getopt32 | ||
| 170 | # define LONGOPTS | ||
| 166 | #endif | 171 | #endif |
| 167 | 172 | ||
| 168 | int run_parts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 173 | int run_parts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| @@ -175,12 +180,10 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv) | |||
| 175 | 180 | ||
| 176 | INIT_G(); | 181 | INIT_G(); |
| 177 | 182 | ||
| 178 | #if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS | ||
| 179 | applet_long_options = runparts_longopts; | ||
| 180 | #endif | ||
| 181 | /* We require exactly one argument: the directory name */ | 183 | /* We require exactly one argument: the directory name */ |
| 182 | opt_complementary = "=1"; | 184 | GETOPT32(argv, "^" "a:*u:" "\0" "=1" LONGOPTS, |
| 183 | getopt32(argv, "a:*u:", &arg_list, &umask_p); | 185 | &arg_list, &umask_p |
| 186 | ); | ||
| 184 | 187 | ||
| 185 | umask(xstrtou_range(umask_p, 8, 0, 07777)); | 188 | umask(xstrtou_range(umask_p, 8, 0, 07777)); |
| 186 | 189 | ||
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 9d60b2c7f..c8b7fa8f2 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
| @@ -79,6 +79,7 @@ Misc options: | |||
| 79 | //config: -N|--nicelevel N | 79 | //config: -N|--nicelevel N |
| 80 | 80 | ||
| 81 | //applet:IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon)) | 81 | //applet:IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon)) |
| 82 | /* not NOEXEC: uses bb_common_bufsiz1 */ | ||
| 82 | 83 | ||
| 83 | //kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o | 84 | //kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o |
| 84 | 85 | ||
| @@ -86,44 +87,15 @@ Misc options: | |||
| 86 | //usage: "[OPTIONS] [-S|-K] ... [-- ARGS...]" | 87 | //usage: "[OPTIONS] [-S|-K] ... [-- ARGS...]" |
| 87 | //usage:#define start_stop_daemon_full_usage "\n\n" | 88 | //usage:#define start_stop_daemon_full_usage "\n\n" |
| 88 | //usage: "Search for matching processes, and then\n" | 89 | //usage: "Search for matching processes, and then\n" |
| 89 | //usage: "-K: stop all matching processes.\n" | 90 | //usage: "-K: stop all matching processes\n" |
| 90 | //usage: "-S: start a process unless a matching process is found.\n" | 91 | //usage: "-S: start a process unless a matching process is found\n" |
| 91 | //usage: IF_FEATURE_START_STOP_DAEMON_LONG_OPTIONS( | ||
| 92 | //usage: "\nProcess matching:" | ||
| 93 | //usage: "\n -u,--user USERNAME|UID Match only this user's processes" | ||
| 94 | //usage: "\n -n,--name NAME Match processes with NAME" | ||
| 95 | //usage: "\n in comm field in /proc/PID/stat" | ||
| 96 | //usage: "\n -x,--exec EXECUTABLE Match processes with this command" | ||
| 97 | //usage: "\n in /proc/PID/{exe,cmdline}" | ||
| 98 | //usage: "\n -p,--pidfile FILE Match a process with PID from the file" | ||
| 99 | //usage: "\n All specified conditions must match" | ||
| 100 | //usage: "\n-S only:" | ||
| 101 | //usage: "\n -x,--exec EXECUTABLE Program to run" | ||
| 102 | //usage: "\n -a,--startas NAME Zeroth argument" | ||
| 103 | //usage: "\n -b,--background Background" | ||
| 104 | //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( | ||
| 105 | //usage: "\n -N,--nicelevel N Change nice level" | ||
| 106 | //usage: ) | ||
| 107 | //usage: "\n -c,--chuid USER[:[GRP]] Change to user/group" | ||
| 108 | //usage: "\n -m,--make-pidfile Write PID to the pidfile specified by -p" | ||
| 109 | //usage: "\n-K only:" | ||
| 110 | //usage: "\n -s,--signal SIG Signal to send" | ||
| 111 | //usage: "\n -t,--test Match only, exit with 0 if a process is found" | ||
| 112 | //usage: "\nOther:" | ||
| 113 | //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( | ||
| 114 | //usage: "\n -o,--oknodo Exit with status 0 if nothing is done" | ||
| 115 | //usage: "\n -v,--verbose Verbose" | ||
| 116 | //usage: ) | ||
| 117 | //usage: "\n -q,--quiet Quiet" | ||
| 118 | //usage: ) | ||
| 119 | //usage: IF_NOT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS( | ||
| 120 | //usage: "\nProcess matching:" | 92 | //usage: "\nProcess matching:" |
| 121 | //usage: "\n -u USERNAME|UID Match only this user's processes" | 93 | //usage: "\n -u USERNAME|UID Match only this user's processes" |
| 122 | //usage: "\n -n NAME Match processes with NAME" | 94 | //usage: "\n -n NAME Match processes with NAME" |
| 123 | //usage: "\n in comm field in /proc/PID/stat" | 95 | //usage: "\n in comm field in /proc/PID/stat" |
| 124 | //usage: "\n -x EXECUTABLE Match processes with this command" | 96 | //usage: "\n -x EXECUTABLE Match processes with this command" |
| 125 | //usage: "\n command in /proc/PID/cmdline" | 97 | //usage: "\n command in /proc/PID/cmdline" |
| 126 | //usage: "\n -p FILE Match a process with PID from the file" | 98 | //usage: "\n -p FILE Match a process with PID from FILE" |
| 127 | //usage: "\n All specified conditions must match" | 99 | //usage: "\n All specified conditions must match" |
| 128 | //usage: "\n-S only:" | 100 | //usage: "\n-S only:" |
| 129 | //usage: "\n -x EXECUTABLE Program to run" | 101 | //usage: "\n -x EXECUTABLE Program to run" |
| @@ -132,18 +104,17 @@ Misc options: | |||
| 132 | //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( | 104 | //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( |
| 133 | //usage: "\n -N N Change nice level" | 105 | //usage: "\n -N N Change nice level" |
| 134 | //usage: ) | 106 | //usage: ) |
| 135 | //usage: "\n -c USER[:[GRP]] Change to user/group" | 107 | //usage: "\n -c USER[:[GRP]] Change user/group" |
| 136 | //usage: "\n -m Write PID to the pidfile specified by -p" | 108 | //usage: "\n -m Write PID to pidfile specified by -p" |
| 137 | //usage: "\n-K only:" | 109 | //usage: "\n-K only:" |
| 138 | //usage: "\n -s SIG Signal to send" | 110 | //usage: "\n -s SIG Signal to send" |
| 139 | //usage: "\n -t Match only, exit with 0 if a process is found" | 111 | //usage: "\n -t Match only, exit with 0 if found" |
| 140 | //usage: "\nOther:" | 112 | //usage: "\nOther:" |
| 141 | //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( | 113 | //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( |
| 142 | //usage: "\n -o Exit with status 0 if nothing is done" | 114 | //usage: "\n -o Exit with status 0 if nothing is done" |
| 143 | //usage: "\n -v Verbose" | 115 | //usage: "\n -v Verbose" |
| 144 | //usage: ) | 116 | //usage: ) |
| 145 | //usage: "\n -q Quiet" | 117 | //usage: "\n -q Quiet" |
| 146 | //usage: ) | ||
| 147 | 118 | ||
| 148 | #include <sys/resource.h> | 119 | #include <sys/resource.h> |
| 149 | 120 | ||
| @@ -409,11 +380,11 @@ static const char start_stop_daemon_longopts[] ALIGN1 = | |||
| 409 | "quiet\0" No_argument "q" | 380 | "quiet\0" No_argument "q" |
| 410 | "test\0" No_argument "t" | 381 | "test\0" No_argument "t" |
| 411 | "make-pidfile\0" No_argument "m" | 382 | "make-pidfile\0" No_argument "m" |
| 412 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY | 383 | # if ENABLE_FEATURE_START_STOP_DAEMON_FANCY |
| 413 | "oknodo\0" No_argument "o" | 384 | "oknodo\0" No_argument "o" |
| 414 | "verbose\0" No_argument "v" | 385 | "verbose\0" No_argument "v" |
| 415 | "nicelevel\0" Required_argument "N" | 386 | "nicelevel\0" Required_argument "N" |
| 416 | #endif | 387 | # endif |
| 417 | "startas\0" Required_argument "a" | 388 | "startas\0" Required_argument "a" |
| 418 | "name\0" Required_argument "n" | 389 | "name\0" Required_argument "n" |
| 419 | "signal\0" Required_argument "s" | 390 | "signal\0" Required_argument "s" |
| @@ -421,10 +392,15 @@ static const char start_stop_daemon_longopts[] ALIGN1 = | |||
| 421 | "chuid\0" Required_argument "c" | 392 | "chuid\0" Required_argument "c" |
| 422 | "exec\0" Required_argument "x" | 393 | "exec\0" Required_argument "x" |
| 423 | "pidfile\0" Required_argument "p" | 394 | "pidfile\0" Required_argument "p" |
| 424 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY | 395 | # if ENABLE_FEATURE_START_STOP_DAEMON_FANCY |
| 425 | "retry\0" Required_argument "R" | 396 | "retry\0" Required_argument "R" |
| 426 | #endif | 397 | # endif |
| 427 | ; | 398 | ; |
| 399 | # define GETOPT32 getopt32long | ||
| 400 | # define LONGOPTS start_stop_daemon_longopts, | ||
| 401 | #else | ||
| 402 | # define GETOPT32 getopt32 | ||
| 403 | # define LONGOPTS | ||
| 428 | #endif | 404 | #endif |
| 429 | 405 | ||
| 430 | int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 406 | int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| @@ -445,19 +421,18 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
| 445 | 421 | ||
| 446 | INIT_G(); | 422 | INIT_G(); |
| 447 | 423 | ||
| 448 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS | 424 | opt = GETOPT32(argv, "^" |
| 449 | applet_long_options = start_stop_daemon_longopts; | 425 | "KSbqtma:n:s:u:c:x:p:" |
| 450 | #endif | 426 | IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:") |
| 451 | 427 | /* -K or -S is required; they are mutually exclusive */ | |
| 452 | /* -K or -S is required; they are mutually exclusive */ | 428 | /* -p is required if -m is given */ |
| 453 | /* -p is required if -m is given */ | 429 | /* -xpun (at least one) is required if -K is given */ |
| 454 | /* -xpun (at least one) is required if -K is given */ | 430 | /* -xa (at least one) is required if -S is given */ |
| 455 | /* -xa (at least one) is required if -S is given */ | 431 | /* -q turns off -v */ |
| 456 | /* -q turns off -v */ | 432 | "\0" |
| 457 | opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa" | 433 | "K:S:K--S:S--K:m?p:K?xpun:S?xa" |
| 458 | IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"); | 434 | IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"), |
| 459 | opt = getopt32(argv, "KSbqtma:n:s:u:c:x:p:" | 435 | LONGOPTS |
| 460 | IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), | ||
| 461 | &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile | 436 | &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile |
| 462 | IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) | 437 | IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) |
| 463 | /* We accept and ignore -R <param> / --retry <param> */ | 438 | /* We accept and ignore -R <param> / --retry <param> */ |
| @@ -516,6 +491,11 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
| 516 | /* DAEMON_DEVNULL_STDIO is superfluous - | 491 | /* DAEMON_DEVNULL_STDIO is superfluous - |
| 517 | * it's always done by bb_daemonize() */ | 492 | * it's always done by bb_daemonize() */ |
| 518 | #else | 493 | #else |
| 494 | /* Daemons usually call bb_daemonize_or_rexec(), but SSD can do | ||
| 495 | * without: SSD is not itself a daemon, it _execs_ a daemon. | ||
| 496 | * The usual NOMMU problem of "child can't run indefinitely, | ||
| 497 | * it must exec" does not bite us: we exec anyway. | ||
| 498 | */ | ||
| 519 | pid_t pid = xvfork(); | 499 | pid_t pid = xvfork(); |
| 520 | if (pid != 0) { | 500 | if (pid != 0) { |
| 521 | /* parent */ | 501 | /* parent */ |
| @@ -525,12 +505,8 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
| 525 | } | 505 | } |
| 526 | /* Child */ | 506 | /* Child */ |
| 527 | setsid(); /* detach from controlling tty */ | 507 | setsid(); /* detach from controlling tty */ |
| 528 | /* Redirect stdio to /dev/null, close extra FDs. | 508 | /* Redirect stdio to /dev/null, close extra FDs */ |
| 529 | * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */ | 509 | bb_daemon_helper(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS); |
| 530 | bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO | ||
| 531 | + DAEMON_CLOSE_EXTRA_FDS | ||
| 532 | + DAEMON_ONLY_SANITIZE, | ||
| 533 | NULL /* argv, unused */ ); | ||
| 534 | #endif | 510 | #endif |
| 535 | } | 511 | } |
| 536 | if (opt & OPT_MAKEPID) { | 512 | if (opt & OPT_MAKEPID) { |
diff --git a/debianutils/which.c b/debianutils/which.c index 23a481438..fbfd19cdc 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | //config: which is used to find programs in your PATH and | 12 | //config: which is used to find programs in your PATH and |
| 13 | //config: print out their pathnames. | 13 | //config: print out their pathnames. |
| 14 | 14 | ||
| 15 | //applet:IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP)) | 15 | //applet:IF_WHICH(APPLET_NOFORK(which, which, BB_DIR_USR_BIN, BB_SUID_DROP, which)) |
| 16 | 16 | ||
| 17 | //kbuild:lib-$(CONFIG_WHICH) += which.o | 17 | //kbuild:lib-$(CONFIG_WHICH) += which.o |
| 18 | 18 | ||
| @@ -37,8 +37,7 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
| 37 | if (!env_path) | 37 | if (!env_path) |
| 38 | env_path = bb_default_root_path; | 38 | env_path = bb_default_root_path; |
| 39 | 39 | ||
| 40 | opt_complementary = "-1"; /* at least one argument */ | 40 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); |
| 41 | getopt32(argv, "a"); | ||
| 42 | argv += optind; | 41 | argv += optind; |
| 43 | 42 | ||
| 44 | do { | 43 | do { |
| @@ -73,6 +72,8 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
| 73 | char *tmp; | 72 | char *tmp; |
| 74 | 73 | ||
| 75 | path = tmp = xstrdup(env_path); | 74 | path = tmp = xstrdup(env_path); |
| 75 | //NOFORK FIXME: nested xmallocs (one is inside find_executable()) | ||
| 76 | //can leak memory on failure | ||
| 76 | while ((p = find_executable(*argv, &tmp)) != NULL) { | 77 | while ((p = find_executable(*argv, &tmp)) != NULL) { |
| 77 | missing = 0; | 78 | missing = 0; |
| 78 | puts(p); | 79 | puts(p); |
