From cfdd5862248e017ac26ee3b0c133fc57c66ae14b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 6 Feb 2007 17:05:14 +0000 Subject: [PATCH] add -conf, -db, and -log params to the binary to allow for running multiple copies of freeswitch concurrently on the same box. Please note that these params may change in the future. Patch from Bret McDanel. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4133 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ src/switch_core.c | 6 ++-- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/switch.c b/src/switch.c index a548e571a8..0b0ec561c2 100644 --- a/src/switch.c +++ b/src/switch.c @@ -26,6 +26,7 @@ * Anthony Minessale II * Michael Jerris * Pawel Pierscionek + * Bret McDanel * * * switch.c -- Main @@ -206,6 +207,8 @@ int main(int argc, char *argv[]) pid_t pid = 0; // int x; // int die = 0; // + char *usageDesc; + int alt_dirs = 0; #ifdef WIN32 SERVICE_TABLE_ENTRY dispatchTable[] = @@ -213,9 +216,35 @@ int main(int argc, char *argv[]) { SERVICENAME, &service_main }, { NULL, NULL } }; + usageDesc = "these are the optional arguments you can pass to freeswitch\n" + "\t-service -- start freeswitch as a service, cannot be used if loaded as a console app\n" + "\t-install -- install freeswitch as a service\n" + "\t-uninstall -- remove freeswitch as a service\n" + "\t-hp -- enable high priority settings\n" + "\t-stop -- stop freeswitch\n" + "\t-nc -- do not output to a console and background\n" + "\t-conf [confdir] -- specify an alternate config dir\n" + "\t-log [logdir] -- specify an alternate log dir\n" + "\t-db [dbdir] -- specify an alternate db dir\n"; +#else + usageDesc = "these are the optional arguments you can pass to freeswitch\n" + "\t-help -- this message\n" + "\t-nf -- no forking\n" + "\t-hp -- enable high priority settings\n" + "\t-stop -- stop freeswitch\n" + "\t-nc -- do not output to a console and background\n" + "\t-vg -- enable valgrind mode\n" + "\t-conf [confdir] -- specify an alternate config dir\n" + "\t-log [logdir] -- specify an alternate log dir\n" + "\t-db [dbdir] -- specify an alternate db dir\n"; + #endif for (x = 1; x < argc; x++) { + if (argv[x] && !strcmp(argv[x], "-help")) { + printf("%s\n",usageDesc); + exit(0); + } #ifdef WIN32 if (x == 1) { if (argv[x] && !strcmp(argv[x], "-service")) { @@ -281,12 +310,54 @@ int main(int argc, char *argv[]) if (argv[x] && !strcmp(argv[x], "-vg")) { vg++; } + + if (argv[x] && !strcmp(argv[x], "-conf")) { + x++; + if (argv[x] && strlen(argv[x])) { + SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(argv[x])+1); + strcpy(SWITCH_GLOBAL_dirs.conf_dir,argv[x]); + alt_dirs++; + } else { + fprintf(stderr, "When using -conf you must specify a config directory\n"); + return 255; + } + } + + if (argv[x] && !strcmp(argv[x], "-log")) { + x++; + if (argv[x] && strlen(argv[x])) { + SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(argv[x])+1); + strcpy(SWITCH_GLOBAL_dirs.log_dir,argv[x]); + alt_dirs++; + } else { + fprintf(stderr, "When using -log you must specify a log directory\n"); + return 255; + } + } + + if (argv[x] && !strcmp(argv[x], "-db")) { + x++; + if (argv[x] && strlen(argv[x])) { + SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(argv[x])+1); + strcpy(SWITCH_GLOBAL_dirs.db_dir,argv[x]); + alt_dirs++; + } else { + fprintf(stderr, "When using -db you must specify a db directory\n"); + return 255; + } + } + } if (die) { return freeswitch_kill_background(); } + if (alt_dirs && alt_dirs !=3) { + fprintf(stderr, "You must use -conf, -log, and -db together\n"); + return 255; + } + if (nc) { signal(SIGHUP, handle_SIGHUP); diff --git a/src/switch_core.c b/src/switch_core.c index 41f10104b0..717b31c020 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -3936,9 +3936,9 @@ SWITCH_DECLARE(void) switch_core_set_globals(void) #else SWITCH_GLOBAL_dirs.base_dir = SWITCH_PREFIX_DIR; SWITCH_GLOBAL_dirs.mod_dir = SWITCH_MOD_DIR; - SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR; - SWITCH_GLOBAL_dirs.log_dir = SWITCH_LOG_DIR; - SWITCH_GLOBAL_dirs.db_dir = SWITCH_DB_DIR; + if(!SWITCH_GLOBAL_dirs.conf_dir) SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR; + if(!SWITCH_GLOBAL_dirs.log_dir) SWITCH_GLOBAL_dirs.log_dir = SWITCH_LOG_DIR; + if(!SWITCH_GLOBAL_dirs.db_dir) SWITCH_GLOBAL_dirs.db_dir = SWITCH_DB_DIR; SWITCH_GLOBAL_dirs.script_dir = SWITCH_SCRIPT_DIR; SWITCH_GLOBAL_dirs.htdocs_dir = SWITCH_HTDOCS_DIR; SWITCH_GLOBAL_dirs.grammar_dir = SWITCH_GRAMMAR_DIR;