gspawn: Handle EINTR in a few more cases
authorColin Walters <walters@verbum.org>
Fri, 10 Jun 2011 14:14:25 +0000 (10:14 -0400)
committerColin Walters <walters@verbum.org>
Tue, 14 Jun 2011 23:23:35 +0000 (19:23 -0400)
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

index 1e7d38a..4cd5a1a 100644 (file)
@@ -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);
     }