Top level source file for Asterisk - the Open Source PBX. Implementation of PBX core functions and CLI interface. More...
#include "asterisk.h"#include "asterisk/_private.h"#include <sys/time.h>#include <fcntl.h>#include <signal.h>#include <sched.h>#include <sys/un.h>#include <sys/wait.h>#include <ctype.h>#include <sys/resource.h>#include <grp.h>#include <pwd.h>#include <sys/stat.h>#include <sys/sysinfo.h>#include <regex.h>#include "asterisk/paths.h"#include "asterisk/network.h"#include "asterisk/cli.h"#include "asterisk/channel.h"#include "asterisk/features.h"#include "asterisk/ulaw.h"#include "asterisk/alaw.h"#include "asterisk/callerid.h"#include "asterisk/image.h"#include "asterisk/tdd.h"#include "asterisk/term.h"#include "asterisk/manager.h"#include "asterisk/cdr.h"#include "asterisk/cel.h"#include "asterisk/pbx.h"#include "asterisk/enum.h"#include "asterisk/http.h"#include "asterisk/udptl.h"#include "asterisk/app.h"#include "asterisk/lock.h"#include "asterisk/utils.h"#include "asterisk/file.h"#include "asterisk/io.h"#include "editline/histedit.h"#include "asterisk/config.h"#include "asterisk/ast_version.h"#include "asterisk/linkedlists.h"#include "asterisk/devicestate.h"#include "asterisk/module.h"#include "asterisk/dsp.h"#include "asterisk/buildinfo.h"#include "asterisk/xmldoc.h"#include "asterisk/poll-compat.h"#include "asterisk/ccss.h"#include "asterisk/test.h"#include "asterisk/aoc.h"#include "../defaults.h"Go to the source code of this file.
Data Structures | |
| struct | _cfg_paths |
| struct | ast_atexit |
| struct | atexits |
| struct | console |
| struct | file_version |
| struct | file_versions |
| struct | profile_data |
| struct | profile_entry |
| struct | thread_list |
| struct | thread_list_t |
Defines | |
| #define | AST_MAX_CONNECTS 128 |
| #define | ASTERISK_PROMPT "*CLI> " |
| #define | ASTERISK_PROMPT2 "%s*CLI> " |
| #define | DEFINE_PROFILE_MIN_MAX_VALUES |
| #define | EL_BUF_SIZE 512 |
| #define | FORMAT "%-25.25s %-40.40s\n" |
| #define | MAX_HISTORY_COMMAND_LENGTH 256 |
| #define | NUM_MSGS 64 |
| #define | WELCOME_MESSAGE |
| Welcome message when starting a CLI interface. | |
Enumerations | |
| enum | shutdown_nice_t { NOT_SHUTTING_DOWN = -2, SHUTTING_DOWN = -1, SHUTDOWN_FAST, SHUTDOWN_NORMAL, SHUTDOWN_NICE, SHUTDOWN_REALLY_NICE } |
Functions | |
| static void | __ast_unregister_atexit (void(*func)(void)) |
| static void | __quit_handler (int num) |
| static void | __remote_quit_handler (int num) |
| static void | _child_handler (int sig) |
| static void | _hup_handler (int num) |
| static void | _null_sig_handler (int sig) |
| NULL handler so we can collect the child exit status. | |
| static void | _urg_handler (int num) |
| Urgent handler. | |
| int | ast_add_profile (const char *name, uint64_t scale) |
| allocates a counter with a given name and scale. | |
| static int | ast_all_zeros (char *s) |
| static int | ast_cli_display_match_list (char **matches, int len, int max) |
| char * | ast_complete_source_filename (const char *partial, int n) |
| void | ast_console_puts (const char *string) |
| void | ast_console_puts_mutable (const char *string, int level) |
| log the string to the console, and all attached console clients | |
| void | ast_console_toggle_loglevel (int fd, int level, int state) |
| enable or disable a logging level to a specified console | |
| void | ast_console_toggle_mute (int fd, int silent) |
| mute or unmute a console from logging | |
| static int | ast_el_add_history (char *) |
| static int | ast_el_initialize (void) |
| static int | ast_el_read_char (EditLine *editline, char *cp) |
| static int | ast_el_read_history (char *) |
| static int | ast_el_sort_compare (const void *i1, const void *i2) |
| static char ** | ast_el_strtoarr (char *buf) |
| static int | ast_el_write_history (char *) |
| const char * | ast_file_version_find (const char *file) |
| Find version for given module name. | |
| static int | ast_makesocket (void) |
| int64_t | ast_mark (int i, int startstop) |
| static void | ast_network_puts (const char *string) |
| write the string to all attached console clients | |
| static void | ast_network_puts_mutable (const char *string, int level) |
| log the string to all attached console clients | |
| int64_t | ast_profile (int i, int64_t delta) |
| static void | ast_readconfig (void) |
| int | ast_register_atexit (void(*func)(void)) |
| Register a function to be executed before Asterisk exits. | |
| void | ast_register_file_version (const char *file, const char *version) |
| Register the version of a source code file with the core. | |
| void | ast_register_thread (char *name) |
| static void | ast_remotecontrol (char *data) |
| void | ast_replace_sigchld (void) |
| Replace the SIGCHLD handler. | |
| static void | ast_run_atexits (void) |
| int | ast_safe_system (const char *s) |
| Safely spawn an external program while closing file descriptors. | |
| int | ast_set_priority (int pri) |
| We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing. | |
| static int | ast_tryconnect (void) |
| void | ast_unregister_atexit (void(*func)(void)) |
| Unregister a function registered with ast_register_atexit(). | |
| void | ast_unregister_file_version (const char *file) |
| Unregister a source code file from the core. | |
| void | ast_unregister_thread (void *id) |
| void | ast_unreplace_sigchld (void) |
| Restore the SIGCHLD handler. | |
| static int | can_safely_quit (shutdown_nice_t niceness, int restart) |
| static void | canary_exit (void) |
| static void * | canary_thread (void *unused) |
| static char * | cli_complete (EditLine *editline, int ch) |
| static char * | cli_prompt (EditLine *editline) |
| static void | console_verboser (const char *s) |
| static void | consolehandler (char *s) |
| static void | destroy_match_list (char **match_list, int matches) |
| static void | env_init (void) |
| static int | fdprint (int fd, const char *s) |
| static int | fdsend (int fd, const char *s) |
| static const char * | fix_header (char *outbuf, int maxout, const char *s, char *cmp) |
| static char * | handle_abort_shutdown (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_bang (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_clear_profile (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_restart_gracefully (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_restart_now (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_restart_when_convenient (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_show_profile (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_show_settings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Give an overview of core settings. | |
| static char * | handle_show_sysinfo (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Give an overview of system statistics. | |
| static char * | handle_show_threads (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_show_version_files (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command to list module versions. | |
| static char * | handle_stop_gracefully (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_stop_now (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_stop_when_convenient (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static void * | listener (void *unused) |
| int | main (int argc, char *argv[]) |
| static void | main_atexit (void) |
| static void * | monitor_sig_flags (void *unused) |
| static void * | netconsole (void *vconsole) |
| static void | network_verboser (const char *s) |
| static void | print_intro_message (const char *runuser, const char *rungroup) |
| static void | quit_handler (int num, shutdown_nice_t niceness, int restart) |
| static __inline uint64_t | rdtsc (void) |
| static int | read_credentials (int fd, char *buffer, size_t size, struct console *con) |
| read() function supporting the reception of user credentials. | |
| static void | really_quit (int num, shutdown_nice_t niceness, int restart) |
| static int | remoteconsolehandler (char *s) |
| static void | run_startup_commands (void) |
| static void | set_icon (char *text) |
| static void | set_title (char *text) |
| Set an X-term or screen title. | |
| static void | set_ulimit (int value) |
| Set maximum open files. | |
| static int | show_cli_help (void) |
| static char * | show_license (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static int | show_version (void) |
| static char * | show_warranty (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
Variables | |
| static char * | _argv [256] |
| struct ast_flags | ast_compat = { 0 } |
| const char * | ast_config_AST_AGI_DIR = cfg_paths.agi_dir |
| const char * | ast_config_AST_CONFIG_DIR = cfg_paths.config_dir |
| const char * | ast_config_AST_CONFIG_FILE = cfg_paths.config_file |
| static char | ast_config_AST_CTL [PATH_MAX] = "asterisk.ctl" |
| static char | ast_config_AST_CTL_GROUP [PATH_MAX] = "\0" |
| static char | ast_config_AST_CTL_OWNER [PATH_MAX] = "\0" |
| static char | ast_config_AST_CTL_PERMISSIONS [PATH_MAX] |
| const char * | ast_config_AST_DATA_DIR = cfg_paths.data_dir |
| const char * | ast_config_AST_DB = cfg_paths.db_path |
| const char * | ast_config_AST_KEY_DIR = cfg_paths.key_dir |
| const char * | ast_config_AST_LOG_DIR = cfg_paths.log_dir |
| const char * | ast_config_AST_MODULE_DIR = cfg_paths.module_dir |
| const char * | ast_config_AST_MONITOR_DIR = cfg_paths.monitor_dir |
| const char * | ast_config_AST_PID = cfg_paths.pid_path |
| const char * | ast_config_AST_RUN_DIR = cfg_paths.run_dir |
| const char * | ast_config_AST_RUN_GROUP = cfg_paths.run_group |
| const char * | ast_config_AST_RUN_USER = cfg_paths.run_user |
| const char * | ast_config_AST_SOCKET = cfg_paths.socket_path |
| const char * | ast_config_AST_SPOOL_DIR = cfg_paths.spool_dir |
| const char * | ast_config_AST_SYSTEM_NAME = cfg_paths.system_name |
| const char * | ast_config_AST_VAR_DIR = cfg_paths.var_dir |
| static int | ast_consock = -1 |
| struct ast_eid | ast_eid_default |
| Global EID. | |
| unsigned int | ast_FD_SETSIZE |
| struct timeval | ast_lastreloadtime |
| pid_t | ast_mainpid |
| struct ast_flags | ast_options = { AST_DEFAULT_OPTIONS } |
| static int | ast_socket = -1 |
| struct timeval | ast_startuptime |
| static char | canary_filename [128] |
| static int | canary_pid = 0 |
| static struct _cfg_paths | cfg_paths |
| static struct sigaction | child_handler |
| static struct ast_cli_entry | cli_asterisk [] |
| static struct ast_cli_entry | cli_asterisk_shutdown [] |
| Shutdown Asterisk CLI commands. | |
| struct console | consoles [AST_MAX_CONNECTS] |
| static pthread_t | consolethread = AST_PTHREADT_NULL |
| char | defaultlanguage [MAX_LANGUAGE] = DEFAULT_LANGUAGE |
| static EditLine * | el |
| static History * | el_hist |
| static struct sigaction | hup_handler |
| static struct sigaction | ignore_sig_handler |
| static const char | license_lines [] |
| static pthread_t | lthread |
| static pthread_t | mon_sig_flags |
| static int | multi_thread_safe |
| static struct sigaction | null_sig_handler |
| int | option_debug |
| int | option_maxcalls |
| int | option_maxfiles |
| double | option_maxload |
| long | option_minmemfree |
| int | option_verbose |
| static struct profile_data * | prof_data |
| static struct ast_str * | prompt = NULL |
| static char | randompool [256] |
| char | record_cache_dir [AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR |
| static char * | remotehostname |
| static int | restartnow |
| static unsigned int | safe_system_level = 0 |
| Keep track of how many threads are currently trying to wait*() on a child process. | |
| static ast_mutex_t | safe_system_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
| static struct sigaction | safe_system_prev_handler |
| static shutdown_nice_t | shuttingdown = NOT_SHUTTING_DOWN |
| static int | sig_alert_pipe [2] = { -1, -1 } |
| struct { | |
| unsigned int need_quit:1 | |
| unsigned int need_quit_handler:1 | |
| unsigned int need_reload:1 | |
| } | sig_flags |
| static struct sigaction | urg_handler |
| static const char | warranty_lines [] |
Top level source file for Asterisk - the Open Source PBX. Implementation of PBX core functions and CLI interface.
Definition in file asterisk.c.
| #define AST_MAX_CONNECTS 128 |
Definition at line 158 of file asterisk.c.
Referenced by ast_console_toggle_loglevel(), ast_console_toggle_mute(), ast_makesocket(), ast_network_puts(), ast_network_puts_mutable(), and listener().
| #define ASTERISK_PROMPT "*CLI> " |
Definition at line 2242 of file asterisk.c.
Referenced by cli_prompt().
| #define ASTERISK_PROMPT2 "%s*CLI> " |
Definition at line 2244 of file asterisk.c.
Referenced by cli_prompt().
| #define DEFINE_PROFILE_MIN_MAX_VALUES |
Definition at line 788 of file asterisk.c.
Referenced by handle_clear_profile(), and handle_show_profile().
| #define EL_BUF_SIZE 512 |
Referenced by ast_el_read_char().
| #define FORMAT "%-25.25s %-40.40s\n" |
| #define MAX_HISTORY_COMMAND_LENGTH 256 |
Definition at line 2787 of file asterisk.c.
Referenced by ast_el_add_history().
| #define NUM_MSGS 64 |
Definition at line 159 of file asterisk.c.
| #define WELCOME_MESSAGE |
Welcome message when starting a CLI interface.
Definition at line 162 of file asterisk.c.
Referenced by ast_el_read_char(), and print_intro_message().
| enum shutdown_nice_t |
| NOT_SHUTTING_DOWN | |
| SHUTTING_DOWN | |
| SHUTDOWN_FAST | |
| SHUTDOWN_NORMAL | |
| SHUTDOWN_NICE | |
| SHUTDOWN_REALLY_NICE |
Definition at line 282 of file asterisk.c.
00282 { 00283 NOT_SHUTTING_DOWN = -2, 00284 SHUTTING_DOWN = -1, 00285 /* Valid values for quit_handler niceness below: */ 00286 SHUTDOWN_FAST, 00287 SHUTDOWN_NORMAL, 00288 SHUTDOWN_NICE, 00289 SHUTDOWN_REALLY_NICE 00290 } shutdown_nice_t;
| static void __ast_unregister_atexit | ( | void(*)(void) | func | ) | [static] |
Definition at line 962 of file asterisk.c.
References ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_atexit::func, and ast_atexit::list.
Referenced by ast_register_atexit(), and ast_unregister_atexit().
00963 { 00964 struct ast_atexit *ae; 00965 00966 AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) { 00967 if (ae->func == func) { 00968 AST_LIST_REMOVE_CURRENT(list); 00969 ast_free(ae); 00970 break; 00971 } 00972 } 00973 AST_LIST_TRAVERSE_SAFE_END; 00974 }
| static void __quit_handler | ( | int | num | ) | [static] |
Definition at line 1849 of file asterisk.c.
References errno, sig_alert_pipe, and sig_flags.
Referenced by main().
01850 { 01851 int a = 0; 01852 sig_flags.need_quit = 1; 01853 if (sig_alert_pipe[1] != -1) { 01854 if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) { 01855 fprintf(stderr, "quit_handler: write() failed: %s\n", strerror(errno)); 01856 } 01857 } 01858 /* There is no need to restore the signal handler here, since the app 01859 * is going to exit */ 01860 }
| static void __remote_quit_handler | ( | int | num | ) | [static] |
Definition at line 1862 of file asterisk.c.
References sig_flags.
Referenced by ast_remotecontrol().
01863 { 01864 sig_flags.need_quit = 1; 01865 }
| static void _child_handler | ( | int | sig | ) | [static] |
Definition at line 1578 of file asterisk.c.
01579 { 01580 /* Must not ever ast_log or ast_verbose within signal handler */ 01581 int n, status, save_errno = errno; 01582 01583 /* 01584 * Reap all dead children -- not just one 01585 */ 01586 for (n = 0; wait4(-1, &status, WNOHANG, NULL) > 0; n++) 01587 ; 01588 if (n == 0 && option_debug) 01589 printf("Huh? Child handler, but nobody there?\n"); 01590 errno = save_errno; 01591 }
| static void _hup_handler | ( | int | num | ) | [static] |
Definition at line 1557 of file asterisk.c.
References _argv, errno, restartnow, sig_alert_pipe, and sig_flags.
01558 { 01559 int a = 0, save_errno = errno; 01560 if (option_verbose > 1) 01561 printf("Received HUP signal -- Reloading configs\n"); 01562 if (restartnow) 01563 execvp(_argv[0], _argv); 01564 sig_flags.need_reload = 1; 01565 if (sig_alert_pipe[1] != -1) { 01566 if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) { 01567 fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno)); 01568 } 01569 } 01570 errno = save_errno; 01571 }
| static void _null_sig_handler | ( | int | sig | ) | [static] |
NULL handler so we can collect the child exit status.
Definition at line 1014 of file asterisk.c.
| static void _urg_handler | ( | int | num | ) | [static] |
Urgent handler.
Called by soft_hangup to interrupt the poll, read, or other system call. We don't actually need to do anything though. Remember: Cannot EVER ast_log from within a signal handler
Definition at line 1547 of file asterisk.c.
| int ast_add_profile | ( | const char * | name, | |
| uint64_t | scale | |||
| ) |
allocates a counter with a given name and scale.
support for event profiling
Definition at line 707 of file asterisk.c.
References ast_calloc, ast_realloc, ast_strdup, profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, profile_data::max_size, profile_entry::name, prof_data, profile_entry::scale, and profile_entry::value.
Referenced by extension_match_core().
00708 { 00709 int l = sizeof(struct profile_data); 00710 int n = 10; /* default entries */ 00711 00712 if (prof_data == NULL) { 00713 prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry)); 00714 if (prof_data == NULL) 00715 return -1; 00716 prof_data->entries = 0; 00717 prof_data->max_size = n; 00718 } 00719 if (prof_data->entries >= prof_data->max_size) { 00720 void *p; 00721 n = prof_data->max_size + 20; 00722 p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry)); 00723 if (p == NULL) 00724 return -1; 00725 prof_data = p; 00726 prof_data->max_size = n; 00727 } 00728 n = prof_data->entries++; 00729 prof_data->e[n].name = ast_strdup(name); 00730 prof_data->e[n].value = 0; 00731 prof_data->e[n].events = 0; 00732 prof_data->e[n].mark = 0; 00733 prof_data->e[n].scale = scale; 00734 return n; 00735 }
| static int ast_all_zeros | ( | char * | s | ) | [static] |
Definition at line 1909 of file asterisk.c.
Referenced by consolehandler(), and remoteconsolehandler().
| static int ast_cli_display_match_list | ( | char ** | matches, | |
| int | len, | |||
| int | max | |||
| ) | [static] |
Definition at line 2579 of file asterisk.c.
References ast_el_sort_compare(), ast_free, and ast_get_termcols().
Referenced by cli_complete().
02580 { 02581 int i, idx, limit, count; 02582 int screenwidth = 0; 02583 int numoutput = 0, numoutputline = 0; 02584 02585 screenwidth = ast_get_termcols(STDOUT_FILENO); 02586 02587 /* find out how many entries can be put on one line, with two spaces between strings */ 02588 limit = screenwidth / (max + 2); 02589 if (limit == 0) 02590 limit = 1; 02591 02592 /* how many lines of output */ 02593 count = len / limit; 02594 if (count * limit < len) 02595 count++; 02596 02597 idx = 1; 02598 02599 qsort(&matches[0], (size_t)(len), sizeof(char *), ast_el_sort_compare); 02600 02601 for (; count > 0; count--) { 02602 numoutputline = 0; 02603 for (i = 0; i < limit && matches[idx]; i++, idx++) { 02604 02605 /* Don't print dupes */ 02606 if ( (matches[idx+1] != NULL && strcmp(matches[idx], matches[idx+1]) == 0 ) ) { 02607 i--; 02608 ast_free(matches[idx]); 02609 matches[idx] = NULL; 02610 continue; 02611 } 02612 02613 numoutput++; 02614 numoutputline++; 02615 fprintf(stdout, "%-*s ", max, matches[idx]); 02616 ast_free(matches[idx]); 02617 matches[idx] = NULL; 02618 } 02619 if (numoutputline > 0) 02620 fprintf(stdout, "\n"); 02621 } 02622 02623 return numoutput; 02624 }
| char* ast_complete_source_filename | ( | const char * | partial, | |
| int | n | |||
| ) |
Definition at line 356 of file asterisk.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, file_version::file, len(), and ast_atexit::list.
Referenced by handle_verbose().
00357 { 00358 struct file_version *find; 00359 size_t len = strlen(partial); 00360 int count = 0; 00361 char *res = NULL; 00362 00363 AST_RWLIST_RDLOCK(&file_versions); 00364 AST_RWLIST_TRAVERSE(&file_versions, find, list) { 00365 if (!strncasecmp(find->file, partial, len) && ++count > n) { 00366 res = ast_strdup(find->file); 00367 break; 00368 } 00369 } 00370 AST_RWLIST_UNLOCK(&file_versions); 00371 return res; 00372 }
| void ast_console_puts | ( | const char * | string | ) |
write the string to the console, and all attached console clients
Definition at line 1208 of file asterisk.c.
References ast_network_puts().
01209 { 01210 fputs(string, stdout); 01211 fflush(stdout); 01212 ast_network_puts(string); 01213 }
| void ast_console_puts_mutable | ( | const char * | string, | |
| int | level | |||
| ) |
log the string to the console, and all attached console clients
Definition at line 1185 of file asterisk.c.
References ast_network_puts_mutable().
Referenced by init_logger_chain(), logger_print_normal(), and make_logchannel().
01186 { 01187 fputs(string, stdout); 01188 fflush(stdout); 01189 ast_network_puts_mutable(string, level); 01190 }
| void ast_console_toggle_loglevel | ( | int | fd, | |
| int | level, | |||
| int | state | |||
| ) |
enable or disable a logging level to a specified console
enables or disables logging of a specified level to the console fd specifies the index of the console receiving the level change level specifies the index of the logging level being toggled state indicates whether logging will be on or off (0 for off, 1 for on)
Definition at line 1122 of file asterisk.c.
References AST_MAX_CONNECTS, consoles, console::levels, and NUMLOGLEVELS.
Referenced by handle_logger_set_level().
01123 { 01124 int x; 01125 01126 if (level >= NUMLOGLEVELS) { 01127 level = NUMLOGLEVELS - 1; 01128 } 01129 01130 for (x = 0;x < AST_MAX_CONNECTS; x++) { 01131 if (fd == consoles[x].fd) { 01132 /* 01133 * Since the logging occurs when levels are false, set to 01134 * flipped iinput because this function accepts 0 as off and 1 as on 01135 */ 01136 consoles[x].levels[level] = state ? 0 : 1; 01137 return; 01138 } 01139 } 01140 }
| void ast_console_toggle_mute | ( | int | fd, | |
| int | silent | |||
| ) |
mute or unmute a console from logging
Definition at line 1145 of file asterisk.c.
References ast_cli(), AST_MAX_CONNECTS, consoles, console::mute, and mute.
Referenced by handle_logger_mute().
01146 { 01147 int x; 01148 for (x = 0;x < AST_MAX_CONNECTS; x++) { 01149 if (fd == consoles[x].fd) { 01150 if (consoles[x].mute) { 01151 consoles[x].mute = 0; 01152 if (!silent) 01153 ast_cli(fd, "Console is not muted anymore.\n"); 01154 } else { 01155 consoles[x].mute = 1; 01156 if (!silent) 01157 ast_cli(fd, "Console is muted.\n"); 01158 } 01159 return; 01160 } 01161 } 01162 ast_cli(fd, "Couldn't find remote console.\n"); 01163 }
| static int ast_el_add_history | ( | char * | buf | ) | [static] |
Definition at line 2789 of file asterisk.c.
References ast_el_initialize(), ast_strdupa, ast_strip(), el, el_hist, and MAX_HISTORY_COMMAND_LENGTH.
Referenced by consolehandler(), and remoteconsolehandler().
02790 { 02791 HistEvent ev; 02792 02793 if (el_hist == NULL || el == NULL) 02794 ast_el_initialize(); 02795 if (strlen(buf) > (MAX_HISTORY_COMMAND_LENGTH - 1)) 02796 return 0; 02797 return (history(el_hist, &ev, H_ENTER, ast_strip(ast_strdupa(buf)))); 02798 }
| static int ast_el_initialize | ( | void | ) | [static] |
Definition at line 2752 of file asterisk.c.
References cli_complete(), cli_prompt(), el, and el_hist.
Referenced by ast_el_add_history(), ast_el_read_history(), ast_el_write_history(), ast_remotecontrol(), and main().
02753 { 02754 HistEvent ev; 02755 char *editor = getenv("AST_EDITOR"); 02756 02757 if (el != NULL) 02758 el_end(el); 02759 if (el_hist != NULL) 02760 history_end(el_hist); 02761 02762 el = el_init("asterisk", stdin, stdout, stderr); 02763 el_set(el, EL_PROMPT, cli_prompt); 02764 02765 el_set(el, EL_EDITMODE, 1); 02766 el_set(el, EL_EDITOR, editor ? editor : "emacs"); 02767 el_hist = history_init(); 02768 if (!el || !el_hist) 02769 return -1; 02770 02771 /* setup history with 100 entries */ 02772 history(el_hist, &ev, H_SETSIZE, 100); 02773 02774 el_set(el, EL_HIST, history, el_hist); 02775 02776 el_set(el, EL_ADDFN, "ed-complete", "Complete argument", cli_complete); 02777 /* Bind <tab> to command completion */ 02778 el_set(el, EL_BIND, "^I", "ed-complete", NULL); 02779 /* Bind ? to command completion */ 02780 el_set(el, EL_BIND, "?", "ed-complete", NULL); 02781 /* Bind ^D to redisplay */ 02782 el_set(el, EL_BIND, "^D", "ed-redisplay", NULL); 02783 02784 return 0; 02785 }
| static int ast_el_read_char | ( | EditLine * | editline, | |
| char * | cp | |||
| ) | [static] |
Definition at line 2281 of file asterisk.c.
References ast_opt_exec, ast_opt_mute, ast_opt_reconnect, ast_poll, ast_tryconnect(), EL_BUF_SIZE, errno, fdsend(), quit_handler(), SHUTDOWN_FAST, sig_flags, term_quit(), and WELCOME_MESSAGE.
Referenced by ast_remotecontrol(), and main().
02282 { 02283 int num_read = 0; 02284 int lastpos = 0; 02285 struct pollfd fds[2]; 02286 int res; 02287 int max; 02288 #define EL_BUF_SIZE 512 02289 char buf[EL_BUF_SIZE]; 02290 02291 for (;;) { 02292 max = 1; 02293 fds[0].fd = ast_consock; 02294 fds[0].events = POLLIN; 02295 if (!ast_opt_exec) { 02296 fds[1].fd = STDIN_FILENO; 02297 fds[1].events = POLLIN; 02298 max++; 02299 } 02300 res = ast_poll(fds, max, -1); 02301 if (res < 0) { 02302 if (sig_flags.need_quit || sig_flags.need_quit_handler) 02303 break; 02304 if (errno == EINTR) 02305 continue; 02306 fprintf(stderr, "poll failed: %s\n", strerror(errno)); 02307 break; 02308 } 02309 02310 if (!ast_opt_exec && fds[1].revents) { 02311 num_read = read(STDIN_FILENO, cp, 1); 02312 if (num_read < 1) { 02313 break; 02314 } else 02315 return (num_read); 02316 } 02317 if (fds[0].revents) { 02318 char *tmp; 02319 res = read(ast_consock, buf, sizeof(buf) - 1); 02320 /* if the remote side disappears exit */ 02321 if (res < 1) { 02322 fprintf(stderr, "\nDisconnected from Asterisk server\n"); 02323 if (!ast_opt_reconnect) { 02324 quit_handler(0, SHUTDOWN_FAST, 0); 02325 } else { 02326 int tries; 02327 int reconnects_per_second = 20; 02328 fprintf(stderr, "Attempting to reconnect for 30 seconds\n"); 02329 for (tries = 0; tries < 30 * reconnects_per_second; tries++) { 02330 if (ast_tryconnect()) { 02331 fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries); 02332 printf("%s", term_quit()); 02333 WELCOME_MESSAGE; 02334 if (!ast_opt_mute) 02335 fdsend(ast_consock, "logger mute silent"); 02336 else 02337 printf("log and verbose output currently muted ('logger mute' to unmute)\n"); 02338 break; 02339 } else 02340 usleep(1000000 / reconnects_per_second); 02341 } 02342 if (tries >= 30 * reconnects_per_second) { 02343 fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n"); 02344 quit_handler(0, SHUTDOWN_FAST, 0); 02345 } 02346 } 02347 continue; 02348 } 02349 02350 buf[res] = '\0'; 02351 02352 /* Strip preamble from asynchronous events, too */ 02353 for (tmp = buf; *tmp; tmp++) { 02354 if (*tmp == 127) { 02355 memmove(tmp, tmp + 1, strlen(tmp)); 02356 tmp--; 02357 res--; 02358 } 02359 } 02360 02361 /* Write over the CLI prompt */ 02362 if (!ast_opt_exec && !lastpos) { 02363 if (write(STDOUT_FILENO, "\r[0K", 5) < 0) { 02364 } 02365 } 02366 if (write(STDOUT_FILENO, buf, res) < 0) { 02367 } 02368 if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (buf[res-2] == '\n'))) { 02369 *cp = CC_REFRESH; 02370 return(1); 02371 } else 02372 lastpos = 1; 02373 } 02374 } 02375 02376 *cp = '\0'; 02377 return (0); 02378 }
| static int ast_el_read_history | ( | char * | filename | ) | [static] |
Definition at line 2810 of file asterisk.c.
References ast_el_initialize(), el, and el_hist.
Referenced by ast_remotecontrol(), and main().
02811 { 02812 HistEvent ev; 02813 02814 if (el_hist == NULL || el == NULL) 02815 ast_el_initialize(); 02816 02817 return (history(el_hist, &ev, H_LOAD, filename)); 02818 }
| static int ast_el_sort_compare | ( | const void * | i1, | |
| const void * | i2 | |||
| ) | [static] |
Definition at line 2569 of file asterisk.c.
Referenced by ast_cli_display_match_list().
| static char** ast_el_strtoarr | ( | char * | buf | ) | [static] |
Definition at line 2521 of file asterisk.c.
References AST_CLI_COMPLETE_EOF, ast_realloc, ast_strdup, and destroy_match_list().
Referenced by cli_complete().
02522 { 02523 char *retstr; 02524 char **match_list = NULL; 02525 char **new_list; 02526 size_t match_list_len = 1; 02527 int matches = 0; 02528 02529 while ((retstr = strsep(&buf, " "))) { 02530 if (!strcmp(retstr, AST_CLI_COMPLETE_EOF)) { 02531 break; 02532 } 02533 if (matches + 1 >= match_list_len) { 02534 match_list_len <<= 1; 02535 new_list = ast_realloc(match_list, match_list_len * sizeof(char *)); 02536 if (!new_list) { 02537 destroy_match_list(match_list, matches); 02538 return NULL; 02539 } 02540 match_list = new_list; 02541 } 02542 02543 retstr = ast_strdup(retstr); 02544 if (!retstr) { 02545 destroy_match_list(match_list, matches); 02546 return NULL; 02547 } 02548 match_list[matches++] = retstr; 02549 } 02550 02551 if (!match_list) { 02552 return NULL; 02553 } 02554 02555 if (matches >= match_list_len) { 02556 new_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)); 02557 if (!new_list) { 02558 destroy_match_list(match_list, matches); 02559 return NULL; 02560 } 02561 match_list = new_list; 02562 } 02563 02564 match_list[matches] = NULL; 02565 02566 return match_list; 02567 }
| static int ast_el_write_history | ( | char * | filename | ) | [static] |
Definition at line 2800 of file asterisk.c.
References ast_el_initialize(), el, and el_hist.
Referenced by really_quit().
02801 { 02802 HistEvent ev; 02803 02804 if (el_hist == NULL || el == NULL) 02805 ast_el_initialize(); 02806 02807 return (history(el_hist, &ev, H_SAVE, filename)); 02808 }
| const char* ast_file_version_find | ( | const char * | file | ) |
Find version for given module name.
| file | Module name (i.e. chan_sip.so) |
Definition at line 375 of file asterisk.c.
References AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, file_version::file, ast_atexit::list, and file_version::version.
Referenced by manager_modulecheck().
00376 { 00377 struct file_version *iterator; 00378 00379 AST_RWLIST_WRLOCK(&file_versions); 00380 AST_RWLIST_TRAVERSE(&file_versions, iterator, list) { 00381 if (!strcasecmp(iterator->file, file)) 00382 break; 00383 } 00384 AST_RWLIST_UNLOCK(&file_versions); 00385 if (iterator) 00386 return iterator->version; 00387 return NULL; 00388 }
| static int ast_makesocket | ( | void | ) | [static] |
Definition at line 1446 of file asterisk.c.
References AF_LOCAL, ast_config_AST_CTL_GROUP, ast_config_AST_CTL_OWNER, ast_config_AST_CTL_PERMISSIONS, ast_config_AST_SOCKET, ast_copy_string(), ast_log(), AST_MAX_CONNECTS, ast_pthread_create_background, ast_register_verbose(), ast_strlen_zero(), consoles, errno, listener(), LOG_WARNING, lthread, and network_verboser().
Referenced by main().
01447 { 01448 struct sockaddr_un sunaddr; 01449 int res; 01450 int x; 01451 uid_t uid = -1; 01452 gid_t gid = -1; 01453 01454 for (x = 0; x < AST_MAX_CONNECTS; x++) 01455 consoles[x].fd = -1; 01456 unlink(ast_config_AST_SOCKET); 01457 ast_socket = socket(PF_LOCAL, SOCK_STREAM, 0); 01458 if (ast_socket < 0) { 01459 ast_log(LOG_WARNING, "Unable to create control socket: %s\n", strerror(errno)); 01460 return -1; 01461 } 01462 memset(&sunaddr, 0, sizeof(sunaddr)); 01463 sunaddr.sun_family = AF_LOCAL; 01464 ast_copy_string(sunaddr.sun_path, ast_config_AST_SOCKET, sizeof(sunaddr.sun_path)); 01465 res = bind(ast_socket, (struct sockaddr *)&sunaddr, sizeof(sunaddr)); 01466 if (res) { 01467 ast_log(LOG_WARNING, "Unable to bind socket to %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01468 close(ast_socket); 01469 ast_socket = -1; 01470 return -1; 01471 } 01472 res = listen(ast_socket, 2); 01473 if (res < 0) { 01474 ast_log(LOG_WARNING, "Unable to listen on socket %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01475 close(ast_socket); 01476 ast_socket = -1; 01477 return -1; 01478 } 01479 if (ast_register_verbose(network_verboser)) { 01480 ast_log(LOG_WARNING, "Unable to register network verboser?\n"); 01481 } 01482 01483 if (ast_pthread_create_background(<hread, NULL, listener, NULL)) { 01484 ast_log(LOG_WARNING, "Unable to create listener thread.\n"); 01485 close(ast_socket); 01486 return -1; 01487 } 01488 01489 if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) { 01490 struct passwd *pw; 01491 if ((pw = getpwnam(ast_config_AST_CTL_OWNER)) == NULL) 01492 ast_log(LOG_WARNING, "Unable to find uid of user %s\n", ast_config_AST_CTL_OWNER); 01493 else 01494 uid = pw->pw_uid; 01495 } 01496 01497 if (!ast_strlen_zero(ast_config_AST_CTL_GROUP)) { 01498 struct group *grp; 01499 if ((grp = getgrnam(ast_config_AST_CTL_GROUP)) == NULL) 01500 ast_log(LOG_WARNING, "Unable to find gid of group %s\n", ast_config_AST_CTL_GROUP); 01501 else 01502 gid = grp->gr_gid; 01503 } 01504 01505 if (chown(ast_config_AST_SOCKET, uid, gid) < 0) 01506 ast_log(LOG_WARNING, "Unable to change ownership of %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01507 01508 if (!ast_strlen_zero(ast_config_AST_CTL_PERMISSIONS)) { 01509 int p1; 01510 mode_t p; 01511 sscanf(ast_config_AST_CTL_PERMISSIONS, "%30o", &p1); 01512 p = p1; 01513 if ((chmod(ast_config_AST_SOCKET, p)) < 0) 01514 ast_log(LOG_WARNING, "Unable to change file permissions of %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01515 } 01516 01517 return 0; 01518 }
| int64_t ast_mark | ( | int | i, | |
| int | startstop | |||
| ) |
Definition at line 772 of file asterisk.c.
References profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, prof_data, rdtsc(), profile_entry::scale, and profile_entry::value.
Referenced by __ast_pthread_mutex_lock(), and extension_match_core().
00773 { 00774 if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */ 00775 return 0; 00776 if (startstop == 1) 00777 prof_data->e[i].mark = rdtsc(); 00778 else { 00779 prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark); 00780 if (prof_data->e[i].scale > 1) 00781 prof_data->e[i].mark /= prof_data->e[i].scale; 00782 prof_data->e[i].value += prof_data->e[i].mark; 00783 prof_data->e[i].events++; 00784 } 00785 return prof_data->e[i].mark; 00786 }
| static void ast_network_puts | ( | const char * | string | ) | [static] |
write the string to all attached console clients
Definition at line 1195 of file asterisk.c.
References AST_MAX_CONNECTS, consoles, and fdprint().
Referenced by ast_console_puts().
01196 { 01197 int x; 01198 for (x = 0; x < AST_MAX_CONNECTS; x++) { 01199 if (consoles[x].fd > -1) 01200 fdprint(consoles[x].p[1], string); 01201 } 01202 }
| static void ast_network_puts_mutable | ( | const char * | string, | |
| int | level | |||
| ) | [static] |
log the string to all attached console clients
Definition at line 1168 of file asterisk.c.
References AST_MAX_CONNECTS, consoles, fdprint(), levels, and mute.
Referenced by ast_console_puts_mutable(), and network_verboser().
| int64_t ast_profile | ( | int | i, | |
| int64_t | delta | |||
| ) |
Definition at line 737 of file asterisk.c.
References profile_data::e, profile_data::entries, profile_entry::events, prof_data, profile_entry::scale, and profile_entry::value.
| static void ast_readconfig | ( | void | ) | [static] |
Definition at line 3011 of file asterisk.c.
References _cfg_paths::agi_dir, AST_CACHE_DIR_LEN, AST_COMPAT_APP_SET, AST_COMPAT_DELIM_PBX_REALTIME, AST_COMPAT_DELIM_RES_AGI, ast_config_AST_CONFIG_FILE, ast_config_AST_CTL, ast_config_AST_CTL_GROUP, ast_config_AST_CTL_OWNER, ast_config_AST_CTL_PERMISSIONS, ast_config_AST_SYSTEM_NAME, ast_config_destroy(), ast_config_load2(), ast_copy_string(), ast_eid_default, ast_language_is_prefix, AST_LOCK_TYPE_FLOCK, AST_LOCK_TYPE_LOCKFILE, ast_log(), AST_OPT_FLAG_ALWAYS_FORK, AST_OPT_FLAG_CACHE_RECORD_FILES, AST_OPT_FLAG_CONSOLE, AST_OPT_FLAG_DONT_WARN, AST_OPT_FLAG_DUMP_CORE, AST_OPT_FLAG_EXEC_INCLUDES, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND, AST_OPT_FLAG_HIDE_CONSOLE_CONNECT, AST_OPT_FLAG_HIGH_PRIORITY, AST_OPT_FLAG_INIT_KEYS, AST_OPT_FLAG_INTERNAL_TIMING, AST_OPT_FLAG_LIGHT_BACKGROUND, AST_OPT_FLAG_LOCK_CONFIG_DIR, AST_OPT_FLAG_NO_COLOR, AST_OPT_FLAG_NO_FORK, AST_OPT_FLAG_QUIET, AST_OPT_FLAG_TIMESTAMP, AST_OPT_FLAG_TRANSCODE_VIA_SLIN, AST_OPT_FLAG_TRANSMIT_SILENCE, ast_opt_override_config, ast_opt_remote, ast_set2_flag, ast_set_default_eid(), ast_set_lock_type(), ast_str_to_eid(), ast_strlen_zero(), ast_true(), ast_variable_browse(), ast_verbose, cfg_paths, config, _cfg_paths::config_dir, CONFIG_FLAG_NOREALTIME, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, _cfg_paths::data_dir, _cfg_paths::db_path, DEFAULT_AGI_DIR, DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_FILE, DEFAULT_DATA_DIR, DEFAULT_DB, DEFAULT_KEY_DIR, DEFAULT_LOG_DIR, DEFAULT_MODULE_DIR, DEFAULT_PID, DEFAULT_RUN_DIR, DEFAULT_SOCKET, DEFAULT_SPOOL_DIR, DEFAULT_VAR_DIR, defaultlanguage, hostname, _cfg_paths::key_dir, live_dangerously, _cfg_paths::log_dir, LOG_ERROR, LOG_WARNING, MAX_LANGUAGE, MAXHOSTNAMELEN, _cfg_paths::module_dir, _cfg_paths::monitor_dir, ast_variable::name, ast_variable::next, pbx_live_dangerously(), _cfg_paths::pid_path, _cfg_paths::run_dir, _cfg_paths::run_group, _cfg_paths::run_user, set_ulimit(), _cfg_paths::socket_path, _cfg_paths::spool_dir, _cfg_paths::system_name, ast_variable::value, _cfg_paths::var_dir, and version.
Referenced by main().
03012 { 03013 struct ast_config *cfg; 03014 struct ast_variable *v; 03015 char *config = DEFAULT_CONFIG_FILE; 03016 char hostname[MAXHOSTNAMELEN] = ""; 03017 struct ast_flags config_flags = { CONFIG_FLAG_NOREALTIME }; 03018 struct { 03019 unsigned int dbdir:1; 03020 unsigned int keydir:1; 03021 } found = { 0, 0 }; 03022 /* Default to true for backward compatibility */ 03023 int live_dangerously = 1; 03024 03025 if (ast_opt_override_config) { 03026 cfg = ast_config_load2(ast_config_AST_CONFIG_FILE, "" /* core, can't reload */, config_flags); 03027 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) { 03028 fprintf(stderr, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE); 03029 } 03030 } else { 03031 cfg = ast_config_load2(config, "" /* core, can't reload */, config_flags); 03032 } 03033 03034 /* init with buildtime config */ 03035 ast_copy_string(cfg_paths.config_dir, DEFAULT_CONFIG_DIR, sizeof(cfg_paths.config_dir)); 03036 ast_copy_string(cfg_paths.spool_dir, DEFAULT_SPOOL_DIR, sizeof(cfg_paths.spool_dir)); 03037 ast_copy_string(cfg_paths.module_dir, DEFAULT_MODULE_DIR, sizeof(cfg_paths.module_dir)); 03038 snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir), "%s/monitor", cfg_paths.spool_dir); 03039 ast_copy_string(cfg_paths.var_dir, DEFAULT_VAR_DIR, sizeof(cfg_paths.var_dir)); 03040 ast_copy_string(cfg_paths.data_dir, DEFAULT_DATA_DIR, sizeof(cfg_paths.data_dir)); 03041 ast_copy_string(cfg_paths.log_dir, DEFAULT_LOG_DIR, sizeof(cfg_paths.log_dir)); 03042 ast_copy_string(cfg_paths.agi_dir, DEFAULT_AGI_DIR, sizeof(cfg_paths.agi_dir)); 03043 ast_copy_string(cfg_paths.db_path, DEFAULT_DB, sizeof(cfg_paths.db_path)); 03044 ast_copy_string(cfg_paths.key_dir, DEFAULT_KEY_DIR, sizeof(cfg_paths.key_dir)); 03045 ast_copy_string(cfg_paths.pid_path, DEFAULT_PID, sizeof(cfg_paths.pid_path)); 03046 ast_copy_string(cfg_paths.socket_path, DEFAULT_SOCKET, sizeof(cfg_paths.socket_path)); 03047 ast_copy_string(cfg_paths.run_dir, DEFAULT_RUN_DIR, sizeof(cfg_paths.run_dir)); 03048 03049 ast_set_default_eid(&ast_eid_default); 03050 03051 /* no asterisk.conf? no problem, use buildtime config! */ 03052 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) { 03053 return; 03054 } 03055 03056 for (v = ast_variable_browse(cfg, "files"); v; v = v->next) { 03057 if (!strcasecmp(v->name, "astctlpermissions")) 03058 ast_copy_string(ast_config_AST_CTL_PERMISSIONS, v->value, sizeof(ast_config_AST_CTL_PERMISSIONS)); 03059 else if (!strcasecmp(v->name, "astctlowner")) 03060 ast_copy_string(ast_config_AST_CTL_OWNER, v->value, sizeof(ast_config_AST_CTL_OWNER)); 03061 else if (!strcasecmp(v->name, "astctlgroup")) 03062 ast_copy_string(ast_config_AST_CTL_GROUP, v->value, sizeof(ast_config_AST_CTL_GROUP)); 03063 else if (!strcasecmp(v->name, "astctl")) 03064 ast_copy_string(ast_config_AST_CTL, v->value, sizeof(ast_config_AST_CTL)); 03065 } 03066 03067 for (v = ast_variable_browse(cfg, "directories"); v; v = v->next) { 03068 if (!strcasecmp(v->name, "astetcdir")) { 03069 ast_copy_string(cfg_paths.config_dir, v->value, sizeof(cfg_paths.config_dir)); 03070 } else if (!strcasecmp(v->name, "astspooldir")) { 03071 ast_copy_string(cfg_paths.spool_dir, v->value, sizeof(cfg_paths.spool_dir)); 03072 snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir), "%s/monitor", v->value); 03073 } else if (!strcasecmp(v->name, "astvarlibdir")) { 03074 ast_copy_string(cfg_paths.var_dir, v->value, sizeof(cfg_paths.var_dir)); 03075 if (!found.dbdir) 03076 snprintf(cfg_paths.db_path, sizeof(cfg_paths.db_path), "%s/astdb", v->value); 03077 } else if (!strcasecmp(v->name, "astdbdir")) { 03078 snprintf(cfg_paths.db_path, sizeof(cfg_paths.db_path), "%s/astdb", v->value); 03079 found.dbdir = 1; 03080 } else if (!strcasecmp(v->name, "astdatadir")) { 03081 ast_copy_string(cfg_paths.data_dir, v->value, sizeof(cfg_paths.data_dir)); 03082 if (!found.keydir) 03083 snprintf(cfg_paths.key_dir, sizeof(cfg_paths.key_dir), "%s/keys", v->value); 03084 } else if (!strcasecmp(v->name, "astkeydir")) { 03085 snprintf(cfg_paths.key_dir, sizeof(cfg_paths.key_dir), "%s/keys", v->value); 03086 found.keydir = 1; 03087 } else if (!strcasecmp(v->name, "astlogdir")) { 03088 ast_copy_string(cfg_paths.log_dir, v->value, sizeof(cfg_paths.log_dir)); 03089 } else if (!strcasecmp(v->name, "astagidir")) { 03090 ast_copy_string(cfg_paths.agi_dir, v->value, sizeof(cfg_paths.agi_dir)); 03091 } else if (!strcasecmp(v->name, "astrundir")) { 03092 snprintf(cfg_paths.pid_path, sizeof(cfg_paths.pid_path), "%s/%s", v->value, "asterisk.pid"); 03093 snprintf(cfg_paths.socket_path, sizeof(cfg_paths.socket_path), "%s/%s", v->value, ast_config_AST_CTL); 03094 ast_copy_string(cfg_paths.run_dir, v->value, sizeof(cfg_paths.run_dir)); 03095 } else if (!strcasecmp(v->name, "astmoddir")) { 03096 ast_copy_string(cfg_paths.module_dir, v->value, sizeof(cfg_paths.module_dir)); 03097 } 03098 } 03099 03100 for (v = ast_variable_browse(cfg, "options"); v; v = v->next) { 03101 /* verbose level (-v at startup) */ 03102 if (!strcasecmp(v->name, "verbose")) { 03103 option_verbose = atoi(v->value); 03104 /* whether or not to force timestamping in CLI verbose output. (-T at startup) */ 03105 } else if (!strcasecmp(v->name, "timestamp")) { 03106 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TIMESTAMP); 03107 /* whether or not to support #exec in config files */ 03108 } else if (!strcasecmp(v->name, "execincludes")) { 03109 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_EXEC_INCLUDES); 03110 /* debug level (-d at startup) */ 03111 } else if (!strcasecmp(v->name, "debug")) { 03112 option_debug = 0; 03113 if (sscanf(v->value, "%30d", &option_debug) != 1) { 03114 option_debug = ast_true(v->value); 03115 } 03116 #if HAVE_WORKING_FORK 03117 /* Disable forking (-f at startup) */ 03118 } else if (!strcasecmp(v->name, "nofork")) { 03119 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_FORK); 03120 /* Always fork, even if verbose or debug are enabled (-F at startup) */ 03121 } else if (!strcasecmp(v->name, "alwaysfork")) { 03122 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_ALWAYS_FORK); 03123 #endif 03124 /* Run quietly (-q at startup ) */ 03125 } else if (!strcasecmp(v->name, "quiet")) { 03126 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_QUIET); 03127 /* Run as console (-c at startup, implies nofork) */ 03128 } else if (!strcasecmp(v->name, "console")) { 03129 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE); 03130 /* Run with high priority if the O/S permits (-p at startup) */ 03131 } else if (!strcasecmp(v->name, "highpriority")) { 03132 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIGH_PRIORITY); 03133 /* Initialize RSA auth keys (IAX2) (-i at startup) */ 03134 } else if (!strcasecmp(v->name, "initcrypto")) { 03135 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_INIT_KEYS); 03136 /* Disable ANSI colors for console (-c at startup) */ 03137 } else if (!strcasecmp(v->name, "nocolor")) { 03138 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_COLOR); 03139 /* Disable some usage warnings for picky people :p */ 03140 } else if (!strcasecmp(v->name, "dontwarn")) { 03141 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_DONT_WARN); 03142 /* Dump core in case of crash (-g) */ 03143 } else if (!strcasecmp(v->name, "dumpcore")) { 03144 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_DUMP_CORE); 03145 /* Cache recorded sound files to another directory during recording */ 03146 } else if (!strcasecmp(v->name, "cache_record_files")) { 03147 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CACHE_RECORD_FILES); 03148 /* Specify cache directory */ 03149 } else if (!strcasecmp(v->name, "record_cache_dir")) { 03150 ast_copy_string(record_cache_dir, v->value, AST_CACHE_DIR_LEN); 03151 /* Build transcode paths via SLINEAR, instead of directly */ 03152 } else if (!strcasecmp(v->name, "transcode_via_sln")) { 03153 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSCODE_VIA_SLIN); 03154 /* Transmit SLINEAR silence while a channel is being recorded or DTMF is being generated on a channel */ 03155 } else if (!strcasecmp(v->name, "transmit_silence_during_record") || !strcasecmp(v->name, "transmit_silence")) { 03156 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSMIT_SILENCE); 03157 /* Enable internal timing */ 03158 } else if (!strcasecmp(v->name, "internal_timing")) { 03159 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_INTERNAL_TIMING); 03160 } else if (!strcasecmp(v->name, "maxcalls")) { 03161 if ((sscanf(v->value, "%30d", &option_maxcalls) != 1) || (option_maxcalls < 0)) { 03162 option_maxcalls = 0; 03163 } 03164 } else if (!strcasecmp(v->name, "maxload")) { 03165 double test[1]; 03166 03167 if (getloadavg(test, 1) == -1) { 03168 ast_log(LOG_ERROR, "Cannot obtain load average on this system. 'maxload' option disabled.\n"); 03169 option_maxload = 0.0; 03170 } else if ((sscanf(v->value, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0)) { 03171 option_maxload = 0.0; 03172 } 03173 /* Set the maximum amount of open files */ 03174 } else if (!strcasecmp(v->name, "maxfiles")) { 03175 option_maxfiles = atoi(v->value); 03176 set_ulimit(option_maxfiles); 03177 /* What user to run as */ 03178 } else if (!strcasecmp(v->name, "runuser")) { 03179 ast_copy_string(cfg_paths.run_user, v->value, sizeof(cfg_paths.run_user)); 03180 /* What group to run as */ 03181 } else if (!strcasecmp(v->name, "rungroup")) { 03182 ast_copy_string(cfg_paths.run_group, v->value, sizeof(cfg_paths.run_group)); 03183 } else if (!strcasecmp(v->name, "systemname")) { 03184 ast_copy_string(cfg_paths.system_name, v->value, sizeof(cfg_paths.system_name)); 03185 } else if (!strcasecmp(v->name, "autosystemname")) { 03186 if (ast_true(v->value)) { 03187 if (!gethostname(hostname, sizeof(hostname) - 1)) 03188 ast_copy_string(cfg_paths.system_name, hostname, sizeof(cfg_paths.system_name)); 03189 else { 03190 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)){ 03191 ast_copy_string(cfg_paths.system_name, "localhost", sizeof(cfg_paths.system_name)); 03192 } 03193 ast_log(LOG_ERROR, "Cannot obtain hostname for this system. Using '%s' instead.\n", ast_config_AST_SYSTEM_NAME); 03194 } 03195 } 03196 } else if (!strcasecmp(v->name, "languageprefix")) { 03197 ast_language_is_prefix = ast_true(v->value); 03198 } else if (!strcasecmp(v->name, "defaultlanguage")) { 03199 ast_copy_string(defaultlanguage, v->value, MAX_LANGUAGE); 03200 } else if (!strcasecmp(v->name, "lockmode")) { 03201 if (!strcasecmp(v->value, "lockfile")) { 03202 ast_set_lock_type(AST_LOCK_TYPE_LOCKFILE); 03203 } else if (!strcasecmp(v->value, "flock")) { 03204 ast_set_lock_type(AST_LOCK_TYPE_FLOCK); 03205 } else { 03206 ast_log(LOG_WARNING, "'%s' is not a valid setting for the lockmode option, " 03207 "defaulting to 'lockfile'\n", v->value); 03208 ast_set_lock_type(AST_LOCK_TYPE_LOCKFILE); 03209 } 03210 #if defined(HAVE_SYSINFO) 03211 } else if (!strcasecmp(v->name, "minmemfree")) { 03212 /* specify the minimum amount of free memory to retain. Asterisk should stop accepting new calls 03213 * if the amount of free memory falls below this watermark */ 03214 if ((sscanf(v->value, "%30ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) { 03215 option_minmemfree = 0; 03216 } 03217 #endif 03218 } else if (!strcasecmp(v->name, "entityid")) { 03219 struct ast_eid tmp_eid; 03220 if (!ast_str_to_eid(&tmp_eid, v->value)) { 03221 ast_verbose("Successfully set global EID to '%s'\n", v->value); 03222 ast_eid_default = tmp_eid; 03223 } else 03224 ast_verbose("Invalid Entity ID '%s' provided\n", v->value); 03225 } else if (!strcasecmp(v->name, "lightbackground")) { 03226 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_LIGHT_BACKGROUND); 03227 } else if (!strcasecmp(v->name, "forceblackbackground")) { 03228 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_FORCE_BLACK_BACKGROUND); 03229 } else if (!strcasecmp(v->name, "hideconnect")) { 03230 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIDE_CONSOLE_CONNECT); 03231 } else if (!strcasecmp(v->name, "lockconfdir")) { 03232 ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_LOCK_CONFIG_DIR); 03233 } else if (!strcasecmp(v->name, "live_dangerously")) { 03234 live_dangerously = ast_true(v->value); 03235 } 03236 } 03237 if (!ast_opt_remote) { 03238 pbx_live_dangerously(live_dangerously); 03239 } 03240 for (v = ast_variable_browse(cfg, "compat"); v; v = v->next) { 03241 float version; 03242 if (sscanf(v->value, "%30f", &version) != 1) { 03243 fprintf(stderr, "Compatibility version for option '%s' is not a number: '%s'\n", v->name, v->value); 03244 continue; 03245 } 03246 if (!strcasecmp(v->name, "app_set")) { 03247 ast_set2_flag(&ast_compat, version < 1.5 ? 1 : 0, AST_COMPAT_APP_SET); 03248 } else if (!strcasecmp(v->name, "res_agi")) { 03249 ast_set2_flag(&ast_compat, version < 1.5 ? 1 : 0, AST_COMPAT_DELIM_RES_AGI); 03250 } else if (!strcasecmp(v->name, "pbx_realtime")) { 03251 ast_set2_flag(&ast_compat, version < 1.5 ? 1 : 0, AST_COMPAT_DELIM_PBX_REALTIME); 03252 } 03253 } 03254 ast_config_destroy(cfg); 03255 }
| int ast_register_atexit | ( | void(*)(void) | func | ) |
Register a function to be executed before Asterisk exits.
| func | The callback function to use. |
| 0 | on success. | |
| -1 | on error. |
Definition at line 976 of file asterisk.c.
References __ast_unregister_atexit(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_atexit::func, and ast_atexit::list.
Referenced by __ast_mm_init_phase_2(), __init_manager(), ast_aoc_cli_init(), ast_builtins_init(), ast_cc_init(), ast_cdr_engine_init(), ast_cel_engine_init(), ast_channels_init(), ast_data_init(), ast_event_init(), ast_features_init(), ast_file_init(), ast_http_init(), ast_image_init(), ast_indications_init(), ast_pbx_init(), ast_stun_init(), ast_test_init(), ast_timing_init(), ast_tps_init(), ast_udptl_init(), ast_utils_init(), astdb_init(), astobj2_init(), dnsmgr_init(), do_reload(), init_framer(), load_module(), load_pbx(), main(), and register_config_cli().
00977 { 00978 struct ast_atexit *ae; 00979 00980 ae = ast_calloc(1, sizeof(*ae)); 00981 if (!ae) { 00982 return -1; 00983 } 00984 ae->func = func; 00985 00986 AST_LIST_LOCK(&atexits); 00987 __ast_unregister_atexit(func); 00988 AST_LIST_INSERT_HEAD(&atexits, ae, list); 00989 AST_LIST_UNLOCK(&atexits); 00990 00991 return 0; 00992 }
| void ast_register_file_version | ( | const char * | file, | |
| const char * | version | |||
| ) |
Register the version of a source code file with the core.
| file | the source file name | |
| version | the version string (typically a SVN revision keyword string) |
This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to register a file with the core.
Definition at line 317 of file asterisk.c.
References ast_calloc, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdupa, ast_strip(), and ast_strip_quoted().
00318 { 00319 struct file_version *new; 00320 char *work; 00321 size_t version_length; 00322 00323 work = ast_strdupa(version); 00324 work = ast_strip(ast_strip_quoted(work, "$", "$")); 00325 version_length = strlen(work) + 1; 00326 00327 if (!(new = ast_calloc(1, sizeof(*new) + version_length))) 00328 return; 00329 00330 new->file = file; 00331 new->version = (char *) new + sizeof(*new); 00332 memcpy(new->version, work, version_length); 00333 AST_RWLIST_WRLOCK(&file_versions); 00334 AST_RWLIST_INSERT_HEAD(&file_versions, new, list); 00335 AST_RWLIST_UNLOCK(&file_versions); 00336 }
| void ast_register_thread | ( | char * | name | ) |
Definition at line 400 of file asterisk.c.
References ast_assert, ast_calloc, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and multi_thread_safe.
Referenced by dummy_start().
00401 { 00402 struct thread_list_t *new = ast_calloc(1, sizeof(*new)); 00403 00404 if (!new) 00405 return; 00406 00407 ast_assert(multi_thread_safe); 00408 new->id = pthread_self(); 00409 new->name = name; /* steal the allocated memory for the thread name */ 00410 AST_RWLIST_WRLOCK(&thread_list); 00411 AST_RWLIST_INSERT_HEAD(&thread_list, new, list); 00412 AST_RWLIST_UNLOCK(&thread_list); 00413 }
| static void ast_remotecontrol | ( | char * | data | ) | [static] |
Definition at line 2820 of file asterisk.c.
References __remote_quit_handler(), ast_alloca, ast_el_initialize(), ast_el_read_char(), ast_el_read_history(), ast_log(), ast_opt_exec, ast_opt_mute, ast_poll, ast_strlen_zero(), ast_verbose, el, el_hist, errno, fdsend(), hostname, LOG_ERROR, LOG_WARNING, prefix, remoteconsolehandler(), remotehostname, sig_flags, and version.
Referenced by main().
02821 { 02822 char buf[80]; 02823 int res; 02824 char filename[80] = ""; 02825 char *hostname; 02826 char *cpid; 02827 char *version; 02828 int pid; 02829 char *stringp = NULL; 02830 02831 char *ebuf; 02832 int num = 0; 02833 02834 memset(&sig_flags, 0, sizeof(sig_flags)); 02835 signal(SIGINT, __remote_quit_handler); 02836 signal(SIGTERM, __remote_quit_handler); 02837 signal(SIGHUP, __remote_quit_handler); 02838 02839 if (read(ast_consock, buf, sizeof(buf)) < 0) { 02840 ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno)); 02841 return; 02842 } 02843 if (data) { 02844 char prefix[] = "cli quit after "; 02845 char *tmp = ast_alloca(strlen(data) + strlen(prefix) + 1); 02846 sprintf(tmp, "%s%s", prefix, data); 02847 if (write(ast_consock, tmp, strlen(tmp) + 1) < 0) { 02848 ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno)); 02849 if (sig_flags.need_quit || sig_flags.need_quit_handler) { 02850 return; 02851 } 02852 } 02853 } 02854 stringp = buf; 02855 hostname = strsep(&stringp, "/"); 02856 cpid = strsep(&stringp, "/"); 02857 version = strsep(&stringp, "\n"); 02858 if (!version) 02859 version = "<Version Unknown>"; 02860 stringp = hostname; 02861 strsep(&stringp, "."); 02862 if (cpid) 02863 pid = atoi(cpid); 02864 else 02865 pid = -1; 02866 if (!data) { 02867 char tmp[80]; 02868 snprintf(tmp, sizeof(tmp), "core set verbose atleast %d", option_verbose); 02869 fdsend(ast_consock, tmp); 02870 snprintf(tmp, sizeof(tmp), "core set debug atleast %d", option_debug); 02871 fdsend(ast_consock, tmp); 02872 if (!ast_opt_mute) 02873 fdsend(ast_consock, "logger mute silent"); 02874 else 02875 printf("log and verbose output currently muted ('logger mute' to unmute)\n"); 02876 } 02877 02878 if (ast_opt_exec && data) { /* hack to print output then exit if asterisk -rx is used */ 02879 struct pollfd fds; 02880 fds.fd = ast_consock; 02881 fds.events = POLLIN; 02882 fds.revents = 0; 02883 while (ast_poll(&fds, 1, 60000) > 0) { 02884 char buffer[512] = "", *curline = buffer, *nextline; 02885 int not_written = 1; 02886 02887 if (sig_flags.need_quit || sig_flags.need_quit_handler) { 02888 break; 02889 } 02890 02891 if (read(ast_consock, buffer, sizeof(buffer) - 1) <= 0) { 02892 break; 02893 } 02894 02895 do { 02896 if ((nextline = strchr(curline, '\n'))) { 02897 nextline++; 02898 } else { 02899 nextline = strchr(curline, '\0'); 02900 } 02901 02902 /* Skip verbose lines */ 02903 if (*curline != 127) { 02904 not_written = 0; 02905 if (write(STDOUT_FILENO, curline, nextline - curline) < 0) { 02906 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 02907 } 02908 } 02909 curline = nextline; 02910 } while (!ast_strlen_zero(curline)); 02911 02912 /* No non-verbose output in 60 seconds. */ 02913 if (not_written) { 02914 break; 02915 } 02916 } 02917 return; 02918 } 02919 02920 ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid); 02921 remotehostname = hostname; 02922 if (getenv("HOME")) 02923 snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); 02924 if (el_hist == NULL || el == NULL) 02925 ast_el_initialize(); 02926 02927 el_set(el, EL_GETCFN, ast_el_read_char); 02928 02929 if (!ast_strlen_zero(filename)) 02930 ast_el_read_history(filename); 02931 02932 for (;;) { 02933 ebuf = (char *)el_gets(el, &num); 02934 02935 if (sig_flags.need_quit || sig_flags.need_quit_handler) { 02936 break; 02937 } 02938 02939 if (!ebuf && write(1, "", 1) < 0) 02940 break; 02941 02942 if (!ast_strlen_zero(ebuf)) { 02943 if (ebuf[strlen(ebuf)-1] == '\n') 02944 ebuf[strlen(ebuf)-1] = '\0'; 02945 if (!remoteconsolehandler(ebuf)) { 02946 /* Strip preamble from output */ 02947 char *temp; 02948 for (temp = ebuf; *temp; temp++) { 02949 if (*temp == 127) { 02950 memmove(temp, temp + 1, strlen(temp)); 02951 temp--; 02952 } 02953 } 02954 res = write(ast_consock, ebuf, strlen(ebuf) + 1); 02955 if (res < 1) { 02956 ast_log(LOG_WARNING, "Unable to write: %s\n", strerror(errno)); 02957 break; 02958 } 02959 } 02960 } 02961 } 02962 printf("\nDisconnected from Asterisk server\n"); 02963 }
| void ast_replace_sigchld | ( | void | ) |
Replace the SIGCHLD handler.
Normally, Asterisk has a SIGCHLD handler that is cleaning up all zombie processes from forking elsewhere in Asterisk. However, if you want to wait*() on the process to retrieve information about it's exit status, then this signal handler needs to be temporarily replaced.
Code that executes this function *must* call ast_unreplace_sigchld() after it is finished doing the wait*().
Definition at line 1033 of file asterisk.c.
References ast_mutex_lock, ast_mutex_unlock, null_sig_handler, safe_system_level, safe_system_lock, and safe_system_prev_handler.
Referenced by ast_safe_fork(), and ast_safe_system().
01034 { 01035 unsigned int level; 01036 01037 ast_mutex_lock(&safe_system_lock); 01038 level = safe_system_level++; 01039 01040 /* only replace the handler if it has not already been done */ 01041 if (level == 0) { 01042 sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler); 01043 } 01044 01045 ast_mutex_unlock(&safe_system_lock); 01046 }
| static void ast_run_atexits | ( | void | ) | [static] |
Definition at line 948 of file asterisk.c.
References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_atexit::func, and ast_atexit::list.
Referenced by really_quit().
00949 { 00950 struct ast_atexit *ae; 00951 00952 AST_LIST_LOCK(&atexits); 00953 while ((ae = AST_LIST_REMOVE_HEAD(&atexits, list))) { 00954 if (ae->func) { 00955 ae->func(); 00956 } 00957 ast_free(ae); 00958 } 00959 AST_LIST_UNLOCK(&atexits); 00960 }
| int ast_safe_system | ( | const char * | s | ) |
Safely spawn an external program while closing file descriptors.
Definition at line 1063 of file asterisk.c.
References ast_close_fds_above_n(), ast_log(), ast_opt_high_priority, ast_replace_sigchld(), ast_set_priority(), ast_unreplace_sigchld(), errno, LOG_WARNING, status, WEXITSTATUS, and WIFEXITED.
Referenced by add_email_attachment(), alarmreceiver_exec(), ast_monitor_stop(), consolehandler(), mixmonitor_thread(), notify_message(), process_text_line(), remoteconsolehandler(), rotate_file(), run_externnotify(), sendmail(), sendpage(), system_exec_helper(), and vm_change_password_shell().
01064 { 01065 pid_t pid; 01066 int res; 01067 struct rusage rusage; 01068 int status; 01069 01070 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) 01071 ast_replace_sigchld(); 01072 01073 #ifdef HAVE_WORKING_FORK 01074 pid = fork(); 01075 #else 01076 pid = vfork(); 01077 #endif 01078 01079 if (pid == 0) { 01080 #ifdef HAVE_CAP 01081 cap_t cap = cap_from_text("cap_net_admin-eip"); 01082 01083 if (cap_set_proc(cap)) { 01084 /* Careful with order! Logging cannot happen after we close FDs */ 01085 ast_log(LOG_WARNING, "Unable to remove capabilities.\n"); 01086 } 01087 cap_free(cap); 01088 #endif 01089 #ifdef HAVE_WORKING_FORK 01090 if (ast_opt_high_priority) 01091 ast_set_priority(0); 01092 /* Close file descriptors and launch system command */ 01093 ast_close_fds_above_n(STDERR_FILENO); 01094 #endif 01095 execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL); 01096 _exit(1); 01097 } else if (pid > 0) { 01098 for (;;) { 01099 res = wait4(pid, &status, 0, &rusage); 01100 if (res > -1) { 01101 res = WIFEXITED(status) ? WEXITSTATUS(status) : -1; 01102 break; 01103 } else if (errno != EINTR) 01104 break; 01105 } 01106 } else { 01107 ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno)); 01108 res = -1; 01109 } 01110 01111 ast_unreplace_sigchld(); 01112 #else /* !defined(HAVE_WORKING_FORK) && !defined(HAVE_WORKING_VFORK) */ 01113 res = -1; 01114 #endif 01115 01116 return res; 01117 }
| int ast_set_priority | ( | int | ) |
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing.
Provided by asterisk.c
Definition at line 1636 of file asterisk.c.
References ast_log(), ast_verbose, LOG_WARNING, sched_setscheduler, and setpriority.
Referenced by app_exec(), ast_safe_system(), canary_thread(), icesencode(), launch_script(), main(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), and spawn_ras().
01637 { 01638 struct sched_param sched; 01639 memset(&sched, 0, sizeof(sched)); 01640 #ifdef __linux__ 01641 if (pri) { 01642 sched.sched_priority = 10; 01643 if (sched_setscheduler(0, SCHED_RR, &sched)) { 01644 ast_log(LOG_WARNING, "Unable to set high priority\n"); 01645 return -1; 01646 } else 01647 if (option_verbose) 01648 ast_verbose("Set to realtime thread\n"); 01649 } else { 01650 sched.sched_priority = 0; 01651 /* According to the manpage, these parameters can never fail. */ 01652 sched_setscheduler(0, SCHED_OTHER, &sched); 01653 } 01654 #else 01655 if (pri) { 01656 if (setpriority(PRIO_PROCESS, 0, -10) == -1) { 01657 ast_log(LOG_WARNING, "Unable to set high priority\n"); 01658 return -1; 01659 } else 01660 if (option_verbose) 01661 ast_verbose("Set to high priority\n"); 01662 } else { 01663 /* According to the manpage, these parameters can never fail. */ 01664 setpriority(PRIO_PROCESS, 0, 0); 01665 } 01666 #endif 01667 return 0; 01668 }
| static int ast_tryconnect | ( | void | ) | [static] |
Definition at line 1520 of file asterisk.c.
References AF_LOCAL, ast_config_AST_SOCKET, ast_copy_string(), and errno.
Referenced by ast_el_read_char(), and main().
01521 { 01522 struct sockaddr_un sunaddr; 01523 int res; 01524 ast_consock = socket(PF_LOCAL, SOCK_STREAM, 0); 01525 if (ast_consock < 0) { 01526 fprintf(stderr, "Unable to create socket: %s\n", strerror(errno)); 01527 return 0; 01528 } 01529 memset(&sunaddr, 0, sizeof(sunaddr)); 01530 sunaddr.sun_family = AF_LOCAL; 01531 ast_copy_string(sunaddr.sun_path, ast_config_AST_SOCKET, sizeof(sunaddr.sun_path)); 01532 res = connect(ast_consock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)); 01533 if (res) { 01534 close(ast_consock); 01535 ast_consock = -1; 01536 return 0; 01537 } else 01538 return 1; 01539 }
| void ast_unregister_atexit | ( | void(*)(void) | func | ) |
Unregister a function registered with ast_register_atexit().
| func | The callback function to unregister. |
Definition at line 994 of file asterisk.c.
References __ast_unregister_atexit(), AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_atexit::func.
Referenced by do_reload(), and unload_module().
00995 { 00996 AST_LIST_LOCK(&atexits); 00997 __ast_unregister_atexit(func); 00998 AST_LIST_UNLOCK(&atexits); 00999 }
| void ast_unregister_file_version | ( | const char * | file | ) |
Unregister a source code file from the core.
| file | the source file name |
This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to automatically unregister the file when the module is unloaded.
Definition at line 338 of file asterisk.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, file_version::file, and ast_atexit::list.
00339 { 00340 struct file_version *find; 00341 00342 AST_RWLIST_WRLOCK(&file_versions); 00343 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) { 00344 if (!strcasecmp(find->file, file)) { 00345 AST_RWLIST_REMOVE_CURRENT(list); 00346 break; 00347 } 00348 } 00349 AST_RWLIST_TRAVERSE_SAFE_END; 00350 AST_RWLIST_UNLOCK(&file_versions); 00351 00352 if (find) 00353 ast_free(find); 00354 }
| void ast_unregister_thread | ( | void * | id | ) |
Definition at line 415 of file asterisk.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, thread_list_t::id, ast_atexit::list, and thread_list_t::name.
Referenced by dummy_start().
00416 { 00417 struct thread_list_t *x; 00418 00419 AST_RWLIST_WRLOCK(&thread_list); 00420 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) { 00421 if ((void *) x->id == id) { 00422 AST_RWLIST_REMOVE_CURRENT(list); 00423 break; 00424 } 00425 } 00426 AST_RWLIST_TRAVERSE_SAFE_END; 00427 AST_RWLIST_UNLOCK(&thread_list); 00428 if (x) { 00429 ast_free(x->name); 00430 ast_free(x); 00431 } 00432 }
| void ast_unreplace_sigchld | ( | void | ) |
Restore the SIGCHLD handler.
This function is called after a call to ast_replace_sigchld. It restores the SIGCHLD handler that cleans up any zombie processes.
Definition at line 1048 of file asterisk.c.
References ast_mutex_lock, ast_mutex_unlock, safe_system_level, safe_system_lock, and safe_system_prev_handler.
Referenced by ast_safe_fork_cleanup(), and ast_safe_system().
01049 { 01050 unsigned int level; 01051 01052 ast_mutex_lock(&safe_system_lock); 01053 level = --safe_system_level; 01054 01055 /* only restore the handler if we are the last one */ 01056 if (level == 0) { 01057 sigaction(SIGCHLD, &safe_system_prev_handler, NULL); 01058 } 01059 01060 ast_mutex_unlock(&safe_system_lock); 01061 }
| static int can_safely_quit | ( | shutdown_nice_t | niceness, | |
| int | restart | |||
| ) | [static] |
Definition at line 1682 of file asterisk.c.
References ast_begin_shutdown(), ast_cdr_engine_term(), ast_mutex_lock, ast_mutex_unlock, ast_opt_console, ast_undestroyed_channels(), ast_verbose, NOT_SHUTTING_DOWN, safe_system_lock, SHUTDOWN_NICE, SHUTDOWN_NORMAL, SHUTDOWN_REALLY_NICE, SHUTTING_DOWN, and shuttingdown.
Referenced by quit_handler().
01683 { 01684 /* Check if someone else isn't already doing this. */ 01685 ast_mutex_lock(&safe_system_lock); 01686 if (shuttingdown != NOT_SHUTTING_DOWN && niceness >= shuttingdown) { 01687 /* Already in progress and other request was less nice. */ 01688 ast_mutex_unlock(&safe_system_lock); 01689 ast_verbose("Ignoring asterisk %s request, already in progress.\n", restart ? "restart" : "shutdown"); 01690 return 0; 01691 } 01692 shuttingdown = niceness; 01693 ast_mutex_unlock(&safe_system_lock); 01694 01695 /* Try to get as many CDRs as possible submitted to the backend engines 01696 * (if in batch mode). really_quit happens to call it again when running 01697 * the atexit handlers, otherwise this would be a bit early. */ 01698 ast_cdr_engine_term(); 01699 01700 if (niceness == SHUTDOWN_NORMAL) { 01701 time_t s, e; 01702 /* Begin shutdown routine, hanging up active channels */ 01703 ast_begin_shutdown(1); 01704 if (option_verbose && ast_opt_console) { 01705 ast_verbose("Beginning asterisk %s....\n", restart ? "restart" : "shutdown"); 01706 } 01707 time(&s); 01708 for (;;) { 01709 time(&e); 01710 /* Wait up to 15 seconds for all channels to go away */ 01711 if ((e - s) > 15 || !ast_undestroyed_channels() || shuttingdown != niceness) { 01712 break; 01713 } 01714 /* Sleep 1/10 of a second */ 01715 usleep(100000); 01716 } 01717 } else if (niceness >= SHUTDOWN_NICE) { 01718 if (niceness != SHUTDOWN_REALLY_NICE) { 01719 ast_begin_shutdown(0); 01720 } 01721 if (option_verbose && ast_opt_console) { 01722 ast_verbose("Waiting for inactivity to perform %s...\n", restart ? "restart" : "halt"); 01723 } 01724 for (;;) { 01725 if (!ast_undestroyed_channels() || shuttingdown != niceness) { 01726 break; 01727 } 01728 sleep(1); 01729 } 01730 } 01731 01732 /* Re-acquire lock and check if someone changed the niceness, in which 01733 * case someone else has taken over the shutdown. */ 01734 ast_mutex_lock(&safe_system_lock); 01735 if (shuttingdown != niceness) { 01736 if (shuttingdown == NOT_SHUTTING_DOWN && option_verbose && ast_opt_console) { 01737 ast_verbose("Asterisk %s cancelled.\n", restart ? "restart" : "shutdown"); 01738 } 01739 ast_mutex_unlock(&safe_system_lock); 01740 return 0; 01741 } 01742 shuttingdown = SHUTTING_DOWN; 01743 ast_mutex_unlock(&safe_system_lock); 01744 01745 return 1; 01746 }
| static void canary_exit | ( | void | ) | [static] |
Definition at line 3312 of file asterisk.c.
References canary_pid.
Referenced by main().
03313 { 03314 if (canary_pid > 0) 03315 kill(canary_pid, SIGKILL); 03316 }
| static void* canary_thread | ( | void * | unused | ) | [static] |
Definition at line 3283 of file asterisk.c.
References ast_log(), ast_set_priority(), ast_tvnow(), canary_filename, and LOG_WARNING.
Referenced by main().
03284 { 03285 struct stat canary_stat; 03286 struct timeval now; 03287 03288 /* Give the canary time to sing */ 03289 sleep(120); 03290 03291 for (;;) { 03292 now = ast_tvnow(); 03293 if (stat(canary_filename, &canary_stat) || now.tv_sec > canary_stat.st_mtime + 60) { 03294 ast_log(LOG_WARNING, 03295 "The canary is no more. He has ceased to be! " 03296 "He's expired and gone to meet his maker! " 03297 "He's a stiff! Bereft of life, he rests in peace. " 03298 "His metabolic processes are now history! He's off the twig! " 03299 "He's kicked the bucket. He's shuffled off his mortal coil, " 03300 "run down the curtain, and joined the bleeding choir invisible!! " 03301 "THIS is an EX-CANARY. (Reducing priority)\n"); 03302 ast_set_priority(0); 03303 pthread_exit(NULL); 03304 } 03305 03306 /* Check the canary once a minute */ 03307 sleep(60); 03308 } 03309 }
| static char* cli_complete | ( | EditLine * | editline, | |
| int | ch | |||
| ) | [static] |
Definition at line 2627 of file asterisk.c.
References AST_CLI_COMPLETE_EOF, ast_cli_completion_matches(), ast_cli_display_match_list(), ast_el_strtoarr(), ast_free, ast_malloc, ast_opt_remote, ast_realloc, and fdsend().
Referenced by ast_el_initialize().
02628 { 02629 int len = 0; 02630 char *ptr; 02631 int nummatches = 0; 02632 char **matches; 02633 int retval = CC_ERROR; 02634 char buf[2048], savechr; 02635 int res; 02636 02637 LineInfo *lf = (LineInfo *)el_line(editline); 02638 02639 savechr = *(char *)lf->cursor; 02640 *(char *)lf->cursor = '\0'; 02641 ptr = (char *)lf->cursor; 02642 if (ptr) { 02643 while (ptr > lf->buffer) { 02644 if (isspace(*ptr)) { 02645 ptr++; 02646 break; 02647 } 02648 ptr--; 02649 } 02650 } 02651 02652 len = lf->cursor - ptr; 02653 02654 if (ast_opt_remote) { 02655 snprintf(buf, sizeof(buf), "_COMMAND NUMMATCHES \"%s\" \"%s\"", lf->buffer, ptr); 02656 fdsend(ast_consock, buf); 02657 if ((res = read(ast_consock, buf, sizeof(buf) - 1)) < 0) { 02658 return (char*)(CC_ERROR); 02659 } 02660 buf[res] = '\0'; 02661 nummatches = atoi(buf); 02662 02663 if (nummatches > 0) { 02664 char *mbuf; 02665 char *new_mbuf; 02666 int mlen = 0, maxmbuf = 2048; 02667 02668 /* Start with a 2048 byte buffer */ 02669 if (!(mbuf = ast_malloc(maxmbuf))) { 02670 lf->cursor[0] = savechr; 02671 return (char *)(CC_ERROR); 02672 } 02673 snprintf(buf, sizeof(buf), "_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr); 02674 fdsend(ast_consock, buf); 02675 res = 0; 02676 mbuf[0] = '\0'; 02677 while (!strstr(mbuf, AST_CLI_COMPLETE_EOF) && res != -1) { 02678 if (mlen + 1024 > maxmbuf) { 02679 /* Every step increment buffer 1024 bytes */ 02680 maxmbuf += 1024; 02681 new_mbuf = ast_realloc(mbuf, maxmbuf); 02682 if (!new_mbuf) { 02683 ast_free(mbuf); 02684 lf->cursor[0] = savechr; 02685 return (char *)(CC_ERROR); 02686 } 02687 mbuf = new_mbuf; 02688 } 02689 /* Only read 1024 bytes at a time */ 02690 res = read(ast_consock, mbuf + mlen, 1024); 02691 if (res > 0) 02692 mlen += res; 02693 } 02694 mbuf[mlen] = '\0'; 02695 02696 matches = ast_el_strtoarr(mbuf); 02697 ast_free(mbuf); 02698 } else 02699 matches = (char **) NULL; 02700 } else { 02701 char **p, *oldbuf=NULL; 02702 nummatches = 0; 02703 matches = ast_cli_completion_matches((char *)lf->buffer,ptr); 02704 for (p = matches; p && *p; p++) { 02705 if (!oldbuf || strcmp(*p,oldbuf)) 02706 nummatches++; 02707 oldbuf = *p; 02708 } 02709 } 02710 02711 if (matches) { 02712 int i; 02713 int matches_num, maxlen, match_len; 02714 02715 if (matches[0][0] != '\0') { 02716 el_deletestr(editline, (int) len); 02717 el_insertstr(editline, matches[0]); 02718 retval = CC_REFRESH; 02719 } 02720 02721 if (nummatches == 1) { 02722 /* Found an exact match */ 02723 el_insertstr(editline, " "); 02724 retval = CC_REFRESH; 02725 } else { 02726 /* Must be more than one match */ 02727 for (i = 1, maxlen = 0; matches[i]; i++) { 02728 match_len = strlen(matches[i]); 02729 if (match_len > maxlen) 02730 maxlen = match_len; 02731 } 02732 matches_num = i - 1; 02733 if (matches_num >1) { 02734 fprintf(stdout, "\n"); 02735 ast_cli_display_match_list(matches, nummatches, maxlen); 02736 retval = CC_REDISPLAY; 02737 } else { 02738 el_insertstr(editline," "); 02739 retval = CC_REFRESH; 02740 } 02741 } 02742 for (i = 0; matches[i]; i++) 02743 ast_free(matches[i]); 02744 ast_free(matches); 02745 } 02746 02747 lf->cursor[0] = savechr; 02748 02749 return (char *)(long)retval; 02750 }
| static char* cli_prompt | ( | EditLine * | editline | ) | [static] |
Definition at line 2382 of file asterisk.c.
References ast_config_AST_SYSTEM_NAME, ast_localtime(), ast_opt_remote, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_str_set(), ast_strftime(), ast_tvnow(), ASTERISK_PROMPT, ASTERISK_PROMPT2, COLOR_BLACK, COLOR_WHITE, hostname, ast_atexit::list, MAXHOSTNAMELEN, remotehostname, and term_color_code().
Referenced by ast_el_initialize().
02383 { 02384 char tmp[100]; 02385 char *pfmt; 02386 int color_used = 0; 02387 static int cli_prompt_changes = 0; 02388 char term_code[20]; 02389 struct passwd *pw; 02390 struct group *gr; 02391 02392 if (prompt == NULL) { 02393 prompt = ast_str_create(100); 02394 } else if (!cli_prompt_changes) { 02395 return ast_str_buffer(prompt); 02396 } else { 02397 ast_str_reset(prompt); 02398 } 02399 02400 if ((pfmt = getenv("ASTERISK_PROMPT"))) { 02401 char *t = pfmt; 02402 struct timeval ts = ast_tvnow(); 02403 while (*t != '\0') { 02404 if (*t == '%') { 02405 char hostname[MAXHOSTNAMELEN] = ""; 02406 int i, which; 02407 struct ast_tm tm = { 0, }; 02408 int fgcolor = COLOR_WHITE, bgcolor = COLOR_BLACK; 02409 02410 t++; 02411 switch (*t) { 02412 case 'C': /* color */ 02413 t++; 02414 if (sscanf(t, "%30d;%30d%n", &fgcolor, &bgcolor, &i) == 2) { 02415 ast_str_append(&prompt, 0, "%s", term_color_code(term_code, fgcolor, bgcolor, sizeof(term_code))); 02416 t += i - 1; 02417 } else if (sscanf(t, "%30d%n", &fgcolor, &i) == 1) { 02418 ast_str_append(&prompt, 0, "%s", term_color_code(term_code, fgcolor, 0, sizeof(term_code))); 02419 t += i - 1; 02420 } 02421 02422 /* If the color has been reset correctly, then there's no need to reset it later */ 02423 color_used = ((fgcolor == COLOR_WHITE) && (bgcolor == COLOR_BLACK)) ? 0 : 1; 02424 break; 02425 case 'd': /* date */ 02426 if (ast_localtime(&ts, &tm, NULL)) { 02427 ast_strftime(tmp, sizeof(tmp), "%Y-%m-%d", &tm); 02428 ast_str_append(&prompt, 0, "%s", tmp); 02429 cli_prompt_changes++; 02430 } 02431 break; 02432 case 'g': /* group */ 02433 if ((gr = getgrgid(getgid()))) { 02434 ast_str_append(&prompt, 0, "%s", gr->gr_name); 02435 } 02436 break; 02437 case 'h': /* hostname */ 02438 if (!gethostname(hostname, sizeof(hostname) - 1)) { 02439 ast_str_append(&prompt, 0, "%s", hostname); 02440 } else { 02441 ast_str_append(&prompt, 0, "%s", "localhost"); 02442 } 02443 break; 02444 case 'H': /* short hostname */ 02445 if (!gethostname(hostname, sizeof(hostname) - 1)) { 02446 char *dotptr; 02447 if ((dotptr = strchr(hostname, '.'))) { 02448 *dotptr = '\0'; 02449 } 02450 ast_str_append(&prompt, 0, "%s", hostname); 02451 } else { 02452 ast_str_append(&prompt, 0, "%s", "localhost"); 02453 } 02454 break; 02455 #ifdef HAVE_GETLOADAVG 02456 case 'l': /* load avg */ 02457 t++; 02458 if (sscanf(t, "%30d", &which) == 1 && which > 0 && which <= 3) { 02459 double list[3]; 02460 getloadavg(list, 3); 02461 ast_str_append(&prompt, 0, "%.2f", list[which - 1]); 02462 cli_prompt_changes++; 02463 } 02464 break; 02465 #endif 02466 case 's': /* Asterisk system name (from asterisk.conf) */ 02467 ast_str_append(&prompt, 0, "%s", ast_config_AST_SYSTEM_NAME); 02468 break; 02469 case 't': /* time */ 02470 if (ast_localtime(&ts, &tm, NULL)) { 02471 ast_strftime(tmp, sizeof(tmp), "%H:%M:%S", &tm); 02472 ast_str_append(&prompt, 0, "%s", tmp); 02473 cli_prompt_changes++; 02474 } 02475 break; 02476 case 'u': /* username */ 02477 if ((pw = getpwuid(getuid()))) { 02478 ast_str_append(&prompt, 0, "%s", pw->pw_name); 02479 } 02480 break; 02481 case '#': /* process console or remote? */ 02482 ast_str_append(&prompt, 0, "%c", ast_opt_remote ? '>' : '#'); 02483 break; 02484 case '%': /* literal % */ 02485 ast_str_append(&prompt, 0, "%c", '%'); 02486 break; 02487 case '\0': /* % is last character - prevent bug */ 02488 t--; 02489 break; 02490 } 02491 } else { 02492 ast_str_append(&prompt, 0, "%c", *t); 02493 } 02494 t++; 02495 } 02496 if (color_used) { 02497 /* Force colors back to normal at end */ 02498 ast_str_append(&prompt, 0, "%s", term_color_code(term_code, 0, 0, sizeof(term_code))); 02499 } 02500 } else if (remotehostname) { 02501 ast_str_set(&prompt, 0, ASTERISK_PROMPT2, remotehostname); 02502 } else { 02503 ast_str_set(&prompt, 0, "%s", ASTERISK_PROMPT); 02504 } 02505 02506 return ast_str_buffer(prompt); 02507 }
| static void console_verboser | ( | const char * | s | ) | [static] |
Definition at line 1884 of file asterisk.c.
References ast_opt_console, AST_PTHREADT_NULL, consolethread, fix_header(), VERBOSE_PREFIX_1, VERBOSE_PREFIX_2, VERBOSE_PREFIX_3, and VERBOSE_PREFIX_4.
Referenced by print_intro_message().
01885 { 01886 char tmp[80]; 01887 const char *c = NULL; 01888 01889 if ((c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_4)) || 01890 (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_3)) || 01891 (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_2)) || 01892 (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_1))) { 01893 fputs(tmp, stdout); 01894 fputs(c, stdout); 01895 } else { 01896 if (*s == 127) { 01897 s++; 01898 } 01899 fputs(s, stdout); 01900 } 01901 01902 fflush(stdout); 01903 01904 /* Wake up a poll()ing console */ 01905 if (ast_opt_console && consolethread != AST_PTHREADT_NULL) 01906 pthread_kill(consolethread, SIGURG); 01907 }
| static void consolehandler | ( | char * | s | ) | [static] |
Definition at line 1919 of file asterisk.c.
References ast_all_zeros(), ast_cli_command, ast_el_add_history(), ast_safe_system(), and term_end().
Referenced by main().
01920 { 01921 printf("%s", term_end()); 01922 fflush(stdout); 01923 01924 /* Called when readline data is available */ 01925 if (!ast_all_zeros(s)) 01926 ast_el_add_history(s); 01927 /* The real handler for bang */ 01928 if (s[0] == '!') { 01929 if (s[1]) 01930 ast_safe_system(s+1); 01931 else 01932 ast_safe_system(getenv("SHELL") ? getenv("SHELL") : "/bin/sh"); 01933 } else 01934 ast_cli_command(STDOUT_FILENO, s); 01935 }
| static void destroy_match_list | ( | char ** | match_list, | |
| int | matches | |||
| ) | [static] |
| static void env_init | ( | void | ) | [static] |
Definition at line 3346 of file asterisk.c.
References ast_build_date, ast_build_hostname, ast_build_kernel, ast_build_machine, ast_build_os, ast_build_user, ast_config_AST_SYSTEM_NAME, and ast_get_version().
Referenced by main().
03347 { 03348 setenv("AST_SYSTEMNAME", ast_config_AST_SYSTEM_NAME, 1); 03349 setenv("AST_BUILD_HOST", ast_build_hostname, 1); 03350 setenv("AST_BUILD_DATE", ast_build_date, 1); 03351 setenv("AST_BUILD_KERNEL", ast_build_kernel, 1); 03352 setenv("AST_BUILD_MACHINE", ast_build_machine, 1); 03353 setenv("AST_BUILD_OS", ast_build_os, 1); 03354 setenv("AST_BUILD_USER", ast_build_user, 1); 03355 setenv("AST_VERSION", ast_get_version(), 1); 03356 }
| static int fdprint | ( | int | fd, | |
| const char * | s | |||
| ) | [static] |
Definition at line 1008 of file asterisk.c.
Referenced by ast_network_puts(), ast_network_puts_mutable(), listener(), and netconsole().
| static int fdsend | ( | int | fd, | |
| const char * | s | |||
| ) | [static] |
Definition at line 1002 of file asterisk.c.
Referenced by ast_el_read_char(), ast_remotecontrol(), and cli_complete().
| static const char* fix_header | ( | char * | outbuf, | |
| int | maxout, | |||
| const char * | s, | |||
| char * | cmp | |||
| ) | [static] |
Definition at line 1867 of file asterisk.c.
References COLOR_GRAY, and term_color().
Referenced by console_verboser().
01868 { 01869 const char *c; 01870 01871 /* Check for verboser preamble */ 01872 if (*s == 127) { 01873 s++; 01874 } 01875 01876 if (!strncmp(s, cmp, strlen(cmp))) { 01877 c = s + strlen(cmp); 01878 term_color(outbuf, cmp, COLOR_GRAY, 0, maxout); 01879 return c; 01880 } 01881 return NULL; 01882 }
| static char* handle_abort_shutdown | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2115 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cancel_shutdown(), ast_mutex_lock, ast_mutex_unlock, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NOT_SHUTTING_DOWN, safe_system_lock, SHUTDOWN_FAST, shuttingdown, and ast_cli_entry::usage.
02116 { 02117 int aborting_shutdown = 0; 02118 02119 switch (cmd) { 02120 case CLI_INIT: 02121 e->command = "core abort shutdown"; 02122 e->usage = 02123 "Usage: core abort shutdown\n" 02124 " Causes Asterisk to abort an executing shutdown or restart, and resume normal\n" 02125 " call operations.\n"; 02126 return NULL; 02127 case CLI_GENERATE: 02128 return NULL; 02129 } 02130 02131 if (a->argc != e->args) 02132 return CLI_SHOWUSAGE; 02133 02134 ast_mutex_lock(&safe_system_lock); 02135 if (shuttingdown >= SHUTDOWN_FAST) { 02136 aborting_shutdown = 1; 02137 shuttingdown = NOT_SHUTTING_DOWN; 02138 } 02139 ast_mutex_unlock(&safe_system_lock); 02140 02141 if (aborting_shutdown) { 02142 ast_cancel_shutdown(); 02143 } 02144 return CLI_SUCCESS; 02145 }
| static char* handle_bang | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2147 of file asterisk.c.
References CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, and ast_cli_entry::usage.
02148 { 02149 switch (cmd) { 02150 case CLI_INIT: 02151 e->command = "!"; 02152 e->usage = 02153 "Usage: !<command>\n" 02154 " Executes a given shell command\n"; 02155 return NULL; 02156 case CLI_GENERATE: 02157 return NULL; 02158 } 02159 02160 return CLI_SUCCESS; 02161 }
| static char* handle_clear_profile | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 836 of file asterisk.c.
References CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, DEFINE_PROFILE_MIN_MAX_VALUES, profile_data::e, profile_entry::events, profile_entry::name, prof_data, ast_cli_entry::usage, and profile_entry::value.
00837 { 00838 int i, min, max; 00839 const char *search = NULL; 00840 switch (cmd) { 00841 case CLI_INIT: 00842 e->command = "core clear profile"; 00843 e->usage = "Usage: core clear profile\n" 00844 " clear profile information"; 00845 return NULL; 00846 case CLI_GENERATE: 00847 return NULL; 00848 } 00849 00850 if (prof_data == NULL) 00851 return 0; 00852 00853 DEFINE_PROFILE_MIN_MAX_VALUES; 00854 for (i= min; i < max; i++) { 00855 if (!search || strstr(prof_data->e[i].name, search)) { 00856 prof_data->e[i].value = 0; 00857 prof_data->e[i].events = 0; 00858 } 00859 } 00860 return CLI_SUCCESS; 00861 }
| static char* handle_restart_gracefully | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2075 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, quit_handler(), SHUTDOWN_NICE, and ast_cli_entry::usage.
02076 { 02077 switch (cmd) { 02078 case CLI_INIT: 02079 e->command = "core restart gracefully"; 02080 e->usage = 02081 "Usage: core restart gracefully\n" 02082 " Causes Asterisk to stop accepting new calls and exec() itself performing a cold\n" 02083 " restart when all active calls have ended.\n"; 02084 return NULL; 02085 case CLI_GENERATE: 02086 return NULL; 02087 } 02088 02089 if (a->argc != e->args) 02090 return CLI_SHOWUSAGE; 02091 quit_handler(0, SHUTDOWN_NICE, 1 /* restart */); 02092 return CLI_SUCCESS; 02093 }
| static char* handle_restart_now | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2055 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, quit_handler(), SHUTDOWN_NORMAL, and ast_cli_entry::usage.
02056 { 02057 switch (cmd) { 02058 case CLI_INIT: 02059 e->command = "core restart now"; 02060 e->usage = 02061 "Usage: core restart now\n" 02062 " Causes Asterisk to hangup all calls and exec() itself performing a cold\n" 02063 " restart.\n"; 02064 return NULL; 02065 case CLI_GENERATE: 02066 return NULL; 02067 } 02068 02069 if (a->argc != e->args) 02070 return CLI_SHOWUSAGE; 02071 quit_handler(0, SHUTDOWN_NORMAL, 1 /* restart */); 02072 return CLI_SUCCESS; 02073 }
| static char* handle_restart_when_convenient | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2095 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, quit_handler(), SHUTDOWN_REALLY_NICE, and ast_cli_entry::usage.
02096 { 02097 switch (cmd) { 02098 case CLI_INIT: 02099 e->command = "core restart when convenient"; 02100 e->usage = 02101 "Usage: core restart when convenient\n" 02102 " Causes Asterisk to perform a cold restart when all active calls have ended.\n"; 02103 return NULL; 02104 case CLI_GENERATE: 02105 return NULL; 02106 } 02107 02108 if (a->argc != e->args) 02109 return CLI_SHOWUSAGE; 02110 ast_cli(a->fd, "Waiting for inactivity to perform restart\n"); 02111 quit_handler(0, SHUTDOWN_REALLY_NICE, 1 /* restart */); 02112 return CLI_SUCCESS; 02113 }
| static char* handle_show_profile | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 801 of file asterisk.c.
References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, DEFINE_PROFILE_MIN_MAX_VALUES, profile_data::e, profile_data::entries, profile_entry::events, ast_cli_args::fd, profile_data::max_size, profile_entry::name, prof_data, profile_entry::scale, ast_cli_entry::usage, and profile_entry::value.
00802 { 00803 int i, min, max; 00804 const char *search = NULL; 00805 switch (cmd) { 00806 case CLI_INIT: 00807 e->command = "core show profile"; 00808 e->usage = "Usage: core show profile\n" 00809 " show profile information"; 00810 return NULL; 00811 case CLI_GENERATE: 00812 return NULL; 00813 } 00814 00815 if (prof_data == NULL) 00816 return 0; 00817 00818 DEFINE_PROFILE_MIN_MAX_VALUES; 00819 ast_cli(a->fd, "profile values (%d, allocated %d)\n-------------------\n", 00820 prof_data->entries, prof_data->max_size); 00821 ast_cli(a->fd, "%6s %8s %10s %12s %12s %s\n", "ID", "Scale", "Events", 00822 "Value", "Average", "Name"); 00823 for (i = min; i < max; i++) { 00824 struct profile_entry *entry = &prof_data->e[i]; 00825 if (!search || strstr(entry->name, search)) 00826 ast_cli(a->fd, "%6d: [%8ld] %10ld %12lld %12lld %s\n", 00827 i, 00828 (long)entry->scale, 00829 (long)entry->events, (long long)entry->value, 00830 (long long)(entry->events ? entry->value / entry->events : entry->value), 00831 entry->name); 00832 } 00833 return CLI_SUCCESS; 00834 }
| static char* handle_show_settings | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Give an overview of core settings.
Definition at line 435 of file asterisk.c.
References ast_active_channels(), ast_build_date, ast_build_kernel, ast_build_machine, ast_build_os, ast_build_user, AST_BUILDOPTS, ast_cli(), ast_config_AST_AGI_DIR, ast_config_AST_CONFIG_DIR, ast_config_AST_CONFIG_FILE, ast_config_AST_DATA_DIR, ast_config_AST_DB, ast_config_AST_KEY_DIR, ast_config_AST_LOG_DIR, ast_config_AST_MODULE_DIR, ast_config_AST_PID, ast_config_AST_RUN_DIR, ast_config_AST_RUN_GROUP, ast_config_AST_RUN_USER, ast_config_AST_SPOOL_DIR, ast_config_AST_SYSTEM_NAME, ast_config_AST_VAR_DIR, ast_eid_default, ast_eid_to_str(), ast_get_version(), ast_language_is_prefix, ast_lastreloadtime, ast_localtime(), AST_OPT_FLAG_EXEC_INCLUDES, AST_OPT_FLAG_GENERIC_PLC, AST_OPT_FLAG_INTERNAL_TIMING, AST_OPT_FLAG_TRANSCODE_VIA_SLIN, AST_OPT_FLAG_TRANSMIT_SILENCE, ast_realtime_enabled(), ast_startuptime, ast_strftime(), ast_test_flag, check_cdr_enabled(), check_manager_enabled(), check_webmanager_enabled(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, defaultlanguage, ast_cli_args::fd, S_OR, and ast_cli_entry::usage.
00436 { 00437 char buf[BUFSIZ]; 00438 struct ast_tm tm; 00439 char eid_str[128]; 00440 00441 switch (cmd) { 00442 case CLI_INIT: 00443 e->command = "core show settings"; 00444 e->usage = "Usage: core show settings\n" 00445 " Show core misc settings"; 00446 return NULL; 00447 case CLI_GENERATE: 00448 return NULL; 00449 } 00450 00451 ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default); 00452 00453 ast_cli(a->fd, "\nPBX Core settings\n"); 00454 ast_cli(a->fd, "-----------------\n"); 00455 ast_cli(a->fd, " Version: %s\n", ast_get_version()); 00456 ast_cli(a->fd, " Build Options: %s\n", S_OR(AST_BUILDOPTS, "(none)")); 00457 if (option_maxcalls) 00458 ast_cli(a->fd, " Maximum calls: %d (Current %d)\n", option_maxcalls, ast_active_channels()); 00459 else 00460 ast_cli(a->fd, " Maximum calls: Not set\n"); 00461 if (option_maxfiles) 00462 ast_cli(a->fd, " Maximum open file handles: %d\n", option_maxfiles); 00463 else 00464 ast_cli(a->fd, " Maximum open file handles: Not set\n"); 00465 ast_cli(a->fd, " Verbosity: %d\n", option_verbose); 00466 ast_cli(a->fd, " Debug level: %d\n", option_debug); 00467 ast_cli(a->fd, " Maximum load average: %lf\n", option_maxload); 00468 #if defined(HAVE_SYSINFO) 00469 ast_cli(a->fd, " Minimum free memory: %ld MB\n", option_minmemfree); 00470 #endif 00471 if (ast_localtime(&ast_startuptime, &tm, NULL)) { 00472 ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm); 00473 ast_cli(a->fd, " Startup time: %s\n", buf); 00474 } 00475 if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) { 00476 ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm); 00477 ast_cli(a->fd, " Last reload time: %s\n", buf); 00478 } 00479 ast_cli(a->fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date); 00480 ast_cli(a->fd, " System name: %s\n", ast_config_AST_SYSTEM_NAME); 00481 ast_cli(a->fd, " Entity ID: %s\n", eid_str); 00482 ast_cli(a->fd, " Default language: %s\n", defaultlanguage); 00483 ast_cli(a->fd, " Language prefix: %s\n", ast_language_is_prefix ? "Enabled" : "Disabled"); 00484 ast_cli(a->fd, " User name and group: %s/%s\n", ast_config_AST_RUN_USER, ast_config_AST_RUN_GROUP); 00485 ast_cli(a->fd, " Executable includes: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES) ? "Enabled" : "Disabled"); 00486 ast_cli(a->fd, " Transcode via SLIN: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled"); 00487 ast_cli(a->fd, " Internal timing: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING) ? "Enabled" : "Disabled"); 00488 ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled"); 00489 ast_cli(a->fd, " Generic PLC: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) ? "Enabled" : "Disabled"); 00490 00491 ast_cli(a->fd, "\n* Subsystems\n"); 00492 ast_cli(a->fd, " -------------\n"); 00493 ast_cli(a->fd, " Manager (AMI): %s\n", check_manager_enabled() ? "Enabled" : "Disabled"); 00494 ast_cli(a->fd, " Web Manager (AMI/HTTP): %s\n", check_webmanager_enabled() ? "Enabled" : "Disabled"); 00495 ast_cli(a->fd, " Call data records: %s\n", check_cdr_enabled() ? "Enabled" : "Disabled"); 00496 ast_cli(a->fd, " Realtime Architecture (ARA): %s\n", ast_realtime_enabled() ? "Enabled" : "Disabled"); 00497 00498 /*! \todo we could check musiconhold, voicemail, smdi, adsi, queues */ 00499 00500 ast_cli(a->fd, "\n* Directories\n"); 00501 ast_cli(a->fd, " -------------\n"); 00502 ast_cli(a->fd, " Configuration file: %s\n", ast_config_AST_CONFIG_FILE); 00503 ast_cli(a->fd, " Configuration directory: %s\n", ast_config_AST_CONFIG_DIR); 00504 ast_cli(a->fd, " Module directory: %s\n", ast_config_AST_MODULE_DIR); 00505 ast_cli(a->fd, " Spool directory: %s\n", ast_config_AST_SPOOL_DIR); 00506 ast_cli(a->fd, " Log directory: %s\n", ast_config_AST_LOG_DIR); 00507 ast_cli(a->fd, " Run/Sockets directory: %s\n", ast_config_AST_RUN_DIR); 00508 ast_cli(a->fd, " PID file: %s\n", ast_config_AST_PID); 00509 ast_cli(a->fd, " VarLib directory: %s\n", ast_config_AST_VAR_DIR); 00510 ast_cli(a->fd, " Data directory: %s\n", ast_config_AST_DATA_DIR); 00511 ast_cli(a->fd, " ASTDB: %s\n", ast_config_AST_DB); 00512 ast_cli(a->fd, " IAX2 Keys directory: %s\n", ast_config_AST_KEY_DIR); 00513 ast_cli(a->fd, " AGI Scripts directory: %s\n", ast_config_AST_AGI_DIR); 00514 ast_cli(a->fd, "\n\n"); 00515 return CLI_SUCCESS; 00516 }
| static char* handle_show_sysinfo | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Give an overview of system statistics.
Definition at line 590 of file asterisk.c.
References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, len(), and ast_cli_entry::usage.
00591 { 00592 uint64_t physmem, freeram; 00593 uint64_t freeswap = 0; 00594 int nprocs = 0; 00595 long uptime = 0; 00596 int totalswap = 0; 00597 #if defined(HAVE_SYSINFO) 00598 struct sysinfo sys_info; 00599 sysinfo(&sys_info); 00600 uptime = sys_info.uptime / 3600; 00601 physmem = sys_info.totalram * sys_info.mem_unit; 00602 freeram = (sys_info.freeram * sys_info.mem_unit) / 1024; 00603 totalswap = (sys_info.totalswap * sys_info.mem_unit) / 1024; 00604 freeswap = (sys_info.freeswap * sys_info.mem_unit) / 1024; 00605 nprocs = sys_info.procs; 00606 #elif defined(HAVE_SYSCTL) 00607 static int pageshift; 00608 struct vmtotal vmtotal; 00609 struct timeval boottime; 00610 time_t now; 00611 int mib[2], pagesize, usedswap = 0; 00612 size_t len; 00613 /* calculate the uptime by looking at boottime */ 00614 time(&now); 00615 mib[0] = CTL_KERN; 00616 mib[1] = KERN_BOOTTIME; 00617 len = sizeof(boottime); 00618 if (sysctl(mib, 2, &boottime, &len, NULL, 0) != -1) { 00619 uptime = now - boottime.tv_sec; 00620 } 00621 uptime = uptime/3600; 00622 /* grab total physical memory */ 00623 mib[0] = CTL_HW; 00624 #if defined(HW_PHYSMEM64) 00625 mib[1] = HW_PHYSMEM64; 00626 #else 00627 mib[1] = HW_PHYSMEM; 00628 #endif 00629 len = sizeof(physmem); 00630 sysctl(mib, 2, &physmem, &len, NULL, 0); 00631 00632 pagesize = getpagesize(); 00633 pageshift = 0; 00634 while (pagesize > 1) { 00635 pageshift++; 00636 pagesize >>= 1; 00637 } 00638 00639 /* we only need the amount of log(2)1024 for our conversion */ 00640 pageshift -= 10; 00641 00642 /* grab vm totals */ 00643 mib[0] = CTL_VM; 00644 mib[1] = VM_METER; 00645 len = sizeof(vmtotal); 00646 sysctl(mib, 2, &vmtotal, &len, NULL, 0); 00647 freeram = (vmtotal.t_free << pageshift); 00648 /* generate swap usage and totals */ 00649 swapmode(&usedswap, &totalswap); 00650 freeswap = (totalswap - usedswap); 00651 /* grab number of processes */ 00652 #if defined(__OpenBSD__) 00653 mib[0] = CTL_KERN; 00654 mib[1] = KERN_NPROCS; 00655 len = sizeof(nprocs); 00656 sysctl(mib, 2, &nprocs, &len, NULL, 0); 00657 #endif 00658 #endif 00659 00660 switch (cmd) { 00661 case CLI_INIT: 00662 e->command = "core show sysinfo"; 00663 e->usage = 00664 "Usage: core show sysinfo\n" 00665 " List current system information.\n"; 00666 return NULL; 00667 case CLI_GENERATE: 00668 return NULL; 00669 } 00670 00671 ast_cli(a->fd, "\nSystem Statistics\n"); 00672 ast_cli(a->fd, "-----------------\n"); 00673 ast_cli(a->fd, " System Uptime: %lu hours\n", uptime); 00674 ast_cli(a->fd, " Total RAM: %" PRIu64 " KiB\n", physmem / 1024); 00675 ast_cli(a->fd, " Free RAM: %" PRIu64 " KiB\n", freeram); 00676 #if defined(HAVE_SYSINFO) 00677 ast_cli(a->fd, " Buffer RAM: %" PRIu64 " KiB\n", ((uint64_t) sys_info.bufferram * sys_info.mem_unit) / 1024); 00678 #endif 00679 #if defined (HAVE_SYSCTL) || defined(HAVE_SWAPCTL) 00680 ast_cli(a->fd, " Total Swap Space: %u KiB\n", totalswap); 00681 ast_cli(a->fd, " Free Swap Space: %" PRIu64 " KiB\n\n", freeswap); 00682 #endif 00683 ast_cli(a->fd, " Number of Processes: %d \n\n", nprocs); 00684 return CLI_SUCCESS; 00685 }
| static char* handle_show_threads | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 518 of file asterisk.c.
References ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, thread_list_t::id, ast_atexit::list, thread_list_t::name, and ast_cli_entry::usage.
00519 { 00520 int count = 0; 00521 struct thread_list_t *cur; 00522 switch (cmd) { 00523 case CLI_INIT: 00524 e->command = "core show threads"; 00525 e->usage = 00526 "Usage: core show threads\n" 00527 " List threads currently active in the system.\n"; 00528 return NULL; 00529 case CLI_GENERATE: 00530 return NULL; 00531 } 00532 00533 AST_RWLIST_RDLOCK(&thread_list); 00534 AST_RWLIST_TRAVERSE(&thread_list, cur, list) { 00535 ast_cli(a->fd, "%p %s\n", (void *)cur->id, cur->name); 00536 count++; 00537 } 00538 AST_RWLIST_UNLOCK(&thread_list); 00539 ast_cli(a->fd, "%d threads listed.\n", count); 00540 return CLI_SUCCESS; 00541 }
| static char* handle_show_version_files | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command to list module versions.
Definition at line 865 of file asterisk.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, file_version::file, FORMAT, ast_atexit::list, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, file_version::version, and ast_cli_args::word.
00866 { 00867 #define FORMAT "%-25.25s %-40.40s\n" 00868 struct file_version *iterator; 00869 regex_t regexbuf; 00870 int havepattern = 0; 00871 int havename = 0; 00872 int count_files = 0; 00873 char *ret = NULL; 00874 int matchlen, which = 0; 00875 struct file_version *find; 00876 00877 switch (cmd) { 00878 case CLI_INIT: 00879 e->command = "core show file version [like]"; 00880 e->usage = 00881 "Usage: core show file version [like <pattern>]\n" 00882 " Lists the revision numbers of the files used to build this copy of Asterisk.\n" 00883 " Optional regular expression pattern is used to filter the file list.\n"; 00884 return NULL; 00885 case CLI_GENERATE: 00886 matchlen = strlen(a->word); 00887 if (a->pos != 3) 00888 return NULL; 00889 AST_RWLIST_RDLOCK(&file_versions); 00890 AST_RWLIST_TRAVERSE(&file_versions, find, list) { 00891 if (!strncasecmp(a->word, find->file, matchlen) && ++which > a->n) { 00892 ret = ast_strdup(find->file); 00893 break; 00894 } 00895 } 00896 AST_RWLIST_UNLOCK(&file_versions); 00897 return ret; 00898 } 00899 00900 00901 switch (a->argc) { 00902 case 6: 00903 if (!strcasecmp(a->argv[4], "like")) { 00904 if (regcomp(®exbuf, a->argv[5], REG_EXTENDED | REG_NOSUB)) 00905 return CLI_SHOWUSAGE; 00906 havepattern = 1; 00907 } else 00908 return CLI_SHOWUSAGE; 00909 break; 00910 case 5: 00911 havename = 1; 00912 break; 00913 case 4: 00914 break; 00915 default: 00916 return CLI_SHOWUSAGE; 00917 } 00918 00919 ast_cli(a->fd, FORMAT, "File", "Revision"); 00920 ast_cli(a->fd, FORMAT, "----", "--------"); 00921 AST_RWLIST_RDLOCK(&file_versions); 00922 AST_RWLIST_TRAVERSE(&file_versions, iterator, list) { 00923 if (havename && strcasecmp(iterator->file, a->argv[4])) 00924 continue; 00925 00926 if (havepattern && regexec(®exbuf, iterator->file, 0, NULL, 0)) 00927 continue; 00928 00929 ast_cli(a->fd, FORMAT, iterator->file, iterator->version); 00930 count_files++; 00931 if (havename) 00932 break; 00933 } 00934 AST_RWLIST_UNLOCK(&file_versions); 00935 if (!havename) { 00936 ast_cli(a->fd, "%d files listed.\n", count_files); 00937 } 00938 00939 if (havepattern) 00940 regfree(®exbuf); 00941 00942 return CLI_SUCCESS; 00943 #undef FORMAT 00944 }
| static char* handle_stop_gracefully | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2015 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, quit_handler(), SHUTDOWN_NICE, and ast_cli_entry::usage.
02016 { 02017 switch (cmd) { 02018 case CLI_INIT: 02019 e->command = "core stop gracefully"; 02020 e->usage = 02021 "Usage: core stop gracefully\n" 02022 " Causes Asterisk to not accept new calls, and exit when all\n" 02023 " active calls have terminated normally.\n"; 02024 return NULL; 02025 case CLI_GENERATE: 02026 return NULL; 02027 } 02028 02029 if (a->argc != e->args) 02030 return CLI_SHOWUSAGE; 02031 quit_handler(0, SHUTDOWN_NICE, 0 /* no restart */); 02032 return CLI_SUCCESS; 02033 }
| static char* handle_stop_now | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1996 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, quit_handler(), SHUTDOWN_NORMAL, and ast_cli_entry::usage.
01997 { 01998 switch (cmd) { 01999 case CLI_INIT: 02000 e->command = "core stop now"; 02001 e->usage = 02002 "Usage: core stop now\n" 02003 " Shuts down a running Asterisk immediately, hanging up all active calls .\n"; 02004 return NULL; 02005 case CLI_GENERATE: 02006 return NULL; 02007 } 02008 02009 if (a->argc != e->args) 02010 return CLI_SHOWUSAGE; 02011 quit_handler(0, SHUTDOWN_NORMAL, 0 /* not restart */); 02012 return CLI_SUCCESS; 02013 }
| static char* handle_stop_when_convenient | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2035 of file asterisk.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, quit_handler(), SHUTDOWN_REALLY_NICE, and ast_cli_entry::usage.
02036 { 02037 switch (cmd) { 02038 case CLI_INIT: 02039 e->command = "core stop when convenient"; 02040 e->usage = 02041 "Usage: core stop when convenient\n" 02042 " Causes Asterisk to perform a shutdown when all active calls have ended.\n"; 02043 return NULL; 02044 case CLI_GENERATE: 02045 return NULL; 02046 } 02047 02048 if (a->argc != e->args) 02049 return CLI_SHOWUSAGE; 02050 ast_cli(a->fd, "Waiting for inactivity to perform halt\n"); 02051 quit_handler(0, SHUTDOWN_REALLY_NICE, 0 /* don't restart */); 02052 return CLI_SUCCESS; 02053 }
| static char* handle_version | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1965 of file asterisk.c.
References ast_cli_args::argc, ast_build_date, ast_build_hostname, ast_build_machine, ast_build_os, ast_build_user, ast_cli(), ast_get_version(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
01966 { 01967 switch (cmd) { 01968 case CLI_INIT: 01969 e->command = "core show version"; 01970 e->usage = 01971 "Usage: core show version\n" 01972 " Shows Asterisk version information.\n"; 01973 return NULL; 01974 case CLI_GENERATE: 01975 return NULL; 01976 } 01977 01978 if (a->argc != 3) 01979 return CLI_SHOWUSAGE; 01980 ast_cli(a->fd, "Asterisk %s built by %s @ %s on a %s running %s on %s\n", 01981 ast_get_version(), ast_build_user, ast_build_hostname, 01982 ast_build_machine, ast_build_os, ast_build_date); 01983 return CLI_SUCCESS; 01984 }
| static void* listener | ( | void * | unused | ) | [static] |
Definition at line 1369 of file asterisk.c.
References AF_LOCAL, ast_log(), AST_MAX_CONNECTS, ast_opt_hide_connect, ast_poll, ast_pthread_create_detached_background, ast_verb, consoles, errno, console::fd, fdprint(), console::gid, len(), LOG_ERROR, LOG_WARNING, console::mute, netconsole(), and console::uid.
Referenced by ast_makesocket().
01370 { 01371 struct sockaddr_un sunaddr; 01372 int s; 01373 socklen_t len; 01374 int x; 01375 int flags; 01376 struct pollfd fds[1]; 01377 for (;;) { 01378 if (ast_socket < 0) 01379 return NULL; 01380 fds[0].fd = ast_socket; 01381 fds[0].events = POLLIN; 01382 s = ast_poll(fds, 1, -1); 01383 pthread_testcancel(); 01384 if (s < 0) { 01385 if (errno != EINTR) 01386 ast_log(LOG_WARNING, "poll returned error: %s\n", strerror(errno)); 01387 continue; 01388 } 01389 len = sizeof(sunaddr); 01390 s = accept(ast_socket, (struct sockaddr *)&sunaddr, &len); 01391 if (s < 0) { 01392 if (errno != EINTR) 01393 ast_log(LOG_WARNING, "Accept returned %d: %s\n", s, strerror(errno)); 01394 } else { 01395 #if !defined(SO_PASSCRED) 01396 { 01397 #else 01398 int sckopt = 1; 01399 /* turn on socket credentials passing. */ 01400 if (setsockopt(s, SOL_SOCKET, SO_PASSCRED, &sckopt, sizeof(sckopt)) < 0) { 01401 ast_log(LOG_WARNING, "Unable to turn on socket credentials passing\n"); 01402 } else { 01403 #endif 01404 for (x = 0; x < AST_MAX_CONNECTS; x++) { 01405 if (consoles[x].fd >= 0) { 01406 continue; 01407 } 01408 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, consoles[x].p)) { 01409 ast_log(LOG_ERROR, "Unable to create pipe: %s\n", strerror(errno)); 01410 consoles[x].fd = -1; 01411 fdprint(s, "Server failed to create pipe\n"); 01412 close(s); 01413 break; 01414 } 01415 flags = fcntl(consoles[x].p[1], F_GETFL); 01416 fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK); 01417 consoles[x].fd = s; 01418 consoles[x].mute = 1; /* Default is muted, we will un-mute if necessary */ 01419 /* Default uid and gid to -2, so then in cli.c/cli_has_permissions() we will be able 01420 to know if the user didn't send the credentials. */ 01421 consoles[x].uid = -2; 01422 consoles[x].gid = -2; 01423 if (ast_pthread_create_detached_background(&consoles[x].t, NULL, netconsole, &consoles[x])) { 01424 ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno)); 01425 close(consoles[x].p[0]); 01426 close(consoles[x].p[1]); 01427 consoles[x].fd = -1; 01428 fdprint(s, "Server failed to spawn thread\n"); 01429 close(s); 01430 } 01431 break; 01432 } 01433 if (x >= AST_MAX_CONNECTS) { 01434 fdprint(s, "No more connections allowed\n"); 01435 ast_log(LOG_WARNING, "No more connections allowed\n"); 01436 close(s); 01437 } else if ((consoles[x].fd > -1) && (!ast_opt_hide_connect)) { 01438 ast_verb(3, "Remote UNIX connection\n"); 01439 } 01440 } 01441 } 01442 } 01443 return NULL; 01444 }
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
< Result from the module load subsystem
Definition at line 3380 of file asterisk.c.
References __ast_mm_init_phase_1(), __ast_mm_init_phase_2(), __quit_handler(), _argv, ARRAY_LEN, ast_alaw_init(), ast_aoc_cli_init(), ast_autoservice_init(), ast_builtins_init(), ast_cc_init(), ast_cdr_engine_init(), ast_cel_engine_init(), ast_channels_init(), ast_clear_flag, ast_cli_perms_init(), ast_cli_register_multiple(), ast_close_fds_above_n(), ast_config_AST_PID, ast_config_AST_RUN_DIR, ast_config_AST_RUN_GROUP, ast_config_AST_RUN_USER, ast_config_AST_SOCKET, ast_copy_string(), ast_data_init(), ast_device_state_engine_init(), ast_dsp_init(), ast_el_initialize(), ast_el_read_char(), ast_el_read_history(), ast_enum_init(), ast_event_init(), ast_fd_init(), ast_FD_SETSIZE, ast_FDMAX, ast_features_init(), ast_file_init(), ast_http_init(), ast_image_init(), ast_indications_init(), ast_language_is_prefix, ast_lastreloadtime, ast_log(), ast_makesocket(), ast_opt_always_fork, ast_opt_console, ast_opt_dump_core, ast_opt_exec, AST_OPT_FLAG_ALWAYS_FORK, AST_OPT_FLAG_CACHE_RECORD_FILES, AST_OPT_FLAG_CONSOLE, AST_OPT_FLAG_DUMP_CORE, AST_OPT_FLAG_EXEC, AST_OPT_FLAG_EXEC_INCLUDES, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND, AST_OPT_FLAG_FULLY_BOOTED, AST_OPT_FLAG_HIGH_PRIORITY, AST_OPT_FLAG_INIT_KEYS, AST_OPT_FLAG_INTERNAL_TIMING, AST_OPT_FLAG_LIGHT_BACKGROUND, AST_OPT_FLAG_MUTE, AST_OPT_FLAG_NO_COLOR, AST_OPT_FLAG_NO_FORK, AST_OPT_FLAG_OVERRIDE_CONFIG, AST_OPT_FLAG_QUIET, AST_OPT_FLAG_RECONNECT, AST_OPT_FLAG_REMOTE, AST_OPT_FLAG_TIMESTAMP, ast_opt_high_priority, ast_opt_no_fork, ast_opt_remote, ast_pbx_init(), ast_process_pending_reloads(), ast_pthread_create_detached, ast_readconfig(), ast_register_atexit(), ast_remotecontrol(), ast_select(), ast_set_flag, ast_set_priority(), ast_ssl_init(), ast_startuptime, ast_strdupa, ast_strlen_zero(), ast_stun_init(), ast_term_init(), ast_test_flag, ast_test_init(), ast_timing_init(), ast_tps_init(), ast_tryconnect(), ast_tvnow(), ast_udptl_init(), ast_ulaw_init(), ast_utils_init(), ast_verbose, ast_xmldoc_load_documentation(), astdb_init(), astobj2_init(), callerid_init(), canary_exit(), canary_filename, canary_pid, canary_thread(), cfg_paths, COLOR_BLACK, COLOR_BRWHITE, _cfg_paths::config_file, consolehandler(), consolethread, dnsmgr_init(), dnsmgr_start_refresh(), el, el_hist, env_init(), errno, EVENT_FLAG_SYSTEM, f, FD_SET, FD_ZERO, hostname, ignore_sig_handler, init_framer(), init_logger(), init_manager(), load_modules(), load_pbx(), LOG_WARNING, main_atexit(), manager_event, MAXHOSTNAMELEN, mon_sig_flags, monitor_sig_flags(), multi_thread_safe, print_intro_message(), quit_handler(), randompool, read_config_maps(), register_config_cli(), run_startup_commands(), set_icon(), set_title(), show_cli_help(), show_version(), SHUTDOWN_FAST, sig_alert_pipe, sig_flags, _cfg_paths::socket_path, tdd_init(), term_color(), term_end(), term_quit(), and threadstorage_init().
03381 { 03382 int c; 03383 char filename[80] = ""; 03384 char hostname[MAXHOSTNAMELEN] = ""; 03385 char tmp[80]; 03386 char * xarg = NULL; 03387 int x; 03388 FILE *f; 03389 sigset_t sigs; 03390 int num; 03391 int isroot = 1, rundir_exists = 0; 03392 char *buf; 03393 const char *runuser = NULL, *rungroup = NULL; 03394 char *remotesock = NULL; 03395 int moduleresult; /*!< Result from the module load subsystem */ 03396 struct rlimit l; 03397 03398 /* Remember original args for restart */ 03399 if (argc > ARRAY_LEN(_argv) - 1) { 03400 fprintf(stderr, "Truncating argument size to %d\n", (int)ARRAY_LEN(_argv) - 1); 03401 argc = ARRAY_LEN(_argv) - 1; 03402 } 03403 for (x = 0; x < argc; x++) 03404 _argv[x] = argv[x]; 03405 _argv[x] = NULL; 03406 03407 if (geteuid() != 0) 03408 isroot = 0; 03409 03410 /* if the progname is rasterisk consider it a remote console */ 03411 if (argv[0] && (strstr(argv[0], "rasterisk")) != NULL) { 03412 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE); 03413 } 03414 if (gethostname(hostname, sizeof(hostname)-1)) 03415 ast_copy_string(hostname, "<Unknown>", sizeof(hostname)); 03416 ast_mainpid = getpid(); 03417 03418 if (getenv("HOME")) 03419 snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); 03420 /* Check for options */ 03421 while ((c = getopt(argc, argv, "BC:cde:FfG:ghIiL:M:mnpqRrs:TtU:VvWXx:")) != -1) { 03422 /*!\note Please keep the ordering here to alphabetical, capital letters 03423 * first. This will make it easier in the future to select unused 03424 * option flags for new features. */ 03425 switch (c) { 03426 case 'B': /* Force black background */ 03427 ast_set_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND); 03428 ast_clear_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND); 03429 break; 03430 case 'X': 03431 ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES); 03432 break; 03433 case 'C': 03434 ast_copy_string(cfg_paths.config_file, optarg, sizeof(cfg_paths.config_file)); 03435 ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG); 03436 break; 03437 case 'c': 03438 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE); 03439 break; 03440 case 'd': 03441 option_debug++; 03442 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK); 03443 break; 03444 #if defined(HAVE_SYSINFO) 03445 case 'e': 03446 if ((sscanf(&optarg[1], "%30ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) { 03447 option_minmemfree = 0; 03448 } 03449 break; 03450 #endif 03451 #if HAVE_WORKING_FORK 03452 case 'F': 03453 ast_set_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK); 03454 break; 03455 case 'f': 03456 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK); 03457 break; 03458 #endif 03459 case 'G': 03460 rungroup = ast_strdupa(optarg); 03461 break; 03462 case 'g': 03463 ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE); 03464 break; 03465 case 'h': 03466 show_cli_help(); 03467 exit(0); 03468 case 'I': 03469 ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING); 03470 break; 03471 case 'i': 03472 ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS); 03473 break; 03474 case 'L': 03475 if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0)) { 03476 option_maxload = 0.0; 03477 } 03478 break; 03479 case 'M': 03480 if ((sscanf(optarg, "%30d", &option_maxcalls) != 1) || (option_maxcalls < 0)) { 03481 option_maxcalls = 0; 03482 } 03483 break; 03484 case 'm': 03485 ast_set_flag(&ast_options, AST_OPT_FLAG_MUTE); 03486 break; 03487 case 'n': 03488 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR); 03489 break; 03490 case 'p': 03491 ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY); 03492 break; 03493 case 'q': 03494 ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET); 03495 break; 03496 case 'R': 03497 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT); 03498 break; 03499 case 'r': 03500 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE); 03501 break; 03502 case 's': 03503 remotesock = ast_strdupa(optarg); 03504 break; 03505 case 'T': 03506 ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP); 03507 break; 03508 case 't': 03509 ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES); 03510 break; 03511 case 'U': 03512 runuser = ast_strdupa(optarg); 03513 break; 03514 case 'V': 03515 show_version(); 03516 exit(0); 03517 case 'v': 03518 option_verbose++; 03519 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK); 03520 break; 03521 case 'W': /* White background */ 03522 ast_set_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND); 03523 ast_clear_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND); 03524 break; 03525 case 'x': 03526 /* -r is implied by -x so set the flags -r sets as well. */ 03527 ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE); 03528 03529 ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC | AST_OPT_FLAG_NO_COLOR); 03530 xarg = ast_strdupa(optarg); 03531 break; 03532 case '?': 03533 exit(1); 03534 } 03535 } 03536 03537 /* For remote connections, change the name of the remote connection. 03538 * We do this for the benefit of init scripts (which need to know if/when 03539 * the main asterisk process has died yet). */ 03540 if (ast_opt_remote) { 03541 strcpy(argv[0], "rasterisk"); 03542 for (x = 1; x < argc; x++) { 03543 argv[x] = argv[0] + 10; 03544 } 03545 } 03546 03547 ast_readconfig(); 03548 env_init(); 03549 03550 if (ast_opt_remote && remotesock != NULL) 03551 ast_copy_string((char *) cfg_paths.socket_path, remotesock, sizeof(cfg_paths.socket_path)); 03552 03553 if (!ast_language_is_prefix && !ast_opt_remote) { 03554 fprintf(stderr, "The 'languageprefix' option in asterisk.conf is deprecated; in a future release it will be removed, and your sound files will need to be organized in the 'new style' language layout.\n"); 03555 } 03556 03557 if (ast_opt_always_fork && (ast_opt_remote || ast_opt_console)) { 03558 fprintf(stderr, "'alwaysfork' is not compatible with console or remote console mode; ignored\n"); 03559 ast_clear_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK); 03560 } 03561 03562 if (ast_opt_dump_core) { 03563 memset(&l, 0, sizeof(l)); 03564 l.rlim_cur = RLIM_INFINITY; 03565 l.rlim_max = RLIM_INFINITY; 03566 if (setrlimit(RLIMIT_CORE, &l)) { 03567 fprintf(stderr, "Unable to disable core size resource limit: %s\n", strerror(errno)); 03568 } 03569 } 03570 03571 if (getrlimit(RLIMIT_NOFILE, &l)) { 03572 fprintf(stderr, "Unable to check file descriptor limit: %s\n", strerror(errno)); 03573 } 03574 03575 #if !defined(CONFIGURE_RAN_AS_ROOT) 03576 /* Check if select(2) will run with more file descriptors */ 03577 do { 03578 int fd, fd2; 03579 ast_fdset readers; 03580 struct timeval tv = { 0, }; 03581 03582 if (l.rlim_cur <= FD_SETSIZE) { 03583 /* The limit of select()able FDs is irrelevant, because we'll never 03584 * open one that high. */ 03585 break; 03586 } 03587 03588 if (!(fd = open("/dev/null", O_RDONLY))) { 03589 fprintf(stderr, "Cannot open a file descriptor at boot? %s\n", strerror(errno)); 03590 break; /* XXX Should we exit() here? XXX */ 03591 } 03592 03593 fd2 = (l.rlim_cur > sizeof(readers) * 8 ? sizeof(readers) * 8 : l.rlim_cur) - 1; 03594 if (dup2(fd, fd2) < 0) { 03595 fprintf(stderr, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno)); 03596 close(fd); 03597 break; 03598 } 03599 03600 FD_ZERO(&readers); 03601 FD_SET(fd2, &readers); 03602 if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) { 03603 fprintf(stderr, "Maximum select()able file descriptor is %d\n", FD_SETSIZE); 03604 } 03605 ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur; 03606 close(fd); 03607 close(fd2); 03608 } while (0); 03609 #elif defined(HAVE_VARIABLE_FDSET) 03610 ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur; 03611 #endif /* !defined(CONFIGURE_RAN_AS_ROOT) */ 03612 03613 if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP)) 03614 rungroup = ast_config_AST_RUN_GROUP; 03615 if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER)) 03616 runuser = ast_config_AST_RUN_USER; 03617 03618 /* Must install this signal handler up here to ensure that if the canary 03619 * fails to execute that it doesn't kill the Asterisk process. 03620 */ 03621 sigaction(SIGCHLD, &child_handler, NULL); 03622 03623 /* It's common on some platforms to clear /var/run at boot. Create the 03624 * socket file directory before we drop privileges. */ 03625 if (mkdir(ast_config_AST_RUN_DIR, 0755)) { 03626 if (errno == EEXIST) { 03627 rundir_exists = 1; 03628 } else { 03629 fprintf(stderr, "Unable to create socket file directory. Remote consoles will not be able to connect! (%s)\n", strerror(x)); 03630 } 03631 } 03632 03633 #ifndef __CYGWIN__ 03634 03635 if (isroot) { 03636 ast_set_priority(ast_opt_high_priority); 03637 } 03638 03639 if (isroot && rungroup) { 03640 struct group *gr; 03641 gr = getgrnam(rungroup); 03642 if (!gr) { 03643 fprintf(stderr, "No such group '%s'!\n", rungroup); 03644 exit(1); 03645 } 03646 if (!rundir_exists && chown(ast_config_AST_RUN_DIR, -1, gr->gr_gid)) { 03647 fprintf(stderr, "Unable to chgrp run directory to %d (%s)\n", (int) gr->gr_gid, rungroup); 03648 } 03649 if (setgid(gr->gr_gid)) { 03650 fprintf(stderr, "Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup); 03651 exit(1); 03652 } 03653 if (setgroups(0, NULL)) { 03654 fprintf(stderr, "Unable to drop unneeded groups\n"); 03655 exit(1); 03656 } 03657 } 03658 03659 if (runuser && !ast_test_flag(&ast_options, AST_OPT_FLAG_REMOTE)) { 03660 #ifdef HAVE_CAP 03661 int has_cap = 1; 03662 #endif /* HAVE_CAP */ 03663 struct passwd *pw; 03664 pw = getpwnam(runuser); 03665 if (!pw) { 03666 fprintf(stderr, "No such user '%s'!\n", runuser); 03667 exit(1); 03668 } 03669 if (chown(ast_config_AST_RUN_DIR, pw->pw_uid, -1)) { 03670 fprintf(stderr, "Unable to chown run directory to %d (%s)\n", (int) pw->pw_uid, runuser); 03671 } 03672 #ifdef HAVE_CAP 03673 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { 03674 ast_log(LOG_WARNING, "Unable to keep capabilities.\n"); 03675 has_cap = 0; 03676 } 03677 #endif /* HAVE_CAP */ 03678 if (!isroot && pw->pw_uid != geteuid()) { 03679 fprintf(stderr, "Asterisk started as nonroot, but runuser '%s' requested.\n", runuser); 03680 exit(1); 03681 } 03682 if (!rungroup) { 03683 if (setgid(pw->pw_gid)) { 03684 fprintf(stderr, "Unable to setgid to %d!\n", (int)pw->pw_gid); 03685 exit(1); 03686 } 03687 if (isroot && initgroups(pw->pw_name, pw->pw_gid)) { 03688 fprintf(stderr, "Unable to init groups for '%s'\n", runuser); 03689 exit(1); 03690 } 03691 } 03692 if (setuid(pw->pw_uid)) { 03693 fprintf(stderr, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser); 03694 exit(1); 03695 } 03696 #ifdef HAVE_CAP 03697 if (has_cap) { 03698 cap_t cap; 03699 03700 cap = cap_from_text("cap_net_admin=eip"); 03701 03702 if (cap_set_proc(cap)) { 03703 fprintf(stderr, "Unable to install capabilities.\n"); 03704 } 03705 if (cap_free(cap)) { 03706 fprintf(stderr, "Unable to drop capabilities.\n"); 03707 } 03708 } 03709 #endif /* HAVE_CAP */ 03710 } 03711 03712 #endif /* __CYGWIN__ */ 03713 03714 #ifdef linux 03715 if (geteuid() && ast_opt_dump_core) { 03716 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) { 03717 fprintf(stderr, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno)); 03718 } 03719 } 03720 #endif 03721 03722 { 03723 #if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) 03724 #if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS) 03725 #define eaccess euidaccess 03726 #endif 03727 char dir[PATH_MAX]; 03728 if (!getcwd(dir, sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) { 03729 fprintf(stderr, "Unable to access the running directory (%s). Changing to '/' for compatibility.\n", strerror(errno)); 03730 /* If we cannot access the CWD, then we couldn't dump core anyway, 03731 * so chdir("/") won't break anything. */ 03732 if (chdir("/")) { 03733 /* chdir(/) should never fail, so this ends up being a no-op */ 03734 fprintf(stderr, "chdir(\"/\") failed?!! %s\n", strerror(errno)); 03735 } 03736 } else 03737 #endif /* defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) */ 03738 if (!ast_opt_no_fork && !ast_opt_dump_core) { 03739 /* Backgrounding, but no cores, so chdir won't break anything. */ 03740 if (chdir("/")) { 03741 fprintf(stderr, "Unable to chdir(\"/\") ?!! %s\n", strerror(errno)); 03742 } 03743 } 03744 } 03745 03746 if (ast_tryconnect()) { 03747 /* One is already running */ 03748 if (ast_opt_remote) { 03749 multi_thread_safe = 1; 03750 if (ast_opt_exec) { 03751 ast_remotecontrol(xarg); 03752 quit_handler(0, SHUTDOWN_FAST, 0); 03753 exit(0); 03754 } 03755 print_intro_message(runuser, rungroup); 03756 printf("%s", term_quit()); 03757 ast_remotecontrol(NULL); 03758 quit_handler(0, SHUTDOWN_FAST, 0); 03759 exit(0); 03760 } else { 03761 fprintf(stderr, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET); 03762 printf("%s", term_quit()); 03763 exit(1); 03764 } 03765 } else if (ast_opt_remote || ast_opt_exec) { 03766 fprintf(stderr, "Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET); 03767 printf("%s", term_quit()); 03768 exit(1); 03769 } 03770 03771 /* This needs to remain as high up in the initial start up as possible. 03772 * daemon causes a fork to occur, which has all sorts of unintended 03773 * consequences for things that interact with threads. This call *must* 03774 * occur before anything in Asterisk spawns or manipulates thread related 03775 * primitives. */ 03776 #if HAVE_WORKING_FORK 03777 if (ast_opt_always_fork || !ast_opt_no_fork) { 03778 #ifndef HAVE_SBIN_LAUNCHD 03779 if (daemon(1, 0) < 0) { 03780 fprintf(stderr, "daemon() failed: %s\n", strerror(errno)); 03781 } else { 03782 ast_mainpid = getpid(); 03783 } 03784 #else 03785 fprintf(stderr, "Mac OS X detected. Use 'launchctl load /Library/LaunchDaemon/org.asterisk.asterisk.plist'.\n"); 03786 #endif 03787 } 03788 #endif 03789 03790 /* At this point everything has been forked successfully, 03791 * we have determined that we aren't attempting to connect to 03792 * an Asterisk instance, and that there isn't one already running. */ 03793 multi_thread_safe = 1; 03794 03795 #if defined(__AST_DEBUG_MALLOC) 03796 __ast_mm_init_phase_1(); 03797 #endif /* defined(__AST_DEBUG_MALLOC) */ 03798 03799 /* Spawning of astcanary must happen AFTER the call to daemon(3) */ 03800 if (isroot && ast_opt_high_priority) { 03801 snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR); 03802 03803 /* Don't let the canary child kill Asterisk, if it dies immediately */ 03804 sigaction(SIGPIPE, &ignore_sig_handler, NULL); 03805 03806 canary_pid = fork(); 03807 if (canary_pid == 0) { 03808 char canary_binary[128], *lastslash, ppid[12]; 03809 03810 /* Reset signal handler */ 03811 signal(SIGCHLD, SIG_DFL); 03812 signal(SIGPIPE, SIG_DFL); 03813 03814 ast_close_fds_above_n(0); 03815 ast_set_priority(0); 03816 snprintf(ppid, sizeof(ppid), "%d", (int) ast_mainpid); 03817 03818 execlp("astcanary", "astcanary", canary_filename, ppid, (char *)NULL); 03819 03820 /* If not found, try the same path as used to execute asterisk */ 03821 ast_copy_string(canary_binary, argv[0], sizeof(canary_binary)); 03822 if ((lastslash = strrchr(canary_binary, '/'))) { 03823 ast_copy_string(lastslash + 1, "astcanary", sizeof(canary_binary) + canary_binary - (lastslash + 1)); 03824 execl(canary_binary, "astcanary", canary_filename, ppid, (char *)NULL); 03825 } 03826 03827 /* Should never happen */ 03828 _exit(1); 03829 } else if (canary_pid > 0) { 03830 pthread_t dont_care; 03831 ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL); 03832 } 03833 03834 /* Kill the canary when we exit */ 03835 ast_register_atexit(canary_exit); 03836 } 03837 03838 /* Blindly write the PID file. */ 03839 unlink(ast_config_AST_PID); 03840 f = fopen(ast_config_AST_PID, "w"); 03841 if (f) { 03842 fprintf(f, "%ld\n", (long)ast_mainpid); 03843 fclose(f); 03844 } else { 03845 fprintf(stderr, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno)); 03846 } 03847 03848 /* Initialize the terminal. Since all processes have been forked, 03849 * we can now start using the standard log messages. 03850 */ 03851 ast_term_init(); 03852 printf("%s", term_end()); 03853 fflush(stdout); 03854 03855 print_intro_message(runuser, rungroup); 03856 03857 if (ast_opt_console && !option_verbose) { 03858 ast_verbose("[ Initializing Custom Configuration Options ]\n"); 03859 } 03860 /* custom config setup */ 03861 register_config_cli(); 03862 read_config_maps(); 03863 03864 if (ast_opt_console) { 03865 if (el_hist == NULL || el == NULL) 03866 ast_el_initialize(); 03867 03868 if (!ast_strlen_zero(filename)) 03869 ast_el_read_history(filename); 03870 } 03871 03872 ast_ulaw_init(); 03873 ast_alaw_init(); 03874 tdd_init(); 03875 callerid_init(); 03876 ast_builtins_init(); 03877 03878 if (ast_utils_init()) { 03879 printf("%s", term_quit()); 03880 exit(1); 03881 } 03882 03883 if (ast_tps_init()) { 03884 printf("%s", term_quit()); 03885 exit(1); 03886 } 03887 03888 if (ast_fd_init()) { 03889 printf("%s", term_quit()); 03890 exit(1); 03891 } 03892 03893 if (ast_pbx_init()) { 03894 printf("%s", term_quit()); 03895 exit(1); 03896 } 03897 03898 if (ast_event_init()) { 03899 printf("%s", term_quit()); 03900 exit(1); 03901 } 03902 03903 #ifdef TEST_FRAMEWORK 03904 if (ast_test_init()) { 03905 printf("%s", term_quit()); 03906 exit(1); 03907 } 03908 #endif 03909 03910 ast_aoc_cli_init(); 03911 03912 ast_makesocket(); 03913 sigemptyset(&sigs); 03914 sigaddset(&sigs, SIGHUP); 03915 sigaddset(&sigs, SIGTERM); 03916 sigaddset(&sigs, SIGINT); 03917 sigaddset(&sigs, SIGPIPE); 03918 sigaddset(&sigs, SIGWINCH); 03919 pthread_sigmask(SIG_BLOCK, &sigs, NULL); 03920 sigaction(SIGURG, &urg_handler, NULL); 03921 signal(SIGINT, __quit_handler); 03922 signal(SIGTERM, __quit_handler); 03923 sigaction(SIGHUP, &hup_handler, NULL); 03924 sigaction(SIGPIPE, &ignore_sig_handler, NULL); 03925 03926 /* ensure that the random number generators are seeded with a different value every time 03927 Asterisk is started 03928 */ 03929 srand((unsigned int) getpid() + (unsigned int) time(NULL)); 03930 initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool)); 03931 03932 if (init_logger()) { /* Start logging subsystem */ 03933 printf("%s", term_quit()); 03934 exit(1); 03935 } 03936 03937 threadstorage_init(); 03938 03939 astobj2_init(); 03940 03941 ast_autoservice_init(); 03942 03943 if (ast_timing_init()) { 03944 printf("%s", term_quit()); 03945 exit(1); 03946 } 03947 03948 if (ast_ssl_init()) { 03949 printf("%s", term_quit()); 03950 exit(1); 03951 } 03952 03953 #ifdef AST_XML_DOCS 03954 /* Load XML documentation. */ 03955 ast_xmldoc_load_documentation(); 03956 #endif 03957 03958 /* initialize the data retrieval API */ 03959 if (ast_data_init()) { 03960 printf ("%s", term_quit()); 03961 exit(1); 03962 } 03963 03964 ast_channels_init(); 03965 03966 if ((moduleresult = load_modules(1))) { /* Load modules, pre-load only */ 03967 printf("%s", term_quit()); 03968 exit(moduleresult == -2 ? 2 : 1); 03969 } 03970 03971 if (dnsmgr_init()) { /* Initialize the DNS manager */ 03972 printf("%s", term_quit()); 03973 exit(1); 03974 } 03975 03976 ast_http_init(); /* Start the HTTP server, if needed */ 03977 03978 if (init_manager()) { 03979 printf("%s", term_quit()); 03980 exit(1); 03981 } 03982 03983 if (ast_cdr_engine_init()) { 03984 printf("%s", term_quit()); 03985 exit(1); 03986 } 03987 03988 if (ast_cel_engine_init()) { 03989 printf("%s", term_quit()); 03990 exit(1); 03991 } 03992 03993 if (ast_device_state_engine_init()) { 03994 printf("%s", term_quit()); 03995 exit(1); 03996 } 03997 03998 ast_dsp_init(); 03999 ast_udptl_init(); 04000 04001 if (ast_image_init()) { 04002 printf("%s", term_quit()); 04003 exit(1); 04004 } 04005 04006 if (ast_file_init()) { 04007 printf("%s", term_quit()); 04008 exit(1); 04009 } 04010 04011 if (load_pbx()) { 04012 printf("%s", term_quit()); 04013 exit(1); 04014 } 04015 04016 if (ast_indications_init()) { 04017 printf("%s", term_quit()); 04018 exit(1); 04019 } 04020 04021 if (ast_features_init()) { 04022 printf("%s", term_quit()); 04023 exit(1); 04024 } 04025 04026 if (init_framer()) { 04027 printf("%s", term_quit()); 04028 exit(1); 04029 } 04030 04031 if (astdb_init()) { 04032 printf("%s", term_quit()); 04033 exit(1); 04034 } 04035 04036 if (ast_enum_init()) { 04037 printf("%s", term_quit()); 04038 exit(1); 04039 } 04040 04041 if (ast_cc_init()) { 04042 printf("%s", term_quit()); 04043 exit(1); 04044 } 04045 04046 if ((moduleresult = load_modules(0))) { /* Load modules */ 04047 printf("%s", term_quit()); 04048 exit(moduleresult == -2 ? 2 : 1); 04049 } 04050 04051 /* loads the cli_permissoins.conf file needed to implement cli restrictions. */ 04052 ast_cli_perms_init(0); 04053 04054 ast_stun_init(); 04055 04056 dnsmgr_start_refresh(); 04057 04058 /* We might have the option of showing a console, but for now just 04059 do nothing... */ 04060 if (ast_opt_console && !option_verbose) 04061 ast_verbose(" ]\n"); 04062 if (option_verbose || ast_opt_console) 04063 ast_verbose("%s", term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp))); 04064 if (ast_opt_no_fork) 04065 consolethread = pthread_self(); 04066 04067 if (pipe(sig_alert_pipe)) 04068 sig_alert_pipe[0] = sig_alert_pipe[1] = -1; 04069 04070 ast_set_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED); 04071 manager_event(EVENT_FLAG_SYSTEM, "FullyBooted", "Status: Fully Booted\r\n"); 04072 04073 ast_process_pending_reloads(); 04074 04075 pthread_sigmask(SIG_UNBLOCK, &sigs, NULL); 04076 04077 #if defined(__AST_DEBUG_MALLOC) 04078 __ast_mm_init_phase_2(); 04079 #endif /* defined(__AST_DEBUG_MALLOC) */ 04080 04081 ast_lastreloadtime = ast_startuptime = ast_tvnow(); 04082 ast_cli_register_multiple(cli_asterisk_shutdown, ARRAY_LEN(cli_asterisk_shutdown)); 04083 ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk)); 04084 ast_register_atexit(main_atexit); 04085 04086 run_startup_commands(); 04087 04088 if (ast_opt_console) { 04089 /* Console stuff now... */ 04090 /* Register our quit function */ 04091 char title[256]; 04092 04093 ast_pthread_create_detached(&mon_sig_flags, NULL, monitor_sig_flags, NULL); 04094 04095 set_icon("Asterisk"); 04096 snprintf(title, sizeof(title), "Asterisk Console on '%s' (pid %ld)", hostname, (long)ast_mainpid); 04097 set_title(title); 04098 04099 el_set(el, EL_GETCFN, ast_el_read_char); 04100 04101 for (;;) { 04102 if (sig_flags.need_quit || sig_flags.need_quit_handler) { 04103 quit_handler(0, SHUTDOWN_FAST, 0); 04104 break; 04105 } 04106 buf = (char *) el_gets(el, &num); 04107 04108 if (!buf && write(1, "", 1) < 0) 04109 goto lostterm; 04110 04111 if (buf) { 04112 if (buf[strlen(buf)-1] == '\n') 04113 buf[strlen(buf)-1] = '\0'; 04114 04115 consolehandler((char *)buf); 04116 } else if (ast_opt_remote && (write(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n", 04117 strlen("\nUse EXIT or QUIT to exit the asterisk console\n")) < 0)) { 04118 /* Whoa, stdout disappeared from under us... Make /dev/null's */ 04119 int fd; 04120 fd = open("/dev/null", O_RDWR); 04121 if (fd > -1) { 04122 dup2(fd, STDOUT_FILENO); 04123 dup2(fd, STDIN_FILENO); 04124 } else 04125 ast_log(LOG_WARNING, "Failed to open /dev/null to recover from dead console. Bad things will happen!\n"); 04126 break; 04127 } 04128 } 04129 } 04130 04131 monitor_sig_flags(NULL); 04132 04133 lostterm: 04134 return 0; 04135 }
| static void main_atexit | ( | void | ) | [static] |
Definition at line 3375 of file asterisk.c.
References ARRAY_LEN, and ast_cli_unregister_multiple().
Referenced by main().
03376 { 03377 ast_cli_unregister_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk)); 03378 }
| static void* monitor_sig_flags | ( | void * | unused | ) | [static] |
Definition at line 3257 of file asterisk.c.
References ast_module_reload(), ast_poll, AST_PTHREADT_NULL, consolethread, quit_handler(), SHUTDOWN_NORMAL, sig_alert_pipe, and sig_flags.
Referenced by main().
03258 { 03259 for (;;) { 03260 struct pollfd p = { sig_alert_pipe[0], POLLIN, 0 }; 03261 int a; 03262 ast_poll(&p, 1, -1); 03263 if (sig_flags.need_reload) { 03264 sig_flags.need_reload = 0; 03265 ast_module_reload(NULL); 03266 } 03267 if (sig_flags.need_quit) { 03268 sig_flags.need_quit = 0; 03269 if ((consolethread != AST_PTHREADT_NULL) && (consolethread != pthread_self())) { 03270 sig_flags.need_quit_handler = 1; 03271 pthread_kill(consolethread, SIGURG); 03272 } else { 03273 quit_handler(0, SHUTDOWN_NORMAL, 0); 03274 } 03275 } 03276 if (read(sig_alert_pipe[0], &a, sizeof(a)) != sizeof(a)) { 03277 } 03278 } 03279 03280 return NULL; 03281 }
| static void* netconsole | ( | void * | vconsole | ) | [static] |
Definition at line 1281 of file asterisk.c.
References ast_cli_command_multiple_full(), ast_copy_string(), ast_get_version(), ast_log(), ast_opt_hide_connect, ast_poll, ast_verb, errno, console::fd, fdprint(), console::gid, hostname, inbuf(), LOG_ERROR, LOG_WARNING, MAXHOSTNAMELEN, console::p, read_credentials(), and console::uid.
Referenced by listener().
01282 { 01283 struct console *con = vconsole; 01284 char hostname[MAXHOSTNAMELEN] = ""; 01285 char inbuf[512]; 01286 char outbuf[512]; 01287 const char * const end_buf = inbuf + sizeof(inbuf); 01288 char *start_read = inbuf; 01289 int res; 01290 struct pollfd fds[2]; 01291 01292 if (gethostname(hostname, sizeof(hostname)-1)) 01293 ast_copy_string(hostname, "<Unknown>", sizeof(hostname)); 01294 snprintf(outbuf, sizeof(outbuf), "%s/%ld/%s\n", hostname, (long)ast_mainpid, ast_get_version()); 01295 fdprint(con->fd, outbuf); 01296 for (;;) { 01297 fds[0].fd = con->fd; 01298 fds[0].events = POLLIN; 01299 fds[0].revents = 0; 01300 fds[1].fd = con->p[0]; 01301 fds[1].events = POLLIN; 01302 fds[1].revents = 0; 01303 01304 res = ast_poll(fds, 2, -1); 01305 if (res < 0) { 01306 if (errno != EINTR) 01307 ast_log(LOG_WARNING, "poll returned < 0: %s\n", strerror(errno)); 01308 continue; 01309 } 01310 if (fds[0].revents) { 01311 int cmds_read, bytes_read; 01312 if ((bytes_read = read_credentials(con->fd, start_read, end_buf - start_read, con)) < 1) { 01313 break; 01314 } 01315 /* XXX This will only work if it is the first command, and I'm not sure fixing it is worth the effort. */ 01316 if (strncmp(inbuf, "cli quit after ", 15) == 0) { 01317 ast_cli_command_multiple_full(con->uid, con->gid, con->fd, bytes_read - 15, inbuf + 15); 01318 break; 01319 } 01320 /* ast_cli_command_multiple_full will only process individual commands terminated by a 01321 * NULL and not trailing partial commands. */ 01322 if (!(cmds_read = ast_cli_command_multiple_full(con->uid, con->gid, con->fd, bytes_read + start_read - inbuf, inbuf))) { 01323 /* No commands were read. We either have a short read on the first command 01324 * with space left, or a command that is too long */ 01325 if (start_read + bytes_read < end_buf) { 01326 start_read += bytes_read; 01327 } else { 01328 ast_log(LOG_ERROR, "Command too long! Skipping\n"); 01329 start_read = inbuf; 01330 } 01331 continue; 01332 } 01333 if (start_read[bytes_read - 1] == '\0') { 01334 /* The read ended on a command boundary, start reading again at the head of inbuf */ 01335 start_read = inbuf; 01336 continue; 01337 } 01338 /* If we get this far, we have left over characters that have not been processed. 01339 * Advance to the character after the last command read by ast_cli_command_multiple_full. 01340 * We are guaranteed to have at least cmds_read NULLs */ 01341 while (cmds_read-- && (start_read = strchr(start_read, '\0'))) { 01342 start_read++; 01343 } 01344 memmove(inbuf, start_read, end_buf - start_read); 01345 start_read = end_buf - start_read + inbuf; 01346 } 01347 if (fds[1].revents) { 01348 res = read_credentials(con->p[0], outbuf, sizeof(outbuf), con); 01349 if (res < 1) { 01350 ast_log(LOG_ERROR, "read returned %d\n", res); 01351 break; 01352 } 01353 res = write(con->fd, outbuf, res); 01354 if (res < 1) 01355 break; 01356 } 01357 } 01358 if (!ast_opt_hide_connect) { 01359 ast_verb(3, "Remote UNIX connection disconnected\n"); 01360 } 01361 close(con->fd); 01362 close(con->p[0]); 01363 close(con->p[1]); 01364 con->fd = -1; 01365 01366 return NULL; 01367 }
| static void network_verboser | ( | const char * | s | ) | [static] |
Definition at line 1215 of file asterisk.c.
References __LOG_VERBOSE, and ast_network_puts_mutable().
Referenced by ast_makesocket().
01216 { 01217 ast_network_puts_mutable(s, __LOG_VERBOSE); 01218 }
| static void print_intro_message | ( | const char * | runuser, | |
| const char * | rungroup | |||
| ) | [static] |
Definition at line 3358 of file asterisk.c.
References ast_opt_console, ast_opt_exec, ast_opt_remote, ast_register_verbose(), ast_verbose, console_verboser(), and WELCOME_MESSAGE.
Referenced by main().
03359 { 03360 if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) { 03361 if (ast_register_verbose(console_verboser)) { 03362 fprintf(stderr, "Unable to register console verboser?\n"); 03363 return; 03364 } 03365 WELCOME_MESSAGE; 03366 if (runuser) { 03367 ast_verbose("Running as user '%s'\n", runuser); 03368 } 03369 if (rungroup) { 03370 ast_verbose("Running under group '%s'\n", rungroup); 03371 } 03372 } 03373 }
| static void quit_handler | ( | int | num, | |
| shutdown_nice_t | niceness, | |||
| int | restart | |||
| ) | [static] |
Definition at line 1673 of file asterisk.c.
References can_safely_quit(), and really_quit().
Referenced by ast_el_read_char(), handle_restart_gracefully(), handle_restart_now(), handle_restart_when_convenient(), handle_stop_gracefully(), handle_stop_now(), handle_stop_when_convenient(), main(), monitor_sig_flags(), and remoteconsolehandler().
01674 { 01675 if (can_safely_quit(niceness, restart)) { 01676 really_quit(num, niceness, restart); 01677 /* No one gets here. */ 01678 } 01679 /* It wasn't our time. */ 01680 }
| static __inline uint64_t rdtsc | ( | void | ) | [static] |
Definition at line 766 of file asterisk.c.
Referenced by ast_mark().
| static int read_credentials | ( | int | fd, | |
| char * | buffer, | |||
| size_t | size, | |||
| struct console * | con | |||
| ) | [static] |
read() function supporting the reception of user credentials.
| fd | Socket file descriptor. | |
| buffer | Receive buffer. | |
| size | 'buffer' size. | |
| con | Console structure to set received credentials |
| -1 | on error | |
| the | number of bytes received on success. |
Definition at line 1232 of file asterisk.c.
References console::gid, len(), and console::uid.
Referenced by netconsole().
01233 { 01234 #if defined(SO_PEERCRED) 01235 #ifdef HAVE_STRUCT_SOCKPEERCRED_UID 01236 #define HAVE_STRUCT_UCRED_UID 01237 struct sockpeercred cred; 01238 #else 01239 struct ucred cred; 01240 #endif 01241 socklen_t len = sizeof(cred); 01242 #endif 01243 #if defined(HAVE_GETPEEREID) 01244 uid_t uid; 01245 gid_t gid; 01246 #else 01247 int uid, gid; 01248 #endif 01249 int result; 01250 01251 result = read(fd, buffer, size); 01252 if (result < 0) { 01253 return result; 01254 } 01255 01256 #if defined(SO_PEERCRED) && (defined(HAVE_STRUCT_UCRED_UID) || defined(HAVE_STRUCT_UCRED_CR_UID)) 01257 if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len)) { 01258 return result; 01259 } 01260 #if defined(HAVE_STRUCT_UCRED_UID) 01261 uid = cred.uid; 01262 gid = cred.gid; 01263 #else /* defined(HAVE_STRUCT_UCRED_CR_UID) */ 01264 uid = cred.cr_uid; 01265 gid = cred.cr_gid; 01266 #endif /* defined(HAVE_STRUCT_UCRED_UID) */ 01267 01268 #elif defined(HAVE_GETPEEREID) 01269 if (getpeereid(fd, &uid, &gid)) { 01270 return result; 01271 } 01272 #else 01273 return result; 01274 #endif 01275 con->uid = uid; 01276 con->gid = gid; 01277 01278 return result; 01279 }
| static void really_quit | ( | int | num, | |
| shutdown_nice_t | niceness, | |||
| int | restart | |||
| ) | [static] |
Called when exiting is certain.
Definition at line 1749 of file asterisk.c.
References _argv, ast_active_channels(), ast_config_AST_PID, ast_config_AST_SOCKET, ast_debug, ast_el_write_history(), ast_module_shutdown(), ast_opt_console, ast_opt_exec, ast_opt_remote, AST_PTHREADT_NULL, ast_run_atexits(), ast_strlen_zero(), ast_verbose, clean_time_zones(), close_logger(), consolethread, el, el_hist, EVENT_FLAG_SYSTEM, lthread, manager_event, mon_sig_flags, restartnow, SHUTDOWN_NICE, sig_alert_pipe, and term_quit().
Referenced by quit_handler().
01750 { 01751 int active_channels; 01752 01753 if (niceness >= SHUTDOWN_NICE) { 01754 ast_module_shutdown(); 01755 } 01756 01757 if (ast_opt_console || (ast_opt_remote && !ast_opt_exec)) { 01758 char filename[80] = ""; 01759 if (getenv("HOME")) { 01760 snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); 01761 } 01762 if (!ast_strlen_zero(filename)) { 01763 ast_el_write_history(filename); 01764 } 01765 if (consolethread == AST_PTHREADT_NULL || consolethread == pthread_self()) { 01766 /* Only end if we are the consolethread, otherwise there's a race with that thread. */ 01767 if (el != NULL) { 01768 el_end(el); 01769 } 01770 if (el_hist != NULL) { 01771 history_end(el_hist); 01772 } 01773 } else if (mon_sig_flags == pthread_self()) { 01774 if (consolethread != AST_PTHREADT_NULL) { 01775 pthread_kill(consolethread, SIGURG); 01776 } 01777 } 01778 } 01779 active_channels = ast_active_channels(); 01780 /* The manager event for shutdown must happen prior to ast_run_atexits, as 01781 * the manager interface will dispose of its sessions as part of its 01782 * shutdown. 01783 */ 01784 manager_event(EVENT_FLAG_SYSTEM, "Shutdown", "Shutdown: %s\r\n" 01785 "Restart: %s\r\n", 01786 active_channels ? "Uncleanly" : "Cleanly", 01787 restart ? "True" : "False"); 01788 if (option_verbose && ast_opt_console) { 01789 ast_verbose("Asterisk %s ending (%d).\n", 01790 active_channels ? "uncleanly" : "cleanly", num); 01791 } 01792 01793 if (option_verbose) 01794 ast_verbose("Executing last minute cleanups\n"); 01795 ast_run_atexits(); 01796 01797 ast_debug(1, "Asterisk ending (%d).\n", num); 01798 if (ast_socket > -1) { 01799 pthread_cancel(lthread); 01800 close(ast_socket); 01801 ast_socket = -1; 01802 unlink(ast_config_AST_SOCKET); 01803 pthread_kill(lthread, SIGURG); 01804 pthread_join(lthread, NULL); 01805 } 01806 if (ast_consock > -1) 01807 close(ast_consock); 01808 if (!ast_opt_remote) 01809 unlink(ast_config_AST_PID); 01810 if (sig_alert_pipe[0]) 01811 close(sig_alert_pipe[0]); 01812 if (sig_alert_pipe[1]) 01813 close(sig_alert_pipe[1]); 01814 printf("%s", term_quit()); 01815 if (restart) { 01816 int i; 01817 if (option_verbose || ast_opt_console) 01818 ast_verbose("Preparing for Asterisk restart...\n"); 01819 /* Mark all FD's for closing on exec */ 01820 for (i = 3; i < 32768; i++) { 01821 fcntl(i, F_SETFD, FD_CLOEXEC); 01822 } 01823 if (option_verbose || ast_opt_console) 01824 ast_verbose("Asterisk is now restarting...\n"); 01825 restartnow = 1; 01826 01827 /* close logger */ 01828 close_logger(); 01829 clean_time_zones(); 01830 01831 /* If there is a consolethread running send it a SIGHUP 01832 so it can execvp, otherwise we can do it ourselves */ 01833 if ((consolethread != AST_PTHREADT_NULL) && (consolethread != pthread_self())) { 01834 pthread_kill(consolethread, SIGHUP); 01835 /* Give the signal handler some time to complete */ 01836 sleep(2); 01837 } else 01838 execvp(_argv[0], _argv); 01839 01840 } else { 01841 /* close logger */ 01842 close_logger(); 01843 clean_time_zones(); 01844 } 01845 01846 exit(0); 01847 }
| static int remoteconsolehandler | ( | char * | s | ) | [static] |
Definition at line 1937 of file asterisk.c.
References ast_all_zeros(), ast_el_add_history(), ast_safe_system(), quit_handler(), and SHUTDOWN_FAST.
Referenced by ast_remotecontrol().
01938 { 01939 int ret = 0; 01940 01941 /* Called when readline data is available */ 01942 if (!ast_all_zeros(s)) 01943 ast_el_add_history(s); 01944 /* The real handler for bang */ 01945 if (s[0] == '!') { 01946 if (s[1]) 01947 ast_safe_system(s+1); 01948 else 01949 ast_safe_system(getenv("SHELL") ? getenv("SHELL") : "/bin/sh"); 01950 ret = 1; 01951 } 01952 while (isspace(*s)) { 01953 s++; 01954 } 01955 01956 if ((strncasecmp(s, "quit", 4) == 0 || strncasecmp(s, "exit", 4) == 0) && 01957 (s[4] == '\0' || isspace(s[4]))) { 01958 quit_handler(0, SHUTDOWN_FAST, 0); 01959 ret = 1; 01960 } 01961 01962 return ret; 01963 }
| static void run_startup_commands | ( | void | ) | [static] |
Definition at line 3318 of file asterisk.c.
References ast_cli_command, ast_config_destroy(), ast_config_load2(), ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by main().
03319 { 03320 int fd; 03321 struct ast_config *cfg; 03322 struct ast_flags cfg_flags = { 0 }; 03323 struct ast_variable *v; 03324 03325 if (!(cfg = ast_config_load2("cli.conf", "" /* core, can't reload */, cfg_flags))) 03326 return; 03327 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) { 03328 return; 03329 } 03330 03331 fd = open("/dev/null", O_RDWR); 03332 if (fd < 0) { 03333 ast_config_destroy(cfg); 03334 return; 03335 } 03336 03337 for (v = ast_variable_browse(cfg, "startup_commands"); v; v = v->next) { 03338 if (ast_true(v->value)) 03339 ast_cli_command(fd, v->name); 03340 } 03341 03342 close(fd); 03343 ast_config_destroy(cfg); 03344 }
| static void set_icon | ( | char * | text | ) | [static] |
Definition at line 1628 of file asterisk.c.
Referenced by main().
01629 { 01630 if (getenv("TERM") && strstr(getenv("TERM"), "xterm")) 01631 fprintf(stdout, "\033]1;%s\007", text); 01632 }
| static void set_title | ( | char * | text | ) | [static] |
Set an X-term or screen title.
Definition at line 1622 of file asterisk.c.
Referenced by main().
01623 { 01624 if (getenv("TERM") && strstr(getenv("TERM"), "xterm")) 01625 fprintf(stdout, "\033]2;%s\007", text); 01626 }
| static void set_ulimit | ( | int | value | ) | [static] |
Set maximum open files.
Definition at line 1599 of file asterisk.c.
References ast_log(), errno, LOG_NOTICE, and LOG_WARNING.
Referenced by ast_readconfig().
01600 { 01601 struct rlimit l = {0, 0}; 01602 01603 if (value <= 0) { 01604 ast_log(LOG_WARNING, "Unable to change max files open to invalid value %i\n",value); 01605 return; 01606 } 01607 01608 l.rlim_cur = value; 01609 l.rlim_max = value; 01610 01611 if (setrlimit(RLIMIT_NOFILE, &l)) { 01612 ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n",strerror(errno)); 01613 return; 01614 } 01615 01616 ast_log(LOG_NOTICE, "Setting max files open to %d\n",value); 01617 01618 return; 01619 }
| static int show_cli_help | ( | void | ) | [static] |
Definition at line 2971 of file asterisk.c.
References ast_get_version().
Referenced by main().
02972 { 02973 printf("Asterisk %s, Copyright (C) 1999 - 2013, Digium, Inc. and others.\n", ast_get_version()); 02974 printf("Usage: asterisk [OPTIONS]\n"); 02975 printf("Valid Options:\n"); 02976 printf(" -V Display version number and exit\n"); 02977 printf(" -C <configfile> Use an alternate configuration file\n"); 02978 printf(" -G <group> Run as a group other than the caller\n"); 02979 printf(" -U <user> Run as a user other than the caller\n"); 02980 printf(" -c Provide console CLI\n"); 02981 printf(" -d Enable extra debugging\n"); 02982 #if HAVE_WORKING_FORK 02983 printf(" -f Do not fork\n"); 02984 printf(" -F Always fork\n"); 02985 #endif 02986 printf(" -g Dump core in case of a crash\n"); 02987 printf(" -h This help screen\n"); 02988 printf(" -i Initialize crypto keys at startup\n"); 02989 printf(" -I Enable internal timing if DAHDI timer is available\n"); 02990 printf(" -L <load> Limit the maximum load average before rejecting new calls\n"); 02991 printf(" -M <value> Limit the maximum number of calls to the specified value\n"); 02992 printf(" -m Mute debugging and console output on the console\n"); 02993 printf(" -n Disable console colorization\n"); 02994 printf(" -p Run as pseudo-realtime thread\n"); 02995 printf(" -q Quiet mode (suppress output)\n"); 02996 printf(" -r Connect to Asterisk on this machine\n"); 02997 printf(" -R Same as -r, except attempt to reconnect if disconnected\n"); 02998 printf(" -s <socket> Connect to Asterisk via socket <socket> (only valid with -r)\n"); 02999 printf(" -t Record soundfiles in /var/tmp and move them where they\n"); 03000 printf(" belong after they are done\n"); 03001 printf(" -T Display the time in [Mmm dd hh:mm:ss] format for each line\n"); 03002 printf(" of output to the CLI\n"); 03003 printf(" -v Increase verbosity (multiple v's = more verbose)\n"); 03004 printf(" -x <cmd> Execute command <cmd> (implies -r)\n"); 03005 printf(" -X Execute includes by default (allows #exec in asterisk.conf)\n"); 03006 printf(" -W Adjust terminal colors to compensate for a light background\n"); 03007 printf("\n"); 03008 return 0; 03009 }
| static char* show_license | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2224 of file asterisk.c.
References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
02225 { 02226 switch (cmd) { 02227 case CLI_INIT: 02228 e->command = "core show license"; 02229 e->usage = 02230 "Usage: core show license\n" 02231 " Shows the license(s) for this copy of Asterisk.\n"; 02232 return NULL; 02233 case CLI_GENERATE: 02234 return NULL; 02235 } 02236 02237 ast_cli(a->fd, "%s", license_lines); 02238 02239 return CLI_SUCCESS; 02240 }
| static int show_version | ( | void | ) | [static] |
Definition at line 2965 of file asterisk.c.
References ast_get_version().
Referenced by main().
02966 { 02967 printf("Asterisk %s\n", ast_get_version()); 02968 return 0; 02969 }
| static char* show_warranty | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2187 of file asterisk.c.
References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
02188 { 02189 switch (cmd) { 02190 case CLI_INIT: 02191 e->command = "core show warranty"; 02192 e->usage = 02193 "Usage: core show warranty\n" 02194 " Shows the warranty (if any) for this copy of Asterisk.\n"; 02195 return NULL; 02196 case CLI_GENERATE: 02197 return NULL; 02198 } 02199 02200 ast_cli(a->fd, "%s", warranty_lines); 02201 02202 return CLI_SUCCESS; 02203 }
char* _argv[256] [static] |
Definition at line 281 of file asterisk.c.
Referenced by _hup_handler(), main(), and really_quit().
| const char* ast_config_AST_AGI_DIR = cfg_paths.agi_dir |
Definition at line 263 of file asterisk.c.
Referenced by handle_show_settings(), and launch_script().
| const char* ast_config_AST_CONFIG_DIR = cfg_paths.config_dir |
Definition at line 255 of file asterisk.c.
Referenced by action_createconfig(), ast_module_reload(), compile_script(), config_text_file_load(), handle_cli_dialplan_save(), handle_show_settings(), ices_exec(), launch_script(), lua_read_extensions_file(), message_template_parse_filebody(), pbx_load_module(), and set_fn().
| const char* ast_config_AST_CONFIG_FILE = cfg_paths.config_file |
Definition at line 256 of file asterisk.c.
Referenced by ast_readconfig(), handle_show_settings(), and launch_script().
char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl" [static] |
Definition at line 277 of file asterisk.c.
Referenced by ast_readconfig().
char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0" [static] |
Definition at line 276 of file asterisk.c.
Referenced by ast_makesocket(), and ast_readconfig().
char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0" [static] |
Definition at line 275 of file asterisk.c.
Referenced by ast_makesocket(), and ast_readconfig().
char ast_config_AST_CTL_PERMISSIONS[PATH_MAX] [static] |
Definition at line 274 of file asterisk.c.
Referenced by ast_makesocket(), and ast_readconfig().
| const char* ast_config_AST_DATA_DIR = cfg_paths.data_dir |
Definition at line 261 of file asterisk.c.
Referenced by ast_linear_stream(), build_filename(), handle_show_settings(), launch_script(), make_filename(), moh_scan_files(), phoneprov_callback(), pp_each_extension_helper(), reload_firmware(), setup_privacy_args(), and static_callback().
| const char* ast_config_AST_DB = cfg_paths.db_path |
Definition at line 267 of file asterisk.c.
Referenced by dbinit(), and handle_show_settings().
| const char* ast_config_AST_KEY_DIR = cfg_paths.key_dir |
Definition at line 264 of file asterisk.c.
Referenced by crypto_load(), handle_cli_keys_init(), handle_show_settings(), launch_script(), and osp_create_provider().
| const char* ast_config_AST_LOG_DIR = cfg_paths.log_dir |
Definition at line 262 of file asterisk.c.
Referenced by __ast_mm_init_phase_2(), apply_general_options(), csv_log(), handle_show_settings(), init_logger(), launch_script(), load_config(), load_module(), logger_queue_init(), logger_queue_restart(), make_logchannel(), OpenHistory(), reload_logger(), testclient_exec(), testserver_exec(), write_history(), and writefile().
| const char* ast_config_AST_MODULE_DIR = cfg_paths.module_dir |
Definition at line 257 of file asterisk.c.
Referenced by complete_fn(), handle_show_settings(), launch_script(), load_dynamic_module(), and load_modules().
| const char* ast_config_AST_MONITOR_DIR = cfg_paths.monitor_dir |
Definition at line 259 of file asterisk.c.
Referenced by ast_monitor_change_fname(), ast_monitor_start(), chanspy_exec(), extenspy_exec(), launch_script(), and mixmonitor_exec().
| const char* ast_config_AST_PID = cfg_paths.pid_path |
Definition at line 268 of file asterisk.c.
Referenced by handle_show_settings(), main(), and really_quit().
| const char* ast_config_AST_RUN_DIR = cfg_paths.run_dir |
Definition at line 265 of file asterisk.c.
Referenced by handle_show_settings(), launch_script(), and main().
| const char* ast_config_AST_RUN_GROUP = cfg_paths.run_group |
Definition at line 271 of file asterisk.c.
Referenced by action_coresettings(), handle_show_settings(), and main().
| const char* ast_config_AST_RUN_USER = cfg_paths.run_user |
Definition at line 270 of file asterisk.c.
Referenced by action_coresettings(), handle_show_settings(), and main().
| const char* ast_config_AST_SOCKET = cfg_paths.socket_path |
Definition at line 269 of file asterisk.c.
Referenced by ast_makesocket(), ast_tryconnect(), ast_var_Config(), main(), and really_quit().
| const char* ast_config_AST_SPOOL_DIR = cfg_paths.spool_dir |
Definition at line 258 of file asterisk.c.
Referenced by app_exec(), conf_run(), dictate_exec(), filename_parse(), handle_show_settings(), launch_script(), load_module(), sms_nextoutgoing(), and sms_writefile().
| const char* ast_config_AST_SYSTEM_NAME = cfg_paths.system_name |
Definition at line 272 of file asterisk.c.
Referenced by __ast_channel_alloc_ap(), __init_manager(), action_coresettings(), ast_readconfig(), ast_str_retrieve_variable(), cli_prompt(), env_init(), handle_show_settings(), realtime_update_peer(), and reload_config().
| const char* ast_config_AST_VAR_DIR = cfg_paths.var_dir |
Definition at line 260 of file asterisk.c.
Referenced by ael2_semantic_check(), handle_show_settings(), and launch_script().
int ast_consock = -1 [static] |
UNIX Socket for controlling another asterisk
Definition at line 198 of file asterisk.c.
| struct ast_eid ast_eid_default |
Global EID.
This is set in asterisk.conf, or determined automatically by taking the mac address of an Ethernet interface on the system.
Definition at line 192 of file asterisk.c.
Referenced by aji_devstate_cb(), aji_handle_pubsub_event(), aji_mwi_cb(), aji_publish_device_state(), aji_publish_mwi(), ast_event_append_eid(), ast_event_cb(), ast_readconfig(), ast_str_retrieve_variable(), evt_event_deliver_cb(), handle_show_settings(), and set_config().
| unsigned int ast_FD_SETSIZE |
| struct timeval ast_lastreloadtime |
Definition at line 218 of file asterisk.c.
Referenced by action_corestatus(), ast_module_reload(), ast_var_Config(), handle_show_settings(), handle_showuptime(), and main().
| pid_t ast_mainpid |
Definition at line 199 of file asterisk.c.
Referenced by safe_append(), and scan_service().
int ast_socket = -1 [static] |
UNIX Socket for allowing remote control
Definition at line 197 of file asterisk.c.
| struct timeval ast_startuptime |
Definition at line 217 of file asterisk.c.
Referenced by action_corestatus(), ast_var_Config(), handle_show_settings(), handle_showcalls(), handle_showuptime(), and main().
char canary_filename[128] [static] |
Definition at line 296 of file asterisk.c.
Referenced by canary_thread(), and main().
int canary_pid = 0 [static] |
Definition at line 295 of file asterisk.c.
Referenced by canary_exit(), and main().
struct _cfg_paths cfg_paths [static] |
Definition at line 253 of file asterisk.c.
Referenced by ast_readconfig(), and main().
struct sigaction child_handler [static] |
{
.sa_handler = _child_handler,
.sa_flags = SA_RESTART,
}
Definition at line 1593 of file asterisk.c.
struct ast_cli_entry cli_asterisk[] [static] |
Definition at line 2263 of file asterisk.c.
struct ast_cli_entry cli_asterisk_shutdown[] [static] |
Shutdown Asterisk CLI commands.
Definition at line 2254 of file asterisk.c.
Definition at line 224 of file asterisk.c.
Referenced by ast_console_toggle_loglevel(), ast_console_toggle_mute(), ast_makesocket(), ast_network_puts(), ast_network_puts_mutable(), and listener().
pthread_t consolethread = AST_PTHREADT_NULL [static] |
Definition at line 293 of file asterisk.c.
Referenced by console_verboser(), main(), monitor_sig_flags(), and really_quit().
| char defaultlanguage[MAX_LANGUAGE] = DEFAULT_LANGUAGE |
Definition at line 226 of file asterisk.c.
Referenced by __ast_channel_alloc_ap(), ast_readconfig(), and handle_show_settings().
EditLine* el [static] |
Definition at line 221 of file asterisk.c.
Referenced by __ast_internal_context_destroy(), ast_add_extension2_lockopt(), ast_el_add_history(), ast_el_initialize(), ast_el_read_history(), ast_el_write_history(), ast_remotecontrol(), handle_cli_dialplan_save(), main(), really_quit(), and show_dialplan_helper().
History* el_hist [static] |
Definition at line 220 of file asterisk.c.
Referenced by ast_el_add_history(), ast_el_initialize(), ast_el_read_history(), ast_el_write_history(), ast_remotecontrol(), main(), and really_quit().
struct sigaction hup_handler [static] |
{
.sa_handler = _hup_handler,
.sa_flags = SA_RESTART,
}
Definition at line 1573 of file asterisk.c.
struct sigaction ignore_sig_handler [static] |
{
.sa_handler = SIG_IGN,
}
Definition at line 1023 of file asterisk.c.
Referenced by main().
const char license_lines[] [static] |
Definition at line 2205 of file asterisk.c.
pthread_t lthread [static] |
Definition at line 1220 of file asterisk.c.
Referenced by ast_makesocket(), and really_quit().
pthread_t mon_sig_flags [static] |
Definition at line 294 of file asterisk.c.
Referenced by main(), and really_quit().
int multi_thread_safe [static] |
Definition at line 297 of file asterisk.c.
Referenced by ast_register_thread(), and main().
| unsigned int need_quit |
Definition at line 304 of file asterisk.c.
| unsigned int need_quit_handler |
Definition at line 305 of file asterisk.c.
| unsigned int need_reload |
Definition at line 303 of file asterisk.c.
struct sigaction null_sig_handler [static] |
{
.sa_handler = _null_sig_handler,
.sa_flags = SA_RESTART,
}
Definition at line 1018 of file asterisk.c.
Referenced by ast_replace_sigchld().
struct profile_data* prof_data [static] |
Definition at line 702 of file asterisk.c.
Referenced by ast_add_profile(), ast_mark(), ast_profile(), handle_clear_profile(), and handle_show_profile().
Definition at line 2380 of file asterisk.c.
Referenced by auth_exec(), handle_speechrecognize(), minivm_accmess_exec(), and pw_cb().
char randompool[256] [static] |
Definition at line 299 of file asterisk.c.
Referenced by main().
| char record_cache_dir[AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR |
Definition at line 195 of file asterisk.c.
Referenced by ast_writefile().
char* remotehostname [static] |
Definition at line 222 of file asterisk.c.
Referenced by ast_remotecontrol(), and cli_prompt().
int restartnow [static] |
Definition at line 292 of file asterisk.c.
Referenced by _hup_handler(), and really_quit().
unsigned int safe_system_level = 0 [static] |
Keep track of how many threads are currently trying to wait*() on a child process.
Definition at line 1030 of file asterisk.c.
Referenced by ast_replace_sigchld(), and ast_unreplace_sigchld().
ast_mutex_t safe_system_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } [static] |
Definition at line 1027 of file asterisk.c.
Referenced by ast_replace_sigchld(), ast_unreplace_sigchld(), can_safely_quit(), and handle_abort_shutdown().
struct sigaction safe_system_prev_handler [static] |
Definition at line 1031 of file asterisk.c.
Referenced by ast_replace_sigchld(), and ast_unreplace_sigchld().
shutdown_nice_t shuttingdown = NOT_SHUTTING_DOWN [static] |
Definition at line 291 of file asterisk.c.
Referenced by can_safely_quit(), and handle_abort_shutdown().
int sig_alert_pipe[2] = { -1, -1 } [static] |
Definition at line 301 of file asterisk.c.
Referenced by __quit_handler(), _hup_handler(), main(), monitor_sig_flags(), and really_quit().
struct { ... } sig_flags [static] |
Referenced by __quit_handler(), __remote_quit_handler(), _hup_handler(), ast_el_read_char(), ast_remotecontrol(), main(), and monitor_sig_flags().
struct sigaction urg_handler [static] |
{
.sa_handler = _urg_handler,
.sa_flags = SA_RESTART,
}
Definition at line 1552 of file asterisk.c.
const char warranty_lines[] [static] |
Definition at line 2162 of file asterisk.c.
1.6.1