mess around on win32 a little
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@675 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7174e8ae8a
commit
fb9b21144b
|
@ -106,7 +106,7 @@ struct switch_core_runtime;
|
||||||
\param console optional FILE stream for output
|
\param console optional FILE stream for output
|
||||||
\note to be called at application startup
|
\note to be called at application startup
|
||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(switch_status) switch_core_init(FILE *console);
|
SWITCH_DECLARE(switch_status) switch_core_init(char *console);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Destroy the core
|
\brief Destroy the core
|
||||||
|
|
109
src/switch.c
109
src/switch.c
|
@ -30,9 +30,36 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
#ifndef SWITCH_LOG_DIR
|
||||||
|
#ifdef WIN32
|
||||||
|
#define SWITCH_LOG_DIR ".\\log"
|
||||||
|
#else
|
||||||
|
#define SWITCH_LOG_DIR "/usr/local/freeswitch/log"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static int RUNNING = 0;
|
static int RUNNING = 0;
|
||||||
|
|
||||||
|
static int handle_SIGPIPE(int sig)
|
||||||
|
{
|
||||||
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Sig Pipe!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#ifdef TRAP_BUS
|
||||||
|
static int handle_SIGBUS(int sig)
|
||||||
|
{
|
||||||
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Sig BUS!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* no ctl-c mofo */
|
||||||
|
static int handle_SIGINT(int sig)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int handle_SIGHUP(int sig)
|
static int handle_SIGHUP(int sig)
|
||||||
{
|
{
|
||||||
RUNNING = 0;
|
RUNNING = 0;
|
||||||
|
@ -41,30 +68,54 @@ static int handle_SIGHUP(int sig)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
char *lfile = "freeswitch.log";
|
||||||
|
char *pfile = "freeswitch.pid";
|
||||||
|
char path[256] = "";
|
||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
switch_event *event;
|
switch_event *event;
|
||||||
int bg = 0;
|
int bg = 0;
|
||||||
FILE *out = NULL;
|
FILE *f;
|
||||||
|
#ifdef WIN32
|
||||||
|
char sep = '\\';
|
||||||
|
#else
|
||||||
|
char sep = '/';
|
||||||
|
int pid;
|
||||||
|
nice(-20);
|
||||||
|
|
||||||
|
if (argv[1] && !strcmp(argv[1], "-stop")) {
|
||||||
|
pid_t pid = 0;
|
||||||
|
snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, pfile);
|
||||||
|
if ((f = fopen(path, "r")) == 0) {
|
||||||
|
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
fscanf(f, "%d", &pid);
|
||||||
|
if (pid > 0) {
|
||||||
|
kill(pid, SIGTERM);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* set signal handlers */
|
||||||
|
(void) signal(SIGINT, (void *) handle_SIGINT);
|
||||||
|
#ifdef SIGPIPE
|
||||||
|
(void) signal(SIGPIPE, (void *) handle_SIGPIPE);
|
||||||
|
#endif
|
||||||
|
#ifdef TRAP_BUS
|
||||||
|
(void) signal(SIGBUS, (void *) handle_SIGBUS);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (argv[1] && !strcmp(argv[1], "-nc")) {
|
if (argv[1] && !strcmp(argv[1], "-nc")) {
|
||||||
bg++;
|
bg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bg) {
|
if (bg) {
|
||||||
#ifdef WIN32
|
|
||||||
char *path = ".\\freeswitch.log";
|
|
||||||
#else
|
|
||||||
int pid;
|
|
||||||
char *path = "/var/log/freeswitch.log";
|
|
||||||
nice(-20);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((out = fopen(path, "a")) == 0) {
|
|
||||||
fprintf(stderr, "Cannot open output file.\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) signal(SIGHUP, (void *) handle_SIGHUP);
|
(void) signal(SIGHUP, (void *) handle_SIGHUP);
|
||||||
|
(void) signal(SIGTERM, (void *) handle_SIGHUP);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
|
@ -76,7 +127,20 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_core_init(out) != SWITCH_STATUS_SUCCESS) {
|
snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, pfile);
|
||||||
|
if ((f = fopen(path, "w")) == 0) {
|
||||||
|
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "%d", getpid());
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (bg) {
|
||||||
|
snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, lfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (switch_core_init(bg ? path : NULL) != SWITCH_STATUS_SUCCESS) {
|
||||||
err = "Cannot Initilize\n";
|
err = "Cannot Initilize\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,10 +163,22 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "freeswitch Version %s Started\n\n", SWITCH_VERSION_FULL);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "freeswitch Version %s Started\n\n", SWITCH_VERSION_FULL);
|
||||||
|
snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, pfile);
|
||||||
|
|
||||||
if (bg) {
|
if (bg) {
|
||||||
|
bg = 0;
|
||||||
RUNNING = 1;
|
RUNNING = 1;
|
||||||
while(RUNNING) {
|
while(RUNNING) {
|
||||||
|
#ifdef WIN32
|
||||||
|
bg++;
|
||||||
|
if(bg == 100) {
|
||||||
|
if ((f = fopen(path, "r")) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
bg = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
switch_yield(10000);
|
switch_yield(10000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -118,8 +194,7 @@ int main(int argc, char *argv[])
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Clean up modules.\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Clean up modules.\n");
|
||||||
switch_loadable_module_shutdown();
|
switch_loadable_module_shutdown();
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Tearing down environment.\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Tearing down environment.\n");
|
||||||
switch_core_destroy();
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Exiting Now.\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Exiting Now.\n");
|
||||||
|
switch_core_destroy();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,6 @@ struct switch_core_runtime {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
static int handle_SIGINT(int sig);
|
|
||||||
static int handle_SIGPIPE(int sig);
|
|
||||||
static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj);
|
static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj);
|
||||||
static void switch_core_standard_on_init(switch_core_session *session);
|
static void switch_core_standard_on_init(switch_core_session *session);
|
||||||
static void switch_core_standard_on_hangup(switch_core_session *session);
|
static void switch_core_standard_on_hangup(switch_core_session *session);
|
||||||
|
@ -114,24 +112,6 @@ static void switch_core_standard_on_transmit(switch_core_session *session);
|
||||||
/* The main runtime obj we keep this hidden for ourselves */
|
/* The main runtime obj we keep this hidden for ourselves */
|
||||||
static struct switch_core_runtime runtime;
|
static struct switch_core_runtime runtime;
|
||||||
|
|
||||||
static int handle_SIGPIPE(int sig)
|
|
||||||
{
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Sig Pipe!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#ifdef TRAP_BUS
|
|
||||||
static int handle_SIGBUS(int sig)
|
|
||||||
{
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Sig BUS!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* no ctl-c mofo */
|
|
||||||
static int handle_SIGINT(int sig)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static void db_pick_path(char *dbname, char *buf, size_t size)
|
static void db_pick_path(char *dbname, char *buf, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -2195,13 +2175,19 @@ static void core_event_handler(switch_event *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status) switch_core_init(FILE *console)
|
SWITCH_DECLARE(switch_status) switch_core_init(char *console)
|
||||||
{
|
{
|
||||||
#ifdef EMBED_PERL
|
#ifdef EMBED_PERL
|
||||||
PerlInterpreter *my_perl;
|
PerlInterpreter *my_perl;
|
||||||
#endif
|
#endif
|
||||||
|
if(console) {
|
||||||
runtime.console = console ? console : stdout;
|
if ((runtime.console = fopen(console, "a")) == 0) {
|
||||||
|
fprintf(stderr, "Cannot open output file %s.\n", console);
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
runtime.console = stdout;
|
||||||
|
}
|
||||||
|
|
||||||
/* INIT APR and Create the pool context */
|
/* INIT APR and Create the pool context */
|
||||||
if (apr_initialize() != APR_SUCCESS) {
|
if (apr_initialize() != APR_SUCCESS) {
|
||||||
|
@ -2252,14 +2238,6 @@ SWITCH_DECLARE(switch_status) switch_core_init(FILE *console)
|
||||||
|
|
||||||
switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
|
switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
|
||||||
|
|
||||||
/* set signal handlers and startup time */
|
|
||||||
(void) signal(SIGINT, (void *) handle_SIGINT);
|
|
||||||
#ifdef SIGPIPE
|
|
||||||
(void) signal(SIGPIPE, (void *) handle_SIGPIPE);
|
|
||||||
#endif
|
|
||||||
#ifdef TRAP_BUS
|
|
||||||
(void) signal(SIGBUS, (void *) handle_SIGBUS);
|
|
||||||
#endif
|
|
||||||
time(&runtime.initiated);
|
time(&runtime.initiated);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
@ -2290,5 +2268,10 @@ SWITCH_DECLARE(switch_status) switch_core_destroy(void)
|
||||||
apr_terminate();
|
apr_terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(runtime.console != stdout && runtime.console != stderr) {
|
||||||
|
fclose(runtime.console);
|
||||||
|
runtime.console = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue