Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 5b17693 | 2000-09-22 20:22:28 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | a37d5b7 | 2000-09-23 06:10:14 +0000 | [diff] [blame] | 3 | * Mini xargs implementation for busybox |
Eric Andersen | 5b17693 | 2000-09-22 20:22:28 +0000 | [diff] [blame] | 4 | * |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 5 | * (C) 2002,2003 by Vladimir Oleynik <dzo@simtreas.ru> |
Glenn L McGrath | f57674e | 2002-11-10 21:47:17 +0000 | [diff] [blame] | 6 | * |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 7 | * Special thanks |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 8 | * - Mark Whitley and Glenn McGrath for stimulus to rewrite :) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 9 | * - Mike Rendell <michael@cs.mun.ca> |
| 10 | * and David MacKenzie <djm@gnu.ai.mit.edu>. |
Eric Andersen | 5b17693 | 2000-09-22 20:22:28 +0000 | [diff] [blame] | 11 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 12 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | a37d5b7 | 2000-09-23 06:10:14 +0000 | [diff] [blame] | 13 | * |
Glenn L McGrath | 40c9489 | 2003-10-30 22:51:33 +0000 | [diff] [blame] | 14 | * xargs is described in the Single Unix Specification v3 at |
| 15 | * http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html |
Eric Andersen | 5b17693 | 2000-09-22 20:22:28 +0000 | [diff] [blame] | 16 | */ |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 17 | //config:config XARGS |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 18 | //config: bool "xargs (7.2 kb)" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 19 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 20 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 21 | //config: xargs is used to execute a specified command for |
| 22 | //config: every item from standard input. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 23 | //config: |
| 24 | //config:config FEATURE_XARGS_SUPPORT_CONFIRMATION |
| 25 | //config: bool "Enable -p: prompt and confirmation" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 26 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 27 | //config: depends on XARGS |
| 28 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 29 | //config: Support -p: prompt the user whether to run each command |
| 30 | //config: line and read a line from the terminal. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 31 | //config: |
| 32 | //config:config FEATURE_XARGS_SUPPORT_QUOTES |
| 33 | //config: bool "Enable single and double quotes and backslash" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 34 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 35 | //config: depends on XARGS |
| 36 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 37 | //config: Support quoting in the input. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 38 | //config: |
| 39 | //config:config FEATURE_XARGS_SUPPORT_TERMOPT |
| 40 | //config: bool "Enable -x: exit if -s or -n is exceeded" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 41 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 42 | //config: depends on XARGS |
| 43 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 44 | //config: Support -x: exit if the command size (see the -s or -n option) |
| 45 | //config: is exceeded. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 46 | //config: |
| 47 | //config:config FEATURE_XARGS_SUPPORT_ZERO_TERM |
| 48 | //config: bool "Enable -0: NUL-terminated input" |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 49 | //config: default y |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 50 | //config: depends on XARGS |
| 51 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 52 | //config: Support -0: input items are terminated by a NUL character |
| 53 | //config: instead of whitespace, and the quotes and backslash |
| 54 | //config: are not special. |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 55 | //config: |
| 56 | //config:config FEATURE_XARGS_SUPPORT_REPL_STR |
| 57 | //config: bool "Enable -I STR: string to replace" |
| 58 | //config: default y |
| 59 | //config: depends on XARGS |
| 60 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 61 | //config: Support -I STR and -i[STR] options. |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 62 | //config: |
| 63 | //config:config FEATURE_XARGS_SUPPORT_PARALLEL |
| 64 | //config: bool "Enable -P N: processes to run in parallel" |
| 65 | //config: default y |
| 66 | //config: depends on XARGS |
Johannes Schindelin | f8ee849 | 2017-08-25 22:42:05 +0200 | [diff] [blame] | 67 | //config: |
| 68 | //config:config FEATURE_XARGS_SUPPORT_ARGS_FILE |
| 69 | //config: bool "Enable -a FILE: use FILE instead of stdin" |
| 70 | //config: default y |
| 71 | //config: depends on XARGS |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 72 | |
Denys Vlasenko | 7cfe6ea | 2011-03-03 09:51:57 +0100 | [diff] [blame] | 73 | //applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs)) |
| 74 | |
| 75 | //kbuild:lib-$(CONFIG_XARGS) += xargs.o |
| 76 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 77 | #include "libbb.h" |
Denys Vlasenko | e6a2f4c | 2016-04-21 16:26:30 +0200 | [diff] [blame] | 78 | #include "common_bufsiz.h" |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 79 | |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 80 | /* This is a NOEXEC applet. Be very careful! */ |
| 81 | |
| 82 | |
| 83 | //#define dbg_msg(...) bb_error_msg(__VA_ARGS__) |
| 84 | #define dbg_msg(...) ((void)0) |
| 85 | |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 86 | |
| 87 | #ifdef TEST |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 88 | # ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION |
| 89 | # define ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION 1 |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 90 | # endif |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 91 | # ifndef ENABLE_FEATURE_XARGS_SUPPORT_QUOTES |
| 92 | # define ENABLE_FEATURE_XARGS_SUPPORT_QUOTES 1 |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 93 | # endif |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 94 | # ifndef ENABLE_FEATURE_XARGS_SUPPORT_TERMOPT |
| 95 | # define ENABLE_FEATURE_XARGS_SUPPORT_TERMOPT 1 |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 96 | # endif |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 97 | # ifndef ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM |
| 98 | # define ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM 1 |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 99 | # endif |
| 100 | #endif |
| 101 | |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 102 | |
| 103 | struct globals { |
| 104 | char **args; |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 105 | #if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR |
| 106 | char **argv; |
| 107 | const char *repl_str; |
| 108 | char eol_ch; |
| 109 | #endif |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 110 | const char *eof_str; |
| 111 | int idx; |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 112 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
| 113 | int running_procs; |
| 114 | int max_procs; |
| 115 | #endif |
| 116 | smalluint xargs_exitcode; |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 117 | } FIX_ALIASING; |
Denys Vlasenko | e6a2f4c | 2016-04-21 16:26:30 +0200 | [diff] [blame] | 118 | #define G (*(struct globals*)bb_common_bufsiz1) |
Denys Vlasenko | 7cfe6ea | 2011-03-03 09:51:57 +0100 | [diff] [blame] | 119 | #define INIT_G() do { \ |
Denys Vlasenko | 47cfbf3 | 2016-04-21 18:18:48 +0200 | [diff] [blame] | 120 | setup_common_bufsiz(); \ |
Denys Vlasenko | 7cfe6ea | 2011-03-03 09:51:57 +0100 | [diff] [blame] | 121 | G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 122 | G.idx = 0; \ |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 123 | IF_FEATURE_XARGS_SUPPORT_PARALLEL(G.running_procs = 0;) \ |
| 124 | IF_FEATURE_XARGS_SUPPORT_PARALLEL(G.max_procs = 1;) \ |
| 125 | G.xargs_exitcode = 0; \ |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 126 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ |
| 127 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \ |
Denys Vlasenko | 7cfe6ea | 2011-03-03 09:51:57 +0100 | [diff] [blame] | 128 | } while (0) |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 129 | |
| 130 | |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 131 | /* |
| 132 | * Returns 0 if xargs should continue (but may set G.xargs_exitcode to 123). |
| 133 | * Else sets G.xargs_exitcode to error code and returns nonzero. |
| 134 | * |
| 135 | * If G.max_procs == 0, performs final waitpid() loop for all children. |
| 136 | */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 137 | static int xargs_exec(void) |
Glenn L McGrath | f57674e | 2002-11-10 21:47:17 +0000 | [diff] [blame] | 138 | { |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 139 | int status; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 140 | |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 141 | #if !ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 142 | status = spawn_and_wait(G.args); |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 143 | #else |
| 144 | if (G.max_procs == 1) { |
| 145 | status = spawn_and_wait(G.args); |
| 146 | } else { |
| 147 | pid_t pid; |
| 148 | int wstat; |
| 149 | again: |
| 150 | if (G.running_procs >= G.max_procs) |
| 151 | pid = safe_waitpid(-1, &wstat, 0); |
| 152 | else |
| 153 | pid = wait_any_nohang(&wstat); |
| 154 | if (pid > 0) { |
| 155 | /* We may have children we don't know about: |
| 156 | * sh -c 'sleep 1 & exec xargs ...' |
| 157 | * Do not make G.running_procs go negative. |
| 158 | */ |
| 159 | if (G.running_procs != 0) |
| 160 | G.running_procs--; |
| 161 | status = WIFSIGNALED(wstat) |
| 162 | ? 0x180 + WTERMSIG(wstat) |
| 163 | : WEXITSTATUS(wstat); |
| 164 | if (status > 0 && status < 255) { |
| 165 | /* See below why 123 does not abort */ |
| 166 | G.xargs_exitcode = 123; |
| 167 | status = 0; |
| 168 | } |
| 169 | if (status == 0) |
| 170 | goto again; /* maybe we have more children? */ |
| 171 | /* else: "bad" status, will bail out */ |
| 172 | } else if (G.max_procs != 0) { |
| 173 | /* Not in final waitpid() loop, |
| 174 | * and G.running_procs < G.max_procs: start more procs |
| 175 | */ |
| 176 | status = spawn(G.args); |
| 177 | /* here "status" actually holds pid, or -1 */ |
| 178 | if (status > 0) { |
| 179 | G.running_procs++; |
| 180 | status = 0; |
| 181 | } |
| 182 | /* else: status == -1 (failed to fork or exec) */ |
| 183 | } else { |
| 184 | /* final waitpid() loop: must be ECHILD "no more children" */ |
| 185 | status = 0; |
| 186 | } |
| 187 | } |
| 188 | #endif |
| 189 | /* Manpage: |
| 190 | * """xargs exits with the following status: |
| 191 | * 0 if it succeeds |
| 192 | * 123 if any invocation of the command exited with status 1-125 |
| 193 | * 124 if the command exited with status 255 |
| 194 | * ("""If any invocation of the command exits with a status of 255, |
| 195 | * xargs will stop immediately without reading any further input. |
| 196 | * An error message is issued on stderr when this happens.""") |
| 197 | * 125 if the command is killed by a signal |
| 198 | * 126 if the command cannot be run |
| 199 | * 127 if the command is not found |
| 200 | * 1 if some other error occurred.""" |
| 201 | */ |
Denis Vlasenko | cd7001f | 2007-04-09 21:32:30 +0000 | [diff] [blame] | 202 | if (status < 0) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 203 | bb_simple_perror_msg(G.args[0]); |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 204 | status = (errno == ENOENT) ? 127 : 126; |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 205 | } |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 206 | else if (status >= 0x180) { |
Denys Vlasenko | f3e2838 | 2018-10-30 14:40:17 +0100 | [diff] [blame] | 207 | bb_error_msg("'%s' terminated by signal %u", |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 208 | G.args[0], status - 0x180); |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 209 | status = 125; |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 210 | } |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 211 | else if (status != 0) { |
| 212 | if (status == 255) { |
| 213 | bb_error_msg("%s: exited with status 255; aborting", G.args[0]); |
Denys Vlasenko | f3e2838 | 2018-10-30 14:40:17 +0100 | [diff] [blame] | 214 | status = 124; |
| 215 | goto ret; |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 216 | } |
| 217 | /* "123 if any invocation of the command exited with status 1-125" |
| 218 | * This implies that nonzero exit code is remembered, |
| 219 | * but does not cause xargs to stop: we return 0. |
| 220 | */ |
| 221 | G.xargs_exitcode = 123; |
| 222 | status = 0; |
| 223 | } |
Denys Vlasenko | f3e2838 | 2018-10-30 14:40:17 +0100 | [diff] [blame] | 224 | ret: |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 225 | if (status != 0) |
| 226 | G.xargs_exitcode = status; |
| 227 | return status; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 228 | } |
Glenn L McGrath | 9982596 | 2003-10-09 11:06:45 +0000 | [diff] [blame] | 229 | |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 230 | /* In POSIX/C locale isspace is only these chars: "\t\n\v\f\r" and space. |
| 231 | * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13. |
| 232 | */ |
| 233 | #define ISSPACE(a) ({ unsigned char xargs__isspace = (a) - 9; xargs__isspace == (' ' - 9) || xargs__isspace <= (13 - 9); }) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 234 | |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 235 | static void store_param(char *s) |
| 236 | { |
| 237 | /* Grow by 256 elements at once */ |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 238 | if (!(G.idx & 0xff)) { /* G.idx == N*256? */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 239 | /* Enlarge, make G.args[(N+1)*256 - 1] last valid idx */ |
| 240 | G.args = xrealloc(G.args, sizeof(G.args[0]) * (G.idx + 0x100)); |
| 241 | } |
| 242 | G.args[G.idx++] = s; |
| 243 | } |
| 244 | |
| 245 | /* process[0]_stdin: |
| 246 | * Read characters into buf[n_max_chars+1], and when parameter delimiter |
| 247 | * is seen, store the address of a new parameter to args[]. |
| 248 | * If reading discovers that last chars do not form the complete |
| 249 | * parameter, the pointer to the first such "tail character" is returned. |
Maninder Singh | 97c6491 | 2015-05-25 13:46:36 +0200 | [diff] [blame] | 250 | * (buf has extra byte at the end to accommodate terminating NUL |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 251 | * of "tail characters" string). |
| 252 | * Otherwise, the returned pointer points to NUL byte. |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 253 | * On entry, buf[] may contain some "seed chars" which are to become |
| 254 | * the beginning of the first parameter. |
| 255 | */ |
| 256 | |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 257 | #if ENABLE_FEATURE_XARGS_SUPPORT_QUOTES |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 258 | static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 259 | { |
| 260 | #define NORM 0 |
| 261 | #define QUOTE 1 |
| 262 | #define BACKSLASH 2 |
| 263 | #define SPACE 4 |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 264 | char q = '\0'; /* quote char */ |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 265 | char state = NORM; |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 266 | char *s = buf; /* start of the word */ |
| 267 | char *p = s + strlen(buf); /* end of the word */ |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 268 | |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 269 | buf += n_max_chars; /* past buffer's end */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 270 | |
| 271 | /* "goto ret" is used instead of "break" to make control flow |
| 272 | * more obvious: */ |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 273 | |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 274 | while (1) { |
| 275 | int c = getchar(); |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 276 | if (c == EOF) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 277 | if (p != s) |
| 278 | goto close_word; |
| 279 | goto ret; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 280 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 281 | if (state == BACKSLASH) { |
| 282 | state = NORM; |
| 283 | goto set; |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 284 | } |
| 285 | if (state == QUOTE) { |
Denis Vlasenko | 58394b1 | 2007-04-15 08:38:50 +0000 | [diff] [blame] | 286 | if (c != q) |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 287 | goto set; |
Denis Vlasenko | 58394b1 | 2007-04-15 08:38:50 +0000 | [diff] [blame] | 288 | q = '\0'; |
| 289 | state = NORM; |
Denis Vlasenko | 51742f4 | 2007-04-12 00:32:05 +0000 | [diff] [blame] | 290 | } else { /* if (state == NORM) */ |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 291 | if (ISSPACE(c)) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 292 | if (p != s) { |
| 293 | close_word: |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 294 | state = SPACE; |
Denis Vlasenko | 58394b1 | 2007-04-15 08:38:50 +0000 | [diff] [blame] | 295 | c = '\0'; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 296 | goto set; |
| 297 | } |
| 298 | } else { |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 299 | if (c == '\\') { |
| 300 | state = BACKSLASH; |
| 301 | } else if (c == '\'' || c == '"') { |
| 302 | q = c; |
| 303 | state = QUOTE; |
| 304 | } else { |
Denis Vlasenko | 58394b1 | 2007-04-15 08:38:50 +0000 | [diff] [blame] | 305 | set: |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 306 | *p++ = c; |
| 307 | } |
| 308 | } |
| 309 | } |
"Vladimir N. Oleynik" | 59c4e5c | 2006-01-30 13:51:50 +0000 | [diff] [blame] | 310 | if (state == SPACE) { /* word's delimiter or EOF detected */ |
Eric Andersen | 252183e | 2003-10-31 08:19:44 +0000 | [diff] [blame] | 311 | if (q) { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 312 | bb_error_msg_and_die("unmatched %s quote", |
Eric Andersen | 252183e | 2003-10-31 08:19:44 +0000 | [diff] [blame] | 313 | q == '\'' ? "single" : "double"); |
| 314 | } |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 315 | /* A full word is loaded */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 316 | if (G.eof_str) { |
| 317 | if (strcmp(s, G.eof_str) == 0) { |
| 318 | while (getchar() != EOF) |
| 319 | continue; |
| 320 | p = s; |
| 321 | goto ret; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 322 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 323 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 324 | store_param(s); |
| 325 | dbg_msg("args[]:'%s'", s); |
| 326 | s = p; |
| 327 | n_max_arg--; |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 328 | if (n_max_arg == 0) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 329 | goto ret; |
| 330 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 331 | state = NORM; |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 332 | } |
| 333 | if (p == buf) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 334 | goto ret; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 335 | } |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 336 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 337 | ret: |
| 338 | *p = '\0'; |
Denys Vlasenko | c28cafb | 2010-06-14 12:38:36 +0200 | [diff] [blame] | 339 | /* store_param(NULL) - caller will do it */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 340 | dbg_msg("return:'%s'", s); |
| 341 | return s; |
Glenn L McGrath | f57674e | 2002-11-10 21:47:17 +0000 | [diff] [blame] | 342 | } |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 343 | #else |
Eric Andersen | 252183e | 2003-10-31 08:19:44 +0000 | [diff] [blame] | 344 | /* The variant does not support single quotes, double quotes or backslash */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 345 | static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf) |
Eric Andersen | 92a61c1 | 2000-09-22 20:01:23 +0000 | [diff] [blame] | 346 | { |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 347 | char *s = buf; /* start of the word */ |
| 348 | char *p = s + strlen(buf); /* end of the word */ |
Glenn L McGrath | add3ead | 2003-10-04 14:44:27 +0000 | [diff] [blame] | 349 | |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 350 | buf += n_max_chars; /* past buffer's end */ |
Eric Andersen | 92a61c1 | 2000-09-22 20:01:23 +0000 | [diff] [blame] | 351 | |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 352 | while (1) { |
| 353 | int c = getchar(); |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 354 | if (c == EOF) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 355 | if (p == s) |
| 356 | goto ret; |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 357 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 358 | if (c == EOF || ISSPACE(c)) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 359 | if (p == s) |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 360 | continue; |
| 361 | c = EOF; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 362 | } |
Denis Vlasenko | 58394b1 | 2007-04-15 08:38:50 +0000 | [diff] [blame] | 363 | *p++ = (c == EOF ? '\0' : c); |
"Vladimir N. Oleynik" | 59c4e5c | 2006-01-30 13:51:50 +0000 | [diff] [blame] | 364 | if (c == EOF) { /* word's delimiter or EOF detected */ |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 365 | /* A full word is loaded */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 366 | if (G.eof_str) { |
| 367 | if (strcmp(s, G.eof_str) == 0) { |
| 368 | while (getchar() != EOF) |
| 369 | continue; |
| 370 | p = s; |
| 371 | goto ret; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 372 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 373 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 374 | store_param(s); |
| 375 | dbg_msg("args[]:'%s'", s); |
| 376 | s = p; |
| 377 | n_max_arg--; |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 378 | if (n_max_arg == 0) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 379 | goto ret; |
| 380 | } |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 381 | } |
| 382 | if (p == buf) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 383 | goto ret; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 384 | } |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 385 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 386 | ret: |
| 387 | *p = '\0'; |
Denys Vlasenko | c28cafb | 2010-06-14 12:38:36 +0200 | [diff] [blame] | 388 | /* store_param(NULL) - caller will do it */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 389 | dbg_msg("return:'%s'", s); |
| 390 | return s; |
Eric Andersen | 92a61c1 | 2000-09-22 20:01:23 +0000 | [diff] [blame] | 391 | } |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 392 | #endif /* FEATURE_XARGS_SUPPORT_QUOTES */ |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 393 | |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 394 | #if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 395 | static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 396 | { |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 397 | char *s = buf; /* start of the word */ |
| 398 | char *p = s + strlen(buf); /* end of the word */ |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 399 | |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 400 | buf += n_max_chars; /* past buffer's end */ |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 401 | |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 402 | while (1) { |
| 403 | int c = getchar(); |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 404 | if (c == EOF) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 405 | if (p == s) |
| 406 | goto ret; |
Denis Vlasenko | 58394b1 | 2007-04-15 08:38:50 +0000 | [diff] [blame] | 407 | c = '\0'; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 408 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 409 | *p++ = c; |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 410 | if (c == '\0') { /* NUL or EOF detected */ |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 411 | /* A full word is loaded */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 412 | store_param(s); |
| 413 | dbg_msg("args[]:'%s'", s); |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 414 | s = p; |
Denys Vlasenko | f7e929e | 2010-06-15 10:02:04 +0200 | [diff] [blame] | 415 | n_max_arg--; |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 416 | if (n_max_arg == 0) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 417 | goto ret; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 418 | } |
Denys Vlasenko | 237aece | 2010-06-15 10:18:01 +0200 | [diff] [blame] | 419 | } |
| 420 | if (p == buf) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 421 | goto ret; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 422 | } |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 423 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 424 | ret: |
| 425 | *p = '\0'; |
Denys Vlasenko | c28cafb | 2010-06-14 12:38:36 +0200 | [diff] [blame] | 426 | /* store_param(NULL) - caller will do it */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 427 | dbg_msg("return:'%s'", s); |
| 428 | return s; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 429 | } |
Denis Vlasenko | 1b4b2cb | 2007-04-09 21:30:53 +0000 | [diff] [blame] | 430 | #endif /* FEATURE_XARGS_SUPPORT_ZERO_TERM */ |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 431 | |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 432 | #if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR |
| 433 | /* |
| 434 | * Used if -I<repl> was specified. |
| 435 | * In this mode, words aren't appended to PROG ARGS. |
| 436 | * Instead, entire input line is read, then <repl> string |
| 437 | * in every PROG and ARG is replaced with the line: |
| 438 | * echo -e "ho ho\nhi" | xargs -I_ cmd __ _ |
| 439 | * results in "cmd 'ho hoho ho' 'ho ho'"; "cmd 'hihi' 'hi'". |
| 440 | * -n MAX_ARGS seems to be ignored. |
| 441 | * Tested with GNU findutils 4.5.10. |
| 442 | */ |
| 443 | //FIXME: n_max_chars is not handled the same way as in GNU findutils. |
| 444 | //FIXME: quoting is not implemented. |
| 445 | static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg UNUSED_PARAM, char *buf) |
| 446 | { |
| 447 | int i; |
| 448 | char *end, *p; |
| 449 | |
| 450 | /* Free strings from last invocation, if any */ |
| 451 | for (i = 0; G.args && G.args[i]; i++) |
| 452 | if (G.args[i] != G.argv[i]) |
| 453 | free(G.args[i]); |
| 454 | |
| 455 | end = buf + n_max_chars; |
| 456 | p = buf; |
| 457 | |
| 458 | while (1) { |
| 459 | int c = getchar(); |
| 460 | if (c == EOF || c == G.eol_ch) { |
| 461 | if (p == buf) |
| 462 | goto ret; /* empty line */ |
| 463 | c = '\0'; |
| 464 | } |
| 465 | *p++ = c; |
| 466 | if (c == '\0') { /* EOL or EOF detected */ |
| 467 | i = 0; |
| 468 | while (G.argv[i]) { |
| 469 | char *arg = G.argv[i]; |
| 470 | int count = count_strstr(arg, G.repl_str); |
| 471 | if (count != 0) |
Denys Vlasenko | 3795266 | 2014-02-27 15:02:36 +0100 | [diff] [blame] | 472 | arg = xmalloc_substitute_string(arg, count, G.repl_str, buf); |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 473 | store_param(arg); |
| 474 | dbg_msg("args[]:'%s'", arg); |
| 475 | i++; |
| 476 | } |
| 477 | p = buf; |
| 478 | goto ret; |
| 479 | } |
| 480 | if (p == end) { |
| 481 | goto ret; |
| 482 | } |
| 483 | } |
| 484 | ret: |
| 485 | *p = '\0'; |
| 486 | /* store_param(NULL) - caller will do it */ |
| 487 | dbg_msg("return:'%s'", buf); |
| 488 | return buf; |
| 489 | } |
| 490 | #endif |
| 491 | |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 492 | #if ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION |
| 493 | /* Prompt the user for a response, and |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 494 | * if user responds affirmatively, return true; |
| 495 | * otherwise, return false. Uses "/dev/tty", not stdin. |
| 496 | */ |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 497 | static int xargs_ask_confirmation(void) |
| 498 | { |
| 499 | FILE *tty_stream; |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 500 | int r; |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 501 | |
| 502 | tty_stream = xfopen_for_read(CURRENT_TTY); |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 503 | |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 504 | fputs(" ?...", stderr); |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 505 | r = bb_ask_y_confirmation_FILE(tty_stream); |
| 506 | |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 507 | fclose(tty_stream); |
Denys Vlasenko | bae8fc4 | 2018-04-07 15:21:35 +0200 | [diff] [blame] | 508 | |
| 509 | return r; |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 510 | } |
| 511 | #else |
| 512 | # define xargs_ask_confirmation() 1 |
| 513 | #endif |
| 514 | |
Denys Vlasenko | 4f731ce | 2010-06-15 15:40:16 +0200 | [diff] [blame] | 515 | //usage:#define xargs_trivial_usage |
| 516 | //usage: "[OPTIONS] [PROG ARGS]" |
| 517 | //usage:#define xargs_full_usage "\n\n" |
| 518 | //usage: "Run PROG on every item given by stdin\n" |
Denys Vlasenko | 4f731ce | 2010-06-15 15:40:16 +0200 | [diff] [blame] | 519 | //usage: IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( |
Denys Vlasenko | 4d0e2d5 | 2018-07-06 20:49:08 +0200 | [diff] [blame] | 520 | //usage: "\n -0 Input is separated by NULs" |
Denys Vlasenko | 4f731ce | 2010-06-15 15:40:16 +0200 | [diff] [blame] | 521 | //usage: ) |
Johannes Schindelin | f8ee849 | 2017-08-25 22:42:05 +0200 | [diff] [blame] | 522 | //usage: IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( |
| 523 | //usage: "\n -a FILE Read from FILE instead of stdin" |
| 524 | //usage: ) |
Denys Vlasenko | 2452247 | 2019-03-10 14:29:03 +0100 | [diff] [blame^] | 525 | //usage: "\n -r Don't run command if input is empty" |
Denys Vlasenko | 4f731ce | 2010-06-15 15:40:16 +0200 | [diff] [blame] | 526 | //usage: "\n -t Print the command on stderr before execution" |
Denys Vlasenko | 2452247 | 2019-03-10 14:29:03 +0100 | [diff] [blame^] | 527 | //usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION( |
| 528 | //usage: "\n -p Ask user whether to run each command" |
| 529 | //usage: ) |
| 530 | //usage: "\n -E STR,-e[STR] STR stops input processing" |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 531 | //usage: IF_FEATURE_XARGS_SUPPORT_REPL_STR( |
| 532 | //usage: "\n -I STR Replace STR within PROG ARGS with input line" |
| 533 | //usage: ) |
Denys Vlasenko | 2452247 | 2019-03-10 14:29:03 +0100 | [diff] [blame^] | 534 | //usage: "\n -n N Pass no more than N args to PROG" |
| 535 | //usage: "\n -s N Pass command line of no more than N bytes" |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 536 | //usage: IF_FEATURE_XARGS_SUPPORT_PARALLEL( |
| 537 | //usage: "\n -P N Run up to N PROGs in parallel" |
| 538 | //usage: ) |
Denys Vlasenko | 4f731ce | 2010-06-15 15:40:16 +0200 | [diff] [blame] | 539 | //usage: IF_FEATURE_XARGS_SUPPORT_TERMOPT( |
| 540 | //usage: "\n -x Exit if size is exceeded" |
| 541 | //usage: ) |
| 542 | //usage:#define xargs_example_usage |
| 543 | //usage: "$ ls | xargs gzip\n" |
| 544 | //usage: "$ find . -name '*.c' -print | xargs rm\n" |
| 545 | |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 546 | /* Correct regardless of combination of CONFIG_xxx */ |
| 547 | enum { |
| 548 | OPTBIT_VERBOSE = 0, |
| 549 | OPTBIT_NO_EMPTY, |
| 550 | OPTBIT_UPTO_NUMBER, |
| 551 | OPTBIT_UPTO_SIZE, |
| 552 | OPTBIT_EOF_STRING, |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 553 | OPTBIT_EOF_STRING1, |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 554 | IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,) |
| 555 | IF_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,) |
| 556 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,) |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 557 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR ,) |
| 558 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR1 ,) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 559 | |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 560 | OPT_VERBOSE = 1 << OPTBIT_VERBOSE , |
| 561 | OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY , |
| 562 | OPT_UPTO_NUMBER = 1 << OPTBIT_UPTO_NUMBER, |
| 563 | OPT_UPTO_SIZE = 1 << OPTBIT_UPTO_SIZE , |
| 564 | OPT_EOF_STRING = 1 << OPTBIT_EOF_STRING , /* GNU: -e[<param>] */ |
| 565 | OPT_EOF_STRING1 = 1 << OPTBIT_EOF_STRING1, /* SUS: -E<param> */ |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 566 | OPT_INTERACTIVE = IF_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0, |
| 567 | OPT_TERMINATE = IF_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0, |
| 568 | OPT_ZEROTERM = IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0, |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 569 | OPT_REPLSTR = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR )) + 0, |
| 570 | OPT_REPLSTR1 = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR1 )) + 0, |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 571 | }; |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 572 | #define OPTION_STR "+trn:s:e::E:" \ |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 573 | IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \ |
| 574 | IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 575 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \ |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 576 | IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") \ |
Johannes Schindelin | f8ee849 | 2017-08-25 22:42:05 +0200 | [diff] [blame] | 577 | IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") \ |
| 578 | IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( "a:") |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 579 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 580 | int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 581 | int xargs_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 582 | { |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 583 | int initial_idx; |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 584 | int i; |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 585 | char *max_args; |
| 586 | char *max_chars; |
| 587 | char *buf; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 588 | unsigned opt; |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 589 | int n_max_chars; |
| 590 | int n_max_arg; |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 591 | #if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM \ |
| 592 | || ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 593 | char* FAST_FUNC (*read_args)(int, int, char*) = process_stdin; |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 594 | #else |
| 595 | #define read_args process_stdin |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 596 | #endif |
Denys Vlasenko | 58bf902 | 2017-08-30 13:44:27 +0200 | [diff] [blame] | 597 | IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(char *opt_a = NULL;) |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 598 | |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 599 | INIT_G(); |
| 600 | |
Denys Vlasenko | 036585a | 2017-08-08 16:38:18 +0200 | [diff] [blame] | 601 | opt = getopt32long(argv, OPTION_STR, |
| 602 | "no-run-if-empty\0" No_argument "r", |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 603 | &max_args, &max_chars, &G.eof_str, &G.eof_str |
| 604 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str) |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 605 | IF_FEATURE_XARGS_SUPPORT_PARALLEL(, &G.max_procs) |
Johannes Schindelin | f8ee849 | 2017-08-25 22:42:05 +0200 | [diff] [blame] | 606 | IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(, &opt_a) |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 607 | ); |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 608 | |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 609 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
| 610 | if (G.max_procs <= 0) /* -P0 means "run lots of them" */ |
| 611 | G.max_procs = 100; /* let's not go crazy high */ |
| 612 | #endif |
| 613 | |
Johannes Schindelin | f8ee849 | 2017-08-25 22:42:05 +0200 | [diff] [blame] | 614 | #if ENABLE_FEATURE_XARGS_SUPPORT_ARGS_FILE |
| 615 | if (opt_a) |
| 616 | xmove_fd(xopen(opt_a, O_RDONLY), 0); |
| 617 | #endif |
| 618 | |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 619 | /* -E ""? You may wonder why not just omit -E? |
| 620 | * This is used for portability: |
| 621 | * old xargs was using "_" as default for -E / -e */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 622 | if ((opt & OPT_EOF_STRING1) && G.eof_str[0] == '\0') |
| 623 | G.eof_str = NULL; |
Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 624 | |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 625 | if (opt & OPT_ZEROTERM) { |
| 626 | IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin;) |
| 627 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\0';) |
| 628 | } |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 629 | |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 630 | argv += optind; |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 631 | //argc -= optind; |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 632 | if (!argv[0]) { |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 633 | /* default behavior is to echo all the filenames */ |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 634 | *--argv = (char*)"echo"; |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 635 | //argc++; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Denys Vlasenko | f92f1d0 | 2014-06-22 13:54:40 +0200 | [diff] [blame] | 638 | /* |
Denys Vlasenko | 4a96617 | 2010-06-19 21:44:01 +0200 | [diff] [blame] | 639 | * The Open Group Base Specifications Issue 6: |
Denys Vlasenko | d7b5289 | 2010-04-09 14:58:40 +0200 | [diff] [blame] | 640 | * "The xargs utility shall limit the command line length such that |
| 641 | * when the command line is invoked, the combined argument |
| 642 | * and environment lists (see the exec family of functions |
| 643 | * in the System Interfaces volume of IEEE Std 1003.1-2001) |
| 644 | * shall not exceed {ARG_MAX}-2048 bytes". |
| 645 | */ |
Denys Vlasenko | f92f1d0 | 2014-06-22 13:54:40 +0200 | [diff] [blame] | 646 | n_max_chars = bb_arg_max(); |
| 647 | if (n_max_chars > 32 * 1024) |
| 648 | n_max_chars = 32 * 1024; |
| 649 | /* |
| 650 | * POSIX suggests substracting 2048 bytes from sysconf(_SC_ARG_MAX) |
| 651 | * so that the process may safely modify its environment. |
| 652 | */ |
| 653 | n_max_chars -= 2048; |
| 654 | |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 655 | if (opt & OPT_UPTO_SIZE) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 656 | n_max_chars = xatou_range(max_chars, 1, INT_MAX); |
Denys Vlasenko | 4a96617 | 2010-06-19 21:44:01 +0200 | [diff] [blame] | 657 | } |
| 658 | /* Account for prepended fixed arguments */ |
| 659 | { |
| 660 | size_t n_chars = 0; |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 661 | for (i = 0; argv[i]; i++) { |
| 662 | n_chars += strlen(argv[i]) + 1; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 663 | } |
| 664 | n_max_chars -= n_chars; |
Denys Vlasenko | 4a96617 | 2010-06-19 21:44:01 +0200 | [diff] [blame] | 665 | } |
| 666 | /* Sanity check */ |
| 667 | if (n_max_chars <= 0) { |
| 668 | bb_error_msg_and_die("can't fit single argument within argument list size limit"); |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 669 | } |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 670 | |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 671 | buf = xzalloc(n_max_chars + 1); |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 672 | |
Denys Vlasenko | c28cafb | 2010-06-14 12:38:36 +0200 | [diff] [blame] | 673 | n_max_arg = n_max_chars; |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 674 | if (opt & OPT_UPTO_NUMBER) { |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 675 | n_max_arg = xatou_range(max_args, 1, INT_MAX); |
Denys Vlasenko | 4a96617 | 2010-06-19 21:44:01 +0200 | [diff] [blame] | 676 | /* Not necessary, we use growable args[]: */ |
| 677 | /* if (n_max_arg > n_max_chars) n_max_arg = n_max_chars */ |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 680 | #if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR |
| 681 | if (opt & (OPT_REPLSTR | OPT_REPLSTR1)) { |
| 682 | /* |
| 683 | * -I<str>: |
| 684 | * Unmodified args are kept in G.argv[i], |
| 685 | * G.args[i] receives malloced G.argv[i] with <str> replaced |
| 686 | * with input line. Setting this up: |
| 687 | */ |
| 688 | G.args = NULL; |
| 689 | G.argv = argv; |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 690 | read_args = process_stdin_with_replace; |
Aaro Koskinen | 6d777b7 | 2015-10-24 22:01:29 +0200 | [diff] [blame] | 691 | /* Make -I imply -r. GNU findutils seems to do the same: */ |
| 692 | /* (otherwise "echo -n | xargs -I% echo %" would SEGV) */ |
| 693 | opt |= OPT_NO_EMPTY; |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 694 | } else |
| 695 | #endif |
| 696 | { |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 697 | /* Store the command to be executed, part 1. |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 698 | * We can statically allocate (argc + n_max_arg + 1) elements |
| 699 | * and do not bother with resizing args[], but on 64-bit machines |
| 700 | * this results in args[] vector which is ~8 times bigger |
| 701 | * than n_max_chars! That is, with n_max_chars == 20k, |
| 702 | * args[] will take 160k (!), which will most likely be |
| 703 | * almost entirely unused. |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 704 | */ |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 705 | for (i = 0; argv[i]; i++) |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 706 | store_param(argv[i]); |
Denys Vlasenko | 6f06890 | 2014-02-27 11:17:06 +0100 | [diff] [blame] | 707 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 708 | |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 709 | initial_idx = G.idx; |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 710 | while (1) { |
| 711 | char *rem; |
| 712 | |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 713 | G.idx = initial_idx; |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 714 | rem = read_args(n_max_chars, n_max_arg, buf); |
Denys Vlasenko | c28cafb | 2010-06-14 12:38:36 +0200 | [diff] [blame] | 715 | store_param(NULL); |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 716 | |
Denys Vlasenko | b270be3 | 2017-08-24 11:21:27 +0200 | [diff] [blame] | 717 | if (!G.args[initial_idx]) { /* not even one ARG was added? */ |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 718 | if (*rem != '\0') |
| 719 | bb_error_msg_and_die("argument line too long"); |
| 720 | if (opt & OPT_NO_EMPTY) |
| 721 | break; |
| 722 | } |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 723 | opt |= OPT_NO_EMPTY; |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 724 | |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 725 | if (opt & (OPT_INTERACTIVE | OPT_VERBOSE)) { |
Denys Vlasenko | c28cafb | 2010-06-14 12:38:36 +0200 | [diff] [blame] | 726 | const char *fmt = " %s" + 1; |
| 727 | char **args = G.args; |
| 728 | for (i = 0; args[i]; i++) { |
| 729 | fprintf(stderr, fmt, args[i]); |
| 730 | fmt = " %s"; |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 731 | } |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 732 | if (!(opt & OPT_INTERACTIVE)) |
Denys Vlasenko | 19ced5c | 2010-06-06 21:53:09 +0200 | [diff] [blame] | 733 | bb_putchar_stderr('\n'); |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 734 | } |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 735 | |
Denis Vlasenko | 6248a73 | 2006-09-29 08:20:30 +0000 | [diff] [blame] | 736 | if (!(opt & OPT_INTERACTIVE) || xargs_ask_confirmation()) { |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 737 | if (xargs_exec() != 0) |
| 738 | break; /* G.xargs_exitcode is set by xargs_exec() */ |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 739 | } |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 740 | |
| 741 | overlapping_strcpy(buf, rem); |
Denis Vlasenko | d50dda8 | 2008-06-15 05:40:56 +0000 | [diff] [blame] | 742 | } /* while */ |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 743 | |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 744 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 745 | free(G.args); |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 746 | free(buf); |
Denys Vlasenko | 7a4021d | 2010-06-14 00:57:05 +0200 | [diff] [blame] | 747 | } |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 748 | |
Denys Vlasenko | 14551b7 | 2017-08-24 13:23:54 +0200 | [diff] [blame] | 749 | #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
| 750 | G.max_procs = 0; |
| 751 | xargs_exec(); /* final waitpid() loop */ |
| 752 | #endif |
| 753 | |
| 754 | return G.xargs_exitcode; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
| 758 | #ifdef TEST |
| 759 | |
Denis Vlasenko | 8f8f268 | 2006-10-03 21:00:43 +0000 | [diff] [blame] | 760 | const char *applet_name = "debug stuff usage"; |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 761 | |
| 762 | void bb_show_usage(void) |
| 763 | { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 764 | fprintf(stderr, "Usage: %s [-p] [-r] [-t] -[x] [-n max_arg] [-s max_chars]\n", |
Denis Vlasenko | 8f8f268 | 2006-10-03 21:00:43 +0000 | [diff] [blame] | 765 | applet_name); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 766 | exit(EXIT_FAILURE); |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | int main(int argc, char **argv) |
| 770 | { |
Glenn L McGrath | 09c295a | 2003-10-30 22:47:16 +0000 | [diff] [blame] | 771 | return xargs_main(argc, argv); |
Glenn L McGrath | 6179694 | 2003-10-10 12:10:18 +0000 | [diff] [blame] | 772 | } |
Eric Andersen | 252183e | 2003-10-31 08:19:44 +0000 | [diff] [blame] | 773 | #endif /* TEST */ |