Commit 8cb3bd41 authored by reggie@fedora.(none)'s avatar reggie@fedora.(none)

alot of formatting changes that came out of JimW's review

parent f3de5d6b
...@@ -25,7 +25,6 @@ void IMService::Run() ...@@ -25,7 +25,6 @@ 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) ...@@ -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;
...@@ -51,7 +50,7 @@ int HandleServiceOptions(Options options) ...@@ -51,7 +50,7 @@ int HandleServiceOptions(Options options)
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)
...@@ -63,7 +62,7 @@ int HandleServiceOptions(Options options) ...@@ -63,7 +62,7 @@ int HandleServiceOptions(Options options)
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 @@ ...@@ -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,7 +21,7 @@ WindowsService::~WindowsService(void) ...@@ -19,7 +21,7 @@ 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;
...@@ -30,18 +32,19 @@ BOOL WindowsService::Install() ...@@ -30,18 +32,19 @@ BOOL WindowsService::Install()
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);
...@@ -59,28 +62,28 @@ BOOL WindowsService::Init() ...@@ -59,28 +62,28 @@ BOOL WindowsService::Init()
{ (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);
} }
...@@ -90,12 +93,12 @@ BOOL WindowsService::Remove() ...@@ -90,12 +93,12 @@ BOOL WindowsService::Remove()
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() ...@@ -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 ...@@ -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);
...@@ -154,17 +159,17 @@ void WindowsService::HandleControlCode(DWORD opcode) ...@@ -154,17 +159,17 @@ void WindowsService::HandleControlCode(DWORD 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;
......
...@@ -26,18 +26,18 @@ class WindowsService ...@@ -26,18 +26,18 @@ class WindowsService
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);
}; };
......
...@@ -119,7 +119,7 @@ int Instance::start() ...@@ -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() ...@@ -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,7 +182,7 @@ int Instance::launch_and_wait() ...@@ -182,7 +182,7 @@ 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.
...@@ -203,8 +203,8 @@ int Instance::launch_and_wait() ...@@ -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() ...@@ -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 @@ int Instance::stop() ...@@ -371,48 +371,48 @@ int Instance::stop()
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) ...@@ -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() ...@@ -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 @@ class Listener_thread: public Listener_thread_args ...@@ -59,15 +59,15 @@ class Listener_thread: public Listener_thread_args
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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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) ...@@ -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
} }
...@@ -263,7 +267,7 @@ int Listener_thread::create_tcp_socket() ...@@ -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; ...@@ -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 @@ ...@@ -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; ...@@ -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,13 +236,13 @@ C_MODE_END ...@@ -236,13 +236,13 @@ 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="))
...@@ -252,16 +252,17 @@ int Options::load(int argc, char **argv) ...@@ -252,16 +252,17 @@ int Options::load(int argc, char **argv)
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
default to our compiled in default
*/
if (config_file == NULL) 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 */
...@@ -281,7 +282,6 @@ void Options::cleanup() ...@@ -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() ...@@ -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) ...@@ -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) ...@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment