diff options
author | Aditya Mandaleeka <adityam@microsoft.com> | 2016-03-28 20:22:04 -0700 |
---|---|---|
committer | Aditya Mandaleeka <adityam@microsoft.com> | 2016-03-28 20:22:04 -0700 |
commit | b66da08912d8b43c39f743e5a65515d3e74ec432 (patch) | |
tree | 1d742e5fb6440b37aaf9d18e5e335849b4cc6d57 /src/pal | |
parent | 48ce56b9fcd1b5edf5ca28f83d7b623b71e5c925 (diff) | |
download | coreclr-b66da08912d8b43c39f743e5a65515d3e74ec432.tar.gz coreclr-b66da08912d8b43c39f743e5a65515d3e74ec432.tar.bz2 coreclr-b66da08912d8b43c39f743e5a65515d3e74ec432.zip |
Fix stat file parsing to handle executable names with spaces.
Diffstat (limited to 'src/pal')
-rw-r--r-- | src/pal/src/thread/process.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index 4fd2e2d978..593070cae6 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -1903,9 +1903,15 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey) unsigned long long starttime; - // scanf format specifiers for the fields in the stat file are provided by 'man proc'. - int sscanfRet = sscanf(line, - "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu \n", + // According to `man proc`, the second field in the stat file is the filename of the executable, + // in parentheses. Tokenizing the stat file using spaces as separators breaks when that name + // has spaces in it, so we start using sscanf after skipping everything up to and including the + // last closing paren and the space after it. + char *scanStartPosition = strrchr(line, ')') + 2; + + // All the format specifiers for the fields in the stat file are provided by 'man proc'. + int sscanfRet = sscanf(scanStartPosition, + "%*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu \n", &starttime); if (sscanfRet != 1) |