+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
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)
#include <fcntl.h>
#include <signal.h>
#include <string.h>
+#include <stdlib.h> /* for fdwalk */
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
}
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)
{
*/
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
{