]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
The configure-time test whether the proc filesystem is mounted (introduced
authorBart Van Assche <bvanassche@acm.org>
Sun, 23 Aug 2009 09:53:27 +0000 (09:53 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 23 Aug 2009 09:53:27 +0000 (09:53 +0000)
in r10156) broke cross-compilation. This patch converts the configure-time
test into a runtime test. Should fix bug #204843.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10860

configure.in
coregrind/m_aspacemgr/aspacemgr-linux.c
coregrind/m_libcfile.c
coregrind/m_main.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/pub_core_libcfile.h

index edb4274427a1a634f350ed80eb551c1be980ee2e..bd3df63e386fcd4cb98b478879eda10096430f59 100644 (file)
@@ -1469,14 +1469,6 @@ AC_DEFINE([HAVE_TLS], 1, [can use __thread to define thread-local variables])
 fi
 
 
-#----------------------------------------------------------------------------
-# Check for /proc filesystem
-#----------------------------------------------------------------------------
-AC_CHECK_FILES(/proc/self/fd /proc/self/exe /proc/self/maps, 
-    [ AC_DEFINE([HAVE_PROC], 1, [can use /proc filesystem]) ], 
-    [])
-
-
 #----------------------------------------------------------------------------
 # Checks for C header files.
 #----------------------------------------------------------------------------
index 8580b19e05e5eb32f644d6dc50d7dbcb92477889..f7c3446ac3a8c18c54ae0311fb0874247e9365f3 100644 (file)
@@ -2986,8 +2986,6 @@ Bool VG_(am_relocate_nooverlap_client)( /*OUT*/Bool* need_discard,
 #endif // HAVE_MREMAP
 
 
-#if HAVE_PROC
-
 /*-----------------------------------------------------------------*/
 /*---                                                           ---*/
 /*--- A simple parser for /proc/self/maps on Linux 2.4.X/2.6.X. ---*/
@@ -3493,8 +3491,6 @@ Bool VG_(get_changed_segments)(
    return !css_overflowed;
 }
 
-#endif // HAVE_PROC
-
 
 #endif // defined(VGO_linux) || defined(VGO_darwin)
 
index 72a9ea624d25122cf5ef51a934bf2f800927d66c..61d35a545af83f364d85ef93d73b382ba3dc19be 100644 (file)
@@ -1083,6 +1083,23 @@ Char *VG_(dirname)(const Char *path)
    return buf;
 }
 
+/* ---------------------------------------------------------------------
+   proc filesystem
+   ------------------------------------------------------------------ */
+Bool VG_(have_proc_filesystem)(void)
+{
+   static int have_proc_fs = -1;
+
+   if (have_proc_fs < 0)
+   {
+      have_proc_fs
+         = VG_(access)("/proc/self/fd", 1, 0, 0) == 0
+         && VG_(access)("/proc/self/exe", 1, 0, 0) == 0
+         && VG_(access)("/proc/self/maps", 1, 0, 0) == 0;
+   }
+   return have_proc_fs;
+}
+
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
index 216ce548f7584f54622e155726fb6d64bcb6f391..f12b056f72d20922a727d4b02ad1a83a2910ef9f 100644 (file)
@@ -1802,48 +1802,48 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
    // when it tries to open /proc/<pid>/cmdline for itself.
    //   p: setup file descriptors
    //--------------------------------------------------------------
-#if !HAVE_PROC
-   // client shouldn't be using /proc!
-   VG_(cl_cmdline_fd) = -1;
-#else
-   if (!need_help) {
-      HChar  buf[50], buf2[50+64];
-      HChar  nul[1];
-      Int    fd, r;
-      HChar* exename;
+   if (! VG_(have_proc_filesystem)()) {
+           // client shouldn't be using /proc!
+           VG_(cl_cmdline_fd) = -1;
+   } else {
+      if (!need_help) {
+         HChar  buf[50], buf2[50+64];
+         HChar  nul[1];
+         Int    fd, r;
+         HChar* exename;
+
+         VG_(debugLog)(1, "main", "Create fake /proc/<pid>/cmdline\n");
+
+         VG_(sprintf)(buf, "proc_%d_cmdline", VG_(getpid)());
+         fd = VG_(mkstemp)( buf, buf2 );
+         if (fd == -1)
+            VG_(err_config_error)("Can't create client cmdline file in /tmp.");
+
+         nul[0] = 0;
+         exename = VG_(args_the_exename) ? VG_(args_the_exename)
+            : "unknown_exename";
+         VG_(write)(fd, VG_(args_the_exename), 
+                    VG_(strlen)( VG_(args_the_exename) ));
+         VG_(write)(fd, nul, 1);
 
-      VG_(debugLog)(1, "main", "Create fake /proc/<pid>/cmdline\n");
+         for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+            HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+            VG_(write)(fd, arg, VG_(strlen)( arg ));
+            VG_(write)(fd, nul, 1);
+         }
 
-      VG_(sprintf)(buf, "proc_%d_cmdline", VG_(getpid)());
-      fd = VG_(mkstemp)( buf, buf2 );
-      if (fd == -1)
-         VG_(err_config_error)("Can't create client cmdline file in /tmp.");
+         /* Don't bother to seek the file back to the start; instead do
+            it every time a copy of it is given out (by PRE(sys_open)). 
+            That is probably more robust across fork() etc. */
 
-      nul[0] = 0;
-      exename = VG_(args_the_exename) ? VG_(args_the_exename)
-                                      : "unknown_exename";
-      VG_(write)(fd, VG_(args_the_exename), 
-                     VG_(strlen)( VG_(args_the_exename) ));
-      VG_(write)(fd, nul, 1);
+         /* Now delete it, but hang on to the fd. */
+         r = VG_(unlink)( buf2 );
+         if (r)
+            VG_(err_config_error)("Can't delete client cmdline file in /tmp.");
 
-      for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
-         HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
-         VG_(write)(fd, arg, VG_(strlen)( arg ));
-         VG_(write)(fd, nul, 1);
+         VG_(cl_cmdline_fd) = fd;
       }
-
-      /* Don't bother to seek the file back to the start; instead do
-        it every time a copy of it is given out (by PRE(sys_open)). 
-        That is probably more robust across fork() etc. */
-
-      /* Now delete it, but hang on to the fd. */
-      r = VG_(unlink)( buf2 );
-      if (r)
-         VG_(err_config_error)("Can't delete client cmdline file in /tmp.");
-
-      VG_(cl_cmdline_fd) = fd;
    }
-#endif
 
    //--------------------------------------------------------------
    // Init tool part 1: pre_clo_init
index 6332859a4230bb82450bcc0cee4e60428966e254..1063802ae84afc7a7326f38627f3cb7384a8fc59 100644 (file)
@@ -3526,12 +3526,12 @@ PRE(sys_open)
    }
    PRE_MEM_RASCIIZ( "open(filename)", ARG1 );
 
