From 107f913598719c086a8c06c6ed392770fdb777c4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 4 Sep 2009 18:26:15 +0000 Subject: [PATCH] add --with-rundir configure param and -run freeswitch runtime param to adjust the location of the pid file (FSBUILD-188) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14768 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- configure.in | 7 +++++++ src/include/switch_types.h | 1 + src/switch.c | 21 +++++++++++++++++++-- src/switch_core.c | 10 ++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 2c1dbfaf4e..9ded6dfdda 100644 --- a/configure.in +++ b/configure.in @@ -38,6 +38,13 @@ AC_ARG_WITH([modinstdir], 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 diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 69d1072d8f..52fad40abf 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -358,6 +358,7 @@ struct switch_directories { char *mod_dir; char *conf_dir; char *log_dir; + char *run_dir; char *db_dir; char *script_dir; char *temp_dir; diff --git a/src/switch.c b/src/switch.c index 25f26ec1bb..af93113cc7 100644 --- a/src/switch.c +++ b/src/switch.c @@ -91,7 +91,7 @@ static int freeswitch_kill_background() 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 @@ int main(int argc, char *argv[]) "\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 @@ int main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) 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); diff --git a/src/switch_core.c b/src/switch_core.c index 6485e823bb..999b77ab65 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -450,6 +450,14 @@ SWITCH_DECLARE(void) switch_core_set_globals(void) #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_DECLARE(void) switch_core_set_globals(void) 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_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc 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);