Avoid busy loop in wordexp when substituted command closed its stdout
authorAndreas Schwab <schwab@suse.de>
Sat, 19 Jan 2013 16:18:47 +0000 (17:18 +0100)
committerAndreas Schwab <schwab@suse.de>
Mon, 21 Jan 2013 09:40:04 +0000 (10:40 +0100)
ChangeLog
NEWS
posix/wordexp.c

index 3bf3949586b55e174c23fbcb2407864b98fe72f7..9b5346350c89c89252c3145ec1dd45bca10fc548 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-01-21  Andreas Schwab  <schwab@suse.de>
+
+       [BZ #15020]
+       * posix/wordexp.c (exec_comm): Avoid busy loop when command has
+       closed its stdout.
+
 2013-01-20  Andreas Schwab  <schwab@linux-m68k.org>
 
        * sysdeps/powerpc/powerpc32/power4/fpu/mpa.c: Don't include
diff --git a/NEWS b/NEWS
index cf6191bb33a3cbcdbbde82ea5799d8bcdbe000a1..abbbbaeec566c39134fa818e0de2e7ac9321656a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,7 +10,7 @@ Version 2.18
 * The following bugs are resolved with this release:
 
   13951, 14200, 14317, 14327, 14496, 14964, 14981, 14982, 14985, 14994,
-  14996, 15003, 15023.
+  14996, 15003, 15020, 15023.
 
 \f
 Version 2.17
index bf49baab9c78a30ef3344ba96d31a786034346c6..96ce8a4b17697a4ec65663fd9319d696fe8f0a56 100644 (file)
@@ -953,7 +953,12 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
          if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
                                                    bufsize))) < 1)
            {
-             if (TEMP_FAILURE_RETRY (__waitpid (pid, &status, WNOHANG)) == 0)
+             /* If read returned 0 then the process has closed its
+                stdout.  Don't use WNOHANG in that case to avoid busy
+                looping until the process eventually exits.  */
+             if (TEMP_FAILURE_RETRY (__waitpid (pid, &status,
+                                                buflen == 0 ? 0 : WNOHANG))
+                 == 0)
                continue;
              if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
                                                        bufsize))) < 1)
@@ -983,7 +988,12 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
          if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
                                                    bufsize))) < 1)
            {
-             if (TEMP_FAILURE_RETRY (__waitpid (pid, &status, WNOHANG)) == 0)
+             /* If read returned 0 then the process has closed its
+                stdout.  Don't use WNOHANG in that case to avoid busy
+                looping until the process eventually exits.  */
+             if (TEMP_FAILURE_RETRY (__waitpid (pid, &status,
+                                                buflen == 0 ? 0 : WNOHANG))
+                 == 0)
                continue;
              if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
                                                        bufsize))) < 1)