#include <unistd.h>
#include <stdlib.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <asterisk/cli.h>
#include <asterisk/channel.h>
#include <asterisk/ulaw.h>
#include <asterisk/alaw.h>
#include <asterisk/callerid.h>
#include <asterisk/module.h>
#include <asterisk/image.h>
#include <asterisk/tdd.h>
#include <asterisk/term.h>
#include <asterisk/manager.h>
#include <asterisk/pbx.h>
#include <asterisk/enum.h>
#include <asterisk/rtp.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <sched.h>
#include <asterisk/io.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/select.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "editline/histedit.h"
#include "asterisk.h"
#include <asterisk/config.h>
Go to the source code of this file.
Data Structures | |
struct | ast_atexit |
struct | console |
Defines | |
#define | AST_MAX_CONNECTS 128 |
#define | NUM_MSGS 64 |
#define | ASTERISK_PROMPT "*CLI> " |
#define | ASTERISK_PROMPT2 "%s*CLI> " |
Functions | |
int | ast_register_atexit (void(*func)(void)) |
void | ast_unregister_atexit (void(*func)(void)) |
void | ast_console_puts (const char *string) |
int | main (int argc, char *argv[]) |
Variables | |
int | option_verbose = 0 |
int | option_debug = 0 |
int | option_nofork = 0 |
int | option_quiet = 0 |
int | option_console = 0 |
int | option_highpriority = 0 |
int | option_remote = 0 |
int | option_exec = 0 |
int | option_initcrypto = 0 |
int | option_nocolor |
int | option_dumpcore = 0 |
int | option_overrideconfig = 0 |
int | fully_booted = 0 |
time_t | ast_startuptime |
time_t | ast_lastreloadtime |
console | consoles [AST_MAX_CONNECTS] |
char | defaultlanguage [MAX_LANGUAGE] = DEFAULT_LANGUAGE |
char | ast_config_AST_CONFIG_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_CONFIG_FILE [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_MODULE_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_SPOOL_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_VAR_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_LOG_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_AGI_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_DB [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_KEY_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_PID [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_SOCKET [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_RUN_DIR [AST_CONFIG_MAX_PATH] |
char | ast_config_AST_DATA_DIR [AST_CONFIG_MAX_PATH] |
|
Definition at line 49 of file asterisk.c. |
|
Definition at line 756 of file asterisk.c. |
|
Definition at line 758 of file asterisk.c. |
|
Definition at line 50 of file asterisk.c. |
|
Definition at line 169 of file asterisk.c. References string. Referenced by ast_log().
00170 { 00171 fputs(string, stdout); 00172 fflush(stdout); 00173 ast_network_puts(string); 00174 } |
|
Definition at line 110 of file asterisk.c. References ast_mutex_lock, ast_mutex_unlock, ast_unregister_atexit(), and malloc.
00111 { 00112 int res = -1; 00113 struct ast_atexit *ae; 00114 ast_unregister_atexit(func); 00115 ae = malloc(sizeof(struct ast_atexit)); 00116 ast_mutex_lock(&atexitslock); 00117 if (ae) { 00118 memset(ae, 0, sizeof(struct ast_atexit)); 00119 ae->next = atexits; 00120 ae->func = func; 00121 atexits = ae; 00122 res = 0; 00123 } 00124 ast_mutex_unlock(&atexitslock); 00125 return res; 00126 } |
|
Definition at line 128 of file asterisk.c. References ast_mutex_lock, and ast_mutex_unlock. Referenced by ast_register_atexit().
00129 { 00130 struct ast_atexit *ae, *prev = NULL; 00131 ast_mutex_lock(&atexitslock); 00132 ae = atexits; 00133 while(ae) { 00134 if (ae->func == func) { 00135 if (prev) 00136 prev->next = ae->next; 00137 else 00138 atexits = ae->next; 00139 break; 00140 } 00141 prev = ae; 00142 ae = ae->next; 00143 } 00144 ast_mutex_unlock(&atexitslock); 00145 } |
|
Definition at line 1235 of file asterisk.c. References __ast_mm_init(), ast_alaw_init(), ast_cli(), ast_cli_register(), ast_config_AST_CONFIG_FILE, ast_config_AST_PID, ast_config_AST_SOCKET, ast_enum_init(), ast_image_init(), ast_log(), ast_register_verbose(), ast_rtp_init(), ast_startuptime, ast_ulaw_init(), ast_verbose(), astdb_init(), callerid_init(), COLOR_BLACK, COLOR_BRWHITE, fully_booted, init_framer(), init_logger(), init_manager(), load_modules(), load_pbx(), LOG_ERROR, LOG_WARNING, option_console, option_debug, option_dumpcore, option_exec, option_highpriority, option_initcrypto, option_nocolor, option_nofork, option_overrideconfig, option_quiet, option_remote, option_verbose, tdd_init(), term_color(), term_end(), term_init(), and term_quit().
01236 { 01237 int c; 01238 char filename[80] = ""; 01239 char hostname[256]; 01240 char tmp[80]; 01241 char * xarg = NULL; 01242 int x; 01243 FILE *f; 01244 sigset_t sigs; 01245 int num; 01246 char *buf; 01247 01248 /* Remember original args for restart */ 01249 if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) { 01250 fprintf(stderr, "Truncating argument size to %d\n", sizeof(_argv) / sizeof(_argv[0]) - 1); 01251 argc = sizeof(_argv) / sizeof(_argv[0]) - 1; 01252 } 01253 for (x=0;x<argc;x++) 01254 _argv[x] = argv[x]; 01255 _argv[x] = NULL; 01256 01257 if (gethostname(hostname, sizeof(hostname))) 01258 strncpy(hostname, "<Unknown>", sizeof(hostname)-1); 01259 mainpid = getpid(); 01260 ast_ulaw_init(); 01261 ast_alaw_init(); 01262 callerid_init(); 01263 tdd_init(); 01264 if (getenv("HOME")) 01265 snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); 01266 /* Check for options */ 01267 while((c=getopt(argc, argv, "hfdvqprgcinx:C:")) != -1) { 01268 switch(c) { 01269 case 'd': 01270 option_debug++; 01271 option_nofork++; 01272 break; 01273 case 'c': 01274 option_console++; 01275 option_nofork++; 01276 break; 01277 case 'f': 01278 option_nofork++; 01279 break; 01280 case 'n': 01281 option_nocolor++; 01282 break; 01283 case 'r': 01284 option_remote++; 01285 option_nofork++; 01286 break; 01287 case 'p': 01288 option_highpriority++; 01289 break; 01290 case 'v': 01291 option_verbose++; 01292 option_nofork++; 01293 break; 01294 case 'q': 01295 option_quiet++; 01296 break; 01297 case 'x': 01298 option_exec++; 01299 xarg = optarg; 01300 break; 01301 case 'C': 01302 strncpy((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE)); 01303 option_overrideconfig++; 01304 break; 01305 case 'i': 01306 option_initcrypto++; 01307 break; 01308 case'g': 01309 option_dumpcore++; 01310 break; 01311 case 'h': 01312 show_cli_help(); 01313 exit(0); 01314 case '?': 01315 exit(1); 01316 } 01317 } 01318 01319 if (option_dumpcore) { 01320 struct rlimit l; 01321 memset(&l, 0, sizeof(l)); 01322 l.rlim_cur = RLIM_INFINITY; 01323 l.rlim_max = RLIM_INFINITY; 01324 if (setrlimit(RLIMIT_CORE, &l)) { 01325 ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n", strerror(errno)); 01326 } 01327 } 01328 01329 term_init(); 01330 printf(term_end()); 01331 fflush(stdout); 01332 if (option_console && !option_verbose) 01333 ast_verbose("[ Reading Master Configuration ]"); 01334 ast_readconfig(); 01335 01336 if (option_console) { 01337 if (el_hist == NULL || el == NULL) 01338 ast_el_initialize(); 01339 01340 if (strlen(filename)) 01341 ast_el_read_history(filename); 01342 } 01343 01344 if (ast_tryconnect()) { 01345 /* One is already running */ 01346 if (option_remote) { 01347 if (option_exec) { 01348 ast_remotecontrol(xarg); 01349 quit_handler(0, 0, 0, 0); 01350 exit(0); 01351 } 01352 printf(term_quit()); 01353 ast_register_verbose(console_verboser); 01354 ast_verbose( "Asterisk " ASTERISK_VERSION ", Copyright (C) 1999-2004 Digium.\n"); 01355 ast_verbose( "Written by Mark Spencer <markster@digium.com>\n"); 01356 ast_verbose( "=========================================================================\n"); 01357 ast_remotecontrol(NULL); 01358 quit_handler(0, 0, 0, 0); 01359 exit(0); 01360 } else { 01361 ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", (char *)ast_config_AST_SOCKET); 01362 printf(term_quit()); 01363 exit(1); 01364 } 01365 } else if (option_remote || option_exec) { 01366 ast_log(LOG_ERROR, "Unable to connect to remote asterisk\n"); 01367 printf(term_quit()); 01368 exit(1); 01369 } 01370 /* Blindly write pid file since we couldn't connect */ 01371 unlink((char *)ast_config_AST_PID); 01372 f = fopen((char *)ast_config_AST_PID, "w"); 01373 if (f) { 01374 fprintf(f, "%d\n", getpid()); 01375 fclose(f); 01376 } else 01377 ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno)); 01378 01379 if (!option_verbose && !option_debug && !option_nofork && !option_console) { 01380 daemon(0,0); 01381 /* Blindly re-write pid file since we are forking */ 01382 unlink((char *)ast_config_AST_PID); 01383 f = fopen((char *)ast_config_AST_PID, "w"); 01384 if (f) { 01385 fprintf(f, "%d\n", getpid()); 01386 fclose(f); 01387 } else 01388 ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno)); 01389 } 01390 01391 ast_makesocket(); 01392 sigemptyset(&sigs); 01393 sigaddset(&sigs, SIGHUP); 01394 sigaddset(&sigs, SIGTERM); 01395 sigaddset(&sigs, SIGINT); 01396 sigaddset(&sigs, SIGPIPE); 01397 sigaddset(&sigs, SIGWINCH); 01398 pthread_sigmask(SIG_BLOCK, &sigs, NULL); 01399 if (option_console || option_verbose || option_remote) 01400 ast_register_verbose(console_verboser); 01401 /* Print a welcome message if desired */ 01402 if (option_verbose || option_console) { 01403 ast_verbose( "Asterisk " ASTERISK_VERSION ", Copyright (C) 1999-2001 Linux Support Services, Inc.\n"); 01404 ast_verbose( "Written by Mark Spencer <markster@linux-support.net>\n"); 01405 ast_verbose( "=========================================================================\n"); 01406 } 01407 if (option_console && !option_verbose) 01408 ast_verbose("[ Booting..."); 01409 01410 signal(SIGURG, urg_handler); 01411 signal(SIGINT, __quit_handler); 01412 signal(SIGTERM, __quit_handler); 01413 signal(SIGHUP, hup_handler); 01414 signal(SIGCHLD, child_handler); 01415 signal(SIGPIPE, SIG_IGN); 01416 01417 if (set_priority(option_highpriority)) { 01418 printf(term_quit()); 01419 exit(1); 01420 } 01421 if (init_logger()) { 01422 printf(term_quit()); 01423 exit(1); 01424 } 01425 if (init_manager()) { 01426 printf(term_quit()); 01427 exit(1); 01428 } 01429 ast_rtp_init(); 01430 if (ast_image_init()) { 01431 printf(term_quit()); 01432 exit(1); 01433 } 01434 if (load_pbx()) { 01435 printf(term_quit()); 01436 exit(1); 01437 } 01438 if (load_modules()) { 01439 printf(term_quit()); 01440 exit(1); 01441 } 01442 if (init_framer()) { 01443 printf(term_quit()); 01444 exit(1); 01445 } 01446 if (astdb_init()) { 01447 printf(term_quit()); 01448 exit(1); 01449 } 01450 if (ast_enum_init()) { 01451 printf(term_quit()); 01452 exit(1); 01453 } 01454 /* We might have the option of showing a console, but for now just 01455 do nothing... */ 01456 if (option_console && !option_verbose) 01457 ast_verbose(" ]\n"); 01458 if (option_verbose || option_console) 01459 ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp))); 01460 fully_booted = 1; 01461 pthread_sigmask(SIG_UNBLOCK, &sigs, NULL); 01462 #ifdef __AST_DEBUG_MALLOC 01463 __ast_mm_init(); 01464 #endif 01465 time(&ast_startuptime); 01466 ast_cli_register(&astshutdownnow); 01467 ast_cli_register(&astshutdowngracefully); 01468 ast_cli_register(&astrestartnow); 01469 ast_cli_register(&astrestartgracefully); 01470 ast_cli_register(&astrestartwhenconvenient); 01471 ast_cli_register(&astshutdownwhenconvenient); 01472 ast_cli_register(&aborthalt); 01473 ast_cli_register(&astbang); 01474 if (option_console) { 01475 /* Console stuff now... */ 01476 /* Register our quit function */ 01477 char title[256]; 01478 set_icon("Asterisk"); 01479 snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %d)", hostname, mainpid); 01480 set_title(title); 01481 ast_cli_register(&quit); 01482 ast_cli_register(&astexit); 01483 consolethread = pthread_self(); 01484 01485 for (;;) { 01486 buf = (char *)el_gets(el, &num); 01487 if (buf) { 01488 if (buf[strlen(buf)-1] == '\n') 01489 buf[strlen(buf)-1] = '\0'; 01490 01491 consolehandler((char *)buf); 01492 } else { 01493 if (option_remote) 01494 ast_cli(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n"); 01495 else 01496 ast_cli(STDOUT_FILENO, "\nUse STOP NOW to shutdown Asterisk\n"); 01497 } 01498 } 01499 01500 } else { 01501 /* Do nothing */ 01502 ast_select(0,NULL,NULL,NULL,NULL); 01503 } 01504 return 0; 01505 } |
|
Definition at line 102 of file asterisk.c. |
|
Definition at line 96 of file asterisk.c. |
|
Definition at line 97 of file asterisk.c. Referenced by main(). |
|
Definition at line 108 of file asterisk.c. |
|
Definition at line 103 of file asterisk.c. |
|
Definition at line 104 of file asterisk.c. |
|
Definition at line 101 of file asterisk.c. Referenced by init_logger(), and reload_logger(). |
|
Definition at line 98 of file asterisk.c. Referenced by ast_load_resource(), and load_modules(). |
|
Definition at line 105 of file asterisk.c. Referenced by main(). |
|
Definition at line 107 of file asterisk.c. |
|
Definition at line 106 of file asterisk.c. Referenced by main(). |
|
Definition at line 99 of file asterisk.c. Referenced by ast_app_has_voicemail(), and ast_app_messagecount(). |
|
Definition at line 100 of file asterisk.c. |
|
Definition at line 82 of file asterisk.c. Referenced by ast_module_reload(). |
|
Definition at line 81 of file asterisk.c. Referenced by main(). |
|
Definition at line 88 of file asterisk.c. |
|
Definition at line 90 of file asterisk.c. Referenced by ast_channel_alloc(). |
|
Definition at line 64 of file asterisk.c. Referenced by ast_load_resource(), and main(). |
|
Definition at line 56 of file asterisk.c. Referenced by ast_load_resource(), main(), and term_init(). |
|
Definition at line 53 of file asterisk.c. Referenced by ast_channel_register_ex(), ast_channel_unregister(), ast_hangup(), ast_log(), ast_pbx_run(), ast_rtcp_read(), ast_save(), ast_set_read_format(), ast_set_write_format(), ast_softhangup_nolock(), load_modules(), and main(). |
|
Definition at line 62 of file asterisk.c. Referenced by main(). |
|
Definition at line 59 of file asterisk.c. Referenced by main(). |
|
Definition at line 57 of file asterisk.c. Referenced by main(). |
|
Definition at line 60 of file asterisk.c. Referenced by main(). |
|
Definition at line 61 of file asterisk.c. Referenced by main(), and term_init(). |
|
Definition at line 54 of file asterisk.c. Referenced by main(), and term_init(). |
|
Definition at line 63 of file asterisk.c. Referenced by main(). |
|
Definition at line 55 of file asterisk.c. Referenced by load_modules(), and main(). |
|
Definition at line 58 of file asterisk.c. Referenced by main(). |
|