Skip to content

Commit

Permalink
run-mongo: Only use pgrep on OS X
Browse files Browse the repository at this point in the history
The fix to #3999 didn't work on newer Linux systems whose pgrep contains
the backwards-incompatible change
https://gitorious.org/procps/procps/commit/f12277c74d591245767d77badb6bb6af91335656
to not include arguments.

Since the inspiration to use pgrep instead of 'ps ax' was to work around
an OS X bug, just avoid pgrep on Linux in the first place.

Fixes #4115.
  • Loading branch information
glasser committed Apr 3, 2015
1 parent cdaaa6b commit 2815e0e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tools/run-mongo.js
Expand Up @@ -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).
Expand Down

0 comments on commit 2815e0e

Please sign in to comment.