Index: glib/gspawn.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gspawn.c,v
retrieving revision 1.35.2.1
diff -u -r1.35.2.1 gspawn.c
--- glib/gspawn.c	30 Sep 2006 14:21:38 -0000	1.35.2.1
+++ glib/gspawn.c	1 Oct 2006 06:16:54 -0000
@@ -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,25 @@
 }
 
 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 void
+fdwalk (void (cb)(void *data, int fd), void *data)
+{
+  gint open_max;
+  gint fd;
+  
+  open_max = sysconf (_SC_OPEN_MAX);
+  for (fd = 0; fd < open_max; fd++)
+    cb (data, fd);  
+}
+#endif
+
 static gint
 sane_dup2 (gint fd1, gint fd2)
 {
@@ -904,12 +919,7 @@
    */
   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
     {
Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.518.2.8
diff -u -r1.518.2.8 configure.in
--- configure.in	1 Oct 2006 05:51:15 -0000	1.518.2.8
+++ configure.in	1 Oct 2006 06:16:56 -0000
@@ -855,7 +855,7 @@
 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)
 
