* http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html
*/
//config:config XARGS
-//config: bool "xargs (6.7 kb)"
+//config: bool "xargs (7.2 kb)"
//config: default y
//config: help
//config: xargs is used to execute a specified command for
//config: bool "Enable -P N: processes to run in parallel"
//config: default y
//config: depends on XARGS
+//config:
+//config:config FEATURE_XARGS_SUPPORT_ARGS_FILE
+//config: bool "Enable -a FILE: use FILE instead of stdin"
+//config: default y
+//config: depends on XARGS
//applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs))
status = (errno == ENOENT) ? 127 : 126;
}
else if (status >= 0x180) {
- bb_error_msg("'%s' terminated by signal %d",
+ bb_error_msg("'%s' terminated by signal %u",
G.args[0], status - 0x180);
status = 125;
}
else if (status != 0) {
if (status == 255) {
bb_error_msg("%s: exited with status 255; aborting", G.args[0]);
- return 124;
+ status = 124;
+ goto ret;
}
/* "123 if any invocation of the command exited with status 1-125"
* This implies that nonzero exit code is remembered,
G.xargs_exitcode = 123;
status = 0;
}
-
+ ret:
if (status != 0)
G.xargs_exitcode = status;
return status;
static int xargs_ask_confirmation(void)
{
FILE *tty_stream;
- int c, savec;
+ int r;
tty_stream = xfopen_for_read(CURRENT_TTY);
+
fputs(" ?...", stderr);
- fflush_all();
- c = savec = getc(tty_stream);
- while (c != EOF && c != '\n')
- c = getc(tty_stream);
+ r = bb_ask_y_confirmation_FILE(tty_stream);
+
fclose(tty_stream);
- return (savec == 'y' || savec == 'Y');
+
+ return r;
}
#else
# define xargs_ask_confirmation() 1
//usage: "[OPTIONS] [PROG ARGS]"
//usage:#define xargs_full_usage "\n\n"
//usage: "Run PROG on every item given by stdin\n"
-//usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(
-//usage: "\n -p Ask user whether to run each command"
-//usage: )
-//usage: "\n -r Don't run command if input is empty"
//usage: IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(
-//usage: "\n -0 Input is separated by NUL characters"
+//usage: "\n -0 Input is separated by NULs"
+//usage: )
+//usage: IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(
+//usage: "\n -a FILE Read from FILE instead of stdin"
//usage: )
+//usage: "\n -r Don't run command if input is empty"
//usage: "\n -t Print the command on stderr before execution"
-//usage: "\n -e[STR] STR stops input processing"
-//usage: "\n -n N Pass no more than N args to PROG"
-//usage: "\n -s N Pass command line of no more than N bytes"
+//usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(
+//usage: "\n -p Ask user whether to run each command"
+//usage: )
+//usage: "\n -E STR,-e[STR] STR stops input processing"
//usage: IF_FEATURE_XARGS_SUPPORT_REPL_STR(
//usage: "\n -I STR Replace STR within PROG ARGS with input line"
//usage: )
+//usage: "\n -n N Pass no more than N args to PROG"
+//usage: "\n -s N Pass command line of no more than N bytes"
//usage: IF_FEATURE_XARGS_SUPPORT_PARALLEL(
//usage: "\n -P N Run up to N PROGs in parallel"
//usage: )
IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \
IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") \
- IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+")
+ IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") \
+ IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( "a:")
int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int xargs_main(int argc UNUSED_PARAM, char **argv)
#else
#define read_args process_stdin
#endif
+ IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(char *opt_a = NULL;)
INIT_G();
&max_args, &max_chars, &G.eof_str, &G.eof_str
IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str)
IF_FEATURE_XARGS_SUPPORT_PARALLEL(, &G.max_procs)
+ IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(, &opt_a)
);
#if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL
G.max_procs = 100; /* let's not go crazy high */
#endif
+#if ENABLE_FEATURE_XARGS_SUPPORT_ARGS_FILE
+ if (opt_a)
+ xmove_fd(xopen(opt_a, O_RDONLY), 0);
+#endif
+
/* -E ""? You may wonder why not just omit -E?
* This is used for portability:
* old xargs was using "_" as default for -E / -e */
}
/* Sanity check */
if (n_max_chars <= 0) {
- bb_error_msg_and_die("can't fit single argument within argument list size limit");
+ bb_simple_error_msg_and_die("can't fit single argument within argument list size limit");
}
buf = xzalloc(n_max_chars + 1);
if (!G.args[initial_idx]) { /* not even one ARG was added? */
if (*rem != '\0')
- bb_error_msg_and_die("argument line too long");
+ bb_simple_error_msg_and_die("argument line too long");
if (opt & OPT_NO_EMPTY)
break;
}