-#if HAVE_PROC
-   /* Handle the case where the open is of /proc/self/cmdline or
-      /proc/<pid>/cmdline, and just give it a copy of the fd for the
-      fake file we cooked up at startup (in m_main).  Also, seek the
-      cloned fd back to the start. */
+   if (VG_(have_proc_filesystem)())
    {
+      /* Handle the case where the open is of /proc/self/cmdline or
+         /proc/<pid>/cmdline, and just give it a copy of the fd for the
+         fake file we cooked up at startup (in m_main).  Also, seek the
+         cloned fd back to the start. */
       HChar  name[30];
       Char*  arg1s = (Char*) ARG1;
       SysRes sres;
@@ -3551,7 +3551,6 @@ PRE(sys_open)
          return;
       }
    }
-#endif // HAVE_PROC
 
    /* Otherwise handle normally */
    *flags |= SfMayBlock;
@@ -3674,7 +3673,6 @@ PRE(sys_readlink)
    PRE_MEM_WRITE( "readlink(buf)", ARG2,ARG3 );
 
    {
-#if HAVE_PROC
       /*
        * Handle the case where readlink is looking at /proc/self/exe or
        * /proc/<pid>/exe.
@@ -3682,7 +3680,7 @@ PRE(sys_readlink)
       HChar name[25];
       Char* arg1s = (Char*) ARG1;
       VG_(sprintf)(name, "/proc/%d/exe", VG_(getpid)());
-      if (ML_(safe_to_deref)(arg1s, 1) &&
+      if (VG_(have_proc_filesystem()) && ML_(safe_to_deref)(arg1s, 1) &&
           (VG_STREQ(arg1s, name) || VG_STREQ(arg1s, "/proc/self/exe"))
          )
       {
@@ -3690,7 +3688,6 @@ PRE(sys_readlink)
          SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, (UWord)name, 
                                                          ARG2, ARG3));
       } else
-#endif // HAVE_PROC
       {
          /* Normal case */
          SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, ARG1, ARG2, ARG3));
index 548f1b4d709fca1f909cc90b9c153edb6224c855..cc66e2311a13de6c5c33c82c0f42251f07f5247d 100644 (file)
@@ -98,6 +98,10 @@ extern Int VG_(mkstemp) ( HChar* part_of_name, /*OUT*/HChar* fullname );
    calling VG_(get_startup_wd) (in pub_tool_libcfile.h). */
 extern Bool VG_(record_startup_wd) ( void );
 
+/* Whether or not the proc filesystem has been mounted at the /proc
+   mountpoint. */
+extern Bool VG_(have_proc_filesystem)(void);
+
 #endif   // __PUB_CORE_LIBCFILE_H
 
 /*--------------------------------------------------------------------*/