Check for dup2 and use dup instead if we don't have it.

This commit is contained in:
Todd C. Miller
2009-09-03 11:28:07 +00:00
parent c57b8bb7b3
commit 2935e2a5ba
4 changed files with 16 additions and 3 deletions

View File

@@ -101,6 +101,9 @@
/* Define to 1 if you have the <dlfcn.h> header file. */ /* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H #undef HAVE_DLFCN_H
/* Define to 1 if you have the `dup2' function. */
#undef HAVE_DUP2
/* Define to 1 if your glob.h defines the GLOB_BRACE and GLOB_TILDE flags. */ /* Define to 1 if your glob.h defines the GLOB_BRACE and GLOB_TILDE flags. */
#undef HAVE_EXTENDED_GLOB #undef HAVE_EXTENDED_GLOB

3
configure vendored
View File

@@ -15828,7 +15828,8 @@ LIBS=$ac_save_LIBS
for ac_func in strchr strrchr memchr memcpy memset sysconf tzset \
for ac_func in dup2 strchr strrchr memchr memcpy memset sysconf tzset \
strftime setrlimit initgroups getgroups fstat gettimeofday \ strftime setrlimit initgroups getgroups fstat gettimeofday \
regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep
do do

View File

@@ -1834,7 +1834,7 @@ dnl
dnl Function checks dnl Function checks
dnl dnl
AC_FUNC_GETGROUPS AC_FUNC_GETGROUPS
AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf tzset \ AC_CHECK_FUNCS(dup2 strchr strrchr memchr memcpy memset sysconf tzset \
strftime setrlimit initgroups getgroups fstat gettimeofday \ strftime setrlimit initgroups getgroups fstat gettimeofday \
regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep) regcomp setlocale getaddrinfo setsid setenv vhangup nanosleep)
AC_CHECK_FUNCS(openpty, [AC_CHECK_HEADERS(util.h pty.h, [break])], [ AC_CHECK_FUNCS(openpty, [AC_CHECK_HEADERS(util.h pty.h, [break])], [

View File

@@ -268,13 +268,22 @@ script_duplow(fd)
/* sort fds so we can dup them safely */ /* sort fds so we can dup them safely */
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
indices[i] = i; indices[i] = i;
/* XXX - qsort is overkill for this */
qsort(indices, 5, sizeof(int), fdcompar); qsort(indices, 5, sizeof(int), fdcompar);
/* Move pty master/slave and session fds to low numbered fds. */ /* Move pty master/slave and session fds to low numbered fds. */
if (def_script) { if (def_script) {
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
j = indices[i]; j = indices[i];
if (script_fds[j] != fd) {
#ifdef HAVE_DUP2
dup2(script_fds[j], fd); dup2(script_fds[j], fd);
#else
close(fd);
dup(script_fds[j]);
close(script_fds[j]);
#endif
}
script_fds[j] = fd++; script_fds[j] = fd++;
} }
} }