#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 <asterisk/lock.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 | console |
| struct | ast_atexit |
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 |
| int | ast_mainpid |
| 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 768 of file asterisk.c. |
|
|
Definition at line 770 of file asterisk.c. |
|
|
Definition at line 50 of file asterisk.c. |
|
|
Definition at line 174 of file asterisk.c. References string. Referenced by ast_log().
00175 {
00176 fputs(string, stdout);
00177 fflush(stdout);
00178 ast_network_puts(string);
00179 }
|
|
|
Definition at line 115 of file asterisk.c. References ast_mutex_lock, ast_mutex_unlock, ast_unregister_atexit(), and malloc.
00116 {
00117 int res = -1;
00118 struct ast_atexit *ae;
00119 ast_unregister_atexit(func);
00120 ae = malloc(sizeof(struct ast_atexit));
00121 ast_mutex_lock(&atexitslock);
00122 if (ae) {
00123 memset(ae, 0, sizeof(struct ast_atexit));
00124 ae->next = atexits;
00125 ae->func = func;
00126 atexits = ae;
00127 res = 0;
00128 }
00129 ast_mutex_unlock(&atexitslock);
00130 return res;
00131 }
|
|
|
Definition at line 133 of file asterisk.c. References ast_mutex_lock, and ast_mutex_unlock. Referenced by ast_register_atexit().
00134 {
00135 struct ast_atexit *ae, *prev = NULL;
00136 ast_mutex_lock(&atexitslock);
00137 ae = atexits;
00138 while(ae) {
00139 if (ae->func == func) {
00140 if (prev)
00141 prev->next = ae->next;
00142 else
00143 atexits = ae->next;
00144 break;
00145 }
00146 prev = ae;
00147 ae = ae->next;
00148 }
00149 ast_mutex_unlock(&atexitslock);
00150 }
|
|
||||||||||||
|
Definition at line 1272 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_mainpid, 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().
01273 {
01274 int c;
01275 char filename[80] = "";
01276 char hostname[256];
01277 char tmp[80];
01278 char * xarg = NULL;
01279 int x;
01280 FILE *f;
01281 sigset_t sigs;
01282 int num;
01283 char *buf;
01284
01285 /* Remember original args for restart */
01286 if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) {
01287 fprintf(stderr, "Truncating argument size to %d\n", sizeof(_argv) / sizeof(_argv[0]) - 1);
01288 argc = sizeof(_argv) / sizeof(_argv[0]) - 1;
01289 }
01290 for (x=0;x<argc;x++)
01291 _argv[x] = argv[x];
01292 _argv[x] = NULL;
01293
01294 if (gethostname(hostname, sizeof(hostname)))
01295 strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
01296 ast_mainpid = getpid();
01297 ast_ulaw_init();
01298 ast_alaw_init();
01299 callerid_init();
01300 tdd_init();
01301 if (getenv("HOME"))
01302 snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
01303 /* Check for options */
01304 while((c=getopt(argc, argv, "hfdvqprgcinx:C:")) != -1) {
01305 switch(c) {
01306 case 'd':
01307 option_debug++;
01308 option_nofork++;
01309 break;
01310 case 'c':
01311 option_console++;
01312 option_nofork++;
01313 break;
01314 case 'f':
01315 option_nofork++;
01316 break;
01317 case 'n':
01318 option_nocolor++;
01319 break;
01320 case 'r':
01321 option_remote++;
01322 option_nofork++;
01323 break;
01324 case 'p':
01325 option_highpriority++;
01326 break;
01327 case 'v':
01328 option_verbose++;
01329 option_nofork++;
01330 break;
01331 case 'q':
01332 option_quiet++;
01333 break;
01334 case 'x':
01335 option_exec++;
01336 xarg = optarg;
01337 break;
01338 case 'C':
01339 strncpy((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE));
01340 option_overrideconfig++;
01341 break;
01342 case 'i':
01343 option_initcrypto++;
01344 break;
01345 case'g':
01346 option_dumpcore++;
01347 break;
01348 case 'h':
01349 show_cli_help();
01350 exit(0);
01351 case '?':
01352 exit(1);
01353 }
01354 }
01355
01356 if (option_dumpcore) {
01357 struct rlimit l;
01358 memset(&l, 0, sizeof(l));
01359 l.rlim_cur = RLIM_INFINITY;
01360 l.rlim_max = RLIM_INFINITY;
01361 if (setrlimit(RLIMIT_CORE, &l)) {
01362 ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n", strerror(errno));
01363 }
01364 }
01365
01366 term_init();
01367 printf(term_end());
01368 fflush(stdout);
01369 if (option_console && !option_verbose)
01370 ast_verbose("[ Reading Master Configuration ]");
01371 ast_readconfig();
01372
01373 if (option_console) {
01374 if (el_hist == NULL || el == NULL)
01375 ast_el_initialize();
01376
01377 if (strlen(filename))
01378 ast_el_read_history(filename);
01379 }
01380
01381 if (ast_tryconnect()) {
01382 /* One is already running */
01383 if (option_remote) {
01384 if (option_exec) {
01385 ast_remotecontrol(xarg);
01386 quit_handler(0, 0, 0, 0);
01387 exit(0);
01388 }
01389 printf(term_quit());
01390 ast_register_verbose(console_verboser);
01391 ast_verbose( "Asterisk " ASTERISK_VERSION ", Copyright (C) 1999-2004 Digium.\n");
01392 ast_verbose( "Written by Mark Spencer <markster@digium.com>\n");
01393 ast_verbose( "=========================================================================\n");
01394 ast_remotecontrol(NULL);
01395 quit_handler(0, 0, 0, 0);
01396 exit(0);
01397 } else {
01398 ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", (char *)ast_config_AST_SOCKET);
01399 printf(term_quit());
01400 exit(1);
01401 }
01402 } else if (option_remote || option_exec) {
01403 ast_log(LOG_ERROR, "Unable to connect to remote asterisk\n");
01404 printf(term_quit());
01405 exit(1);
01406 }
01407 /* Blindly write pid file since we couldn't connect */
01408 unlink((char *)ast_config_AST_PID);
01409 f = fopen((char *)ast_config_AST_PID, "w");
01410 if (f) {
01411 fprintf(f, "%d\n", getpid());
01412 fclose(f);
01413 } else
01414 ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
01415
01416 if (!option_verbose && !option_debug && !option_nofork && !option_console) {
01417 daemon(0,0);
01418 /* Blindly re-write pid file since we are forking */
01419 unlink((char *)ast_config_AST_PID);
01420 f = fopen((char *)ast_config_AST_PID, "w");
01421 if (f) {
01422 fprintf(f, "%d\n", getpid());
01423 fclose(f);
01424 } else
01425 ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
01426 }
01427
01428 ast_makesocket();
01429 sigemptyset(&sigs);
01430 sigaddset(&sigs, SIGHUP);
01431 sigaddset(&sigs, SIGTERM);
01432 sigaddset(&sigs, SIGINT);
01433 sigaddset(&sigs, SIGPIPE);
01434 sigaddset(&sigs, SIGWINCH);
01435 pthread_sigmask(SIG_BLOCK, &sigs, NULL);
01436 if (option_console || option_verbose || option_remote)
01437 ast_register_verbose(console_verboser);
01438 /* Print a welcome message if desired */
01439 if (option_verbose || option_console) {
01440 ast_verbose( "Asterisk " ASTERISK_VERSION ", Copyright (C) 1999-2001 Linux Support Services, Inc.\n");
01441 ast_verbose( "Written by Mark Spencer <markster@linux-support.net>\n");
01442 ast_verbose( "=========================================================================\n");
01443 }
01444 if (option_console && !option_verbose)
01445 ast_verbose("[ Booting...");
01446
01447 signal(SIGURG, urg_handler);
01448 signal(SIGINT, __quit_handler);
01449 signal(SIGTERM, __quit_handler);
01450 signal(SIGHUP, hup_handler);
01451 signal(SIGCHLD, child_handler);
01452 signal(SIGPIPE, SIG_IGN);
01453
01454 if (set_priority(option_highpriority)) {
01455 printf(term_quit());
01456 exit(1);
01457 }
01458 if (init_logger()) {
01459 printf(term_quit());
01460 exit(1);
01461 }
01462 if (init_manager()) {
01463 printf(term_quit());
01464 exit(1);
01465 }
01466 ast_rtp_init();
01467 if (ast_image_init()) {
01468 printf(term_quit());
01469 exit(1);
01470 }
01471 if (load_pbx()) {
01472 printf(term_quit());
01473 exit(1);
01474 }
01475 if (load_modules()) {
01476 printf(term_quit());
01477 exit(1);
01478 }
01479 if (init_framer()) {
01480 printf(term_quit());
01481 exit(1);
01482 }
01483 if (astdb_init()) {
01484 printf(term_quit());
01485 exit(1);
01486 }
01487 if (ast_enum_init()) {
01488 printf(term_quit());
01489 exit(1);
01490 }
01491 /* We might have the option of showing a console, but for now just
01492 do nothing... */
01493 if (option_console && !option_verbose)
01494 ast_verbose(" ]\n");
01495 if (option_verbose || option_console)
01496 ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp)));
01497 if (option_nofork)
01498 consolethread = pthread_self();
01499 fully_booted = 1;
01500 pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
01501 #ifdef __AST_DEBUG_MALLOC
01502 __ast_mm_init();
01503 #endif
01504 time(&ast_startuptime);
01505 ast_cli_register(&astshutdownnow);
01506 ast_cli_register(&astshutdowngracefully);
01507 ast_cli_register(&astrestartnow);
01508 ast_cli_register(&astrestartgracefully);
01509 ast_cli_register(&astrestartwhenconvenient);
01510 ast_cli_register(&astshutdownwhenconvenient);
01511 ast_cli_register(&aborthalt);
01512 ast_cli_register(&astbang);
01513 if (option_console) {
01514 /* Console stuff now... */
01515 /* Register our quit function */
01516 char title[256];
01517 set_icon("Asterisk");
01518 snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %d)", hostname, ast_mainpid);
01519 set_title(title);
01520 ast_cli_register(&quit);
01521 ast_cli_register(&astexit);
01522
01523 for (;;) {
01524 buf = (char *)el_gets(el, &num);
01525 if (buf) {
01526 if (buf[strlen(buf)-1] == '\n')
01527 buf[strlen(buf)-1] = '\0';
01528
01529 consolehandler((char *)buf);
01530 } else {
01531 if (option_remote)
01532 ast_cli(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n");
01533 else
01534 ast_cli(STDOUT_FILENO, "\nUse STOP NOW to shutdown Asterisk\n");
01535 }
01536 }
01537
01538 } else {
01539 /* Do nothing */
01540 ast_select(0,NULL,NULL,NULL,NULL);
01541 }
01542 return 0;
01543 }
|
|
|
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 68 of file asterisk.c. Referenced by main(). |
|
|
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(). |
|
1.3.6-20040222