Repository: mesos Updated Branches: refs/heads/master 53d354156 -> 9123a5c63
Fixes MESOS-963: OS X command extraction. Review: https://reviews.apache.org/r/18863 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9123a5c6 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9123a5c6 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9123a5c6 Branch: refs/heads/master Commit: 9123a5c6384f2ba95688450ef38bab247d144963 Parents: 53d3541 Author: Benjamin Hindman <[email protected]> Authored: Thu Mar 6 13:45:48 2014 -0800 Committer: Benjamin Hindman <[email protected]> Committed: Thu Mar 6 14:06:38 2014 -0800 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/os/osx.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/9123a5c6/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp index f5bd1c9..8c3ead0 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp @@ -60,6 +60,10 @@ inline Result<Process> process(pid_t pid) // proc_pidpath() instead. Option<std::string> command = None(); + // Alternative implemenations using KERN_PROCARGS2: + // https://bitbucket.org/flub/psi-win32/src/d38f288de3b8/src/arch/macosx/macosx_process.c#cl-552 + // https://gist.github.com/nonowarn/770696 + #ifdef KERN_PROCARGS2 // Looking at the source code of XNU (the Darwin kernel for OS X: // www.opensource.apple.com/source/xnu/xnu-1699.24.23/bsd/kern/kern_sysctl.c), @@ -100,7 +104,16 @@ inline Result<Process> process(pid_t pid) // code will end up just keeping 'command' None (i.e., // tokens.size() will be <= 0). tokens.erase(tokens.begin()); // Remove path. - tokens.erase(tokens.begin() + argc, tokens.end()); + + // In practice it appeared that we might get an 'argc' + // which is greater than 'tokens.size()' which caused us + // to get an invalid iterator from 'tokens.begin() + + // argc', thus we now check that condition here. + if (argc <= tokens.size()) { + tokens.erase(tokens.begin() + argc, tokens.end()); + } + + // If any tokens are left, consider them the command! if (tokens.size() > 0) { command = strings::join(" ", tokens); }
