Revision
14768
Author
mikej
Date
2009-09-04 13:26:15 -0500 (Fri, 04 Sep 2009)

Log Message

add --with-rundir configure param and -run freeswitch runtime param to adjust the location of the pid file (FSBUILD-188)

Modified Paths

Diff

Modified: freeswitch/trunk/configure.in (14767 => 14768)


--- freeswitch/trunk/configure.in	2009-09-04 16:03:28 UTC (rev 14767)
+++ freeswitch/trunk/configure.in	2009-09-04 18:26:15 UTC (rev 14768)
@@ -38,6 +38,13 @@
 AC_SUBST(modinstdir)
 AC_DEFINE_UNQUOTED([SWITCH_MOD_DIR],"${modinstdir}",[where to install the modules to])
 
+# Where to put pidfile
+AC_ARG_WITH([rundir],
+	[AS_HELP_STRING([--with-rundir=DIR], [Put pidfile into this location (default: $prefix/log)])], [rundir="$withval"], [rundir="${prefix}/log"])
+
+AC_SUBST(rundir)
+AC_DEFINE_UNQUOTED([SWITCH_RUN_DIR],"${rundir}",[where to put pidfile to])
+
 if test "$sysconfdir" = "\${prefix}/etc" ; then
     confdir="$prefix/conf"
 else

Modified: freeswitch/trunk/src/include/switch_types.h (14767 => 14768)


--- freeswitch/trunk/src/include/switch_types.h	2009-09-04 16:03:28 UTC (rev 14767)
+++ freeswitch/trunk/src/include/switch_types.h	2009-09-04 18:26:15 UTC (rev 14768)
@@ -358,6 +358,7 @@
 	char *mod_dir;
 	char *conf_dir;
 	char *log_dir;
+	char *run_dir;
 	char *db_dir;
 	char *script_dir;
 	char *temp_dir;

Modified: freeswitch/trunk/src/switch.c (14767 => 14768)


--- freeswitch/trunk/src/switch.c	2009-09-04 16:03:28 UTC (rev 14767)
+++ freeswitch/trunk/src/switch.c	2009-09-04 18:26:15 UTC (rev 14768)
@@ -91,7 +91,7 @@
 	switch_core_set_globals();
 
 	/* get the full path of the pid file. */
-	switch_snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pfile);
+	switch_snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.run_dir, SWITCH_PATH_SEPARATOR, pfile);
 
 	/* open the pid file */
 	if ((f = fopen(path, "r")) == 0) {
@@ -333,6 +333,7 @@
 		"\t-c                     -- output to a console and stay in the foreground\n"
 		"\t-conf [confdir]        -- specify an alternate config dir\n"
 		"\t-log [logdir]          -- specify an alternate log dir\n"
+		"\t-run [rundir]          -- specify an alternate run dir\n"
 		"\t-db [dbdir]            -- specify an alternate db dir\n"
 		"\t-mod [moddir]          -- specify an alternate mod dir\n"
 		"\t-htdocs [htdocsdir]    -- specify an alternate htdocs dir\n"
@@ -559,6 +560,22 @@
 			known_opt++;
 		}
 
+		if (local_argv[x] && !strcmp(local_argv[x], "-run")) {
+			x++;
+			if (local_argv[x] && strlen(local_argv[x])) {
+				SWITCH_GLOBAL_dirs.run_dir = (char *) malloc(strlen(local_argv[x]) + 1);
+				if (!SWITCH_GLOBAL_dirs.run_dir) {
+					fprintf(stderr, "Allocation error\n");
+					return 255;
+				}
+				strcpy(SWITCH_GLOBAL_dirs.run_dir, local_argv[x]);
+			} else {
+				fprintf(stderr, "When using -run you must specify a pid directory\n");
+				return 255;
+			}
+			known_opt++;
+		}
+
 		if (local_argv[x] && !strcmp(local_argv[x], "-db")) {
 			x++;
 			if (local_argv[x] && strlen(local_argv[x])) {
@@ -690,7 +707,7 @@
 	pid = getpid();
 
 	memset(pid_buffer, 0, sizeof(pid_buffer));
-	switch_snprintf(pid_path, sizeof(pid_path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pfile);
+	switch_snprintf(pid_path, sizeof(pid_path), "%s%s%s", SWITCH_GLOBAL_dirs.run_dir, SWITCH_PATH_SEPARATOR, pfile);
 	switch_snprintf(pid_buffer, sizeof(pid_buffer), "%d", pid);
 	pid_len = strlen(pid_buffer);
 

Modified: freeswitch/trunk/src/switch_core.c (14767 => 14768)


--- freeswitch/trunk/src/switch_core.c	2009-09-04 16:03:28 UTC (rev 14767)
+++ freeswitch/trunk/src/switch_core.c	2009-09-04 18:26:15 UTC (rev 14768)
@@ -450,6 +450,14 @@
 #endif
 	}
 
+	if (!SWITCH_GLOBAL_dirs.run_dir && (SWITCH_GLOBAL_dirs.run_dir = (char *) malloc(BUFSIZE))) {
+#ifdef SWITCH_RUN_DIR
+		switch_snprintf(SWITCH_GLOBAL_dirs.run_dir, BUFSIZE, "%s", SWITCH_RUN_DIR);
+#else
+		switch_snprintf(SWITCH_GLOBAL_dirs.run_dir, BUFSIZE, "%s%slog", base_dir, SWITCH_PATH_SEPARATOR);
+#endif
+	}
+
 	if (!SWITCH_GLOBAL_dirs.storage_dir && (SWITCH_GLOBAL_dirs.storage_dir = (char *) malloc(BUFSIZE))) {
 #ifdef SWITCH_STORAGE_DIR
 		switch_snprintf(SWITCH_GLOBAL_dirs.storage_dir, BUFSIZE, "%s", SWITCH_STORAGE_DIR);
@@ -507,6 +515,7 @@
 	switch_assert(SWITCH_GLOBAL_dirs.mod_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.conf_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.log_dir);
+	switch_assert(SWITCH_GLOBAL_dirs.run_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.db_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.script_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.htdocs_dir);
@@ -1195,6 +1204,7 @@
 	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.mod_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);
 	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.conf_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);
 	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.log_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);
+	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.run_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);
 	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.db_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);
 	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.script_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);
 	switch_dir_make_recursive(SWITCH_GLOBAL_dirs.htdocs_dir, SWITCH_DEFAULT_DIR_PERMS, runtime.memory_pool);