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,7 +25,6 @@ void IMService::Run()
|
||||
ReportStatus((DWORD)SERVICE_START_PENDING);
|
||||
|
||||
// init goes here
|
||||
|
||||
ReportStatus((DWORD)SERVICE_RUNNING);
|
||||
|
||||
// wait for main loop to terminate
|
||||
@ -38,7 +37,7 @@ void IMService::Log(const char *msg)
|
||||
|
||||
int HandleServiceOptions(Options options)
|
||||
{
|
||||
int ret_val = 0;
|
||||
int ret_val= 0;
|
||||
|
||||
IMService winService;
|
||||
|
||||
@ -51,7 +50,7 @@ int HandleServiceOptions(Options options)
|
||||
else
|
||||
{
|
||||
log_info("Service failed to install\n");
|
||||
ret_val = -1;
|
||||
ret_val= -1;
|
||||
}
|
||||
}
|
||||
else if (options.remove_service)
|
||||
@ -63,7 +62,7 @@ int HandleServiceOptions(Options options)
|
||||
else
|
||||
{
|
||||
log_info("Service failed to remove\n");
|
||||
ret_val = -1;
|
||||
ret_val= -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -4,13 +4,15 @@
|
||||
|
||||
static WindowsService *gService;
|
||||
|
||||
WindowsService::WindowsService(void)
|
||||
: statusCheckpoint(0), serviceName(NULL), inited(false),
|
||||
WindowsService::WindowsService(void) :
|
||||
statusCheckpoint(0),
|
||||
serviceName(NULL),
|
||||
inited(false),
|
||||
dwAcceptedControls(SERVICE_ACCEPT_STOP)
|
||||
{
|
||||
gService = this;
|
||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
status.dwServiceSpecificExitCode = 0;
|
||||
gService= this;
|
||||
status.dwServiceType= SERVICE_WIN32_OWN_PROCESS;
|
||||
status.dwServiceSpecificExitCode= 0;
|
||||
}
|
||||
|
||||
WindowsService::~WindowsService(void)
|
||||
@ -19,7 +21,7 @@ WindowsService::~WindowsService(void)
|
||||
|
||||
BOOL WindowsService::Install()
|
||||
{
|
||||
bool ret_val=false;
|
||||
bool ret_val= false;
|
||||
SC_HANDLE newService;
|
||||
SC_HANDLE scm;
|
||||
|
||||
@ -30,18 +32,19 @@ BOOL WindowsService::Install()
|
||||
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
|
||||
|
||||
// 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;
|
||||
|
||||
newService = CreateService(scm, serviceName, displayName,
|
||||
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL, szFilePath,
|
||||
NULL, NULL, NULL, username, password);
|
||||
newService= CreateService(scm, serviceName, displayName,
|
||||
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
||||
szFilePath, NULL, NULL, NULL, username,
|
||||
password);
|
||||
|
||||
if (newService)
|
||||
{
|
||||
CloseServiceHandle(newService);
|
||||
ret_val = true;
|
||||
ret_val= true;
|
||||
}
|
||||
|
||||
CloseServiceHandle(scm);
|
||||
@ -59,28 +62,28 @@ BOOL WindowsService::Init()
|
||||
{ (LPSTR)serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
|
||||
{ NULL, NULL }
|
||||
};
|
||||
inited = true;
|
||||
inited= true;
|
||||
return StartServiceCtrlDispatcher(stb); //register with the Service Manager
|
||||
}
|
||||
|
||||
BOOL WindowsService::Remove()
|
||||
{
|
||||
bool ret_val = false;
|
||||
bool ret_val= false;
|
||||
|
||||
if (! IsInstalled())
|
||||
return true;
|
||||
|
||||
// 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)
|
||||
return false;
|
||||
|
||||
SC_HANDLE service = OpenService(scm, serviceName, DELETE);
|
||||
SC_HANDLE service= OpenService(scm, serviceName, DELETE);
|
||||
if (service)
|
||||
{
|
||||
if (DeleteService(service))
|
||||
ret_val = true;
|
||||
DWORD dw = ::GetLastError();
|
||||
ret_val= true;
|
||||
DWORD dw= ::GetLastError();
|
||||
CloseServiceHandle(service);
|
||||
}
|
||||
|
||||
@ -90,12 +93,12 @@ BOOL WindowsService::Remove()
|
||||
|
||||
BOOL WindowsService::IsInstalled()
|
||||
{
|
||||
BOOL ret_val = FALSE;
|
||||
BOOL ret_val= FALSE;
|
||||
|
||||
SC_HANDLE scm = ::OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
|
||||
SC_HANDLE serv_handle = ::OpenService(scm, serviceName, SERVICE_QUERY_STATUS);
|
||||
SC_HANDLE scm= ::OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
|
||||
SC_HANDLE serv_handle= ::OpenService(scm, serviceName, SERVICE_QUERY_STATUS);
|
||||
|
||||
ret_val = serv_handle != NULL;
|
||||
ret_val= serv_handle != NULL;
|
||||
|
||||
::CloseServiceHandle(serv_handle);
|
||||
::CloseServiceHandle(scm);
|
||||
@ -105,34 +108,36 @@ BOOL WindowsService::IsInstalled()
|
||||
|
||||
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(currentState == SERVICE_START_PENDING)
|
||||
status.dwControlsAccepted = 0;
|
||||
status.dwControlsAccepted= 0;
|
||||
else
|
||||
status.dwControlsAccepted = dwAcceptedControls;
|
||||
status.dwControlsAccepted= dwAcceptedControls;
|
||||
|
||||
status.dwCurrentState = currentState;
|
||||
status.dwWin32ExitCode = dwError != 0 ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR;
|
||||
status.dwWaitHint = waitHint;
|
||||
status.dwServiceSpecificExitCode = dwError;
|
||||
status.dwCurrentState= currentState;
|
||||
status.dwWin32ExitCode= dwError != 0 ?
|
||||
ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR;
|
||||
status.dwWaitHint= waitHint;
|
||||
status.dwServiceSpecificExitCode= dwError;
|
||||
|
||||
if(currentState == SERVICE_RUNNING || currentState == SERVICE_STOPPED)
|
||||
{
|
||||
status.dwCheckPoint = 0;
|
||||
statusCheckpoint = 0;
|
||||
status.dwCheckPoint= 0;
|
||||
statusCheckpoint= 0;
|
||||
}
|
||||
else
|
||||
status.dwCheckPoint = ++statusCheckpoint;
|
||||
status.dwCheckPoint= ++statusCheckpoint;
|
||||
|
||||
// Report the status of the service to the service control manager.
|
||||
BOOL result = SetServiceStatus(statusHandle, &status);
|
||||
BOOL result= SetServiceStatus(statusHandle, &status);
|
||||
if (!result)
|
||||
Log("ReportStatus failed");
|
||||
|
||||
@ -141,7 +146,7 @@ BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint, DWORD dwEr
|
||||
|
||||
void WindowsService::RegisterAndRun(DWORD argc, LPTSTR *argv)
|
||||
{
|
||||
statusHandle = ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
|
||||
statusHandle= ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
|
||||
if (statusHandle && ReportStatus(SERVICE_START_PENDING))
|
||||
Run();
|
||||
ReportStatus(SERVICE_STOPPED);
|
||||
@ -154,17 +159,17 @@ void WindowsService::HandleControlCode(DWORD opcode)
|
||||
{
|
||||
case SERVICE_CONTROL_STOP:
|
||||
// Stop the service.
|
||||
status.dwCurrentState = SERVICE_STOP_PENDING;
|
||||
status.dwCurrentState= SERVICE_STOP_PENDING;
|
||||
Stop();
|
||||
break;
|
||||
|
||||
case SERVICE_CONTROL_PAUSE:
|
||||
status.dwCurrentState = SERVICE_PAUSE_PENDING;
|
||||
status.dwCurrentState= SERVICE_PAUSE_PENDING;
|
||||
Pause();
|
||||
break;
|
||||
|
||||
case SERVICE_CONTROL_CONTINUE:
|
||||
status.dwCurrentState = SERVICE_CONTINUE_PENDING;
|
||||
status.dwCurrentState= SERVICE_CONTINUE_PENDING;
|
||||
Continue();
|
||||
break;
|
||||
|
||||
|
@ -26,18 +26,18 @@ public:
|
||||
void Debug(bool debugFlag) { debugging = debugFlag; }
|
||||
|
||||
public:
|
||||
static void WINAPI ServiceMain(DWORD argc, LPTSTR * argv);
|
||||
static void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
|
||||
static void WINAPI ControlHandler(DWORD CtrlType);
|
||||
|
||||
protected:
|
||||
virtual void Run() = 0;
|
||||
virtual void Run()= 0;
|
||||
virtual void Stop() {}
|
||||
virtual void Shutdown() {}
|
||||
virtual void Pause() {}
|
||||
virtual void Continue() {}
|
||||
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 RegisterAndRun(DWORD argc, LPTSTR *argv);
|
||||
};
|
||||
|
@ -119,7 +119,7 @@ int Instance::start()
|
||||
#ifndef __WIN__
|
||||
int Instance::launch_and_wait()
|
||||
{
|
||||
pid_t pid = fork();
|
||||
pid_t pid= fork();
|
||||
|
||||
switch (pid)
|
||||
{
|
||||
@ -160,21 +160,21 @@ int Instance::launch_and_wait()
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
|
||||
ZeroMemory( &si, sizeof(si) );
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory( &pi, sizeof(pi) );
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
|
||||
int cmdlen = 0;
|
||||
for (int i=1; options.argv[i] != 0; i++)
|
||||
cmdlen += strlen(options.argv[i]) + 1;
|
||||
int cmdlen= 0;
|
||||
for (int i= 1; options.argv[i] != 0; i++)
|
||||
cmdlen+= strlen(options.argv[i]) + 1;
|
||||
cmdlen++; // we have to add a single space for CreateProcess (read the docs)
|
||||
|
||||
char *cmdline = NULL;
|
||||
char *cmdline= NULL;
|
||||
if (cmdlen > 0)
|
||||
{
|
||||
cmdline = new char[cmdlen];
|
||||
cmdline[0] = 0;
|
||||
for (int i=1; options.argv[i] != 0; i++)
|
||||
cmdline= new char[cmdlen];
|
||||
cmdline[0]= 0;
|
||||
for (int i= 1; options.argv[i] != 0; i++)
|
||||
{
|
||||
strcat(cmdline, " ");
|
||||
strcat(cmdline, options.argv[i]);
|
||||
@ -182,7 +182,7 @@ int Instance::launch_and_wait()
|
||||
}
|
||||
|
||||
// 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.
|
||||
NULL, // Process handle not inheritable.
|
||||
NULL, // Thread handle not inheritable.
|
||||
@ -203,8 +203,8 @@ int Instance::launch_and_wait()
|
||||
::GetExitCodeProcess(pi.hProcess, &exitcode);
|
||||
|
||||
// Close process and thread handles.
|
||||
CloseHandle( pi.hProcess );
|
||||
CloseHandle( pi.hThread );
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
@ -215,7 +215,7 @@ void Instance::fork_and_monitor()
|
||||
{
|
||||
log_info("starting instance %s", options.instance_name);
|
||||
|
||||
int result = launch_and_wait();
|
||||
int result= launch_and_wait();
|
||||
if (result == -1) return;
|
||||
|
||||
/* set instance state to crashed */
|
||||
@ -371,48 +371,48 @@ err:
|
||||
BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
|
||||
{
|
||||
DWORD dwTID, dwCode, dwErr = 0;
|
||||
HANDLE hProcessDup = INVALID_HANDLE_VALUE;
|
||||
HANDLE hRT = NULL;
|
||||
HINSTANCE hKernel = GetModuleHandle("Kernel32");
|
||||
BOOL bSuccess = FALSE;
|
||||
HANDLE hProcessDup= INVALID_HANDLE_VALUE;
|
||||
HANDLE hRT= NULL;
|
||||
HINSTANCE hKernel= GetModuleHandle("Kernel32");
|
||||
BOOL bSuccess= FALSE;
|
||||
|
||||
BOOL bDup = DuplicateHandle(GetCurrentProcess(),
|
||||
hProcess, GetCurrentProcess(), &hProcessDup, PROCESS_ALL_ACCESS, FALSE, 0);
|
||||
BOOL bDup= DuplicateHandle(GetCurrentProcess(),
|
||||
hProcess, GetCurrentProcess(), &hProcessDup,
|
||||
PROCESS_ALL_ACCESS, FALSE, 0);
|
||||
|
||||
// Detect the special case where the process is
|
||||
// already dead...
|
||||
if ( GetExitCodeProcess((bDup) ? hProcessDup : hProcess, &dwCode) &&
|
||||
(dwCode == STILL_ACTIVE) )
|
||||
if (GetExitCodeProcess((bDup) ? hProcessDup : hProcess, &dwCode) &&
|
||||
(dwCode == STILL_ACTIVE))
|
||||
{
|
||||
FARPROC pfnExitProc;
|
||||
|
||||
pfnExitProc = GetProcAddress(hKernel, "ExitProcess");
|
||||
pfnExitProc= GetProcAddress(hKernel, "ExitProcess");
|
||||
|
||||
hRT = CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE)pfnExitProc, (PVOID)uExitCode, 0, &dwTID);
|
||||
hRT= CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE)pfnExitProc,
|
||||
(PVOID)uExitCode, 0, &dwTID);
|
||||
|
||||
if ( hRT == NULL )
|
||||
dwErr = GetLastError();
|
||||
if (hRT == NULL)
|
||||
dwErr= GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
dwErr = ERROR_PROCESS_ABORTED;
|
||||
}
|
||||
dwErr= ERROR_PROCESS_ABORTED;
|
||||
|
||||
if ( hRT )
|
||||
if (hRT)
|
||||
{
|
||||
// Must wait process to terminate to
|
||||
// guarantee that it has exited...
|
||||
WaitForSingleObject((bDup) ? hProcessDup : hProcess, INFINITE);
|
||||
|
||||
CloseHandle(hRT);
|
||||
bSuccess = TRUE;
|
||||
bSuccess= TRUE;
|
||||
}
|
||||
|
||||
if ( bDup )
|
||||
if (bDup)
|
||||
CloseHandle(hProcessDup);
|
||||
|
||||
if ( !bSuccess )
|
||||
if (!bSuccess)
|
||||
SetLastError(dwErr);
|
||||
|
||||
return bSuccess;
|
||||
@ -420,7 +420,7 @@ BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
|
||||
|
||||
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)
|
||||
::SafeTerminateProcess(processhandle, 0);
|
||||
else
|
||||
|
@ -256,8 +256,8 @@ int Instance_map::load()
|
||||
else
|
||||
argv_options[1]= '\0';
|
||||
|
||||
if (my_search_option_files(Options::config_file, &argc, (char ***) &argv, &args_used,
|
||||
process_option, (void*) this) ||
|
||||
if (my_search_option_files(Options::config_file, &argc, (char ***) &argv,
|
||||
&args_used, process_option, (void*) this) ||
|
||||
complete_initialization())
|
||||
return 1;
|
||||
|
||||
|
@ -59,15 +59,15 @@ private:
|
||||
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_args(args.thread_registry, args.options, args.user_map,
|
||||
args.instance_map)
|
||||
,total_connection_count(0)
|
||||
,thread_info(pthread_self())
|
||||
,num_sockets(0)
|
||||
{
|
||||
num_sockets= 0;
|
||||
}
|
||||
|
||||
|
||||
@ -116,11 +116,11 @@ void Listener_thread::run()
|
||||
#endif
|
||||
|
||||
/* II. Listen sockets and spawn childs */
|
||||
for (int i=0; i < num_sockets; i++)
|
||||
n = max(n, sockets[i]);
|
||||
for (int i= 0; i < num_sockets; i++)
|
||||
n= max(n, sockets[i]);
|
||||
n++;
|
||||
|
||||
while (thread_registry.is_shutdown() == false)
|
||||
while (!thread_registry.is_shutdown())
|
||||
{
|
||||
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 */
|
||||
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) */
|
||||
if (client_fd >= 0) // connection established
|
||||
{
|
||||
Vio *vio = vio_new(client_fd, socket_index==0?VIO_TYPE_SOCKET:VIO_TYPE_TCPIP,
|
||||
socket_index==0?1:0);
|
||||
Vio *vio = vio_new(client_fd, socket_index==0?VIO_TYPE_SOCKET:
|
||||
VIO_TYPE_TCPIP, socket_index==0?1:0);
|
||||
if (vio != 0)
|
||||
handle_new_mysql_connection(vio);
|
||||
else
|
||||
@ -167,7 +167,7 @@ void Listener_thread::run()
|
||||
|
||||
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]);
|
||||
|
||||
#ifndef __WIN__
|
||||
@ -179,6 +179,10 @@ void Listener_thread::run()
|
||||
return;
|
||||
|
||||
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.request_shutdown();
|
||||
my_thread_end();
|
||||
@ -191,7 +195,7 @@ void set_non_blocking(int socket)
|
||||
int flags= fcntl(socket, F_GETFL, 0);
|
||||
fcntl(socket, F_SETFL, flags | O_NONBLOCK);
|
||||
#else
|
||||
u_long arg = 1;
|
||||
u_long arg= 1;
|
||||
ioctlsocket(socket, FIONBIO, &arg);
|
||||
#endif
|
||||
}
|
||||
@ -263,7 +267,7 @@ int Listener_thread::create_tcp_socket()
|
||||
set_no_inherit(ip_socket);
|
||||
|
||||
FD_SET(ip_socket, &read_fds);
|
||||
sockets[num_sockets++] = ip_socket;
|
||||
sockets[num_sockets++]= ip_socket;
|
||||
log_info("accepting connections on ip socket");
|
||||
return 0;
|
||||
}
|
||||
|
@ -85,14 +85,14 @@ bool have_signal;
|
||||
|
||||
void onsignal(int signo)
|
||||
{
|
||||
have_signal = true;
|
||||
have_signal= true;
|
||||
}
|
||||
|
||||
void set_signals(sigset_t *set)
|
||||
{
|
||||
signal(SIGINT, onsignal);
|
||||
signal(SIGTERM, onsignal);
|
||||
have_signal = false;
|
||||
have_signal= false;
|
||||
}
|
||||
|
||||
int my_sigwait(const sigset_t *set, int *sig)
|
||||
|
@ -30,9 +30,9 @@
|
||||
#define QUOTE2(x) #x
|
||||
#define QUOTE(x) QUOTE2(x)
|
||||
|
||||
const char *default_password_file_name = QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
||||
const char *default_log_file_name = QUOTE(DEFAULT_LOG_FILE_NAME);
|
||||
char default_config_file[FN_REFLEN] = "/etc/my.cnf";
|
||||
const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
||||
const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
|
||||
char default_config_file[FN_REFLEN]= "/etc/my.cnf";
|
||||
|
||||
#ifndef __WIN__
|
||||
char Options::run_as_service;
|
||||
@ -52,7 +52,7 @@ uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
|
||||
uint Options::port_number= DEFAULT_PORT;
|
||||
/* just to declare */
|
||||
char **Options::saved_argv;
|
||||
const char *Options::config_file = NULL;
|
||||
const char *Options::config_file= NULL;
|
||||
|
||||
/*
|
||||
List of options, accepted by the instance manager.
|
||||
@ -236,13 +236,13 @@ C_MODE_END
|
||||
int Options::load(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
char** argv_ptr = argv;
|
||||
char **argv_ptr= argv;
|
||||
|
||||
#ifdef __WIN__
|
||||
setup_windows_defaults(*argv);
|
||||
#endif
|
||||
|
||||
config_file=NULL;
|
||||
config_file= NULL;
|
||||
if (argc >= 2)
|
||||
{
|
||||
if (is_prefix(argv[1], "--defaults-file="))
|
||||
@ -252,16 +252,17 @@ int Options::load(int argc, char **argv)
|
||||
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
|
||||
default to our compiled in default
|
||||
*/
|
||||
if (config_file == NULL)
|
||||
{
|
||||
#ifdef __WIN__
|
||||
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file));
|
||||
char *filename = strstr(default_config_file, "mysqlmanager.exe");
|
||||
strcpy(filename, "my.ini");
|
||||
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file)); char *filename= strrchr(default_config_file, "\\");
|
||||
strcpy(filename, "\\my.ini");
|
||||
#endif
|
||||
config_file = default_config_file;
|
||||
config_file= default_config_file;
|
||||
}
|
||||
|
||||
/* config-file options are prepended to command-line ones */
|
||||
@ -281,7 +282,6 @@ void Options::cleanup()
|
||||
{
|
||||
/* free_defaults returns nothing */
|
||||
free_defaults(Options::saved_argv);
|
||||
|
||||
#ifdef __WIN__
|
||||
free((char*)default_password_file_name);
|
||||
#endif
|
||||
@ -291,11 +291,11 @@ void Options::cleanup()
|
||||
|
||||
char* change_extension(const char *src, const char *newext)
|
||||
{
|
||||
char *dot = (char*)strrchr(src, '.');
|
||||
char *dot= (char*)strrchr(src, '.');
|
||||
if (!dot) return (char*)src;
|
||||
|
||||
int newlen = dot-src+strlen(newext)+1;
|
||||
char *temp = (char*)malloc(newlen);
|
||||
int newlen= dot-src+strlen(newext)+1;
|
||||
char *temp= (char*)malloc(newlen);
|
||||
bzero(temp, newlen);
|
||||
strncpy(temp, src, dot-src+1);
|
||||
strcat(temp, newext);
|
||||
@ -304,8 +304,10 @@ char* change_extension(const char *src, const char *newext)
|
||||
|
||||
void Options::setup_windows_defaults(const char *progname)
|
||||
{
|
||||
Options::password_file_name = default_password_file_name = change_extension(progname, "passwd");
|
||||
Options::log_file_name = default_log_file_name = change_extension(progname, "log");
|
||||
Options::password_file_name= default_password_file_name =
|
||||
change_extension(progname, "passwd");
|
||||
Options::log_file_name= default_log_file_name =
|
||||
change_extension(progname, "log");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -62,8 +62,8 @@ int User::init(const char *line)
|
||||
/* assume that newline characater is present */
|
||||
if (password[strlen(password)-2] == '\r')
|
||||
{
|
||||
password[strlen(password)-2] = '\n';
|
||||
password[strlen(password)-1] = 0;
|
||||
password[strlen(password)-2]= '\n';
|
||||
password[strlen(password)-1]= 0;
|
||||
}
|
||||
if (strlen(password) != SCRAMBLED_PASSWORD_CHAR_LENGTH + 1)
|
||||
goto err;
|
||||
|
Reference in New Issue
Block a user