]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - posix/wordexp.c
Use glibc_likely instead __builtin_expect.
[thirdparty/glibc.git] / posix / wordexp.c
index 5ace13720b6a54e5b9f1b63b9c26bc4d3cb08732..b6b65dd993ec7e2ee5e3e88f8800c2e254cb9d5f 100644 (file)
@@ -1,5 +1,5 @@
 /* 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>.
 
@@ -27,6 +27,7 @@
 #include <paths.h>
 #include <pwd.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -822,7 +823,7 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
     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]);
@@ -952,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)
@@ -982,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)