Newer
Older
if (!version)
version = "<Version Unknown>";
Olle Johansson
committed
stringp = hostname;
if (cpid)
pid = atoi(cpid);
else
pid = -1;
snprintf(tmp, sizeof(tmp), "set verbose atleast %d", option_verbose);
snprintf(tmp, sizeof(tmp), "set debug atleast %d", option_debug);
fdprint(ast_consock, tmp);
ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
if (el_hist == NULL || el == NULL)
ast_el_initialize();
el_set(el, EL_GETCFN, ast_el_read_char);
Russell Bryant
committed
if (ast_opt_exec && data) { /* hack to print output then exit if asterisk -rx is used */
struct pollfd fds[0];
fds[0].fd = ast_consock;
fds[0].events = POLLIN;
fds[0].revents = 0;
while(poll(fds, 1, 100) > 0) {
ast_el_read_char(el, &tempchar);
}
Olle Johansson
committed
for (;;) {
if (!ast_strlen_zero(ebuf)) {
if (ebuf[strlen(ebuf)-1] == '\n')
ebuf[strlen(ebuf)-1] = '\0';
if (!remoteconsolehandler(ebuf)) {
res = write(ast_consock, ebuf, strlen(ebuf) + 1);
if (res < 1) {
ast_log(LOG_WARNING, "Unable to write: %s\n", strerror(errno));
break;
}
}
}
}
printf("\nDisconnected from Asterisk server\n");
}
static int show_version(void)
{
printf("Asterisk " ASTERISK_VERSION "\n");
return 0;
}
Olle Johansson
committed
printf("Asterisk " ASTERISK_VERSION ", Copyright (C) 1999 - 2006, Digium, Inc. and others.\n");
printf("Usage: asterisk [OPTIONS]\n");
printf("Valid Options:\n");
printf(" -C <configfile> Use an alternate configuration file\n");
printf(" -G <group> Run as a group other than the caller\n");
printf(" -U <user> Run as a user other than the caller\n");
printf(" -c Provide console CLI\n");
printf(" -d Enable extra debugging\n");
printf(" -f Do not fork\n");
printf(" -g Dump core in case of a crash\n");
printf(" -h This help screen\n");
printf(" -i Initialize crypto keys at startup\n");
Olle Johansson
committed
printf(" -I Enable internal timing if Zaptel timer is available\n");
printf(" -L <load> Limit the maximum load average before rejecting new calls\n");
printf(" -M <value> Limit the maximum number of calls to the specified value\n");
printf(" -n Disable console colorization\n");
printf(" -p Run as pseudo-realtime thread\n");
printf(" -q Quiet mode (suppress output)\n");
printf(" -r Connect to Asterisk on this machine\n");
printf(" -R Connect to Asterisk, and attempt to reconnect if disconnected\n");
printf(" -t Record soundfiles in /var/tmp and move them where they belong after they are done.\n");
printf(" -T Display the time in [Mmm dd hh:mm:ss] format for each line of output to the CLI.\n");
printf(" -v Increase verbosity (multiple v's = more verbose)\n");
printf(" -x <cmd> Execute command <cmd> (only valid with -r)\n");
static void ast_readconfig(void)
{
struct ast_config *cfg;
struct ast_variable *v;
Kevin P. Fleming
committed
char *config = AST_CONFIG_FILE;
Russell Bryant
committed
if (ast_opt_override_config) {
cfg = ast_config_load(ast_config_AST_CONFIG_FILE);
ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
ast_copy_string(ast_config_AST_CONFIG_DIR, AST_CONFIG_DIR, sizeof(ast_config_AST_CONFIG_DIR));
ast_copy_string(ast_config_AST_SPOOL_DIR, AST_SPOOL_DIR, sizeof(ast_config_AST_SPOOL_DIR));
ast_copy_string(ast_config_AST_MODULE_DIR, AST_MODULE_DIR, sizeof(ast_config_AST_MODULE_DIR));
snprintf(ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", ast_config_AST_SPOOL_DIR);
ast_copy_string(ast_config_AST_VAR_DIR, AST_VAR_DIR, sizeof(ast_config_AST_VAR_DIR));
Joshua Colp
committed
ast_copy_string(ast_config_AST_DATA_DIR, AST_DATA_DIR, sizeof(ast_config_AST_DATA_DIR));
ast_copy_string(ast_config_AST_LOG_DIR, AST_LOG_DIR, sizeof(ast_config_AST_LOG_DIR));
ast_copy_string(ast_config_AST_AGI_DIR, AST_AGI_DIR, sizeof(ast_config_AST_AGI_DIR));
ast_copy_string(ast_config_AST_DB, AST_DB, sizeof(ast_config_AST_DB));
ast_copy_string(ast_config_AST_KEY_DIR, AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR));
ast_copy_string(ast_config_AST_PID, AST_PID, sizeof(ast_config_AST_PID));
ast_copy_string(ast_config_AST_SOCKET, AST_SOCKET, sizeof(ast_config_AST_SOCKET));
ast_copy_string(ast_config_AST_RUN_DIR, AST_RUN_DIR, sizeof(ast_config_AST_RUN_DIR));
/* no asterisk.conf? no problem, use buildtime config! */
if (!cfg) {
v = ast_variable_browse(cfg, "files");
while (v) {
if (!strcasecmp(v->name, "astctlpermissions")) {
ast_copy_string(ast_config_AST_CTL_PERMISSIONS, v->value, sizeof(ast_config_AST_CTL_PERMISSIONS));
} else if (!strcasecmp(v->name, "astctlowner")) {
ast_copy_string(ast_config_AST_CTL_OWNER, v->value, sizeof(ast_config_AST_CTL_OWNER));
} else if (!strcasecmp(v->name, "astctlgroup")) {
ast_copy_string(ast_config_AST_CTL_GROUP, v->value, sizeof(ast_config_AST_CTL_GROUP));
} else if (!strcasecmp(v->name, "astctl")) {
ast_copy_string(ast_config_AST_CTL, v->value, sizeof(ast_config_AST_CTL));
}
v = v->next;
v = ast_variable_browse(cfg, "directories");
while(v) {
if (!strcasecmp(v->name, "astetcdir")) {
ast_copy_string(ast_config_AST_CONFIG_DIR, v->value, sizeof(ast_config_AST_CONFIG_DIR));
} else if (!strcasecmp(v->name, "astspooldir")) {
ast_copy_string(ast_config_AST_SPOOL_DIR, v->value, sizeof(ast_config_AST_SPOOL_DIR));
snprintf(ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", v->value);
} else if (!strcasecmp(v->name, "astvarlibdir")) {
ast_copy_string(ast_config_AST_VAR_DIR, v->value, sizeof(ast_config_AST_VAR_DIR));
snprintf(ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
Joshua Colp
committed
} else if (!strcasecmp(v->name, "astdatadir")) {
ast_copy_string(ast_config_AST_DATA_DIR, v->value, sizeof(ast_config_AST_DATA_DIR));
Joshua Colp
committed
snprintf(ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
ast_copy_string(ast_config_AST_LOG_DIR, v->value, sizeof(ast_config_AST_LOG_DIR));
ast_copy_string(ast_config_AST_AGI_DIR, v->value, sizeof(ast_config_AST_AGI_DIR));
snprintf(ast_config_AST_PID, sizeof(ast_config_AST_PID), "%s/%s", v->value, "asterisk.pid");
snprintf(ast_config_AST_SOCKET, sizeof(ast_config_AST_SOCKET), "%s/%s", v->value, ast_config_AST_CTL);
ast_copy_string(ast_config_AST_RUN_DIR, v->value, sizeof(ast_config_AST_RUN_DIR));
ast_copy_string(ast_config_AST_MODULE_DIR, v->value, sizeof(ast_config_AST_MODULE_DIR));
} else if (!strcasecmp(v->name, "languageprefix")) {
ast_language_is_prefix = ast_true(v->value);
v = ast_variable_browse(cfg, "options");
while(v) {
/* verbose level (-v at startup) */
if (!strcasecmp(v->name, "verbose")) {
option_verbose = atoi(v->value);
/* whether or not to force timestamping. (-T at startup) */
} else if (!strcasecmp(v->name, "timestamp")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TIMESTAMP);
/* whether or not to support #exec in config files */
} else if (!strcasecmp(v->name, "execincludes")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_EXEC_INCLUDES);
} else if (!strcasecmp(v->name, "debug")) {
option_debug = 0;
if (sscanf(v->value, "%d", &option_debug) != 1) {
option_debug = ast_true(v->value);
}
/* Disable forking (-f at startup) */
} else if (!strcasecmp(v->name, "nofork")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_FORK);
/* Always fork, even if verbose or debug are enabled (-F at startup) */
} else if (!strcasecmp(v->name, "alwaysfork")) {
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_ALWAYS_FORK);
/* Run quietly (-q at startup ) */
} else if (!strcasecmp(v->name, "quiet")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_QUIET);
/* Run as console (-c at startup, implies nofork) */
} else if (!strcasecmp(v->name, "console")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CONSOLE);
/* Run with high priority if the O/S permits (-p at startup) */
} else if (!strcasecmp(v->name, "highpriority")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIGH_PRIORITY);
/* Initialize RSA auth keys (IAX2) (-i at startup) */
} else if (!strcasecmp(v->name, "initcrypto")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_INIT_KEYS);
/* Disable ANSI colors for console (-c at startup) */
} else if (!strcasecmp(v->name, "nocolor")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_COLOR);
Russell Bryant
committed
/* Disable some usage warnings for picky people :p */
} else if (!strcasecmp(v->name, "dontwarn")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_DONT_WARN);
/* Dump core in case of crash (-g) */
} else if (!strcasecmp(v->name, "dumpcore")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_DUMP_CORE);
/* Cache recorded sound files to another directory during recording */
} else if (!strcasecmp(v->name, "cache_record_files")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CACHE_RECORD_FILES);
/* Specify cache directory */
} else if (!strcasecmp(v->name, "record_cache_dir")) {
ast_copy_string(record_cache_dir, v->value, AST_CACHE_DIR_LEN);
/* Build transcode paths via SLINEAR, instead of directly */
} else if (!strcasecmp(v->name, "transcode_via_sln")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSCODE_VIA_SLIN);
/* Transmit SLINEAR silence while a channel is being recorded */
} else if (!strcasecmp(v->name, "transmit_silence_during_record")) {
Russell Bryant
committed
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSMIT_SILENCE);
/* Enable internal timing */
} else if (!strcasecmp(v->name, "internal_timing")) {
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_INTERNAL_TIMING);
if ((sscanf(v->value, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
} else if (!strcasecmp(v->name, "maxload")) {
Kevin P. Fleming
committed
double test[1];
if (getloadavg(test, 1) == -1) {
ast_log(LOG_ERROR, "Cannot obtain load average on this system. 'maxload' option disabled.\n");
option_maxload = 0.0;
} else if ((sscanf(v->value, "%lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
option_maxload = 0.0;
}
/* What user to run as */
} else if (!strcasecmp(v->name, "runuser")) {
ast_copy_string(ast_config_AST_RUN_USER, v->value, sizeof(ast_config_AST_RUN_USER));
/* What group to run as */
} else if (!strcasecmp(v->name, "rungroup")) {
ast_copy_string(ast_config_AST_RUN_GROUP, v->value, sizeof(ast_config_AST_RUN_GROUP));
} else if (!strcasecmp(v->name, "systemname")) {
ast_copy_string(ast_config_AST_SYSTEM_NAME, v->value, sizeof(ast_config_AST_SYSTEM_NAME));
}
v = v->next;
}
Olle Johansson
committed
char hostname[MAXHOSTNAMELEN] = "";
Olle Johansson
committed
int is_child_of_nonroot = 0;
Olle Johansson
committed
char *runuser = NULL, *rungroup = NULL;
/* Remember original args for restart */
if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) {
fprintf(stderr, "Truncating argument size to %d\n", (int)(sizeof(_argv) / sizeof(_argv[0])) - 1);
argc = sizeof(_argv) / sizeof(_argv[0]) - 1;
}
Olle Johansson
committed
for (x=0; x<argc; x++)
/* if the progname is rasterisk consider it a remote console */
if (argv[0] && (strstr(argv[0], "rasterisk")) != NULL) {
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
}
if (gethostname(hostname, sizeof(hostname)-1))
ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
Mark Spencer
committed
ast_mainpid = getpid();
ast_builtins_init();
Kevin P. Fleming
committed
/* When Asterisk restarts after it has dropped the root privileges,
* it can't issue setuid(), setgid(), setgroups() or set_priority()
Olle Johansson
committed
*/
Kevin P. Fleming
committed
if (getenv("ASTERISK_ALREADY_NONROOT"))
is_child_of_nonroot=1;
if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
Olle Johansson
committed
while ((c = getopt(argc, argv, "tThfdvVqprRgciInx:U:G:C:L:M:")) != -1) {
switch (c) {
case 'F':
ast_set_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
break;
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
case 'R':
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
break;
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
case 'M':
if ((sscanf(optarg, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0))
option_maxcalls = 0;
break;
case 'L':
if ((sscanf(optarg, "%lf", &option_maxload) != 1) || (option_maxload < 0.0))
option_maxload = 0.0;
break;
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC);
Russell Bryant
committed
ast_copy_string(ast_config_AST_CONFIG_FILE, optarg, sizeof(ast_config_AST_CONFIG_FILE));
ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
case 'I':
ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING);
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
Olle Johansson
committed
case 'g':
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
case 'U':
runuser = optarg;
break;
case 'G':
rungroup = optarg;
break;
if (ast_opt_always_fork && (ast_opt_remote || ast_opt_console)) {
ast_log(LOG_WARNING, "'alwaysfork' is not compatible with console or remote console mode; ignored\n");
ast_clear_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
}
Kevin P. Fleming
committed
/* For remote connections, change the name of the remote connection.
* We do this for the benefit of init scripts (which need to know if/when
* the main asterisk process has died yet). */
Russell Bryant
committed
if (ast_opt_remote) {
Kevin P. Fleming
committed
strcpy(argv[0], "rasterisk");
for (x = 1; x < argc; x++) {
argv[x] = argv[0] + 10;
}
}
Kevin P. Fleming
committed
if (ast_opt_console && !option_verbose)
ast_verbose("[ Reading Master Configuration ]");
ast_readconfig();
Russell Bryant
committed
if (ast_opt_dump_core) {
struct rlimit l;
memset(&l, 0, sizeof(l));
l.rlim_cur = RLIM_INFINITY;
l.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_CORE, &l)) {
ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n", strerror(errno));
}
}
if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))
rungroup = ast_config_AST_RUN_GROUP;
if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER))
runuser = ast_config_AST_RUN_USER;
Olle Johansson
committed
Russell Bryant
committed
ast_set_priority(ast_opt_high_priority);
Kevin P. Fleming
committed
if (!is_child_of_nonroot && rungroup) {
struct group *gr;
gr = getgrnam(rungroup);
if (!gr) {
ast_log(LOG_WARNING, "No such group '%s'!\n", rungroup);
exit(1);
}
ast_log(LOG_WARNING, "Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup);
if (setgroups(0, NULL)) {
ast_log(LOG_WARNING, "Unable to drop unneeded groups\n");
exit(1);
}
if (option_verbose)
ast_verbose("Running as group '%s'\n", rungroup);
}
Kevin P. Fleming
committed
if (!is_child_of_nonroot && runuser) {
struct passwd *pw;
pw = getpwnam(runuser);
if (!pw) {
ast_log(LOG_WARNING, "No such user '%s'!\n", runuser);
exit(1);
}
if (!rungroup) {
if (setgid(pw->pw_gid)) {
ast_log(LOG_WARNING, "Unable to setgid to %d!\n", (int)pw->pw_gid);
if (initgroups(pw->pw_name, pw->pw_gid)) {
ast_log(LOG_WARNING, "Unable to init groups for '%s'\n", runuser);
exit(1);
}
if (setuid(pw->pw_uid)) {
ast_log(LOG_WARNING, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
Olle Johansson
committed
setenv("ASTERISK_ALREADY_NONROOT", "yes", 1);
if (option_verbose)
ast_verbose("Running as user '%s'\n", runuser);
}
#ifdef linux
BJ Weschke
committed
if (geteuid() && ast_opt_dump_core) {
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
ast_log(LOG_WARNING, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno));
}
}
#endif
BJ Weschke
committed
term_init();
printf(term_end());
fflush(stdout);
Mark Spencer
committed
Russell Bryant
committed
if (ast_opt_console && !option_verbose)
ast_verbose("[ Initializing Custom Configuration Options ]");
/* custom config setup */
register_config_cli();
Russell Bryant
committed
if (ast_opt_console) {
if (el_hist == NULL || el == NULL)
ast_el_initialize();
if (!ast_strlen_zero(filename))
ast_el_read_history(filename);
if (ast_tryconnect()) {
/* One is already running */
Russell Bryant
committed
if (ast_opt_remote) {
if (ast_opt_exec) {
Russell Bryant
committed
ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET);
Russell Bryant
committed
} else if (ast_opt_remote || ast_opt_exec) {
Olle Johansson
committed
ast_log(LOG_ERROR, "Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET);
/* Blindly write pid file since we couldn't connect */
Russell Bryant
committed
unlink(ast_config_AST_PID);
f = fopen(ast_config_AST_PID, "w");
fprintf(f, "%ld\n", (long)getpid());
Russell Bryant
committed
ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
if (ast_opt_always_fork || !ast_opt_no_fork) {
Olle Johansson
committed
daemon(0, 0);
ast_mainpid = getpid();
/* Blindly re-write pid file since we are forking */
Russell Bryant
committed
unlink(ast_config_AST_PID);
f = fopen(ast_config_AST_PID, "w");
fprintf(f, "%ld\n", (long)ast_mainpid);
Russell Bryant
committed
ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
/* Test recursive mutex locking. */
if (test_for_thread_safety())
ast_verbose("Warning! Asterisk is not thread safe.\n");
ast_makesocket();
sigemptyset(&sigs);
sigaddset(&sigs, SIGHUP);
sigaddset(&sigs, SIGTERM);
sigaddset(&sigs, SIGINT);
sigaddset(&sigs, SIGPIPE);
sigaddset(&sigs, SIGWINCH);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
Russell Bryant
committed
if (ast_opt_console || option_verbose || ast_opt_remote)
Russell Bryant
committed
if (option_verbose || ast_opt_console) {
Russell Bryant
committed
if (ast_opt_console && !option_verbose)
signal(SIGINT, __quit_handler);
signal(SIGTERM, __quit_handler);
signal(SIGCHLD, child_handler);
signal(SIGPIPE, SIG_IGN);
Kevin P. Fleming
committed
/* ensure that the random number generators are seeded with a different value every time
Asterisk is started
*/
srand((unsigned int) getpid() + (unsigned int) time(NULL));
initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool));
Kevin P. Fleming
committed
if (dnsmgr_init()) {
printf(term_quit());
exit(1);
}
Kevin P. Fleming
committed
/* load 'preload' modules, required for access to Realtime-mapped configuration files */
if (load_modules(1)) {
printf(term_quit());
exit(1);
}
ast_http_init();
ast_channels_init();
if (init_manager()) {
printf(term_quit());
exit(1);
}
if (ast_cdr_engine_init()) {
printf(term_quit());
exit(1);
}
Kevin P. Fleming
committed
if (ast_device_state_engine_init()) {
printf(term_quit());
exit(1);
}
if (ast_image_init()) {
printf(term_quit());
Mark Spencer
committed
if (ast_file_init()) {
printf(term_quit());
exit(1);
}
Kevin P. Fleming
committed
if (load_modules(0)) {
}
if (init_framer()) {
printf(term_quit());
if (astdb_init()) {
printf(term_quit());
exit(1);
}
if (ast_enum_init()) {
printf(term_quit());
exit(1);
}
#if 0
/* This should no longer be necessary */
/* sync cust config and reload some internals in case a custom config handler binded to them */
read_ast_cust_config();
reload_manager();
ast_enum_reload();
ast_rtp_reload();
#endif
/* We might have the option of showing a console, but for now just
do nothing... */
Russell Bryant
committed
if (ast_opt_console && !option_verbose)
Russell Bryant
committed
if (option_verbose || ast_opt_console)
ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp)));
Russell Bryant
committed
if (ast_opt_no_fork)
Russell Bryant
committed
ast_set_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED);
Mark Spencer
committed
#ifdef __AST_DEBUG_MALLOC
__ast_mm_init();
#endif
Kevin P. Fleming
committed
ast_cli_register_multiple(core_cli, sizeof(core_cli) / sizeof(core_cli[0]));
Russell Bryant
committed
if (ast_opt_console) {
/* Console stuff now... */
/* Register our quit function */
snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %ld)", hostname, (long)ast_mainpid);
for (;;) {
buf = (char *)el_gets(el, &num);
if (buf) {
if (buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = '\0';
consolehandler((char *)buf);
} else {
if (write(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n",
Olle Johansson
committed
strlen("\nUse EXIT or QUIT to exit the asterisk console\n")) < 0) {
/* Whoa, stdout disappeared from under us... Make /dev/null's */
int fd;
fd = open("/dev/null", O_RDWR);
if (fd > -1) {
dup2(fd, STDOUT_FILENO);
dup2(fd, STDIN_FILENO);
} else
Olle Johansson
committed
ast_log(LOG_WARNING, "Failed to open /dev/null to recover from dead console. Bad things will happen!\n");
for(;;) { /* apparently needed for the MACos */
struct pollfd p = { -1 /* no descriptor */, 0, 0 };
poll(&p, 0, -1);
}