mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-05-29 10:01:41 +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:
parent
c08217c886
commit
6d414c5644
136
src/switch.c
136
src/switch.c
@ -118,52 +118,52 @@ static int freeswitch_kill_background()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SERVICE_STATUS_HANDLE hStatus;
|
SERVICE_STATUS_HANDLE hStatus;
|
||||||
SERVICE_STATUS status;
|
SERVICE_STATUS status;
|
||||||
|
|
||||||
void WINAPI ServiceCtrlHandler( DWORD control )
|
void WINAPI ServiceCtrlHandler( DWORD control )
|
||||||
{
|
{
|
||||||
switch( control )
|
switch( control )
|
||||||
{
|
{
|
||||||
case SERVICE_CONTROL_SHUTDOWN:
|
case SERVICE_CONTROL_SHUTDOWN:
|
||||||
case SERVICE_CONTROL_STOP:
|
case SERVICE_CONTROL_STOP:
|
||||||
// do shutdown stuff here
|
// do shutdown stuff here
|
||||||
switch_core_destroy();
|
switch_core_destroy();
|
||||||
status.dwCurrentState = SERVICE_STOPPED;
|
status.dwCurrentState = SERVICE_STOPPED;
|
||||||
status.dwWin32ExitCode = 0;
|
status.dwWin32ExitCode = 0;
|
||||||
status.dwCheckPoint = 0;
|
status.dwCheckPoint = 0;
|
||||||
status.dwWaitHint = 0;
|
status.dwWaitHint = 0;
|
||||||
break;
|
break;
|
||||||
case SERVICE_CONTROL_INTERROGATE:
|
case SERVICE_CONTROL_INTERROGATE:
|
||||||
// just set the current state to whatever it is...
|
// just set the current state to whatever it is...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetServiceStatus( hStatus, &status );
|
SetServiceStatus( hStatus, &status );
|
||||||
}
|
}
|
||||||
|
|
||||||
void WINAPI service_main( DWORD numArgs, char **args )
|
void WINAPI service_main( DWORD numArgs, char **args )
|
||||||
{
|
{
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
// we have to initialize the service-specific stuff
|
// we have to initialize the service-specific stuff
|
||||||
memset( &status, 0, sizeof(SERVICE_STATUS) );
|
memset( &status, 0, sizeof(SERVICE_STATUS) );
|
||||||
status.dwServiceType = SERVICE_WIN32;
|
status.dwServiceType = SERVICE_WIN32;
|
||||||
status.dwCurrentState = SERVICE_START_PENDING;
|
status.dwCurrentState = SERVICE_START_PENDING;
|
||||||
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
||||||
|
|
||||||
hStatus = RegisterServiceCtrlHandler( SERVICENAME, &ServiceCtrlHandler );
|
hStatus = RegisterServiceCtrlHandler( SERVICENAME, &ServiceCtrlHandler );
|
||||||
|
|
||||||
SetServiceStatus( hStatus, &status );
|
SetServiceStatus( hStatus, &status );
|
||||||
set_high_priority();
|
set_high_priority();
|
||||||
if (switch_core_init_and_modload(lfile, &err) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_init_and_modload(lfile, &err) != SWITCH_STATUS_SUCCESS) {
|
||||||
status.dwCurrentState = SERVICE_STOPPED;
|
status.dwCurrentState = SERVICE_STOPPED;
|
||||||
} else {
|
} else {
|
||||||
status.dwCurrentState = SERVICE_RUNNING;
|
status.dwCurrentState = SERVICE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetServiceStatus( hStatus, &status );
|
SetServiceStatus( hStatus, &status );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@ -183,46 +183,46 @@ int main(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (argv[1] && !strcmp(argv[1], "-service")) {
|
if (argv[1] && !strcmp(argv[1], "-service")) {
|
||||||
if(StartServiceCtrlDispatcher( dispatchTable ) == 0 )
|
if(StartServiceCtrlDispatcher( dispatchTable ) == 0 )
|
||||||
{
|
{
|
||||||
//Not loaded as a service
|
//Not loaded as a service
|
||||||
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
|
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
|
||||||
fprintf(stderr, "To install the service load freeswitch with -install\n");
|
fprintf(stderr, "To install the service load freeswitch with -install\n");
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (argv[1] && !strcmp(argv[1], "-install")) {
|
if (argv[1] && !strcmp(argv[1], "-install")) {
|
||||||
char exePath[1024];
|
char exePath[1024];
|
||||||
char servicePath[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 );
|
GetModuleFileName( NULL, exePath, 1024 );
|
||||||
snprintf(servicePath, sizeof(servicePath), "%s -service", exePath);
|
snprintf(servicePath, sizeof(servicePath), "%s -service", exePath);
|
||||||
CreateService(
|
CreateService(
|
||||||
handle,
|
handle,
|
||||||
SERVICENAME,
|
SERVICENAME,
|
||||||
SERVICENAME,
|
SERVICENAME,
|
||||||
GENERIC_READ | GENERIC_EXECUTE,
|
GENERIC_READ | GENERIC_EXECUTE,
|
||||||
SERVICE_WIN32_OWN_PROCESS,
|
SERVICE_WIN32_OWN_PROCESS,
|
||||||
SERVICE_AUTO_START,
|
SERVICE_AUTO_START,
|
||||||
SERVICE_ERROR_IGNORE,
|
SERVICE_ERROR_IGNORE,
|
||||||
servicePath,
|
servicePath,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (argv[1] && !strcmp(argv[1], "-uninstall")) {
|
if (argv[1] && !strcmp(argv[1], "-uninstall")) {
|
||||||
SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
|
SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
|
||||||
SC_HANDLE service = OpenService( handle, SERVICENAME, DELETE );
|
SC_HANDLE service = OpenService( handle, SERVICENAME, DELETE );
|
||||||
if( service != NULL )
|
if( service != NULL )
|
||||||
{
|
{
|
||||||
// remove the service!
|
// remove the service!
|
||||||
DeleteService( service );
|
DeleteService( service );
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2961,27 +2961,27 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
|
|||||||
char exePath[1024];
|
char exePath[1024];
|
||||||
char *lastbacklash;
|
char *lastbacklash;
|
||||||
GetModuleFileName( NULL, exePath, BUFSIZE );
|
GetModuleFileName( NULL, exePath, BUFSIZE );
|
||||||
lastbacklash = strrchr( exePath, '\\');
|
lastbacklash = strrchr( exePath, '\\');
|
||||||
exePath[(lastbacklash - exePath + 1)] = '\0';
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s\\mod", exePath);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -2998,7 +2998,7 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
|
|||||||
#else
|
#else
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
GetTempPath(dwBufSize, lpPathBuffer);
|
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);
|
snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s", lpPathBuffer);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -3270,5 +3270,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
|
|||||||
apr_terminate();
|
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;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user