]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge revisions 14213 and 14612 from the BUF_REMOVAL branch to trunk.
authorFlorian Krohm <florian@eich-krohm.de>
Thu, 9 Oct 2014 19:22:44 +0000 (19:22 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Thu, 9 Oct 2014 19:22:44 +0000 (19:22 +0000)
The change removes the PATH_MAX limitation from the linux launcher.

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

coregrind/launcher-linux.c

index c91c41c76851b6bdd17076031a9da67e16e6c1c5..64e799c766c9125d43be0c14d153e755b280aec9 100644 (file)
@@ -51,7 +51,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <limits.h>             // PATH_MAX
 
 #ifndef EM_X86_64
 #define EM_X86_64 62    // elf.h doesn't define this on some older systems
@@ -279,7 +278,7 @@ int main(int argc, char** argv, char** envp)
    const char *default_platform;
    const char *cp;
    char *toolfile;
-   char launcher_name[PATH_MAX+1];
+   const char *launcher_name;
    char* new_line;
    char** new_env;
 
@@ -358,17 +357,34 @@ int main(int argc, char** argv, char** envp)
    /* Figure out the name of this executable (viz, the launcher), so
       we can tell stage2.  stage2 will use the name for recursive
       invocations of valgrind on child processes. */
-   memset(launcher_name, 0, PATH_MAX+1);
-   r = readlink("/proc/self/exe", launcher_name, PATH_MAX);
-   if (r == -1) {
-      /* If /proc/self/exe can't be followed, don't give up.  Instead
-         continue with an empty string for VALGRIND_LAUNCHER.  In the
-         sys_execve wrapper, this is tested, and if found to be empty,
-         fail the execve. */
-      fprintf(stderr, "valgrind: warning (non-fatal): "
-                      "readlink(\"/proc/self/exe\") failed.\n");
-      fprintf(stderr, "valgrind: continuing, however --trace-children=yes "
-                      "will not work.\n");
+   unsigned bufsiz = 0;
+   char *buf = NULL;
+
+   while (42) {
+      bufsiz += 500;
+      buf = realloc(buf, bufsiz);
+      if (buf == NULL)
+         barf("realloc of buf failed.");
+      r = readlink("/proc/self/exe", buf, bufsiz);
+      if (r == -1) {
+        /* If /proc/self/exe can't be followed, don't give up.  Instead
+           continue with an empty string for VALGRIND_LAUNCHER.  In the
+           sys_execve wrapper, this is tested, and if found to be empty,
+           fail the execve. */
+        fprintf(stderr, "valgrind: warning (non-fatal): "
+                "readlink(\"/proc/self/exe\") failed.\n");
+        fprintf(stderr, "valgrind: continuing, however --trace-children=yes "
+                "will not work.\n");
+        launcher_name = "";
+        break;
+      }
+      if (r == bufsiz) continue;   // buffer to small; retry
+
+      assert(r < bufsiz);   // paranoia
+
+      buf[r] = '\0';
+      launcher_name = buf;
+      break;
    }
 
    /* tediously augment the env: VALGRIND_LAUNCHER=launcher_name */