|
From: <sv...@va...> - 2014-07-30 21:14:43
|
Author: florian
Date: Wed Jul 30 21:14:34 2014
New Revision: 14213
Log:
Remove PATH_MAX limitation from linux launcher.
Modified:
branches/BUF_REMOVAL/coregrind/launcher-linux.c
Modified: branches/BUF_REMOVAL/coregrind/launcher-linux.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/launcher-linux.c (original)
+++ branches/BUF_REMOVAL/coregrind/launcher-linux.c Wed Jul 30 21:14:34 2014
@@ -271,7 +271,7 @@
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;
@@ -349,17 +349,34 @@
/* 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 += PATH_MAX;
+ 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 */
|