Fix a bug in the last VG_(max_fd) change; VG_(safe_fd) doesn't work before
VG_(max_fd) has been set up.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2128 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c
index f007714..2dcfb7a 100644
--- a/coregrind/vg_main.c
+++ b/coregrind/vg_main.c
@@ -154,7 +154,7 @@
Int VG_(main_pgrp);
/* Maximum allowed application-visible file descriptor */
-Int VG_(max_fd);
+Int VG_(max_fd) = -1;
/* Words. */
static Int baB_off = 0;
@@ -1403,11 +1403,6 @@
vg_assert(VG_(clstk_end) == VG_(client_end));
- if (kp->vgexecfd != -1)
- VG_(vgexecfd) = VG_(safe_fd)(kp->vgexecfd);
- if (kp->clexecfd != -1)
- VG_(clexecfd) = VG_(safe_fd)(kp->clexecfd);
-
if (0) {
if (VG_(have_ssestate))
VG_(printf)("Looks like a SSE-capable CPU\n");
@@ -1437,6 +1432,11 @@
/* Update the soft limit. */
VG_(setrlimit)(VKI_RLIMIT_NOFILE, &rl);
+ if (kp->vgexecfd != -1)
+ VG_(vgexecfd) = VG_(safe_fd)(kp->vgexecfd);
+ if (kp->clexecfd != -1)
+ VG_(clexecfd) = VG_(safe_fd)(kp->clexecfd);
+
/* Read /proc/self/maps into a buffer. Must be before:
- SK_(pre_clo_init)(): so that if it calls VG_(malloc)(), any mmap'd
superblocks are not erroneously identified as being owned by the
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index 850e178..c061535 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -1203,6 +1203,8 @@
{
Int newfd;
+ vg_assert(VG_(max_fd) != -1);
+
newfd = VG_(fcntl)(oldfd, VKI_F_DUPFD, VG_(max_fd)+1);
if (newfd != -1)
VG_(close)(oldfd);