Fix #357585, Padraig O'Briain.
authorMatthias Clasen <mclasen@redhat.com>
Fri, 15 Dec 2006 05:33:32 +0000 (05:33 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 15 Dec 2006 05:33:32 +0000 (05:33 +0000)
2006-12-15  Matthias Clasen  <mclasen@redhat.com>

Fix #357585, Padraig O'Briain.

* configure.in: Check for fdwalk.

* glib/gspawn.c (do_exec): Use fdwalk() to close all
file descriptors.

* glib/gspawn.c (fdwalk): Fallback implementation of
fdwalk.

ChangeLog
configure.in
glib/gspawn.c

index f691dc7..045e7e4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-12-15  Matthias Clasen  <mclasen@redhat.com>
+
+       Fix #357585, Padraig O'Briain.
+       
+       * configure.in: Check for fdwalk.
+       
+       * glib/gspawn.c (do_exec): Use fdwalk() to close all
+       file descriptors. 
+
+       * glib/gspawn.c (fdwalk): Fallback implementation of
+       fdwalk.
+
 2006-12-14  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/gconvert.c (open_converter): Don't use alloca
index 6c0a1bb..4a50909 100644 (file)
@@ -855,7 +855,7 @@ fi
 AC_MSG_RESULT(unsigned $glib_size_type)
 
 # Check for some functions
-AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink)
+AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk)
 # Check for high-resolution sleep functions
 AC_CHECK_FUNCS(nanosleep nsleep)
 
index 5939732..cd97c30 100644 (file)
@@ -30,6 +30,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <string.h>
+#include <stdlib.h>   /* for fdwalk */
 
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
@@ -850,11 +851,29 @@ write_err_and_exit (gint fd, gint msg)
 }
 
 static void
-set_cloexec (gint fd)
+set_cloexec (void *data, gint fd)
 {
-  fcntl (fd, F_SETFD, FD_CLOEXEC);
+  if (fd > 2)
+    fcntl (fd, F_SETFD, FD_CLOEXEC);
 }
 
+#ifndef HAVE_FDWALK
+static int
+fdwalk (int (*cb)(void *data, int fd), void *data)
+{
+  gint open_max;
+  gint fd;
+  gint res;
+
+  res = 0;
+  open_max = sysconf (_SC_OPEN_MAX);
+  for (fd = 0; fd < open_max && res == 0; fd++)
+    res = cb (data, fd);
+
+  return res;
+}
+#endif
+
 static gint
 sane_dup2 (gint fd1, gint fd2)
 {
@@ -904,12 +923,7 @@ do_exec (gint                  child_err_report_fd,
    */
   if (close_descriptors)
     {
-      gint open_max;
-      gint i;
-      
-      open_max = sysconf (_SC_OPEN_MAX);
-      for (i = 3; i < open_max; i++)
-        set_cloexec (i);
+      fdwalk (set_cloexec, NULL);
     }
   else
     {