[glib] gspawn: Handle EINTR in a few more cases



commit 7e1886ba72a36f73296781c5ca5525ae5e8288aa
Author: Colin Walters <walters verbum org>
Date:   Fri Jun 10 10:14:25 2011 -0400

    gspawn: Handle EINTR in a few more cases
    
    I was debugging gthread/tests/spawn-multithreaded.c, and while I
    don't think I actually hit EINTR in any of these cases, it'd be
    good to fix them anyways.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=652072

 glib/gspawn.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/glib/gspawn.c b/glib/gspawn.c
index 1e7d38a..4cd5a1a 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -148,7 +148,10 @@ close_and_invalidate (gint *fd)
     return -1;
   else
     {
+    again:
       ret = close (*fd);
+      if (ret == -1 && errno == EINTR)
+	goto again;
       *fd = -1;
     }
 
@@ -323,10 +326,13 @@ g_spawn_sync (const gchar          *working_directory,
                     NULL, NULL,
                     NULL /* no timeout */);
 
-      if (ret < 0 && errno != EINTR)
+      if (ret < 0)
         {
           int errsv = errno;
 
+	  if (errno == EINTR)
+	    continue;
+
           failed = TRUE;
 
           g_set_error (error,
@@ -993,6 +999,19 @@ sane_dup2 (gint fd1, gint fd2)
   return ret;
 }
 
+static gint
+sane_open (const char *path, gint mode)
+{
+  gint ret;
+
+ retry:
+  ret = open (path, mode);
+  if (ret < 0 && errno == EINTR)
+    goto retry;
+
+  return ret;
+}
+
 enum
 {
   CHILD_CHDIR_FAILED,
@@ -1071,7 +1090,7 @@ do_exec (gint                  child_err_report_fd,
     }
   else if (stdout_to_null)
     {
-      gint write_null = open ("/dev/null", O_WRONLY);
+      gint write_null = sane_open ("/dev/null", O_WRONLY);
       sane_dup2 (write_null, 1);
       close_and_invalidate (&write_null);
     }
@@ -1089,7 +1108,7 @@ do_exec (gint                  child_err_report_fd,
     }
   else if (stderr_to_null)
     {
-      gint write_null = open ("/dev/null", O_WRONLY);
+      gint write_null = sane_open ("/dev/null", O_WRONLY);
       sane_dup2 (write_null, 2);
       close_and_invalidate (&write_null);
     }



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