mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
alot of formatting changes that came out of JimW's review
server-tools/instance-manager/IMService.cpp: fixed tabs and spacing per JimW's review server-tools/instance-manager/WindowsService.cpp: fixed tabs and spacing per JimW's review server-tools/instance-manager/WindowsService.h: fixed tabs and spacing per JimW's review server-tools/instance-manager/commands.cc: fixed tabs and spacing per JimW's review server-tools/instance-manager/instance.cc: fixed tabs and spacing per JimW's review server-tools/instance-manager/instance_map.cc: fixed tabs and spacing per JimW's review server-tools/instance-manager/listener.cc: fixed tabs and spacing per JimW's review server-tools/instance-manager/manager.cc: fixed tabs and spacing per JimW's review server-tools/instance-manager/options.cc: fixed tabs and spacing per JimW's review server-tools/instance-manager/user_map.cc: fixed tabs and spacing per JimW's review
This commit is contained in:
@ -25,8 +25,7 @@ void IMService::Run()
|
|||||||
ReportStatus((DWORD)SERVICE_START_PENDING);
|
ReportStatus((DWORD)SERVICE_START_PENDING);
|
||||||
|
|
||||||
// init goes here
|
// init goes here
|
||||||
|
ReportStatus((DWORD)SERVICE_RUNNING);
|
||||||
ReportStatus((DWORD)SERVICE_RUNNING);
|
|
||||||
|
|
||||||
// wait for main loop to terminate
|
// wait for main loop to terminate
|
||||||
}
|
}
|
||||||
@ -38,7 +37,7 @@ void IMService::Log(const char *msg)
|
|||||||
|
|
||||||
int HandleServiceOptions(Options options)
|
int HandleServiceOptions(Options options)
|
||||||
{
|
{
|
||||||
int ret_val = 0;
|
int ret_val= 0;
|
||||||
|
|
||||||
IMService winService;
|
IMService winService;
|
||||||
|
|
||||||
@ -47,23 +46,23 @@ int HandleServiceOptions(Options options)
|
|||||||
if (winService.IsInstalled())
|
if (winService.IsInstalled())
|
||||||
log_info("Service is already installed\n");
|
log_info("Service is already installed\n");
|
||||||
else if (winService.Install())
|
else if (winService.Install())
|
||||||
log_info("Service installed successfully\n");
|
log_info("Service installed successfully\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_info("Service failed to install\n");
|
log_info("Service failed to install\n");
|
||||||
ret_val = -1;
|
ret_val= -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (options.remove_service)
|
else if (options.remove_service)
|
||||||
{
|
{
|
||||||
if (! winService.IsInstalled())
|
if (! winService.IsInstalled())
|
||||||
log_info("Service is not installed\n");
|
log_info("Service is not installed\n");
|
||||||
else if (winService.Remove())
|
else if (winService.Remove())
|
||||||
log_info("Service removed successfully\n");
|
log_info("Service removed successfully\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_info("Service failed to remove\n");
|
log_info("Service failed to remove\n");
|
||||||
ret_val = -1;
|
ret_val= -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
static WindowsService *gService;
|
static WindowsService *gService;
|
||||||
|
|
||||||
WindowsService::WindowsService(void)
|
WindowsService::WindowsService(void) :
|
||||||
: statusCheckpoint(0), serviceName(NULL), inited(false),
|
statusCheckpoint(0),
|
||||||
|
serviceName(NULL),
|
||||||
|
inited(false),
|
||||||
dwAcceptedControls(SERVICE_ACCEPT_STOP)
|
dwAcceptedControls(SERVICE_ACCEPT_STOP)
|
||||||
{
|
{
|
||||||
gService = this;
|
gService= this;
|
||||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
status.dwServiceType= SERVICE_WIN32_OWN_PROCESS;
|
||||||
status.dwServiceSpecificExitCode = 0;
|
status.dwServiceSpecificExitCode= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowsService::~WindowsService(void)
|
WindowsService::~WindowsService(void)
|
||||||
@ -19,83 +21,84 @@ WindowsService::~WindowsService(void)
|
|||||||
|
|
||||||
BOOL WindowsService::Install()
|
BOOL WindowsService::Install()
|
||||||
{
|
{
|
||||||
bool ret_val=false;
|
bool ret_val= false;
|
||||||
SC_HANDLE newService;
|
SC_HANDLE newService;
|
||||||
SC_HANDLE scm;
|
SC_HANDLE scm;
|
||||||
|
|
||||||
if (IsInstalled()) return true;
|
if (IsInstalled()) return true;
|
||||||
|
|
||||||
// determine the name of the currently executing file
|
// determine the name of the currently executing file
|
||||||
char szFilePath[_MAX_PATH];
|
char szFilePath[_MAX_PATH];
|
||||||
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
|
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
|
||||||
|
|
||||||
// open a connection to the SCM
|
// open a connection to the SCM
|
||||||
if (!(scm = OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE)))
|
if (!(scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
newService = CreateService(scm, serviceName, displayName,
|
newService= CreateService(scm, serviceName, displayName,
|
||||||
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
|
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
|
||||||
SERVICE_ERROR_NORMAL, szFilePath,
|
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
||||||
NULL, NULL, NULL, username, password);
|
szFilePath, NULL, NULL, NULL, username,
|
||||||
|
password);
|
||||||
|
|
||||||
if (newService)
|
if (newService)
|
||||||
{
|
{
|
||||||
CloseServiceHandle(newService);
|
CloseServiceHandle(newService);
|
||||||
ret_val = true;
|
ret_val= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseServiceHandle(scm);
|
CloseServiceHandle(scm);
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WindowsService::Init()
|
BOOL WindowsService::Init()
|
||||||
{
|
{
|
||||||
assert(serviceName != NULL);
|
assert(serviceName != NULL);
|
||||||
|
|
||||||
if (inited) return true;
|
if (inited) return true;
|
||||||
|
|
||||||
SERVICE_TABLE_ENTRY stb[] =
|
SERVICE_TABLE_ENTRY stb[] =
|
||||||
{
|
{
|
||||||
{ (LPSTR)serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
|
{ (LPSTR)serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
inited = true;
|
inited= true;
|
||||||
return StartServiceCtrlDispatcher(stb); //register with the Service Manager
|
return StartServiceCtrlDispatcher(stb); //register with the Service Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WindowsService::Remove()
|
BOOL WindowsService::Remove()
|
||||||
{
|
{
|
||||||
bool ret_val = false;
|
bool ret_val= false;
|
||||||
|
|
||||||
if (! IsInstalled())
|
if (! IsInstalled())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// open a connection to the SCM
|
// open a connection to the SCM
|
||||||
SC_HANDLE scm = OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);
|
SC_HANDLE scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);
|
||||||
if (! scm)
|
if (! scm)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SC_HANDLE service = OpenService(scm, serviceName, DELETE);
|
SC_HANDLE service= OpenService(scm, serviceName, DELETE);
|
||||||
if (service)
|
if (service)
|
||||||
{
|
{
|
||||||
if (DeleteService(service))
|
if (DeleteService(service))
|
||||||
ret_val = true;
|
ret_val= true;
|
||||||
DWORD dw = ::GetLastError();
|
DWORD dw= ::GetLastError();
|
||||||
CloseServiceHandle(service);
|
CloseServiceHandle(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseServiceHandle(scm);
|
CloseServiceHandle(scm);
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WindowsService::IsInstalled()
|
BOOL WindowsService::IsInstalled()
|
||||||
{
|
{
|
||||||
BOOL ret_val = FALSE;
|
BOOL ret_val= FALSE;
|
||||||
|
|
||||||
SC_HANDLE scm = ::OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
|
SC_HANDLE scm= ::OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
|
||||||
SC_HANDLE serv_handle = ::OpenService(scm, serviceName, SERVICE_QUERY_STATUS);
|
SC_HANDLE serv_handle= ::OpenService(scm, serviceName, SERVICE_QUERY_STATUS);
|
||||||
|
|
||||||
ret_val = serv_handle != NULL;
|
ret_val= serv_handle != NULL;
|
||||||
|
|
||||||
::CloseServiceHandle(serv_handle);
|
::CloseServiceHandle(serv_handle);
|
||||||
::CloseServiceHandle(scm);
|
::CloseServiceHandle(scm);
|
||||||
@ -105,34 +108,36 @@ BOOL WindowsService::IsInstalled()
|
|||||||
|
|
||||||
void WindowsService::SetAcceptedControls(DWORD acceptedControls)
|
void WindowsService::SetAcceptedControls(DWORD acceptedControls)
|
||||||
{
|
{
|
||||||
dwAcceptedControls = acceptedControls;
|
dwAcceptedControls= acceptedControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint, DWORD dwError)
|
BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint,
|
||||||
|
DWORD dwError)
|
||||||
{
|
{
|
||||||
if(debugging) return TRUE;
|
if(debugging) return TRUE;
|
||||||
|
|
||||||
if(currentState == SERVICE_START_PENDING)
|
if(currentState == SERVICE_START_PENDING)
|
||||||
status.dwControlsAccepted = 0;
|
status.dwControlsAccepted= 0;
|
||||||
else
|
else
|
||||||
status.dwControlsAccepted = dwAcceptedControls;
|
status.dwControlsAccepted= dwAcceptedControls;
|
||||||
|
|
||||||
status.dwCurrentState = currentState;
|
status.dwCurrentState= currentState;
|
||||||
status.dwWin32ExitCode = dwError != 0 ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR;
|
status.dwWin32ExitCode= dwError != 0 ?
|
||||||
status.dwWaitHint = waitHint;
|
ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR;
|
||||||
status.dwServiceSpecificExitCode = dwError;
|
status.dwWaitHint= waitHint;
|
||||||
|
status.dwServiceSpecificExitCode= dwError;
|
||||||
|
|
||||||
if(currentState == SERVICE_RUNNING || currentState == SERVICE_STOPPED)
|
if(currentState == SERVICE_RUNNING || currentState == SERVICE_STOPPED)
|
||||||
{
|
{
|
||||||
status.dwCheckPoint = 0;
|
status.dwCheckPoint= 0;
|
||||||
statusCheckpoint = 0;
|
statusCheckpoint= 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status.dwCheckPoint = ++statusCheckpoint;
|
status.dwCheckPoint= ++statusCheckpoint;
|
||||||
|
|
||||||
// Report the status of the service to the service control manager.
|
// Report the status of the service to the service control manager.
|
||||||
BOOL result = SetServiceStatus(statusHandle, &status);
|
BOOL result= SetServiceStatus(statusHandle, &status);
|
||||||
if (!result)
|
if (!result)
|
||||||
Log("ReportStatus failed");
|
Log("ReportStatus failed");
|
||||||
|
|
||||||
@ -141,7 +146,7 @@ BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint, DWORD dwEr
|
|||||||
|
|
||||||
void WindowsService::RegisterAndRun(DWORD argc, LPTSTR *argv)
|
void WindowsService::RegisterAndRun(DWORD argc, LPTSTR *argv)
|
||||||
{
|
{
|
||||||
statusHandle = ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
|
statusHandle= ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
|
||||||
if (statusHandle && ReportStatus(SERVICE_START_PENDING))
|
if (statusHandle && ReportStatus(SERVICE_START_PENDING))
|
||||||
Run();
|
Run();
|
||||||
ReportStatus(SERVICE_STOPPED);
|
ReportStatus(SERVICE_STOPPED);
|
||||||
@ -152,41 +157,41 @@ void WindowsService::HandleControlCode(DWORD opcode)
|
|||||||
// Handle the requested control code.
|
// Handle the requested control code.
|
||||||
switch(opcode)
|
switch(opcode)
|
||||||
{
|
{
|
||||||
case SERVICE_CONTROL_STOP:
|
case SERVICE_CONTROL_STOP:
|
||||||
// Stop the service.
|
// Stop the service.
|
||||||
status.dwCurrentState = SERVICE_STOP_PENDING;
|
status.dwCurrentState= SERVICE_STOP_PENDING;
|
||||||
Stop();
|
Stop();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_CONTROL_PAUSE:
|
case SERVICE_CONTROL_PAUSE:
|
||||||
status.dwCurrentState = SERVICE_PAUSE_PENDING;
|
status.dwCurrentState= SERVICE_PAUSE_PENDING;
|
||||||
Pause();
|
Pause();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_CONTROL_CONTINUE:
|
case SERVICE_CONTROL_CONTINUE:
|
||||||
status.dwCurrentState = SERVICE_CONTINUE_PENDING;
|
status.dwCurrentState= SERVICE_CONTINUE_PENDING;
|
||||||
Continue();
|
Continue();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_CONTROL_SHUTDOWN:
|
case SERVICE_CONTROL_SHUTDOWN:
|
||||||
Shutdown();
|
Shutdown();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_CONTROL_INTERROGATE:
|
case SERVICE_CONTROL_INTERROGATE:
|
||||||
ReportStatus(status.dwCurrentState);
|
ReportStatus(status.dwCurrentState);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// invalid control code
|
// invalid control code
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WINAPI WindowsService::ServiceMain(DWORD argc, LPTSTR *argv)
|
void WINAPI WindowsService::ServiceMain(DWORD argc, LPTSTR *argv)
|
||||||
{
|
{
|
||||||
assert(gService != NULL);
|
assert(gService != NULL);
|
||||||
|
|
||||||
// register our service control handler:
|
// register our service control handler:
|
||||||
gService->RegisterAndRun(argc, argv);
|
gService->RegisterAndRun(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
class WindowsService
|
class WindowsService
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
bool inited;
|
bool inited;
|
||||||
const char *serviceName;
|
const char *serviceName;
|
||||||
const char *displayName;
|
const char *displayName;
|
||||||
const char *username;
|
const char *username;
|
||||||
@ -15,29 +15,29 @@ protected:
|
|||||||
bool debugging;
|
bool debugging;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WindowsService(void);
|
WindowsService(void);
|
||||||
~WindowsService(void);
|
~WindowsService(void);
|
||||||
|
|
||||||
BOOL Install();
|
BOOL Install();
|
||||||
BOOL Remove();
|
BOOL Remove();
|
||||||
BOOL Init();
|
BOOL Init();
|
||||||
BOOL IsInstalled();
|
BOOL IsInstalled();
|
||||||
void SetAcceptedControls(DWORD acceptedControls);
|
void SetAcceptedControls(DWORD acceptedControls);
|
||||||
void Debug(bool debugFlag) { debugging = debugFlag; }
|
void Debug(bool debugFlag) { debugging = debugFlag; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void WINAPI ServiceMain(DWORD argc, LPTSTR * argv);
|
static void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
|
||||||
static void WINAPI ControlHandler(DWORD CtrlType);
|
static void WINAPI ControlHandler(DWORD CtrlType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Run() = 0;
|
virtual void Run()= 0;
|
||||||
virtual void Stop() {}
|
virtual void Stop() {}
|
||||||
virtual void Shutdown() {}
|
virtual void Shutdown() {}
|
||||||
virtual void Pause() {}
|
virtual void Pause() {}
|
||||||
virtual void Continue() {}
|
virtual void Continue() {}
|
||||||
virtual void Log(const char *msg) {}
|
virtual void Log(const char *msg) {}
|
||||||
|
|
||||||
BOOL ReportStatus(DWORD currentStatus, DWORD waitHint=3000, DWORD dwError=0);
|
BOOL ReportStatus(DWORD currentStatus, DWORD waitHint= 3000, DWORD dwError=0);
|
||||||
void HandleControlCode(DWORD opcode);
|
void HandleControlCode(DWORD opcode);
|
||||||
void RegisterAndRun(DWORD argc, LPTSTR *argv);
|
void RegisterAndRun(DWORD argc, LPTSTR *argv);
|
||||||
};
|
};
|
||||||
|
@ -691,7 +691,7 @@ int Set_option::correct_file(int skip)
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
error= modify_defaults_file(Options::config_file, option,
|
error= modify_defaults_file(Options::config_file, option,
|
||||||
option_value, instance_name, skip);
|
option_value, instance_name, skip);
|
||||||
if (error > 0)
|
if (error > 0)
|
||||||
return ER_OUT_OF_RESOURCES;
|
return ER_OUT_OF_RESOURCES;
|
||||||
else if (error < 0)
|
else if (error < 0)
|
||||||
|
@ -119,7 +119,7 @@ int Instance::start()
|
|||||||
#ifndef __WIN__
|
#ifndef __WIN__
|
||||||
int Instance::launch_and_wait()
|
int Instance::launch_and_wait()
|
||||||
{
|
{
|
||||||
pid_t pid = fork();
|
pid_t pid= fork();
|
||||||
|
|
||||||
switch (pid)
|
switch (pid)
|
||||||
{
|
{
|
||||||
@ -160,21 +160,21 @@ int Instance::launch_and_wait()
|
|||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
|
|
||||||
ZeroMemory( &si, sizeof(si) );
|
ZeroMemory(&si, sizeof(si));
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
ZeroMemory( &pi, sizeof(pi) );
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
|
|
||||||
int cmdlen = 0;
|
int cmdlen= 0;
|
||||||
for (int i=1; options.argv[i] != 0; i++)
|
for (int i= 1; options.argv[i] != 0; i++)
|
||||||
cmdlen += strlen(options.argv[i]) + 1;
|
cmdlen+= strlen(options.argv[i]) + 1;
|
||||||
cmdlen++; // we have to add a single space for CreateProcess (read the docs)
|
cmdlen++; // we have to add a single space for CreateProcess (read the docs)
|
||||||
|
|
||||||
char *cmdline = NULL;
|
char *cmdline= NULL;
|
||||||
if (cmdlen > 0)
|
if (cmdlen > 0)
|
||||||
{
|
{
|
||||||
cmdline = new char[cmdlen];
|
cmdline= new char[cmdlen];
|
||||||
cmdline[0] = 0;
|
cmdline[0]= 0;
|
||||||
for (int i=1; options.argv[i] != 0; i++)
|
for (int i= 1; options.argv[i] != 0; i++)
|
||||||
{
|
{
|
||||||
strcat(cmdline, " ");
|
strcat(cmdline, " ");
|
||||||
strcat(cmdline, options.argv[i]);
|
strcat(cmdline, options.argv[i]);
|
||||||
@ -182,16 +182,16 @@ int Instance::launch_and_wait()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the child process.
|
// Start the child process.
|
||||||
BOOL result = CreateProcess(options.mysqld_path, // file to execute
|
BOOL result= CreateProcess(options.mysqld_path, // file to execute
|
||||||
cmdline, // Command line.
|
cmdline, // Command line.
|
||||||
NULL, // Process handle not inheritable.
|
NULL, // Process handle not inheritable.
|
||||||
NULL, // Thread handle not inheritable.
|
NULL, // Thread handle not inheritable.
|
||||||
FALSE, // Set handle inheritance to FALSE.
|
FALSE, // Set handle inheritance to FALSE.
|
||||||
0, // No creation flags.
|
0, // No creation flags.
|
||||||
NULL, // Use parent's environment block.
|
NULL, // Use parent's environment block.
|
||||||
NULL, // Use parent's starting directory.
|
NULL, // 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.
|
||||||
delete cmdline;
|
delete cmdline;
|
||||||
if (! result)
|
if (! result)
|
||||||
return -1;
|
return -1;
|
||||||
@ -203,8 +203,8 @@ int Instance::launch_and_wait()
|
|||||||
::GetExitCodeProcess(pi.hProcess, &exitcode);
|
::GetExitCodeProcess(pi.hProcess, &exitcode);
|
||||||
|
|
||||||
// Close process and thread handles.
|
// Close process and thread handles.
|
||||||
CloseHandle( pi.hProcess );
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle( pi.hThread );
|
CloseHandle(pi.hThread);
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ void Instance::fork_and_monitor()
|
|||||||
{
|
{
|
||||||
log_info("starting instance %s", options.instance_name);
|
log_info("starting instance %s", options.instance_name);
|
||||||
|
|
||||||
int result = launch_and_wait();
|
int result= launch_and_wait();
|
||||||
if (result == -1) return;
|
if (result == -1) return;
|
||||||
|
|
||||||
/* set instance state to crashed */
|
/* set instance state to crashed */
|
||||||
@ -371,48 +371,48 @@ err:
|
|||||||
BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
|
BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
|
||||||
{
|
{
|
||||||
DWORD dwTID, dwCode, dwErr = 0;
|
DWORD dwTID, dwCode, dwErr = 0;
|
||||||
HANDLE hProcessDup = INVALID_HANDLE_VALUE;
|
HANDLE hProcessDup= INVALID_HANDLE_VALUE;
|
||||||
HANDLE hRT = NULL;
|
HANDLE hRT= NULL;
|
||||||
HINSTANCE hKernel = GetModuleHandle("Kernel32");
|
HINSTANCE hKernel= GetModuleHandle("Kernel32");
|
||||||
BOOL bSuccess = FALSE;
|
BOOL bSuccess= FALSE;
|
||||||
|
|
||||||
BOOL bDup = DuplicateHandle(GetCurrentProcess(),
|
BOOL bDup= DuplicateHandle(GetCurrentProcess(),
|
||||||
hProcess, GetCurrentProcess(), &hProcessDup, PROCESS_ALL_ACCESS, FALSE, 0);
|
hProcess, GetCurrentProcess(), &hProcessDup,
|
||||||
|
PROCESS_ALL_ACCESS, FALSE, 0);
|
||||||
|
|
||||||
// Detect the special case where the process is
|
// Detect the special case where the process is
|
||||||
// already dead...
|
// already dead...
|
||||||
if ( GetExitCodeProcess((bDup) ? hProcessDup : hProcess, &dwCode) &&
|
if (GetExitCodeProcess((bDup) ? hProcessDup : hProcess, &dwCode) &&
|
||||||
(dwCode == STILL_ACTIVE) )
|
(dwCode == STILL_ACTIVE))
|
||||||
{
|
{
|
||||||
FARPROC pfnExitProc;
|
FARPROC pfnExitProc;
|
||||||
|
|
||||||
pfnExitProc = GetProcAddress(hKernel, "ExitProcess");
|
pfnExitProc= GetProcAddress(hKernel, "ExitProcess");
|
||||||
|
|
||||||
hRT = CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
|
hRT= CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
|
||||||
(LPTHREAD_START_ROUTINE)pfnExitProc, (PVOID)uExitCode, 0, &dwTID);
|
(LPTHREAD_START_ROUTINE)pfnExitProc,
|
||||||
|
(PVOID)uExitCode, 0, &dwTID);
|
||||||
|
|
||||||
if ( hRT == NULL )
|
if (hRT == NULL)
|
||||||
dwErr = GetLastError();
|
dwErr= GetLastError();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
dwErr= ERROR_PROCESS_ABORTED;
|
||||||
dwErr = ERROR_PROCESS_ABORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( hRT )
|
if (hRT)
|
||||||
{
|
{
|
||||||
// Must wait process to terminate to
|
// Must wait process to terminate to
|
||||||
// guarantee that it has exited...
|
// guarantee that it has exited...
|
||||||
WaitForSingleObject((bDup) ? hProcessDup : hProcess, INFINITE);
|
WaitForSingleObject((bDup) ? hProcessDup : hProcess, INFINITE);
|
||||||
|
|
||||||
CloseHandle(hRT);
|
CloseHandle(hRT);
|
||||||
bSuccess = TRUE;
|
bSuccess= TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( bDup )
|
if (bDup)
|
||||||
CloseHandle(hProcessDup);
|
CloseHandle(hProcessDup);
|
||||||
|
|
||||||
if ( !bSuccess )
|
if (!bSuccess)
|
||||||
SetLastError(dwErr);
|
SetLastError(dwErr);
|
||||||
|
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
@ -420,7 +420,7 @@ BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
|
|||||||
|
|
||||||
int kill(pid_t pid, int signum)
|
int kill(pid_t pid, int signum)
|
||||||
{
|
{
|
||||||
HANDLE processhandle = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
|
HANDLE processhandle= ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
|
||||||
if (signum == SIGTERM)
|
if (signum == SIGTERM)
|
||||||
::SafeTerminateProcess(processhandle, 0);
|
::SafeTerminateProcess(processhandle, 0);
|
||||||
else
|
else
|
||||||
|
@ -256,8 +256,8 @@ int Instance_map::load()
|
|||||||
else
|
else
|
||||||
argv_options[1]= '\0';
|
argv_options[1]= '\0';
|
||||||
|
|
||||||
if (my_search_option_files(Options::config_file, &argc, (char ***) &argv, &args_used,
|
if (my_search_option_files(Options::config_file, &argc, (char ***) &argv,
|
||||||
process_option, (void*) this) ||
|
&args_used, process_option, (void*) this) ||
|
||||||
complete_initialization())
|
complete_initialization())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -59,15 +59,15 @@ private:
|
|||||||
int create_unix_socket(struct sockaddr_un &unix_socket_address);
|
int create_unix_socket(struct sockaddr_un &unix_socket_address);
|
||||||
};
|
};
|
||||||
|
|
||||||
const int LISTEN_BACK_LOG_SIZE = 5; // standard backlog size
|
const int LISTEN_BACK_LOG_SIZE= 5; // standard backlog size
|
||||||
|
|
||||||
Listener_thread::Listener_thread(const Listener_thread_args &args) :
|
Listener_thread::Listener_thread(const Listener_thread_args &args) :
|
||||||
Listener_thread_args(args.thread_registry, args.options, args.user_map,
|
Listener_thread_args(args.thread_registry, args.options, args.user_map,
|
||||||
args.instance_map)
|
args.instance_map)
|
||||||
,total_connection_count(0)
|
,total_connection_count(0)
|
||||||
,thread_info(pthread_self())
|
,thread_info(pthread_self())
|
||||||
|
,num_sockets(0)
|
||||||
{
|
{
|
||||||
num_sockets= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,11 +116,11 @@ void Listener_thread::run()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* II. Listen sockets and spawn childs */
|
/* II. Listen sockets and spawn childs */
|
||||||
for (int i=0; i < num_sockets; i++)
|
for (int i= 0; i < num_sockets; i++)
|
||||||
n = max(n, sockets[i]);
|
n= max(n, sockets[i]);
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
while (thread_registry.is_shutdown() == false)
|
while (!thread_registry.is_shutdown())
|
||||||
{
|
{
|
||||||
fd_set read_fds_arg= read_fds;
|
fd_set read_fds_arg= read_fds;
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ void Listener_thread::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int socket_index=0; socket_index < num_sockets; socket_index++)
|
for (int socket_index= 0; socket_index < num_sockets; socket_index++)
|
||||||
{
|
{
|
||||||
/* Assuming that rc > 0 as we asked to wait forever */
|
/* Assuming that rc > 0 as we asked to wait forever */
|
||||||
if (FD_ISSET(sockets[socket_index], &read_fds_arg))
|
if (FD_ISSET(sockets[socket_index], &read_fds_arg))
|
||||||
@ -149,8 +149,8 @@ void Listener_thread::run()
|
|||||||
/* accept may return -1 (failure or spurious wakeup) */
|
/* accept may return -1 (failure or spurious wakeup) */
|
||||||
if (client_fd >= 0) // connection established
|
if (client_fd >= 0) // connection established
|
||||||
{
|
{
|
||||||
Vio *vio = vio_new(client_fd, socket_index==0?VIO_TYPE_SOCKET:VIO_TYPE_TCPIP,
|
Vio *vio = vio_new(client_fd, socket_index==0?VIO_TYPE_SOCKET:
|
||||||
socket_index==0?1:0);
|
VIO_TYPE_TCPIP, socket_index==0?1:0);
|
||||||
if (vio != 0)
|
if (vio != 0)
|
||||||
handle_new_mysql_connection(vio);
|
handle_new_mysql_connection(vio);
|
||||||
else
|
else
|
||||||
@ -167,7 +167,7 @@ void Listener_thread::run()
|
|||||||
|
|
||||||
log_info("Listener_thread::run(): shutdown requested, exiting...");
|
log_info("Listener_thread::run(): shutdown requested, exiting...");
|
||||||
|
|
||||||
for (int i=0; i < num_sockets; i++)
|
for (int i= 0; i < num_sockets; i++)
|
||||||
close(sockets[i]);
|
close(sockets[i]);
|
||||||
|
|
||||||
#ifndef __WIN__
|
#ifndef __WIN__
|
||||||
@ -179,6 +179,10 @@ void Listener_thread::run()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
// we have to close the ip sockets in case of error
|
||||||
|
for (int i= 0; i < num_sockets; i++)
|
||||||
|
close(sockets[i]);
|
||||||
|
|
||||||
thread_registry.unregister_thread(&thread_info);
|
thread_registry.unregister_thread(&thread_info);
|
||||||
thread_registry.request_shutdown();
|
thread_registry.request_shutdown();
|
||||||
my_thread_end();
|
my_thread_end();
|
||||||
@ -191,7 +195,7 @@ void set_non_blocking(int socket)
|
|||||||
int flags= fcntl(socket, F_GETFL, 0);
|
int flags= fcntl(socket, F_GETFL, 0);
|
||||||
fcntl(socket, F_SETFL, flags | O_NONBLOCK);
|
fcntl(socket, F_SETFL, flags | O_NONBLOCK);
|
||||||
#else
|
#else
|
||||||
u_long arg = 1;
|
u_long arg= 1;
|
||||||
ioctlsocket(socket, FIONBIO, &arg);
|
ioctlsocket(socket, FIONBIO, &arg);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -245,7 +249,7 @@ int Listener_thread::create_tcp_socket()
|
|||||||
log_error("Listener_thread::run(): bind(ip socket) failed, '%s'",
|
log_error("Listener_thread::run(): bind(ip socket) failed, '%s'",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
close(ip_socket);
|
close(ip_socket);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(ip_socket, LISTEN_BACK_LOG_SIZE))
|
if (listen(ip_socket, LISTEN_BACK_LOG_SIZE))
|
||||||
@ -263,7 +267,7 @@ int Listener_thread::create_tcp_socket()
|
|||||||
set_no_inherit(ip_socket);
|
set_no_inherit(ip_socket);
|
||||||
|
|
||||||
FD_SET(ip_socket, &read_fds);
|
FD_SET(ip_socket, &read_fds);
|
||||||
sockets[num_sockets++] = ip_socket;
|
sockets[num_sockets++]= ip_socket;
|
||||||
log_info("accepting connections on ip socket");
|
log_info("accepting connections on ip socket");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -85,14 +85,14 @@ bool have_signal;
|
|||||||
|
|
||||||
void onsignal(int signo)
|
void onsignal(int signo)
|
||||||
{
|
{
|
||||||
have_signal = true;
|
have_signal= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_signals(sigset_t *set)
|
void set_signals(sigset_t *set)
|
||||||
{
|
{
|
||||||
signal(SIGINT, onsignal);
|
signal(SIGINT, onsignal);
|
||||||
signal(SIGTERM, onsignal);
|
signal(SIGTERM, onsignal);
|
||||||
have_signal = false;
|
have_signal= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int my_sigwait(const sigset_t *set, int *sig)
|
int my_sigwait(const sigset_t *set, int *sig)
|
||||||
|
@ -30,9 +30,9 @@
|
|||||||
#define QUOTE2(x) #x
|
#define QUOTE2(x) #x
|
||||||
#define QUOTE(x) QUOTE2(x)
|
#define QUOTE(x) QUOTE2(x)
|
||||||
|
|
||||||
const char *default_password_file_name = QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
||||||
const char *default_log_file_name = QUOTE(DEFAULT_LOG_FILE_NAME);
|
const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
|
||||||
char default_config_file[FN_REFLEN] = "/etc/my.cnf";
|
char default_config_file[FN_REFLEN]= "/etc/my.cnf";
|
||||||
|
|
||||||
#ifndef __WIN__
|
#ifndef __WIN__
|
||||||
char Options::run_as_service;
|
char Options::run_as_service;
|
||||||
@ -52,7 +52,7 @@ uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
|
|||||||
uint Options::port_number= DEFAULT_PORT;
|
uint Options::port_number= DEFAULT_PORT;
|
||||||
/* just to declare */
|
/* just to declare */
|
||||||
char **Options::saved_argv;
|
char **Options::saved_argv;
|
||||||
const char *Options::config_file = NULL;
|
const char *Options::config_file= NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
List of options, accepted by the instance manager.
|
List of options, accepted by the instance manager.
|
||||||
@ -236,33 +236,34 @@ C_MODE_END
|
|||||||
int Options::load(int argc, char **argv)
|
int Options::load(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
char** argv_ptr = argv;
|
char **argv_ptr= argv;
|
||||||
|
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
setup_windows_defaults(*argv);
|
setup_windows_defaults(*argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
config_file=NULL;
|
config_file= NULL;
|
||||||
if (argc >= 2)
|
if (argc >= 2)
|
||||||
{
|
{
|
||||||
if (is_prefix(argv[1], "--defaults-file="))
|
if (is_prefix(argv[1], "--defaults-file="))
|
||||||
config_file=argv[1];
|
config_file=argv[1];
|
||||||
if (is_prefix(argv[1],"--defaults-file=") ||
|
if (is_prefix(argv[1],"--defaults-file=") ||
|
||||||
is_prefix(argv[1],"--defaults-extra-file="))
|
is_prefix(argv[1],"--defaults-extra-file="))
|
||||||
Options::first_option= argv[1];
|
Options::first_option= argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// we were not given a config file on the command line so we
|
/*
|
||||||
// set have to construct a new argv array
|
we were not given a config file on the command line so we
|
||||||
if (config_file == NULL)
|
default to our compiled in default
|
||||||
{
|
*/
|
||||||
|
if (config_file == NULL)
|
||||||
|
{
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file));
|
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file)); char *filename= strrchr(default_config_file, "\\");
|
||||||
char *filename = strstr(default_config_file, "mysqlmanager.exe");
|
strcpy(filename, "\\my.ini");
|
||||||
strcpy(filename, "my.ini");
|
|
||||||
#endif
|
#endif
|
||||||
config_file = default_config_file;
|
config_file= default_config_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config-file options are prepended to command-line ones */
|
/* config-file options are prepended to command-line ones */
|
||||||
load_defaults(config_file, default_groups, &argc, &argv);
|
load_defaults(config_file, default_groups, &argc, &argv);
|
||||||
@ -281,7 +282,6 @@ void Options::cleanup()
|
|||||||
{
|
{
|
||||||
/* free_defaults returns nothing */
|
/* free_defaults returns nothing */
|
||||||
free_defaults(Options::saved_argv);
|
free_defaults(Options::saved_argv);
|
||||||
|
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
free((char*)default_password_file_name);
|
free((char*)default_password_file_name);
|
||||||
#endif
|
#endif
|
||||||
@ -291,11 +291,11 @@ void Options::cleanup()
|
|||||||
|
|
||||||
char* change_extension(const char *src, const char *newext)
|
char* change_extension(const char *src, const char *newext)
|
||||||
{
|
{
|
||||||
char *dot = (char*)strrchr(src, '.');
|
char *dot= (char*)strrchr(src, '.');
|
||||||
if (!dot) return (char*)src;
|
if (!dot) return (char*)src;
|
||||||
|
|
||||||
int newlen = dot-src+strlen(newext)+1;
|
int newlen= dot-src+strlen(newext)+1;
|
||||||
char *temp = (char*)malloc(newlen);
|
char *temp= (char*)malloc(newlen);
|
||||||
bzero(temp, newlen);
|
bzero(temp, newlen);
|
||||||
strncpy(temp, src, dot-src+1);
|
strncpy(temp, src, dot-src+1);
|
||||||
strcat(temp, newext);
|
strcat(temp, newext);
|
||||||
@ -304,8 +304,10 @@ char* change_extension(const char *src, const char *newext)
|
|||||||
|
|
||||||
void Options::setup_windows_defaults(const char *progname)
|
void Options::setup_windows_defaults(const char *progname)
|
||||||
{
|
{
|
||||||
Options::password_file_name = default_password_file_name = change_extension(progname, "passwd");
|
Options::password_file_name= default_password_file_name =
|
||||||
Options::log_file_name = default_log_file_name = change_extension(progname, "log");
|
change_extension(progname, "passwd");
|
||||||
|
Options::log_file_name= default_log_file_name =
|
||||||
|
change_extension(progname, "log");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -62,8 +62,8 @@ int User::init(const char *line)
|
|||||||
/* assume that newline characater is present */
|
/* assume that newline characater is present */
|
||||||
if (password[strlen(password)-2] == '\r')
|
if (password[strlen(password)-2] == '\r')
|
||||||
{
|
{
|
||||||
password[strlen(password)-2] = '\n';
|
password[strlen(password)-2]= '\n';
|
||||||
password[strlen(password)-1] = 0;
|
password[strlen(password)-1]= 0;
|
||||||
}
|
}
|
||||||
if (strlen(password) != SCRAMBLED_PASSWORD_CHAR_LENGTH + 1)
|
if (strlen(password) != SCRAMBLED_PASSWORD_CHAR_LENGTH + 1)
|
||||||
goto err;
|
goto err;
|
||||||
|
Reference in New Issue
Block a user