/* POSIX.2 wordexp implementation.
- Copyright (C) 1997-2003,2005,2006,2008,2011 Free Software Foundation, Inc.
+ Copyright (C) 1997-2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Tim Waugh <tim@cyberelk.demon.co.uk>.
#include <paths.h>
#include <pwd.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
args[1] = "-nc";
/* Redirect output. */
- if (__builtin_expect (fildes[1] != STDOUT_FILENO, 1))
+ if (__glibc_likely (fildes[1] != STDOUT_FILENO))
{
__dup2 (fildes[1], STDOUT_FILENO);
__close (fildes[1]);
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)
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)