[Freeswitch-svn] [commit] r4133 - freeswitch/trunk/src

Freeswitch SVN mikej at freeswitch.org
Tue Feb 6 12:05:14 EST 2007


Author: mikej
Date: Tue Feb  6 12:05:14 2007
New Revision: 4133

Modified:
   freeswitch/trunk/src/switch.c
   freeswitch/trunk/src/switch_core.c

Log:
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.

Modified: freeswitch/trunk/src/switch.c
==============================================================================
--- freeswitch/trunk/src/switch.c	(original)
+++ freeswitch/trunk/src/switch.c	Tue Feb  6 12:05:14 2007
@@ -26,6 +26,7 @@
  * Anthony Minessale II <anthmct at yahoo.com>
  * Michael Jerris <mike at jerris.com>
  * Pawel Pierscionek <pawel at voiceworks.pl>
+ * Bret McDanel <trixter AT 0xdecafbad.com>
  *
  *
  * switch.c -- Main
@@ -206,6 +207,8 @@
 	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 @@
 		{ 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 @@
 		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);

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Tue Feb  6 12:05:14 2007
@@ -3936,9 +3936,9 @@
 #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;



More information about the Freeswitch-svn mailing list