Fix #357585, Padraig O'Briain.

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.
This commit is contained in:
Matthias Clasen 2006-12-15 05:33:32 +00:00 committed by Matthias Clasen
parent 0fffe4abc4
commit af475972c6
3 changed files with 35 additions and 9 deletions

View File

@ -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

View 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)

View 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
{