bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xargs -p operations out of order!


From: Bernhard Voelker
Subject: Re: xargs -p operations out of order!
Date: Fri, 02 Aug 2013 14:17:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5

On 08/01/2013 12:11 AM, Eric Blake wrote:
> Indeed, I think you have a real bug after all - xargs should not be
> prompting for the fourth command until after it reaps the echo process
> spawned by the affirmative answer to the third prompt.

The fix seems to be quite easy (i.e. I didn't see any side effects).

Have a nice day,
Berny



>From 92c6596d151c93797d559036b4af879c1c320259 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Fri, 2 Aug 2013 14:16:27 +0200
Subject: [PATCH] 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 process terminated before prompting for the
next command.
* NEWS: Mention the fix.

Reported by address@hidden in
http://lists.gnu.org/archive/html/bug-findutils/2013-07/msg00015.html
---
 NEWS          |  2 ++
 xargs/xargs.c | 15 ++++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/NEWS b/NEWS
index 4349a21..e0a41a3 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,8 @@ database, though they are in the ChangeLog:

 *** Don't delete header files in "lib/" for "make clean".

+*** xargs: wait for process before prompting in interactive mode (-p)
+
 These following fixed bugs are recorded at
 https://savannah.gnu.org/bugs/?group=findutils:

diff --git a/xargs/xargs.c b/xargs/xargs.c
index e0b2421..35c1198 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);

-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]