summaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2013-01-19 17:18:47 +0100
committerAndreas Schwab <schwab@suse.de>2013-01-21 10:40:04 +0100
commitab087e0aa4bd9f12a73ca0b248f02d8a22d49e46 (patch)
tree17451ec254a5877b2ad063306d719e744bc7adbd /posix
parentba6f5ae50b86b58b8735671db2c4798249e42ddf (diff)
downloadglibc-ab087e0aa4bd9f12a73ca0b248f02d8a22d49e46.tar.gz
Avoid busy loop in wordexp when substituted command closed its stdout
Diffstat (limited to 'posix')
-rw-r--r--posix/wordexp.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/posix/wordexp.c b/posix/wordexp.c
index bf49baab9c..96ce8a4b17 100644
--- a/posix/wordexp.c
+++ b/posix/wordexp.c
@@ -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)