From fcebaf2c9f079ec32df39acaaffea18000674a1a Mon Sep 17 00:00:00 2001 From: David Glasser Date: Fri, 27 Mar 2015 16:22:44 -0700 Subject: [PATCH] findMongoPids: use pgrep where available ps corrupts some non-ASCII characters on OS X. pgrep doesn't, but isn't available everywhere. Fixes #3999. --- tools/run-mongo.js | 20 +++++++++++++++++++- tools/tests/mongo.js | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/tools/run-mongo.js b/tools/run-mongo.js index ded13f4169..9a58f85215 100644 --- a/tools/run-mongo.js +++ b/tools/run-mongo.js @@ -124,8 +124,26 @@ if (process.platform === 'win32') { var fut = new Future; // 'ps ax' should be standard across all MacOS and Linux. + // However, ps on OS X corrupts some non-ASCII characters in arguments, + // such as т (CYRILLIC SMALL LETTER TE), leading to this function + // failing to properly match pathnames with those characters. #3999 + // + // pgrep appears to do a better job (and has output that is roughly + // similar; it lacks a few fields that we don't care about). Plus, + // it can do some of the grepping for us. + // + // 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( - 'ps ax', + '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', // 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). diff --git a/tools/tests/mongo.js b/tools/tests/mongo.js index bfbf14d99c..7a4554b3fb 100644 --- a/tools/tests/mongo.js +++ b/tools/tests/mongo.js @@ -19,3 +19,27 @@ selftest.define("mongo failover", ["slow"], function () { run.expectEnd(); run.expectExit(0); }); + +// Regression test for #3999. Note the Cyrillic character in the pathname. +// (Also, tests `meteor mongo` at all...) +selftest.define("mongo in unicode dir", function () { + var s = new Sandbox(); + var appDir = 'asdfтasdf'; + s.createApp(appDir, 'standard-app'); + s.cd(appDir); + + var run = s.run(); + run.waitSecs(15); + run.match(appDir); + run.match('proxy'); + run.match('Started MongoDB'); + + var mongoRun = s.run('mongo'); + mongoRun.match('MongoDB shell'); + mongoRun.match('connecting to: 127.0.0.1'); + // Note: when mongo shell's input is not a tty, there is no prompt. + mongoRun.write('db.version()\n'); + mongoRun.match(/2\.6\.\d+/); + mongoRun.stop(); + run.stop(); +});