From 402995517928df09672ffa3ba7524d32ef809f61 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 8 Mar 2010 12:54:39 -0800 Subject: [PATCH] SERVER-705 return return code when stopping mongod program --- shell/servers.js | 2 +- shell/utils.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/shell/servers.js b/shell/servers.js index 648e06db14b..518916a8011 100644 --- a/shell/servers.js +++ b/shell/servers.js @@ -621,7 +621,7 @@ ReplTest.prototype.stop = function( master , signal ){ this.stop( false ); return; } - stopMongod( this.getPort( master ) , signal || 15 ); + return stopMongod( this.getPort( master ) , signal || 15 ); } allocatePorts = function( n ) { diff --git a/shell/utils.cpp b/shell/utils.cpp index 8f2268b7bd7..6ba70f12b70 100644 --- a/shell/utils.cpp +++ b/shell/utils.cpp @@ -523,12 +523,13 @@ namespace mongo { } - void killDb( int port, pid_t _pid, int signal ) { + int killDb( int port, pid_t _pid, int signal ) { pid_t pid; + int exitCode = 0; if ( port > 0 ) { if( dbs.count( port ) != 1 ) { cout << "No db started on port: " << port << endl; - return; + return 0; } pid = dbs[ port ].first; } else { @@ -546,7 +547,7 @@ namespace mongo { cout << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl; kill_wrapper( pid, SIGKILL, port ); } - if(wait_for_pid(pid, false)) + if(wait_for_pid(pid, false, &exitCode)) break; sleepms( 1000 ); } @@ -568,6 +569,8 @@ namespace mongo { if ( i > 4 || signal == SIGKILL ) { sleepms( 4000 ); // allow operating system to reclaim resources } + + return exitCode; } int getSignal( const BSONObj &a ) { @@ -586,18 +589,18 @@ namespace mongo { assert( a.nFields() == 1 || a.nFields() == 2 ); assert( a.firstElement().isNumber() ); int port = int( a.firstElement().number() ); - killDb( port, 0, getSignal( a ) ); + int code = killDb( port, 0, getSignal( a ) ); cout << "shell: stopped mongo program on port " << port << endl; - return undefined_; + return BSON( "" << code ); } BSONObj StopMongoProgramByPid( const BSONObj &a ) { assert( a.nFields() == 1 || a.nFields() == 2 ); assert( a.firstElement().isNumber() ); int pid = int( a.firstElement().number() ); - killDb( 0, pid, getSignal( a ) ); + int code = killDb( 0, pid, getSignal( a ) ); cout << "shell: stopped mongo program on pid " << pid << endl; - return undefined_; + return BSON( "" << code ); } void KillMongoProgramInstances() {