forked from Mirrors/freeswitch
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:
parent
c08217c886
commit
6d414c5644
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
|
||||
|
@ -2961,27 +2961,27 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
|
||||
char exePath[1024];
|
||||
char *lastbacklash;
|
||||
GetModuleFileName( NULL, exePath, BUFSIZE );
|
||||
lastbacklash = strrchr( exePath, '\\');
|
||||
lastbacklash = strrchr( exePath, '\\');
|
||||
exePath[(lastbacklash - exePath + 1)] = '\0';
|
||||
if ((SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.base_dir && (SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.base_dir, BUFSIZE, "%s", exePath);
|
||||
}
|
||||
if ((SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.mod_dir && (SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%s\\mod", exePath);
|
||||
}
|
||||
if ((SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s\\conf", exePath);
|
||||
}
|
||||
if ((SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.log_dir && (SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%s\\log", exePath);
|
||||
}
|
||||
if ((SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.db_dir && (SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%s\\db", exePath);
|
||||
}
|
||||
if ((SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.script_dir && (SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%s\\scripts", exePath);
|
||||
}
|
||||
if ((SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s\\mod", exePath);
|
||||
}
|
||||
#else
|
||||
@ -2998,7 +2998,7 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
|
||||
#else
|
||||
#ifdef WIN32
|
||||
GetTempPath(dwBufSize, lpPathBuffer);
|
||||
if ((SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
|
||||
if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
|
||||
snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s", lpPathBuffer);
|
||||
}
|
||||
#else
|
||||
@ -3270,5 +3270,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
|
||||
apr_terminate();
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
free(SWITCH_GLOBAL_dirs.base_dir);
|
||||
free(SWITCH_GLOBAL_dirs.mod_dir);
|
||||
free(SWITCH_GLOBAL_dirs.conf_dir);
|
||||
free(SWITCH_GLOBAL_dirs.log_dir);
|
||||
free(SWITCH_GLOBAL_dirs.db_dir);
|
||||
free(SWITCH_GLOBAL_dirs.script_dir);
|
||||
free(SWITCH_GLOBAL_dirs.htdocs_dir);
|
||||
free(SWITCH_GLOBAL_dirs.temp_dir);
|
||||
#endif
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user