mirror of
https://github.com/apple/foundationdb.git
synced 2025-06-02 11:15:50 +08:00
Replace NULL with nullptr in fdbservice
This commit is contained in:
parent
390c26b352
commit
6f9298ed21
@ -113,34 +113,34 @@ public:
|
|||||||
: CServiceBase(SERVICE_NAME, fCanStop, fCanShutdown, fCanPauseContinue), serviceStopping( false )
|
: CServiceBase(SERVICE_NAME, fCanStop, fCanShutdown, fCanPauseContinue), serviceStopping( false )
|
||||||
{
|
{
|
||||||
// Create a manual-reset event to signal the end of the service.
|
// Create a manual-reset event to signal the end of the service.
|
||||||
stoppedEvent = CreateEvent(NULL, true, false, NULL);
|
stoppedEvent = CreateEvent(nullptr, true, false, nullptr);
|
||||||
if (stoppedEvent == NULL)
|
if (stoppedEvent == nullptr)
|
||||||
{
|
{
|
||||||
throw GetLastError();
|
throw GetLastError();
|
||||||
}
|
}
|
||||||
// Create a manual-reset event to signal the end of the service.
|
// Create a manual-reset event to signal the end of the service.
|
||||||
stoppingEvent = CreateEvent(NULL, true, false, NULL);
|
stoppingEvent = CreateEvent(nullptr, true, false, nullptr);
|
||||||
if (stoppingEvent == NULL)
|
if (stoppingEvent == nullptr)
|
||||||
{
|
{
|
||||||
throw GetLastError();
|
throw GetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize child job member
|
// Initialize child job member
|
||||||
childJob = NULL;
|
childJob = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~FDBService(void) {
|
virtual ~FDBService(void) {
|
||||||
if (stoppedEvent) {
|
if (stoppedEvent) {
|
||||||
CloseHandle(stoppedEvent);
|
CloseHandle(stoppedEvent);
|
||||||
stoppedEvent = NULL;
|
stoppedEvent = nullptr;
|
||||||
}
|
}
|
||||||
if (stoppingEvent) {
|
if (stoppingEvent) {
|
||||||
CloseHandle(stoppingEvent);
|
CloseHandle(stoppingEvent);
|
||||||
stoppingEvent = NULL;
|
stoppingEvent = nullptr;
|
||||||
}
|
}
|
||||||
if(childJob) {
|
if(childJob) {
|
||||||
CloseHandle(childJob);
|
CloseHandle(childJob);
|
||||||
childJob = NULL;
|
childJob = nullptr;
|
||||||
}
|
}
|
||||||
logFile.close();
|
logFile.close();
|
||||||
};
|
};
|
||||||
@ -182,7 +182,7 @@ protected:
|
|||||||
std::string GetDefaultConfigFilePath()
|
std::string GetDefaultConfigFilePath()
|
||||||
{
|
{
|
||||||
TCHAR programData[MAX_PATH];
|
TCHAR programData[MAX_PATH];
|
||||||
if (SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, programData) != S_OK)
|
if (SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, programData) != S_OK)
|
||||||
{
|
{
|
||||||
errorExit("resolving CSIDL_COMMON_APPDATA");
|
errorExit("resolving CSIDL_COMMON_APPDATA");
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ protected:
|
|||||||
// Implementation
|
// Implementation
|
||||||
void startTimer() {
|
void startTimer() {
|
||||||
isProcess = false;
|
isProcess = false;
|
||||||
process_or_timer = CreateWaitableTimer(NULL, TRUE, NULL);
|
process_or_timer = CreateWaitableTimer(nullptr, TRUE, nullptr);
|
||||||
if( !process_or_timer )
|
if( !process_or_timer )
|
||||||
svc->errorExit( format( "Error in startTimer(): CreateWaitableTimer (%d)", GetLastError() ).c_str() );
|
svc->errorExit( format( "Error in startTimer(): CreateWaitableTimer (%d)", GetLastError() ).c_str() );
|
||||||
|
|
||||||
@ -292,12 +292,12 @@ protected:
|
|||||||
// Start the child process.
|
// Start the child process.
|
||||||
if (!CreateProcess(command.binary.c_str(), // Command's binary
|
if (!CreateProcess(command.binary.c_str(), // Command's binary
|
||||||
(char *)command.args.c_str(), // Command's args
|
(char *)command.args.c_str(), // Command's args
|
||||||
NULL, // Process handle not inheritable
|
nullptr, // Process handle not inheritable
|
||||||
NULL, // Thread handle not inheritable
|
nullptr, // Thread handle not inheritable
|
||||||
FALSE, // Set handle inheritance to FALSE
|
FALSE, // Set handle inheritance to FALSE
|
||||||
CREATE_NEW_PROCESS_GROUP, // No flags for creation
|
CREATE_NEW_PROCESS_GROUP, // No flags for creation
|
||||||
NULL, // Use parent's environment block
|
nullptr, // Use parent's environment block
|
||||||
NULL, // Use parent's starting directory
|
nullptr, // Use parent's starting directory
|
||||||
&si, // Pointer to STARTUPINFO structure
|
&si, // Pointer to STARTUPINFO structure
|
||||||
&pi ) // Pointer to PROCESS_INFORMATION structure
|
&pi ) // Pointer to PROCESS_INFORMATION structure
|
||||||
) {
|
) {
|
||||||
@ -326,7 +326,7 @@ protected:
|
|||||||
// negative numbers are relative times, times are in 100s of ns -- see SetWaitableTimer MSDN docs
|
// negative numbers are relative times, times are in 100s of ns -- see SetWaitableTimer MSDN docs
|
||||||
liDueTime.QuadPart = (LONGLONG)(delaySeconds * -10000000LL);
|
liDueTime.QuadPart = (LONGLONG)(delaySeconds * -10000000LL);
|
||||||
|
|
||||||
if (!SetWaitableTimer(h, &liDueTime, 0, NULL, NULL, 0))
|
if (!SetWaitableTimer(h, &liDueTime, 0, nullptr, nullptr, 0))
|
||||||
errorExit( format( "Error in startTimer(): SetWaitableTimer (%d)", GetLastError() ).c_str() );
|
errorExit( format( "Error in startTimer(): SetWaitableTimer (%d)", GetLastError() ).c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,11 +371,11 @@ protected:
|
|||||||
escaped.replace( pos, 1, "/" );
|
escaped.replace( pos, 1, "/" );
|
||||||
|
|
||||||
HANDLE hMutex = CreateMutex(
|
HANDLE hMutex = CreateMutex(
|
||||||
NULL, // default security descriptor
|
nullptr, // default security descriptor
|
||||||
TRUE, // attempt to create with ownership
|
TRUE, // attempt to create with ownership
|
||||||
format( "Global\\" SERVICE_NAME ".%s", escaped.c_str() ).c_str() ); // object name
|
format( "Global\\" SERVICE_NAME ".%s", escaped.c_str() ).c_str() ); // object name
|
||||||
|
|
||||||
if (hMutex == NULL)
|
if (hMutex == nullptr)
|
||||||
errorExit( format( "Could not create/aquire global mutex (%s)", escaped.c_str() ).c_str() );
|
errorExit( format( "Could not create/aquire global mutex (%s)", escaped.c_str() ).c_str() );
|
||||||
else
|
else
|
||||||
// In this case ownership on creation flag is ignored. (see MSDN docs)
|
// In this case ownership on creation flag is ignored. (see MSDN docs)
|
||||||
@ -429,7 +429,7 @@ protected:
|
|||||||
|
|
||||||
// FALSE here as "manualReset" means that the timer will go to the unsignaled state once
|
// FALSE here as "manualReset" means that the timer will go to the unsignaled state once
|
||||||
// signalled from a "wait" call.
|
// signalled from a "wait" call.
|
||||||
HANDLE fileErrorReloadHandle = CreateWaitableTimer(NULL, FALSE, NULL);
|
HANDLE fileErrorReloadHandle = CreateWaitableTimer(nullptr, FALSE, nullptr);
|
||||||
if( fileErrorReloadHandle == INVALID_HANDLE_VALUE ) {
|
if( fileErrorReloadHandle == INVALID_HANDLE_VALUE ) {
|
||||||
errorExit( format( "Error creating waitable timer (%d)", GetLastError() ).c_str() );
|
errorExit( format( "Error creating waitable timer (%d)", GetLastError() ).c_str() );
|
||||||
}
|
}
|
||||||
@ -664,12 +664,12 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* getValueMulti(const CSimpleIni& ini, const char* name, ...) {
|
const char* getValueMulti(const CSimpleIni& ini, const char* name, ...) {
|
||||||
const char* ret = NULL;
|
const char* ret = nullptr;
|
||||||
const char* section = NULL;
|
const char* section = nullptr;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, name);
|
va_start(ap, name);
|
||||||
while( !ret && (section = va_arg(ap, const char *) ) ) {
|
while( !ret && (section = va_arg(ap, const char *) ) ) {
|
||||||
ret = ini.GetValue( section, name, NULL );
|
ret = ini.GetValue( section, name, nullptr );
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return ret;
|
return ret;
|
||||||
@ -692,7 +692,7 @@ private:
|
|||||||
return !CSimpleIniA::Entry::KeyOrder()(lhs, rhs);
|
return !CSimpleIniA::Entry::KeyOrder()(lhs, rhs);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
const char* rd = getValueMulti(ini, "restart_delay", ssection.c_str(), section.c_str(), "general", "fdbmonitor", NULL);
|
const char* rd = getValueMulti(ini, "restart_delay", ssection.c_str(), section.c_str(), "general", "fdbmonitor", nullptr);
|
||||||
if(!rd) {
|
if(!rd) {
|
||||||
LogEvent( EVENTLOG_ERROR_TYPE, format( "Unable to resolve restart delay for %s\n", ssection.c_str() ) );
|
LogEvent( EVENTLOG_ERROR_TYPE, format( "Unable to resolve restart delay for %s\n", ssection.c_str() ) );
|
||||||
return result;
|
return result;
|
||||||
@ -705,11 +705,11 @@ private:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* q = getValueMulti(ini, "disable_lifecycle_logging", ssection.c_str(), section.c_str(), "general", NULL);
|
const char* q = getValueMulti(ini, "disable_lifecycle_logging", ssection.c_str(), section.c_str(), "general", nullptr);
|
||||||
if( q && !strcmp(q, "true") )
|
if( q && !strcmp(q, "true") )
|
||||||
result.quiet = true;
|
result.quiet = true;
|
||||||
|
|
||||||
const char* binary = getValueMulti(ini, "command", ssection.c_str(), section.c_str(), "general", NULL);
|
const char* binary = getValueMulti(ini, "command", ssection.c_str(), section.c_str(), "general", nullptr);
|
||||||
if( !binary ) {
|
if( !binary ) {
|
||||||
LogEvent( EVENTLOG_ERROR_TYPE, format( "Unable to resolve command for %s.%d\n", section.c_str(), id ) );
|
LogEvent( EVENTLOG_ERROR_TYPE, format( "Unable to resolve command for %s.%d\n", section.c_str(), id ) );
|
||||||
return result;
|
return result;
|
||||||
@ -727,7 +727,7 @@ private:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string opt = getValueMulti( ini, i.pItem, ssection.c_str(), section.c_str(), "general", NULL );
|
std::string opt = getValueMulti( ini, i.pItem, ssection.c_str(), section.c_str(), "general", nullptr );
|
||||||
|
|
||||||
std::size_t pos = 0;
|
std::size_t pos = 0;
|
||||||
while( (pos = opt.find("$ID", pos)) != opt.npos )
|
while( (pos = opt.find("$ID", pos)) != opt.npos )
|
||||||
@ -814,7 +814,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static FDBService* staticService = NULL;
|
static FDBService* staticService = nullptr;
|
||||||
|
|
||||||
bool consoleHandler(int signal)
|
bool consoleHandler(int signal)
|
||||||
{
|
{
|
||||||
@ -852,7 +852,7 @@ int main(DWORD argc, LPCSTR *argv) {
|
|||||||
for (DWORD loop = 1; loop < argc; loop++)
|
for (DWORD loop = 1; loop < argc; loop++)
|
||||||
{
|
{
|
||||||
// Ignore undefined or non-options
|
// Ignore undefined or non-options
|
||||||
if ((argv[loop] == NULL) ||
|
if ((argv[loop] == nullptr) ||
|
||||||
(argv[loop][0] == '\0'))
|
(argv[loop][0] == '\0'))
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -894,7 +894,7 @@ int main(DWORD argc, LPCSTR *argv) {
|
|||||||
if( !GetEnvironmentVariable( "ALLUSERSPROFILE", programData, 2048 ) ) {
|
if( !GetEnvironmentVariable( "ALLUSERSPROFILE", programData, 2048 ) ) {
|
||||||
throw GetLastError();
|
throw GetLastError();
|
||||||
}
|
}
|
||||||
if( !CreateDirectory( format( "%s\\foundationdb", programData ).c_str(), NULL ) ) {
|
if( !CreateDirectory( format( "%s\\foundationdb", programData ).c_str(), nullptr ) ) {
|
||||||
if( GetLastError() != ERROR_ALREADY_EXISTS )
|
if( GetLastError() != ERROR_ALREADY_EXISTS )
|
||||||
throw GetLastError();
|
throw GetLastError();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#pragma region Static Members
|
#pragma region Static Members
|
||||||
|
|
||||||
// Initialize the singleton service instance.
|
// Initialize the singleton service instance.
|
||||||
CServiceBase *CServiceBase::s_service = NULL;
|
CServiceBase *CServiceBase::s_service = nullptr;
|
||||||
|
|
||||||
|
|
||||||
bool CServiceBase::Run(CServiceBase &service)
|
bool CServiceBase::Run(CServiceBase &service)
|
||||||
@ -36,7 +36,7 @@ bool CServiceBase::Run(CServiceBase &service)
|
|||||||
SERVICE_TABLE_ENTRY serviceTable[] =
|
SERVICE_TABLE_ENTRY serviceTable[] =
|
||||||
{
|
{
|
||||||
{ service.m_name, ServiceMain },
|
{ service.m_name, ServiceMain },
|
||||||
{ NULL, NULL }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connects the main thread of a service process to the service control
|
// Connects the main thread of a service process to the service control
|
||||||
@ -49,12 +49,12 @@ bool CServiceBase::Run(CServiceBase &service)
|
|||||||
|
|
||||||
void WINAPI CServiceBase::ServiceMain(DWORD argc, LPSTR *argv)
|
void WINAPI CServiceBase::ServiceMain(DWORD argc, LPSTR *argv)
|
||||||
{
|
{
|
||||||
assert(s_service != NULL);
|
assert(s_service != nullptr);
|
||||||
|
|
||||||
// Register the handler function for the service
|
// Register the handler function for the service
|
||||||
s_service->m_statusHandle = RegisterServiceCtrlHandler(
|
s_service->m_statusHandle = RegisterServiceCtrlHandler(
|
||||||
s_service->m_name, ServiceCtrlHandler);
|
s_service->m_name, ServiceCtrlHandler);
|
||||||
if (s_service->m_statusHandle == NULL)
|
if (s_service->m_statusHandle == nullptr)
|
||||||
{
|
{
|
||||||
throw GetLastError();
|
throw GetLastError();
|
||||||
}
|
}
|
||||||
@ -117,10 +117,10 @@ CServiceBase::CServiceBase(char *serviceName,
|
|||||||
bool fCanShutdown,
|
bool fCanShutdown,
|
||||||
bool fCanPauseContinue)
|
bool fCanPauseContinue)
|
||||||
{
|
{
|
||||||
// Service name must be a valid string and cannot be NULL.
|
// Service name must be a valid string and cannot be nullptr.
|
||||||
m_name = (serviceName == NULL) ? "" : serviceName;
|
m_name = (serviceName == nullptr) ? "" : serviceName;
|
||||||
|
|
||||||
m_statusHandle = NULL;
|
m_statusHandle = nullptr;
|
||||||
|
|
||||||
// The service runs in its own process.
|
// The service runs in its own process.
|
||||||
m_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
m_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||||
@ -383,10 +383,10 @@ void CServiceBase::SetServiceStatus(DWORD dwCurrentState,
|
|||||||
//
|
//
|
||||||
void CServiceBase::WriteEventLogEntry(const char *message, int wType)
|
void CServiceBase::WriteEventLogEntry(const char *message, int wType)
|
||||||
{
|
{
|
||||||
HANDLE hEventSource = NULL;
|
HANDLE hEventSource = nullptr;
|
||||||
LPCSTR lpszStrings[2] = { NULL, NULL };
|
LPCSTR lpszStrings[2] = { nullptr, nullptr };
|
||||||
|
|
||||||
hEventSource = RegisterEventSource(NULL, m_name);
|
hEventSource = RegisterEventSource(nullptr, m_name);
|
||||||
if (hEventSource)
|
if (hEventSource)
|
||||||
{
|
{
|
||||||
lpszStrings[0] = m_name;
|
lpszStrings[0] = m_name;
|
||||||
@ -396,11 +396,11 @@ void CServiceBase::WriteEventLogEntry(const char *message, int wType)
|
|||||||
wType, // Event type
|
wType, // Event type
|
||||||
0, // Event category
|
0, // Event category
|
||||||
0, // Event identifier
|
0, // Event identifier
|
||||||
NULL, // No security identifier
|
nullptr, // No security identifier
|
||||||
2, // Size of lpszStrings array
|
2, // Size of lpszStrings array
|
||||||
0, // No binary data
|
0, // No binary data
|
||||||
lpszStrings, // Array of strings
|
lpszStrings, // Array of strings
|
||||||
NULL // No binary data
|
nullptr // No binary data
|
||||||
);
|
);
|
||||||
|
|
||||||
DeregisterEventSource(hEventSource);
|
DeregisterEventSource(hEventSource);
|
||||||
@ -415,4 +415,4 @@ void CServiceBase::WriteErrorLogEntry(const char *function, int error)
|
|||||||
WriteEventLogEntry(message, EVENTLOG_ERROR_TYPE);
|
WriteEventLogEntry(message, EVENTLOG_ERROR_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user