#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 <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)) |
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 48 of file asterisk.c. |
|
Definition at line 710 of file asterisk.c. |
|
Definition at line 712 of file asterisk.c. |
|
Definition at line 49 of file asterisk.c. |
|
Definition at line 109 of file asterisk.c. References ast_mutex_lock, ast_mutex_unlock, ast_unregister_atexit(), and malloc.
00110 { 00111 int res = -1; 00112 struct ast_atexit *ae; 00113 ast_unregister_atexit(func); 00114 ae = malloc(sizeof(struct ast_atexit)); 00115 ast_mutex_lock(&atexitslock); 00116 if (ae) { 00117 memset(ae, 0, sizeof(struct ast_atexit)); 00118 ae->next = atexits; 00119 ae->func = func; 00120 atexits = ae; 00121 res = 0; 00122 } 00123 ast_mutex_unlock(&atexitslock); 00124 return res; 00125 } |
|
Definition at line 127 of file asterisk.c. References ast_mutex_lock, and ast_mutex_unlock. Referenced by ast_register_atexit().
00128 { 00129 struct ast_atexit *ae, *prev = NULL; 00130 ast_mutex_lock(&atexitslock); 00131 ae = atexits; 00132 while(ae) { 00133 if (ae->func == func) { 00134 if (prev) 00135 prev->next = ae->next; 00136 else 00137 atexits = ae->next; 00138 break; 00139 } 00140 prev = ae; 00141 ae = ae->next; 00142 } 00143 ast_mutex_unlock(&atexitslock); 00144 } |
|
Definition at line 1187 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().
01188 { 01189 char c; 01190 char filename[80] = ""; 01191 char hostname[256]; 01192 char tmp[80]; 01193 char * xarg = NULL; 01194 int x; 01195 FILE *f; 01196 sigset_t sigs; 01197 int num; 01198 char *buf; 01199 01200 /* Remember original args for restart */ 01201 if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) { 01202 fprintf(stderr, "Truncating argument size to %d\n", sizeof(_argv) / sizeof(_argv[0]) - 1); 01203 argc = sizeof(_argv) / sizeof(_argv[0]) - 1; 01204 } 01205 for (x=0;x<argc;x++) 01206 _argv[x] = argv[x]; 01207 _argv[x] = NULL; 01208 01209 if (gethostname(hostname, sizeof(hostname))) 01210 strncpy(hostname, "<Unknown>", sizeof(hostname)-1); 01211 mainpid = getpid(); 01212 ast_ulaw_init(); 01213 ast_alaw_init(); 01214 callerid_init(); 01215 tdd_init(); 01216 if (getenv("HOME")) 01217 snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); 01218 /* Check for options */ 01219 while((c=getopt(argc, argv, "hfdvqprgcinx:C:")) != EOF) { 01220 switch(c) { 01221 case 'd': 01222 option_debug++; 01223 option_nofork++; 01224 break; 01225 case 'c': 01226 option_console++; 01227 option_nofork++; 01228 break; 01229 case 'f': 01230 option_nofork++; 01231 break; 01232 case 'n': 01233 option_nocolor++; 01234 break; 01235 case 'r': 01236 option_remote++; 01237 option_nofork++; 01238 break; 01239 case 'p': 01240 option_highpriority++; 01241 break; 01242 case 'v': 01243 option_verbose++; 01244 option_nofork++; 01245 break; 01246 case 'q': 01247 option_quiet++; 01248 break; 01249 case 'x': 01250 option_exec++; 01251 xarg = optarg; 01252 break; 01253 case 'C': 01254 strncpy((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE)); 01255 option_overrideconfig++; 01256 break; 01257 case 'i': 01258 option_initcrypto++; 01259 break; 01260 case'g': 01261 option_dumpcore++; 01262 break; 01263 case 'h': 01264 show_cli_help(); 01265 exit(0); 01266 case '?': 01267 exit(1); 01268 } 01269 } 01270 01271 if (option_dumpcore) { 01272 struct rlimit l; 01273 memset(&l, 0, sizeof(l)); 01274 l.rlim_cur = RLIM_INFINITY; 01275 l.rlim_max = RLIM_INFINITY; 01276 if (setrlimit(RLIMIT_CORE, &l)) { 01277 ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n", strerror(errno)); 01278 } 01279 } 01280 01281 term_init(); 01282 printf(term_end()); 01283 fflush(stdout); 01284 if (option_console && !option_verbose) 01285 ast_verbose("[ Reading Master Configuration ]"); 01286 ast_readconfig(); 01287 01288 if (option_console) { 01289 if (el_hist == NULL || el == NULL) 01290 ast_el_initialize(); 01291 01292 if (strlen(filename)) 01293 ast_el_read_history(filename); 01294 } 01295 01296 if (ast_tryconnect()) { 01297 /* One is already running */ 01298 if (option_remote) { 01299 if (option_exec) { 01300 ast_remotecontrol(xarg); 01301 quit_handler(0, 0, 0, 0); 01302 exit(0); 01303 } 01304 printf(term_quit()); 01305 ast_register_verbose(console_verboser); 01306 ast_verbose( "Asterisk " ASTERISK_VERSION ", Copyright (C) 1999-2001 Linux Support Services, Inc.\n"); 01307 ast_verbose( "Written by Mark Spencer <markster@linux-support.net>\n"); 01308 ast_verbose( "=========================================================================\n"); 01309 ast_remotecontrol(NULL); 01310 quit_handler(0, 0, 0, 0); 01311 exit(0); 01312 } else { 01313 ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", (char *)ast_config_AST_SOCKET); 01314 printf(term_quit()); 01315 exit(1); 01316 } 01317 } else if (option_remote || option_exec) { 01318 ast_log(LOG_ERROR, "Unable to connect to remote asterisk\n"); 01319 printf(term_quit()); 01320 exit(1); 01321 } 01322 /* Blindly write pid file since we couldn't connect */ 01323 unlink((char *)ast_config_AST_PID); 01324 f = fopen((char *)ast_config_AST_PID, "w"); 01325 if (f) { 01326 fprintf(f, "%d\n", getpid()); 01327 fclose(f); 01328 } else 01329 ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno)); 01330 01331 if (!option_verbose && !option_debug && !option_nofork && !option_console) { 01332 #if 1 01333 daemon(0,0); 01334 #else 01335 pid = fork(); 01336 if (pid < 0) { 01337 ast_log(LOG_ERROR, "Unable to fork(): %s\n", strerror(errno)); 01338 printf(term_quit()); 01339 exit(1); 01340 } 01341 if (pid) 01342 exit(0); 01343 #endif 01344 } 01345 01346 ast_makesocket(); 01347 sigemptyset(&sigs); 01348 sigaddset(&sigs, SIGHUP); 01349 sigaddset(&sigs, SIGTERM); 01350 sigaddset(&sigs, SIGINT); 01351 sigaddset(&sigs, SIGPIPE); 01352 sigaddset(&sigs, SIGWINCH); 01353 pthread_sigmask(SIG_BLOCK, &sigs, NULL); 01354 if (option_console || option_verbose || option_remote) 01355 ast_register_verbose(console_verboser); 01356 /* Print a welcome message if desired */ 01357 if (option_verbose || option_console) { 01358 ast_verbose( "Asterisk " ASTERISK_VERSION ", Copyright (C) 1999-2001 Linux Support Services, Inc.\n"); 01359 ast_verbose( "Written by Mark Spencer <markster@linux-support.net>\n"); 01360 ast_verbose( "=========================================================================\n"); 01361 } 01362 if (option_console && !option_verbose) 01363 ast_verbose("[ Booting..."); 01364 signal(SIGURG, urg_handler); 01365 signal(SIGINT, __quit_handler); 01366 signal(SIGTERM, __quit_handler); 01367 signal(SIGHUP, hup_handler); 01368 signal(SIGPIPE, pipe_handler); 01369 if (set_priority(option_highpriority)) { 01370 printf(term_quit()); 01371 exit(1); 01372 } 01373 if (init_logger()) { 01374 printf(term_quit()); 01375 exit(1); 01376 } 01377 if (init_manager()) { 01378 printf(term_quit()); 01379 exit(1); 01380 } 01381 ast_rtp_init(); 01382 if (ast_image_init()) { 01383 printf(term_quit()); 01384 exit(1); 01385 } 01386 if (load_pbx()) { 01387 printf(term_quit()); 01388 exit(1); 01389 } 01390 if (load_modules()) { 01391 printf(term_quit()); 01392 exit(1); 01393 } 01394 if (init_framer()) { 01395 printf(term_quit()); 01396 exit(1); 01397 } 01398 if (astdb_init()) { 01399 printf(term_quit()); 01400 exit(1); 01401 } 01402 if (ast_enum_init()) { 01403 printf(term_quit()); 01404 exit(1); 01405 } 01406 /* We might have the option of showing a console, but for now just 01407 do nothing... */ 01408 if (option_console && !option_verbose) 01409 ast_verbose(" ]\n"); 01410 if (option_verbose || option_console) 01411 ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp))); 01412 fully_booted = 1; 01413 pthread_sigmask(SIG_UNBLOCK, &sigs, NULL); 01414 #ifdef __AST_DEBUG_MALLOC 01415 __ast_mm_init(); 01416 #endif 01417 time(&ast_startuptime); 01418 ast_cli_register(&astshutdownnow); 01419 ast_cli_register(&astshutdowngracefully); 01420 ast_cli_register(&astrestartnow); 01421 ast_cli_register(&astrestartgracefully); 01422 ast_cli_register(&astrestartwhenconvenient); 01423 ast_cli_register(&astshutdownwhenconvenient); 01424 ast_cli_register(&aborthalt); 01425 if (option_console) { 01426 /* Console stuff now... */ 01427 /* Register our quit function */ 01428 char title[256]; 01429 set_icon("Asterisk"); 01430 snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %d)", hostname, mainpid); 01431 set_title(title); 01432 ast_cli_register(&quit); 01433 ast_cli_register(&astexit); 01434 consolethread = pthread_self(); 01435 01436 for (;;) { 01437 buf = (char *)el_gets(el, &num); 01438 if (buf) { 01439 if (buf[strlen(buf)-1] == '\n') 01440 buf[strlen(buf)-1] = '\0'; 01441 01442 consolehandler((char *)buf); 01443 } else { 01444 if (option_remote) 01445 ast_cli(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n"); 01446 else 01447 ast_cli(STDOUT_FILENO, "\nUse STOP NOW to shutdown Asterisk\n"); 01448 } 01449 } 01450 01451 } else { 01452 /* Do nothing */ 01453 ast_select(0,NULL,NULL,NULL,NULL); 01454 } 01455 return 0; 01456 } |
|
Definition at line 101 of file asterisk.c. |
|
Definition at line 95 of file asterisk.c. |
|
Definition at line 96 of file asterisk.c. Referenced by main(). |
|
Definition at line 107 of file asterisk.c. |
|
Definition at line 102 of file asterisk.c. |
|
Definition at line 103 of file asterisk.c. |
|
Definition at line 100 of file asterisk.c. Referenced by init_logger(), and reload_logger(). |
|
Definition at line 97 of file asterisk.c. Referenced by ast_load_resource(), and load_modules(). |
|
Definition at line 104 of file asterisk.c. Referenced by main(). |
|
Definition at line 106 of file asterisk.c. |
|
Definition at line 105 of file asterisk.c. Referenced by main(). |
|
Definition at line 98 of file asterisk.c. Referenced by ast_app_has_voicemail(), and ast_app_messagecount(). |
|
Definition at line 99 of file asterisk.c. |
|
Definition at line 81 of file asterisk.c. Referenced by ast_module_reload(). |
|
Definition at line 80 of file asterisk.c. Referenced by main(). |
|
Definition at line 87 of file asterisk.c. |
|
Definition at line 89 of file asterisk.c. Referenced by ast_channel_alloc(). |
|
Definition at line 63 of file asterisk.c. Referenced by ast_load_resource(), and main(). |
|
Definition at line 55 of file asterisk.c. Referenced by ast_load_resource(), main(), and term_init(). |
|
Definition at line 52 of file asterisk.c. Referenced by ast_channel_register_ex(), ast_channel_unregister(), ast_context_create(), 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 61 of file asterisk.c. Referenced by main(). |
|
Definition at line 58 of file asterisk.c. Referenced by main(). |
|
Definition at line 56 of file asterisk.c. Referenced by main(). |
|
Definition at line 59 of file asterisk.c. Referenced by main(). |
|
Definition at line 60 of file asterisk.c. Referenced by main(), and term_init(). |
|
Definition at line 53 of file asterisk.c. Referenced by main(), and term_init(). |
|
Definition at line 62 of file asterisk.c. Referenced by main(). |
|
Definition at line 54 of file asterisk.c. Referenced by load_modules(), and main(). |
|
Definition at line 57 of file asterisk.c. Referenced by main(). |
|