Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean remerge of SERVER-1189 Improves logging in util/ntservice.cpp

I just manually recomitted the changes.
  • Loading branch information...
commit efde5cf575afd1cb8ffe9493d0452042287f3a99 1 parent f753d63
@zippy1981 zippy1981 authored erh committed
View
8 db/db.vcproj
@@ -1502,6 +1502,14 @@
>
</File>
<File
+ RelativePath="..\util\text.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\util\text.h"
+ >
+ </File>
+ <File
RelativePath="..\util\unittest.h"
>
</File>
View
2  s/balancer_policy.cpp
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "../pch.h"
+#include "pch.h"
#include "../client/dbclient.h"
#include "config.h"
View
18 s/dbgrid.vcproj
@@ -185,6 +185,10 @@
>
</File>
<File
+ RelativePath=".\balancer_policy.cpp"
+ >
+ </File>
+ <File
RelativePath=".\chunk.cpp"
>
</File>
@@ -263,11 +267,7 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
- RelativePath=".\gridconfig.h"
- >
- </File>
- <File
- RelativePath=".\griddatabase.h"
+ RelativePath=".\balancer_policy.h"
>
</File>
<File
@@ -313,6 +313,10 @@
RelativePath="..\pch.h"
>
</File>
+ <File
+ RelativePath="..\util\text.h"
+ >
+ </File>
</Filter>
</Filter>
<Filter
@@ -1009,6 +1013,10 @@
>
</File>
<File
+ RelativePath="..\util\text.cpp"
+ >
+ </File>
+ <File
RelativePath="..\util\util.cpp"
>
</File>
View
7 util/mmap_win.cpp
@@ -17,6 +17,7 @@
#include "pch.h"
#include "mmap.h"
+#include "text.h"
#include <windows.h>
namespace mongo {
@@ -40,12 +41,6 @@ namespace mongo {
CloseHandle(fd);
fd = 0;
}
-
- std::wstring toWideString(const char *s) {
- std::basic_ostringstream<TCHAR> buf;
- buf << s;
- return buf.str();
- }
unsigned mapped = 0;
View
42 util/ntservice.cpp
@@ -17,6 +17,7 @@
#include "pch.h"
#include "ntservice.h"
+#include "text.h"
#include <direct.h>
#if defined(_WIN32)
@@ -49,19 +50,23 @@ namespace mongo {
std::string arg( argv[ i ] );
// replace install command to indicate process is being started as a service
- if ( arg == "--install" )
+ if ( arg == "--install" ) {
arg = "--service";
+ }
commandLine << arg << " ";
}
SC_HANDLE schSCManager = ::OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
- if ( schSCManager == NULL )
+ if ( schSCManager == NULL ) {
return false;
+ }
std::basic_ostringstream< TCHAR > commandLineWide;
commandLineWide << commandLine.str().c_str();
+ log() << "Creating service " << toUtf8String(serviceName) << "." << endl;
+
// create new service
SC_HANDLE schService = ::CreateService( schSCManager, serviceName.c_str(), displayName.c_str(),
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
@@ -69,6 +74,7 @@ namespace mongo {
commandLineWide.str().c_str(), NULL, NULL, L"\0\0", NULL, NULL );
if ( schService == NULL ) {
+ log() << "Error creating service." << endl;
::CloseServiceHandle( schSCManager );
return false;
}
@@ -89,8 +95,13 @@ namespace mongo {
// set service recovery options
serviceInstalled = ::ChangeServiceConfig2( schService, SERVICE_CONFIG_FAILURE_ACTIONS, &serviceFailure );
+
+ log() << "Service creation successful." << endl;
}
-
+ else {
+ log() << "Service creation seems to have partially failed. Check the event log for more details." << endl;
+ }
+
::CloseServiceHandle( schService );
::CloseServiceHandle( schSCManager );
@@ -99,12 +110,13 @@ namespace mongo {
bool ServiceController::removeService( const std::wstring& serviceName ) {
SC_HANDLE schSCManager = ::OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
- if ( schSCManager == NULL )
+ if ( schSCManager == NULL ) {
return false;
+ }
SC_HANDLE schService = ::OpenService( schSCManager, serviceName.c_str(), SERVICE_ALL_ACCESS );
-
if ( schService == NULL ) {
+ log() << "Could not get a service handle for " << toUtf8String(serviceName) << "." << endl;
::CloseServiceHandle( schSCManager );
return false;
}
@@ -113,20 +125,30 @@ namespace mongo {
// stop service if its running
if ( ::ControlService( schService, SERVICE_CONTROL_STOP, &serviceStatus ) ) {
+ log() << "Service " << toUtf8String(serviceName) << " is currently running. Stopping service." << endl;
while ( ::QueryServiceStatus( schService, &serviceStatus ) ) {
if ( serviceStatus.dwCurrentState == SERVICE_STOP_PENDING )
- {
- Sleep( 1000 );
- }
- else { break; }
+ {
+ Sleep( 1000 );
+ }
+ else { break; }
}
+ log() << "Service stopped." << endl;
}
+ log() << "Deleting service " << toUtf8String(serviceName) << "." << endl;
bool serviceRemoved = ::DeleteService( schService );
::CloseServiceHandle( schService );
::CloseServiceHandle( schSCManager );
+ if (serviceRemoved) {
+ log() << "Service deleted successfully." << endl;
+ }
+ else {
+ log() << "Failed to delete service." << endl;
+ }
+
return serviceRemoved;
}
@@ -185,4 +207,4 @@ namespace mongo {
} // namespace mongo
-#endif
+#endif
View
41 util/text.cpp
@@ -59,5 +59,46 @@ namespace mongo{
}
if (left!=0) return false; // string ended mid-codepoint
return true;
+ }
+
+ #if defined(_WIN32)
+
+ std::string toUtf8String(const std::wstring& wide)
+ {
+ if (wide.size() > boost::integer_traits<int>::const_max)
+ throw std::length_error(
+ "Wide string cannot be more than INT_MAX characters long.");
+ if (wide.size() == 0)
+ return "";
+
+ // Calculate necessary buffer size
+ int len = ::WideCharToMultiByte(
+ CP_UTF8, 0, wide.c_str(), static_cast<int>(wide.size()),
+ NULL, 0, NULL, NULL);
+
+ // Perform actual conversion
+ if (len > 0)
+ {
+ std::vector<char> buffer(len);
+ len = ::WideCharToMultiByte(
+ CP_UTF8, 0, wide.c_str(), static_cast<int>(wide.size()),
+ &buffer[0], static_cast<int>(buffer.size()), NULL, NULL);
+ if (len > 0)
+ {
+ assert(len == static_cast<int>(buffer.size()));
+ return std::string(&buffer[0], buffer.size());
+ }
+ }
+
+ throw boost::system::system_error(
+ ::GetLastError(), boost::system::system_category);
+ }
+
+ std::wstring toWideString(const char *s) {
+ std::basic_ostringstream<TCHAR> buf;
+ buf << s;
+ return buf.str();
}
+
+ #endif
}
View
10 util/text.h
@@ -96,6 +96,14 @@ namespace mongo {
* guarantee that the codepoints are valid.
*/
bool isValidUTF8(const char *s);
- inline bool isValidUTF8(string s) { return isValidUTF8(s.c_str()); }
+ inline bool isValidUTF8(string s) { return isValidUTF8(s.c_str()); }
+
+ #if defined(_WIN32)
+
+ std::string toUtf8String(const std::wstring& wide);
+
+ std::wstring toWideString(const char *s);
+
+ #endif
}
Please sign in to comment.
Something went wrong with that request. Please try again.