mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 09:36:46 +00:00
fix windows line endings and fix potential memory leak from SWITCH_GLOBAL_dirs on win32.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2340 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
136
src/switch.c
136
src/switch.c
@@ -118,52 +118,52 @@ static int freeswitch_kill_background()
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
SERVICE_STATUS_HANDLE hStatus;
|
||||
SERVICE_STATUS status;
|
||||
|
||||
void WINAPI ServiceCtrlHandler( DWORD control )
|
||||
{
|
||||
switch( control )
|
||||
{
|
||||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
case SERVICE_CONTROL_STOP:
|
||||
// do shutdown stuff here
|
||||
switch_core_destroy();
|
||||
status.dwCurrentState = SERVICE_STOPPED;
|
||||
status.dwWin32ExitCode = 0;
|
||||
status.dwCheckPoint = 0;
|
||||
status.dwWaitHint = 0;
|
||||
break;
|
||||
case SERVICE_CONTROL_INTERROGATE:
|
||||
// just set the current state to whatever it is...
|
||||
break;
|
||||
}
|
||||
|
||||
SetServiceStatus( hStatus, &status );
|
||||
}
|
||||
|
||||
void WINAPI service_main( DWORD numArgs, char **args )
|
||||
{
|
||||
SERVICE_STATUS_HANDLE hStatus;
|
||||
SERVICE_STATUS status;
|
||||
|
||||
void WINAPI ServiceCtrlHandler( DWORD control )
|
||||
{
|
||||
switch( control )
|
||||
{
|
||||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
case SERVICE_CONTROL_STOP:
|
||||
// do shutdown stuff here
|
||||
switch_core_destroy();
|
||||
status.dwCurrentState = SERVICE_STOPPED;
|
||||
status.dwWin32ExitCode = 0;
|
||||
status.dwCheckPoint = 0;
|
||||
status.dwWaitHint = 0;
|
||||
break;
|
||||
case SERVICE_CONTROL_INTERROGATE:
|
||||
// just set the current state to whatever it is...
|
||||
break;
|
||||
}
|
||||
|
||||
SetServiceStatus( hStatus, &status );
|
||||
}
|
||||
|
||||
void WINAPI service_main( DWORD numArgs, char **args )
|
||||
{
|
||||
const char *err = NULL;
|
||||
// we have to initialize the service-specific stuff
|
||||
memset( &status, 0, sizeof(SERVICE_STATUS) );
|
||||
status.dwServiceType = SERVICE_WIN32;
|
||||
status.dwCurrentState = SERVICE_START_PENDING;
|
||||
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
||||
|
||||
hStatus = RegisterServiceCtrlHandler( SERVICENAME, &ServiceCtrlHandler );
|
||||
|
||||
SetServiceStatus( hStatus, &status );
|
||||
// we have to initialize the service-specific stuff
|
||||
memset( &status, 0, sizeof(SERVICE_STATUS) );
|
||||
status.dwServiceType = SERVICE_WIN32;
|
||||
status.dwCurrentState = SERVICE_START_PENDING;
|
||||
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
||||
|
||||
hStatus = RegisterServiceCtrlHandler( SERVICENAME, &ServiceCtrlHandler );
|
||||
|
||||
SetServiceStatus( hStatus, &status );
|
||||
set_high_priority();
|
||||
if (switch_core_init_and_modload(lfile, &err) != SWITCH_STATUS_SUCCESS) {
|
||||
status.dwCurrentState = SERVICE_STOPPED;
|
||||
status.dwCurrentState = SERVICE_STOPPED;
|
||||
} else {
|
||||
status.dwCurrentState = SERVICE_RUNNING;
|
||||
}
|
||||
|
||||
SetServiceStatus( hStatus, &status );
|
||||
}
|
||||
|
||||
|
||||
SetServiceStatus( hStatus, &status );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -183,46 +183,46 @@ int main(int argc, char *argv[])
|
||||
};
|
||||
|
||||
if (argv[1] && !strcmp(argv[1], "-service")) {
|
||||
if(StartServiceCtrlDispatcher( dispatchTable ) == 0 )
|
||||
{
|
||||
//Not loaded as a service
|
||||
if(StartServiceCtrlDispatcher( dispatchTable ) == 0 )
|
||||
{
|
||||
//Not loaded as a service
|
||||
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
|
||||
fprintf(stderr, "To install the service load freeswitch with -install\n");
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
if (argv[1] && !strcmp(argv[1], "-install")) {
|
||||
char exePath[1024];
|
||||
char servicePath[1024];
|
||||
|
||||
SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
|
||||
SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
|
||||
GetModuleFileName( NULL, exePath, 1024 );
|
||||
snprintf(servicePath, sizeof(servicePath), "%s -service", exePath);
|
||||
CreateService(
|
||||
handle,
|
||||
SERVICENAME,
|
||||
SERVICENAME,
|
||||
GENERIC_READ | GENERIC_EXECUTE,
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_IGNORE,
|
||||
servicePath,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
CreateService(
|
||||
handle,
|
||||
SERVICENAME,
|
||||
SERVICENAME,
|
||||
GENERIC_READ | GENERIC_EXECUTE,
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_IGNORE,
|
||||
servicePath,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
exit(0);
|
||||
}
|
||||
if (argv[1] && !strcmp(argv[1], "-uninstall")) {
|
||||
SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
|
||||
SC_HANDLE service = OpenService( handle, SERVICENAME, DELETE );
|
||||
if( service != NULL )
|
||||
{
|
||||
// remove the service!
|
||||
DeleteService( service );
|
||||
}
|
||||
SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
|
||||
SC_HANDLE service = OpenService( handle, SERVICENAME, DELETE );
|
||||
if( service != NULL )
|
||||
{
|
||||
// remove the service!
|
||||
DeleteService( service );
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user