diff --git a/tools/run-mongo.js b/tools/run-mongo.js index 9a58f852151..86e86a50d3f 100644 --- a/tools/run-mongo.js +++ b/tools/run-mongo.js @@ -135,15 +135,26 @@ if (process.platform === 'win32') { // However, 'pgrep' only started shipping with OS X 10.8 (and may be less // common on Linux too), so we check to see if it exists and fall back to // 'ps' if we can't find it. - child_process.exec( - 'if type pgrep >/dev/null 2>&1; then ' + + // + // We avoid using pgrep on Linux, because some versions of Linux pgrep + // require you to pass -a/--list-full to include the arguments in the + // output, and other versions fail if you pass that option. We have not + // observed the Unicode corruption on Linux, so using ps ax there is fine. + var psScript = 'ps ax'; + if (process.platform === 'darwin') { + psScript = + 'if type pgrep >/dev/null 2>&1; then ' + // -lf means to display and match against full argument lists. // pgrep exits 1 if no processes match the argument; we're OK // considering this as a success, but we don't want other errors // to be ignored. Note that this is sh not bash, so we can't use // [[. 'pgrep -lf mongod; test "$?" -eq 0 -o "$?" -eq 1;' + - 'else ps ax; fi', + 'else ps ax; fi'; + } + + child_process.exec( + psScript, // we don't want this to randomly fail just because you're running lots of // processes. 10MB should be more than ps ax will ever spit out; the default // is 200K, which at least one person hit (#2158).