mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-15 05:08:26 +00:00
freeswitch: Rework option handling in main() and other clean ups.
Use a chain of "else if" statements, drop known_opt completely. Added bonus: We stop trying to parse option arguments as (possible) options. Arguments of -u/-g and path options (-conf) now check whether their argument starts with a dash ('-') and error out in case it does (= next option, not a valid argument). Use PATH_MAX for everything that stores files / directories. Use switch_bool_t and SWITCH_TRUE/_FALSE for boolean variables. Use EXIT_SUCCESS/_FAILURE for exit() calls. Get rid of excessive indenting (especially in the win32 parts of main()). NOTE: Win32 parts untested. Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
parent
659ea9f117
commit
f9d0e249a1
468
src/switch.c
468
src/switch.c
@ -113,7 +113,7 @@ static void handle_SIGCHLD(int sig)
|
|||||||
static int freeswitch_kill_background()
|
static int freeswitch_kill_background()
|
||||||
{
|
{
|
||||||
FILE *f; /* FILE handle to open the pid file */
|
FILE *f; /* FILE handle to open the pid file */
|
||||||
char path[256] = ""; /* full path of the PID file */
|
char path[PATH_MAX] = ""; /* full path of the PID file */
|
||||||
pid_t pid = 0; /* pid from the pid file */
|
pid_t pid = 0; /* pid from the pid file */
|
||||||
|
|
||||||
/* set the globals so we can use the global paths. */
|
/* set the globals so we can use the global paths. */
|
||||||
@ -375,22 +375,34 @@ static const char const usage[] =
|
|||||||
"\t-scripts [scriptsdir] -- specify an alternate scripts dir\n";
|
"\t-scripts [scriptsdir] -- specify an alternate scripts dir\n";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if value string starts with "-"
|
||||||
|
*/
|
||||||
|
static switch_bool_t is_option(const char *p)
|
||||||
|
{
|
||||||
|
/* skip whitespaces */
|
||||||
|
while ((*p == 13) || (*p == 10) || (*p == 9) || (*p == 32) || (*p == 11)) p++;
|
||||||
|
return (p[0] == '-');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* the main application entry point */
|
/* the main application entry point */
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char pid_path[256] = ""; /* full path to the pid file */
|
char pid_path[PATH_MAX] = ""; /* full path to the pid file */
|
||||||
char pid_buffer[32] = ""; /* pid string */
|
char pid_buffer[32] = ""; /* pid string */
|
||||||
char old_pid_buffer[32] = ""; /* pid string */
|
char old_pid_buffer[32] = ""; /* pid string */
|
||||||
switch_size_t pid_len, old_pid_len;
|
switch_size_t pid_len, old_pid_len;
|
||||||
const char *err = NULL; /* error value for return from freeswitch initialization */
|
const char *err = NULL; /* error value for return from freeswitch initialization */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int nf = 0; /* TRUE if we are running in nofork mode */
|
switch_bool_t nf = SWITCH_FALSE; /* TRUE if we are running in nofork mode */
|
||||||
|
switch_bool_t do_wait = SWITCH_FALSE;
|
||||||
char *runas_user = NULL;
|
char *runas_user = NULL;
|
||||||
char *runas_group = NULL;
|
char *runas_group = NULL;
|
||||||
#else
|
#else
|
||||||
int win32_service = 0;
|
switch_bool_t win32_service = SWITCH_FALSE;
|
||||||
#endif
|
#endif
|
||||||
int nc = 0; /* TRUE if we are running in noconsole mode */
|
switch_bool_t nc = SWITCH_FALSE; /* TRUE if we are running in noconsole mode */
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
int i, x;
|
int i, x;
|
||||||
char *opts;
|
char *opts;
|
||||||
@ -399,11 +411,7 @@ int main(int argc, char *argv[])
|
|||||||
int local_argc = argc;
|
int local_argc = argc;
|
||||||
char *arg_argv[128] = { 0 };
|
char *arg_argv[128] = { 0 };
|
||||||
int alt_dirs = 0, log_set = 0, run_set = 0, do_kill = 0;
|
int alt_dirs = 0, log_set = 0, run_set = 0, do_kill = 0;
|
||||||
int known_opt;
|
|
||||||
int priority = 0;
|
int priority = 0;
|
||||||
#ifndef WIN32
|
|
||||||
int do_wait = 0;
|
|
||||||
#endif
|
|
||||||
#ifdef __sun
|
#ifdef __sun
|
||||||
switch_core_flag_t flags = SCF_USE_SQL;
|
switch_core_flag_t flags = SCF_USE_SQL;
|
||||||
#else
|
#else
|
||||||
@ -415,7 +423,7 @@ int main(int argc, char *argv[])
|
|||||||
switch_memory_pool_t *pool = NULL;
|
switch_memory_pool_t *pool = NULL;
|
||||||
#ifdef HAVE_SETRLIMIT
|
#ifdef HAVE_SETRLIMIT
|
||||||
struct rlimit rlp;
|
struct rlimit rlp;
|
||||||
int waste = 0;
|
switch_bool_t waste = SWITCH_FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (x = 0; x < argc; x++) {
|
for (x = 0; x < argc; x++) {
|
||||||
@ -430,13 +438,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (local_argv[0] && strstr(local_argv[0], "freeswitchd")) {
|
if (local_argv[0] && strstr(local_argv[0], "freeswitchd")) {
|
||||||
nc++;
|
nc = SWITCH_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 1; x < local_argc; x++) {
|
for (x = 1; x < local_argc; x++) {
|
||||||
known_opt = 0;
|
|
||||||
|
|
||||||
if (switch_strlen_zero(local_argv[x]))
|
if (switch_strlen_zero(local_argv[x]))
|
||||||
continue;
|
continue;
|
||||||
@ -446,330 +452,317 @@ int main(int argc, char *argv[])
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (x == 1) {
|
if (x == 1 && !strcmp(local_argv[x], "-service")) {
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-service")) {
|
/* New installs will always have the service name specified, but keep a default for compat */
|
||||||
/* New installs will always have the service name specified, but keep a default for compat */
|
x++;
|
||||||
x++;
|
if (!switch_strlen_zero(local_argv[x])) {
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
switch_copy_string(service_name, local_argv[x], SERVICENAME_MAXLEN);
|
||||||
switch_copy_string(service_name, local_argv[x], SERVICENAME_MAXLEN);
|
} else {
|
||||||
} else {
|
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
|
||||||
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
|
|
||||||
}
|
|
||||||
known_opt++;
|
|
||||||
win32_service++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-install")) {
|
|
||||||
char exePath[1024];
|
|
||||||
char servicePath[1024];
|
|
||||||
x++;
|
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
|
||||||
switch_copy_string(service_name, local_argv[x], SERVICENAME_MAXLEN);
|
|
||||||
} else {
|
|
||||||
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
|
|
||||||
}
|
|
||||||
known_opt++;
|
|
||||||
GetModuleFileName(NULL, exePath, 1024);
|
|
||||||
snprintf(servicePath, sizeof(servicePath), "%s -service %s", exePath, service_name);
|
|
||||||
{ /* Perform service installation */
|
|
||||||
SC_HANDLE hService;
|
|
||||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
|
||||||
if (!hSCManager) {
|
|
||||||
fprintf(stderr, "Could not open service manager (%d).\n", GetLastError());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
hService = CreateService(hSCManager, service_name, service_name, GENERIC_READ | GENERIC_EXECUTE | SERVICE_CHANGE_CONFIG, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, servicePath, NULL, NULL, NULL, NULL, /* Service start name */
|
|
||||||
NULL);
|
|
||||||
if (!hService) {
|
|
||||||
fprintf(stderr, "Error creating freeswitch service (%d).\n", GetLastError());
|
|
||||||
} else {
|
|
||||||
/* Set desc, and don't care if it succeeds */
|
|
||||||
SERVICE_DESCRIPTION desc;
|
|
||||||
desc.lpDescription = "The FreeSWITCH service.";
|
|
||||||
if (!ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &desc)) {
|
|
||||||
fprintf(stderr, "FreeSWITCH installed, but could not set the service description (%d).\n", GetLastError());
|
|
||||||
}
|
|
||||||
CloseServiceHandle(hService);
|
|
||||||
}
|
|
||||||
CloseServiceHandle(hSCManager);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-uninstall")) {
|
win32_service = SWITCH_TRUE;
|
||||||
x++;
|
continue;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
|
||||||
switch_copy_string(service_name, local_argv[x], SERVICENAME_MAXLEN);
|
|
||||||
} else {
|
|
||||||
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
|
|
||||||
}
|
|
||||||
{ /* Do the uninstallation */
|
|
||||||
SC_HANDLE hService;
|
|
||||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
|
||||||
if (!hSCManager) {
|
|
||||||
fprintf(stderr, "Could not open service manager (%d).\n", GetLastError());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
hService = OpenService(hSCManager, service_name, DELETE);
|
|
||||||
known_opt++;
|
|
||||||
if (hService != NULL) {
|
|
||||||
/* remove the service! */
|
|
||||||
if (!DeleteService(hService)) {
|
|
||||||
fprintf(stderr, "Error deleting service (%d).\n", GetLastError());
|
|
||||||
}
|
|
||||||
CloseServiceHandle(hService);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Error opening service (%d).\n", GetLastError());
|
|
||||||
}
|
|
||||||
CloseServiceHandle(hSCManager);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-monotonic-clock")) {
|
else if (x == 1 && !strcmp(local_argv[x], "-install")) {
|
||||||
|
char servicePath[PATH_MAX];
|
||||||
|
char exePath[PATH_MAX];
|
||||||
|
SC_HANDLE hService;
|
||||||
|
SC_HANDLE hSCManager;
|
||||||
|
SERVICE_DESCRIPTION desc;
|
||||||
|
desc.lpDescription = "The FreeSWITCH service.";
|
||||||
|
|
||||||
|
x++;
|
||||||
|
if (!switch_strlen_zero(local_argv[x])) {
|
||||||
|
switch_copy_string(service_name, local_argv[x], SERVICENAME_MAXLEN);
|
||||||
|
} else {
|
||||||
|
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
GetModuleFileName(NULL, exePath, sizeof(exePath));
|
||||||
|
snprintf(servicePath, sizeof(servicePath), "%s -service %s", exePath, service_name);
|
||||||
|
|
||||||
|
/* Perform service installation */
|
||||||
|
|
||||||
|
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
|
if (!hSCManager) {
|
||||||
|
fprintf(stderr, "Could not open service manager (%d).\n", GetLastError());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
hService = CreateService(hSCManager, service_name, service_name, GENERIC_READ | GENERIC_EXECUTE | SERVICE_CHANGE_CONFIG, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
|
||||||
|
servicePath, NULL, NULL, NULL, NULL, /* Service start name */ NULL);
|
||||||
|
if (!hService) {
|
||||||
|
fprintf(stderr, "Error creating freeswitch service (%d).\n", GetLastError());
|
||||||
|
CloseServiceHandle(hSCManager);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set desc, and don't care if it succeeds */
|
||||||
|
if (!ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &desc)) {
|
||||||
|
fprintf(stderr, "FreeSWITCH installed, but could not set the service description (%d).\n", GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseServiceHandle(hService);
|
||||||
|
CloseServiceHandle(hSCManager);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (x == 1 && !strcmp(local_argv[x], "-uninstall")) {
|
||||||
|
SC_HANDLE hService;
|
||||||
|
SC_HANDLE hSCManager;
|
||||||
|
BOOL deleted;
|
||||||
|
|
||||||
|
x++;
|
||||||
|
if (!switch_strlen_zero(local_argv[x])) {
|
||||||
|
switch_copy_string(service_name, local_argv[x], SERVICENAME_MAXLEN);
|
||||||
|
} else {
|
||||||
|
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do the uninstallation */
|
||||||
|
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
|
if (!hSCManager) {
|
||||||
|
fprintf(stderr, "Could not open service manager (%d).\n", GetLastError());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
hService = OpenService(hSCManager, service_name, DELETE);
|
||||||
|
if (!hService) {
|
||||||
|
fprintf(stderr, "Error opening service (%d).\n", GetLastError());
|
||||||
|
CloseServiceHandle(hSCManager);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove the service! */
|
||||||
|
deleted = DeleteService(hService);
|
||||||
|
if (!deleted) {
|
||||||
|
fprintf(stderr, "Error deleting service (%d).\n", GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseServiceHandle(hService);
|
||||||
|
CloseServiceHandle(hSCManager);
|
||||||
|
exit(deleted ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!strcmp(local_argv[x], "-monotonic-clock")) {
|
||||||
flags |= SCF_USE_WIN32_MONOTONIC;
|
flags |= SCF_USE_WIN32_MONOTONIC;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-u")) {
|
else if (!strcmp(local_argv[x], "-u")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
runas_user = local_argv[x];
|
fprintf(stderr, "Option '%s' requires an argument!\n", local_argv[x - 1]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
known_opt++;
|
runas_user = local_argv[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-g")) {
|
else if (!strcmp(local_argv[x], "-g")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
runas_group = local_argv[x];
|
fprintf(stderr, "Option '%s' requires an argument!\n", local_argv[x - 1]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
known_opt++;
|
runas_group = local_argv[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nf")) {
|
else if (!strcmp(local_argv[x], "-nf")) {
|
||||||
nf++;
|
nf = SWITCH_TRUE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-version")) {
|
else if (!strcmp(local_argv[x], "-version")) {
|
||||||
fprintf(stdout, "FreeSWITCH version: %s\n", SWITCH_VERSION_FULL);
|
fprintf(stdout, "FreeSWITCH version: %s\n", SWITCH_VERSION_FULL);
|
||||||
return 0;
|
exit(EXIT_SUCCESS);
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SETRLIMIT
|
#ifdef HAVE_SETRLIMIT
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-core")) {
|
else if (!strcmp(local_argv[x], "-core")) {
|
||||||
memset(&rlp, 0, sizeof(rlp));
|
memset(&rlp, 0, sizeof(rlp));
|
||||||
rlp.rlim_cur = RLIM_INFINITY;
|
rlp.rlim_cur = RLIM_INFINITY;
|
||||||
rlp.rlim_max = RLIM_INFINITY;
|
rlp.rlim_max = RLIM_INFINITY;
|
||||||
setrlimit(RLIMIT_CORE, &rlp);
|
setrlimit(RLIMIT_CORE, &rlp);
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-waste")) {
|
else if (!strcmp(local_argv[x], "-waste")) {
|
||||||
fprintf(stderr, "WARNING: Wasting up to 8 megs of memory per thread.\n");
|
fprintf(stderr, "WARNING: Wasting up to 8 megs of memory per thread.\n");
|
||||||
sleep(2);
|
sleep(2);
|
||||||
waste++;
|
waste = SWITCH_TRUE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-no-auto-stack")) {
|
else if (!strcmp(local_argv[x], "-no-auto-stack")) {
|
||||||
waste++;
|
waste = SWITCH_TRUE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else if (!strcmp(local_argv[x], "-hp") || !strcmp(local_argv[x], "-rp")) {
|
||||||
if (local_argv[x] && (!strcmp(local_argv[x], "-hp") || !strcmp(local_argv[x], "-rp"))) {
|
|
||||||
priority = 2;
|
priority = 2;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-lp")) {
|
else if (!strcmp(local_argv[x], "-lp")) {
|
||||||
priority = -1;
|
priority = -1;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-np")) {
|
else if (!strcmp(local_argv[x], "-np")) {
|
||||||
priority = 1;
|
priority = 1;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nosql")) {
|
else if (!strcmp(local_argv[x], "-nosql")) {
|
||||||
flags &= ~SCF_USE_SQL;
|
flags &= ~SCF_USE_SQL;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nonat")) {
|
else if (!strcmp(local_argv[x], "-nonat")) {
|
||||||
flags &= ~SCF_USE_AUTO_NAT;
|
flags &= ~SCF_USE_AUTO_NAT;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nonatmap")) {
|
else if (!strcmp(local_argv[x], "-nonatmap")) {
|
||||||
flags &= ~SCF_USE_NAT_MAPPING;
|
flags &= ~SCF_USE_NAT_MAPPING;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-heavy-timer")) {
|
else if (!strcmp(local_argv[x], "-heavy-timer")) {
|
||||||
flags |= SCF_USE_HEAVY_TIMING;
|
flags |= SCF_USE_HEAVY_TIMING;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nort")) {
|
else if (!strcmp(local_argv[x], "-nort")) {
|
||||||
flags &= ~SCF_USE_CLOCK_RT;
|
flags &= ~SCF_USE_CLOCK_RT;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nocal")) {
|
else if (!strcmp(local_argv[x], "-nocal")) {
|
||||||
flags &= ~SCF_CALIBRATE_CLOCK;
|
flags &= ~SCF_CALIBRATE_CLOCK;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-vg")) {
|
else if (!strcmp(local_argv[x], "-vg")) {
|
||||||
flags |= SCF_VG;
|
flags |= SCF_VG;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-stop")) {
|
else if (!strcmp(local_argv[x], "-stop")) {
|
||||||
do_kill++;
|
do_kill = SWITCH_TRUE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-nc")) {
|
else if (!strcmp(local_argv[x], "-nc")) {
|
||||||
nc++;
|
nc = SWITCH_TRUE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-ncwait")) {
|
else if (!strcmp(local_argv[x], "-ncwait")) {
|
||||||
nc++;
|
nc = SWITCH_TRUE;
|
||||||
do_wait++;
|
do_wait = SWITCH_TRUE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-c")) {
|
else if (!strcmp(local_argv[x], "-c")) {
|
||||||
nc = 0;
|
nc = SWITCH_FALSE;
|
||||||
known_opt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-conf")) {
|
else if (!strcmp(local_argv[x], "-conf")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
|
||||||
if (!SWITCH_GLOBAL_dirs.conf_dir) {
|
|
||||||
fprintf(stderr, "Allocation error\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
strcpy(SWITCH_GLOBAL_dirs.conf_dir, local_argv[x]);
|
|
||||||
alt_dirs++;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -conf you must specify a config directory\n");
|
fprintf(stderr, "When using -conf you must specify a config directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
|
SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
||||||
|
if (!SWITCH_GLOBAL_dirs.conf_dir) {
|
||||||
|
fprintf(stderr, "Allocation error\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
strcpy(SWITCH_GLOBAL_dirs.conf_dir, local_argv[x]);
|
||||||
|
alt_dirs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-mod")) {
|
else if (!strcmp(local_argv[x], "-mod")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
|
||||||
if (!SWITCH_GLOBAL_dirs.mod_dir) {
|
|
||||||
fprintf(stderr, "Allocation error\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
strcpy(SWITCH_GLOBAL_dirs.mod_dir, local_argv[x]);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -mod you must specify a module directory\n");
|
fprintf(stderr, "When using -mod you must specify a module directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
|
SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
||||||
|
if (!SWITCH_GLOBAL_dirs.mod_dir) {
|
||||||
|
fprintf(stderr, "Allocation error\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
strcpy(SWITCH_GLOBAL_dirs.mod_dir, local_argv[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-log")) {
|
else if (!strcmp(local_argv[x], "-log")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
|
||||||
if (!SWITCH_GLOBAL_dirs.log_dir) {
|
|
||||||
fprintf(stderr, "Allocation error\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
strcpy(SWITCH_GLOBAL_dirs.log_dir, local_argv[x]);
|
|
||||||
alt_dirs++;
|
|
||||||
log_set++;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -log you must specify a log directory\n");
|
fprintf(stderr, "When using -log you must specify a log directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
|
SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
||||||
|
if (!SWITCH_GLOBAL_dirs.log_dir) {
|
||||||
|
fprintf(stderr, "Allocation error\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
strcpy(SWITCH_GLOBAL_dirs.log_dir, local_argv[x]);
|
||||||
|
alt_dirs++;
|
||||||
|
log_set = SWITCH_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-run")) {
|
else if (!strcmp(local_argv[x], "-run")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(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]);
|
|
||||||
run_set++;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -run you must specify a pid directory\n");
|
fprintf(stderr, "When using -run you must specify a pid directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
|
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]);
|
||||||
|
run_set = SWITCH_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-db")) {
|
else if (!strcmp(local_argv[x], "-db")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
|
||||||
if (!SWITCH_GLOBAL_dirs.db_dir) {
|
|
||||||
fprintf(stderr, "Allocation error\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
strcpy(SWITCH_GLOBAL_dirs.db_dir, local_argv[x]);
|
|
||||||
alt_dirs++;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -db you must specify a db directory\n");
|
fprintf(stderr, "When using -db you must specify a db directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
|
SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
||||||
|
if (!SWITCH_GLOBAL_dirs.db_dir) {
|
||||||
|
fprintf(stderr, "Allocation error\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
strcpy(SWITCH_GLOBAL_dirs.db_dir, local_argv[x]);
|
||||||
|
alt_dirs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-scripts")) {
|
else if (!strcmp(local_argv[x], "-scripts")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
|
||||||
if (!SWITCH_GLOBAL_dirs.script_dir) {
|
|
||||||
fprintf(stderr, "Allocation error\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
strcpy(SWITCH_GLOBAL_dirs.script_dir, local_argv[x]);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -scripts you must specify a scripts directory\n");
|
fprintf(stderr, "When using -scripts you must specify a scripts directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
|
SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
||||||
|
if (!SWITCH_GLOBAL_dirs.script_dir) {
|
||||||
|
fprintf(stderr, "Allocation error\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
strcpy(SWITCH_GLOBAL_dirs.script_dir, local_argv[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_argv[x] && !strcmp(local_argv[x], "-htdocs")) {
|
else if (!strcmp(local_argv[x], "-htdocs")) {
|
||||||
x++;
|
x++;
|
||||||
if (!switch_strlen_zero(local_argv[x])) {
|
if (switch_strlen_zero(local_argv[x]) || is_option(local_argv[x])) {
|
||||||
SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
|
||||||
if (!SWITCH_GLOBAL_dirs.htdocs_dir) {
|
|
||||||
fprintf(stderr, "Allocation error\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
strcpy(SWITCH_GLOBAL_dirs.htdocs_dir, local_argv[x]);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "When using -htdocs you must specify a htdocs directory\n");
|
fprintf(stderr, "When using -htdocs you must specify a htdocs directory\n");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
known_opt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!known_opt) {
|
SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(strlen(local_argv[x]) + 1);
|
||||||
|
if (!SWITCH_GLOBAL_dirs.htdocs_dir) {
|
||||||
|
fprintf(stderr, "Allocation error\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
strcpy(SWITCH_GLOBAL_dirs.htdocs_dir, local_argv[x]);
|
||||||
|
}
|
||||||
|
/* Unknown option (always last!) */
|
||||||
|
else {
|
||||||
fprintf(stderr, "Unknown option '%s', see '%s -help' for a list of valid options\n",
|
fprintf(stderr, "Unknown option '%s', see '%s -help' for a list of valid options\n",
|
||||||
local_argv[x], local_argv[0]);
|
local_argv[x], local_argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -879,21 +872,20 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (win32_service) {
|
if (win32_service) {
|
||||||
{ /* Attempt to start service */
|
/* Attempt to start service */
|
||||||
SERVICE_TABLE_ENTRY dispatchTable[] = {
|
SERVICE_TABLE_ENTRY dispatchTable[] = {
|
||||||
{service_name, &service_main}
|
{service_name, &service_main}
|
||||||
,
|
,
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
service_flags = flags; /* copy parsed flags for service startup */
|
service_flags = flags; /* copy parsed flags for service startup */
|
||||||
|
|
||||||
if (StartServiceCtrlDispatcher(dispatchTable) == 0) {
|
if (StartServiceCtrlDispatcher(dispatchTable) == 0) {
|
||||||
/* Not loaded as a service */
|
/* Not loaded as a service */
|
||||||
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
|
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
|
||||||
fprintf(stderr, "To install the service load freeswitch with -install\n");
|
fprintf(stderr, "To install the service load freeswitch with -install\n");
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user