summaryrefslogtreecommitdiff
path: root/xargs
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2013-08-02 14:17:14 +0200
committerJames Youngman <jay@gnu.org>2013-09-21 23:18:19 +0100
commit169161fa0e6bd29541cdb68abb673c213779594f (patch)
tree828c52c89e5b6067834bbcaefdf89d0b77bcf2b3 /xargs
parent29f3173a562edc67361426ab8c7a1789e5814de1 (diff)
downloadfindutils-169161fa0e6bd29541cdb68abb673c213779594f.tar.gz
xargs: wait for process before prompting in interactive mode (-p)
In interactive mode, there is a race between xargs prompting about the next command to be run, vs. the execution of the echo command: $ echo 1 2 | xargs -n 1 -p /bin/echo 1 ?...y /bin/echo 2 ?...1 y 2 This behavior violates POSIX: (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html): The xargs utility shall then invoke the constructed command line and wait for its completion. This sequence shall be repeated until one of the following occurs: [...] * xargs/xargs.c (xargs_do_exec): Move the code for waiting for forked processes up, so that the child process terminates before we prompt for the next command. * NEWS: Mention the fix. Reported by jidanni@jidanni.org in http://lists.gnu.org/archive/html/bug-findutils/2013-07/msg00015.html
Diffstat (limited to 'xargs')
-rw-r--r--xargs/xargs.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/xargs/xargs.c b/xargs/xargs.c
index d773bde6..5e373f2b 100644
--- a/xargs/xargs.c
+++ b/xargs/xargs.c
@@ -1179,15 +1179,16 @@ xargs_do_exec (struct buildcmd_control *ctl, void *usercontext, int argc, char *
(void) argc;
(void) usercontext;
+ if (proc_max)
+ {
+ while (procs_executing >= proc_max)
+ {
+ wait_for_proc (false, 1u);
+ }
+ }
+
if (!query_before_executing || print_args (true))
{
- if (proc_max)
- {
- while (procs_executing >= proc_max)
- {
- wait_for_proc (false, 1u);
- }
- }
if (!query_before_executing && print_command)
print_args (false);