diff options
| author | Ron Yorston <rmy@pobox.com> | 2023-01-05 08:56:27 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2023-01-05 08:56:27 +0000 |
| commit | e5e4a2fec5435192d1672e6db2f335cb5e89f877 (patch) | |
| tree | 08cb827a40817ea4824bc9336d57eda669c4d4b2 /findutils | |
| parent | 4343f3926355f55fc023203c992527fc34bf609e (diff) | |
| parent | b1884deb514c35289d37e7bfbf23f770b0bd09b3 (diff) | |
| download | busybox-w32-e5e4a2fec5435192d1672e6db2f335cb5e89f877.tar.gz busybox-w32-e5e4a2fec5435192d1672e6db2f335cb5e89f877.tar.bz2 busybox-w32-e5e4a2fec5435192d1672e6db2f335cb5e89f877.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'findutils')
| -rw-r--r-- | findutils/xargs.c | 85 |
1 files changed, 51 insertions, 34 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index a0ba89c1e..dd6aa9592 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
| @@ -114,6 +114,8 @@ struct globals { | |||
| 114 | #endif | 114 | #endif |
| 115 | const char *eof_str; | 115 | const char *eof_str; |
| 116 | int idx; | 116 | int idx; |
| 117 | int fd_tty; | ||
| 118 | int fd_stdin; | ||
| 117 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL | 119 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
| 118 | int running_procs; | 120 | int running_procs; |
| 119 | int max_procs; | 121 | int max_procs; |
| @@ -147,6 +149,42 @@ struct globals { | |||
| 147 | IF_FEATURE_XARGS_SUPPORT_QUOTES(G.process_stdin__q = '\0';) \ | 149 | IF_FEATURE_XARGS_SUPPORT_QUOTES(G.process_stdin__q = '\0';) \ |
| 148 | } while (0) | 150 | } while (0) |
| 149 | 151 | ||
| 152 | /* Correct regardless of combination of CONFIG_xxx */ | ||
| 153 | enum { | ||
| 154 | OPTBIT_VERBOSE = 0, | ||
| 155 | OPTBIT_NO_EMPTY, | ||
| 156 | OPTBIT_UPTO_NUMBER, | ||
| 157 | OPTBIT_UPTO_SIZE, | ||
| 158 | OPTBIT_EOF_STRING, | ||
| 159 | OPTBIT_EOF_STRING1, | ||
| 160 | OPTBIT_STDIN_TTY, | ||
| 161 | IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,) | ||
| 162 | IF_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,) | ||
| 163 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,) | ||
| 164 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR ,) | ||
| 165 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR1 ,) | ||
| 166 | |||
| 167 | OPT_VERBOSE = 1 << OPTBIT_VERBOSE , | ||
| 168 | OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY , | ||
| 169 | OPT_UPTO_NUMBER = 1 << OPTBIT_UPTO_NUMBER, | ||
| 170 | OPT_UPTO_SIZE = 1 << OPTBIT_UPTO_SIZE , | ||
| 171 | OPT_EOF_STRING = 1 << OPTBIT_EOF_STRING , /* GNU: -e[<param>] */ | ||
| 172 | OPT_EOF_STRING1 = 1 << OPTBIT_EOF_STRING1, /* SUS: -E<param> */ | ||
| 173 | OPT_STDIN_TTY = 1 << OPTBIT_STDIN_TTY, | ||
| 174 | OPT_INTERACTIVE = IF_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0, | ||
| 175 | OPT_TERMINATE = IF_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0, | ||
| 176 | OPT_ZEROTERM = IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0, | ||
| 177 | OPT_REPLSTR = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR )) + 0, | ||
| 178 | OPT_REPLSTR1 = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR1 )) + 0, | ||
| 179 | }; | ||
| 180 | #define OPTION_STR "+trn:s:e::E:o" \ | ||
| 181 | IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \ | ||
| 182 | IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ | ||
| 183 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \ | ||
| 184 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") \ | ||
| 185 | IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") \ | ||
| 186 | IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( "a:") | ||
| 187 | |||
| 150 | 188 | ||
| 151 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL && ENABLE_PLATFORM_MINGW32 | 189 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL && ENABLE_PLATFORM_MINGW32 |
| 152 | static int wait_for_slot(int *idx) | 190 | static int wait_for_slot(int *idx) |
| @@ -206,6 +244,9 @@ static int xargs_exec(void) | |||
| 206 | { | 244 | { |
| 207 | int status; | 245 | int status; |
| 208 | 246 | ||
| 247 | if (option_mask32 & OPT_STDIN_TTY) | ||
| 248 | xdup2(G.fd_tty, STDIN_FILENO); | ||
| 249 | |||
| 209 | #if !ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL | 250 | #if !ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
| 210 | status = spawn_and_wait(G.args); | 251 | status = spawn_and_wait(G.args); |
| 211 | #else | 252 | #else |
| @@ -310,6 +351,8 @@ static int xargs_exec(void) | |||
| 310 | ret: | 351 | ret: |
| 311 | if (status != 0) | 352 | if (status != 0) |
| 312 | G.xargs_exitcode = status; | 353 | G.xargs_exitcode = status; |
| 354 | if (option_mask32 & OPT_STDIN_TTY) | ||
| 355 | xdup2(G.fd_stdin, STDIN_FILENO); | ||
| 313 | return status; | 356 | return status; |
| 314 | } | 357 | } |
| 315 | 358 | ||
| @@ -628,6 +671,7 @@ static int xargs_ask_confirmation(void) | |||
| 628 | //usage: IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( | 671 | //usage: IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( |
| 629 | //usage: "\n -a FILE Read from FILE instead of stdin" | 672 | //usage: "\n -a FILE Read from FILE instead of stdin" |
| 630 | //usage: ) | 673 | //usage: ) |
| 674 | //usage: "\n -o Reopen stdin as /dev/tty" | ||
| 631 | //usage: "\n -r Don't run command if input is empty" | 675 | //usage: "\n -r Don't run command if input is empty" |
| 632 | //usage: "\n -t Print the command on stderr before execution" | 676 | //usage: "\n -t Print the command on stderr before execution" |
| 633 | //usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION( | 677 | //usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION( |
| @@ -649,40 +693,6 @@ static int xargs_ask_confirmation(void) | |||
| 649 | //usage: "$ ls | xargs gzip\n" | 693 | //usage: "$ ls | xargs gzip\n" |
| 650 | //usage: "$ find . -name '*.c' -print | xargs rm\n" | 694 | //usage: "$ find . -name '*.c' -print | xargs rm\n" |
| 651 | 695 | ||
| 652 | /* Correct regardless of combination of CONFIG_xxx */ | ||
| 653 | enum { | ||
| 654 | OPTBIT_VERBOSE = 0, | ||
| 655 | OPTBIT_NO_EMPTY, | ||
| 656 | OPTBIT_UPTO_NUMBER, | ||
| 657 | OPTBIT_UPTO_SIZE, | ||
| 658 | OPTBIT_EOF_STRING, | ||
| 659 | OPTBIT_EOF_STRING1, | ||
| 660 | IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,) | ||
| 661 | IF_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,) | ||
| 662 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,) | ||
| 663 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR ,) | ||
| 664 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR1 ,) | ||
| 665 | |||
| 666 | OPT_VERBOSE = 1 << OPTBIT_VERBOSE , | ||
| 667 | OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY , | ||
| 668 | OPT_UPTO_NUMBER = 1 << OPTBIT_UPTO_NUMBER, | ||
| 669 | OPT_UPTO_SIZE = 1 << OPTBIT_UPTO_SIZE , | ||
| 670 | OPT_EOF_STRING = 1 << OPTBIT_EOF_STRING , /* GNU: -e[<param>] */ | ||
| 671 | OPT_EOF_STRING1 = 1 << OPTBIT_EOF_STRING1, /* SUS: -E<param> */ | ||
| 672 | OPT_INTERACTIVE = IF_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0, | ||
| 673 | OPT_TERMINATE = IF_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0, | ||
| 674 | OPT_ZEROTERM = IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0, | ||
| 675 | OPT_REPLSTR = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR )) + 0, | ||
| 676 | OPT_REPLSTR1 = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR1 )) + 0, | ||
| 677 | }; | ||
| 678 | #define OPTION_STR "+trn:s:e::E:" \ | ||
| 679 | IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \ | ||
| 680 | IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ | ||
| 681 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \ | ||
| 682 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") \ | ||
| 683 | IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") \ | ||
| 684 | IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( "a:") | ||
| 685 | |||
| 686 | int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 696 | int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 687 | int xargs_main(int argc UNUSED_PARAM, char **argv) | 697 | int xargs_main(int argc UNUSED_PARAM, char **argv) |
| 688 | { | 698 | { |
| @@ -817,6 +827,13 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) | |||
| 817 | store_param(argv[i]); | 827 | store_param(argv[i]); |
| 818 | } | 828 | } |
| 819 | 829 | ||
| 830 | if (opt & OPT_STDIN_TTY) { | ||
| 831 | G.fd_tty = xopen(CURRENT_TTY, O_RDONLY); | ||
| 832 | close_on_exec_on(G.fd_tty); | ||
| 833 | G.fd_stdin = dup(STDIN_FILENO); | ||
| 834 | close_on_exec_on(G.fd_stdin); | ||
| 835 | } | ||
| 836 | |||
| 820 | initial_idx = G.idx; | 837 | initial_idx = G.idx; |
| 821 | while (1) { | 838 | while (1) { |
| 822 | char *rem; | 839 | char *rem; |
