diff options
author | Mathias Stearn <mathias@10gen.com> | 2010-05-11 15:23:50 -0400 |
---|---|---|
committer | Mathias Stearn <redbeard0531@gmail.com> | 2010-05-24 10:36:34 -0400 |
commit | dc461306241ec2263f16220947ac6d49b6d77ee7 (patch) | |
tree | 2da35644c19a90b1605976ceaa20a8b9ed34ea50 | |
parent | 797db1f61ffa77b8e55d4cdaefde45388692d979 (diff) | |
download | mongo-dc461306241ec2263f16220947ac6d49b6d77ee7.tar.gz |
fix windows service registration
(cherry picked from commit d0eccc9c80123e1d7e1fbfad32431d044b925008)
(Backport of SERVER-1070 to v1.4)
-rw-r--r-- | util/ntservice.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/util/ntservice.cpp b/util/ntservice.cpp index 602d98a8e6d..07dce206a02 100644 --- a/util/ntservice.cpp +++ b/util/ntservice.cpp @@ -17,6 +17,7 @@ #include "stdafx.h" #include "ntservice.h" +#include <direct.h> #if defined(_WIN32) @@ -32,17 +33,26 @@ namespace mongo { } bool ServiceController::installService( const std::wstring& serviceName, const std::wstring& displayName, const std::wstring& serviceDesc, int argc, char* argv[] ) { + assert(argc >= 1); + + stringstream commandLine; + + if ( strchr(argv[0], ':') ) { // a crude test for fully qualified path + commandLine << '"' << argv[0] << "\" "; + } else { + char buffer[256]; + assert( _getcwd(buffer, 256) ); + commandLine << '"' << buffer << '\\' << argv[0] << "\" "; + } - std::string commandLine; - - for ( int i = 0; i < argc; i++ ) { + for ( int i = 1; i < argc; i++ ) { std::string arg( argv[ i ] ); // replace install command to indicate process is being started as a service if ( arg == "--install" ) arg = "--service"; - commandLine += arg + " "; + commandLine << arg << " "; } SC_HANDLE schSCManager = ::OpenSCManager( null, null, SC_MANAGER_ALL_ACCESS ); @@ -50,7 +60,7 @@ namespace mongo { return false; std::basic_ostringstream< TCHAR > commandLineWide; - commandLineWide << commandLine.c_str(); + commandLineWide << commandLine.str().c_str(); // create new service SC_HANDLE schService = ::CreateService( schSCManager, serviceName.c_str(), displayName.c_str(), |