AC_FUNC_VFORK
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
-AC_CHECK_FUNCS([clock_gettime ctermid])
+AC_CHECK_FUNCS([clock_gettime closefrom ctermid])
AC_CHECK_FUNCS([dup2])
AC_CHECK_FUNCS([fcntl fdatasync feclearexcept fedisableexcept feenableexcept])
AC_CHECK_FUNCS([fegetenv fegetexcept fegetexceptflag fegetround feholdexcept])
}
#endif /* EMULATE_FPATHCONF */
\f
+#ifdef EMULATE_CLOSEFROM
+
+int
+UX_closefrom (int fd)
+{
+#if ((defined (HAVE_FCNTL)) && (defined (F_CLOSEM)))
+ return (UX_fcntl (fd, F_CLOSEM));
+#elif ((defined (HAVE_FCNTL)) && (defined (F_MAXFD)))
+ int max_fd = (UX_fcntl ((-1), F_MAXFD));
+ int status;
+ if (max_fd < 0) return (max_fd);
+ while (fd <= max_fd)
+ if (((status = (UX_close (fd++))) < 0) && (errno != EBADF))
+ return (status);
+ return (0);
+#else
+ int fd_limit = (UX_SC_OPEN_MAX ());
+ int status;
+ while (fd < fd_limit)
+ if (((status = (UX_close (fd++))) < 0) && (errno != EBADF))
+ return (status);
+ return (0);
+#endif
+}
+
+#endif
+\f
void *
OS_malloc_init (size_t size)
{
extern unsigned long UX_getpagesize (void);
# define EMULATE_GETPAGESIZE
#endif
+
+#ifdef HAVE_CLOSEFROM
+# define UX_closefrom closefrom
+#else
+ extern int UX_closefrom (int);
+# define EMULATE_CLOSEFROM
+#endif
\f
/* poll is somewhat busted on Mac OSX 10.4 (Tiger), so use select. */
#ifdef __APPLE__
goto kill_child;
}
}
- {
- /* Close all other file descriptors. */
- int open_max = (UX_SC_OPEN_MAX ());
- int fd;
- for (fd = 0; (fd < open_max); fd += 1)
- if ((fd == STDIN_FILENO)
- ? (channel_in_type == process_channel_type_none)
- : (fd == STDOUT_FILENO)
- ? (channel_out_type == process_channel_type_none)
- : (fd == STDERR_FILENO)
- ? (channel_err_type == process_channel_type_none)
- : 1)
- (void) UX_close (fd);
- }
+
+ /* Close all file descriptors not used by the child. */
+ /* FIXME: Handle EINTR? */
+ if (channel_in_type == process_channel_type_none)
+ if ((UX_close (STDIN_FILENO)) < 0) goto kill_child;
+ if (channel_out_type == process_channel_type_none)
+ if ((UX_close (STDOUT_FILENO)) < 0) goto kill_child;
+ if (channel_err_type == process_channel_type_none)
+ if ((UX_close (STDERR_FILENO)) < 0) goto kill_child;
+ /* Assumption: STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2. */
+ if ((UX_closefrom (3)) < 0) goto kill_child;
/* Put the signal mask and handlers in a normal state. */
UX_initialize_child_signals ();