Asterisk - The Open Source Telephony Project
21.4.1
|
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 <histedit.h>
#include "asterisk/paths.h"
#include "asterisk/network.h"
#include "asterisk/cli.h"
#include "asterisk/channel.h"
#include "asterisk/translate.h"
#include "asterisk/pickup.h"
#include "asterisk/acl.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/pbx.h"
#include "asterisk/app.h"
#include "asterisk/mwi.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/io.h"
#include "asterisk/config.h"
#include "asterisk/ast_version.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
#include "asterisk/presencestate.h"
#include "asterisk/module.h"
#include "asterisk/buildinfo.h"
#include "asterisk/xmldoc.h"
#include "asterisk/poll-compat.h"
#include "asterisk/test.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/format.h"
#include "asterisk/aoc.h"
#include "asterisk/uuid.h"
#include "asterisk/sorcery.h"
#include "asterisk/bucket.h"
#include "asterisk/stasis.h"
#include "asterisk/json.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stasis_system.h"
#include "asterisk/security_events.h"
#include "asterisk/endpoints.h"
#include "asterisk/codec.h"
#include "asterisk/format_cache.h"
#include "asterisk/media_cache.h"
#include "asterisk/astdb.h"
#include "asterisk/options.h"
#include "asterisk/utf8.h"
#include "../defaults.h"
Go to the source code of this file.
Data Structures | |
struct | ast_atexit |
struct | atexits |
struct | console |
struct | console_state_data |
struct | profile_data |
struct | profile_entry |
struct | thread_list |
struct | thread_list_t |
Macros | |
#define | AF_LOCAL AF_UNIX |
#define | AST_MAX_CONNECTS 128 |
#define | ASTERISK_PROMPT "*CLI> " |
#define | CHAR_T_LIBEDIT wchar_t |
#define | CHAR_TO_LIBEDIT(c) btowc(c) |
#define | CMD_MATCHESARRAY "_COMMAND MATCHESARRAY \"%s\" \"%s\"" |
#define | COPYRIGHT_TAG "Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others." |
#define | DEFINE_PROFILE_MIN_MAX_VALUES |
#define | EL_BUF_SIZE 512 |
#define | MAX_HISTORY_COMMAND_LENGTH 256 |
#define | NUM_MSGS 64 |
#define | PF_LOCAL PF_UNIX |
#define | SHUTDOWN_TIMEOUT 15 /* Seconds */ |
#define | WELCOME_MESSAGE |
Welcome message when starting a CLI interface. | |
Enumerations | |
enum | shutdown_nice_t { NOT_SHUTTING_DOWN, SHUTTING_DOWN_FINAL, SHUTTING_DOWN, SHUTDOWN_FAST, SHUTDOWN_NORMAL, SHUTDOWN_NICE, SHUTDOWN_REALLY_NICE } |
Functions | |
static void | __ast_unregister_atexit (void(*func)(void)) |
static void | __init_console_state (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. More... | |
int | ast_add_profile (const char *name, uint64_t scale) |
allocates a counter with a given name and scale. More... | |
static int | ast_all_zeros (const char *s) |
static void | ast_begin_shutdown (void) |
int | ast_cancel_shutdown (void) |
Cancel an existing shutdown and return to normal operation. More... | |
static void | ast_cli_display_match_list (struct ast_vector_string *matches, int max) |
void | ast_console_puts (const char *string) |
write the string to the root console, and all attached network console clients | |
void | ast_console_puts_mutable (const char *string, int level) |
log the string to the root console, and all attached network console clients More... | |
void | ast_console_puts_mutable_full (const char *message, int level, int sublevel) |
log the string to the console, and all attached console clients More... | |
void | ast_console_toggle_loglevel (int fd, int level, int state) |
enable or disable a logging level to a specified console More... | |
void | ast_console_toggle_mute (int fd, int silent) |
mute or unmute a console from logging | |
static int | ast_el_add_history (const char *) |
static int | ast_el_initialize (void) |
static int | ast_el_read_char (EditLine *editline, CHAR_T_LIBEDIT *cp) |
static void | ast_el_read_default_histfile (void) |
static int | ast_el_read_history (const char *) |
static struct ast_vector_string * | ast_el_strtoarr (char *buf) |
static void | ast_el_write_default_histfile (void) |
static int | ast_el_write_history (const char *) |
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, int sublevel) |
log the string to all attached network console clients | |
int | ast_pbx_uuid_get (char *pbx_uuid, int length) |
Retrieve the PBX UUID. More... | |
int64_t | ast_profile (int i, int64_t delta) |
int | ast_register_atexit (void(*func)(void)) |
Register a function to be executed before Asterisk exits. More... | |
int | ast_register_cleanup (void(*func)(void)) |
Register a function to be executed before Asterisk gracefully exits. More... | |
void | ast_register_thread (char *name) |
static void | ast_remotecontrol (char *data) |
void | ast_replace_sigchld (void) |
Replace the SIGCHLD handler. More... | |
static void | ast_run_atexits (int run_cleanups) |
int | ast_safe_execvp (int dualfork, const char *file, char *const argv[]) |
Safely spawn an external program while closing file descriptors. More... | |
int | ast_safe_system (const char *s) |
Safely spawn an OS shell command while closing file descriptors. More... | |
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. More... | |
int | ast_shutdown_final (void) |
int | ast_shutting_down (void) |
static int | ast_tryconnect (void) |
void | ast_unregister_atexit (void(*func)(void)) |
Unregister a function registered with ast_register_atexit(). More... | |
void | ast_unregister_thread (void *id) |
void | ast_unreplace_sigchld (void) |
Restore the SIGCHLD handler. More... | |
static void | asterisk_daemon (int isroot, const char *runuser, const char *rungroup) |
static int | can_safely_quit (shutdown_nice_t niceness, int restart) |
static void | canary_exit (void) |
static void * | canary_thread (void *unused) |
static void | check_init (int init_result, const char *name) |
static char * | cli_complete (EditLine *editline, int ch) |
static char * | cli_prompt (EditLine *editline) |
static int | console_print (const char *s) |
static int | console_state_init (void *ptr) |
static void | consolehandler (const char *s) |
static void | env_init (void) |
static int | fdprint (int fd, const char *s) |
static int | fdsend (int fd, const char *s) |
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. More... | |
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_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 int | has_priority (void) |
Check whether we were set to high(er) priority. | |
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 int | print_file (int fd, char *desc, const char *filename) |
Print the contents of a file. | |
static void | print_intro_message (const char *runuser, const char *rungroup) |
static void | process_histfile (int(*readwrite)(const char *filename)) |
static void | publish_fully_booted (void) |
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. More... | |
static void | read_pjproject_startup_options (void) |
static void | really_quit (int num, shutdown_nice_t niceness, int restart) |
static int | register_atexit (void(*func)(void), int is_cleanup) |
static int | remoteconsolehandler (const char *s) |
static void | run_startup_commands (void) |
static pid_t | safe_exec_prep (int dualfork) |
fork and perform other preparations for spawning applications | |
static int | safe_exec_wait (pid_t pid) |
wait for spawned application to complete and unreplace sigchld | |
static void | send_rasterisk_connect_commands (void) |
static void | set_header (char *outbuf, int maxout, char level) |
static void | set_icon (char *text) |
static int | set_priority_all (int pri) |
Set priority on all known threads. | |
static void | set_title (char *text) |
Set an X-term or screen title. | |
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) |
static int | wait_for_channels_to_die (shutdown_nice_t niceness, int seconds) |
Variables | |
static char * | _argv [256] |
static int | ast_consock = -1 |
struct timeval | ast_lastreloadtime |
pid_t | ast_mainpid |
static int | ast_socket = -1 |
static int | ast_socket_is_sd = 0 |
struct timeval | ast_startuptime |
static struct atexits | atexits = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
static char | canary_filename [128] |
static int | canary_pid = 0 |
static cap_t | child_cap |
static struct sigaction | child_handler |
static struct ast_cli_entry | cli_asterisk [] |
static struct ast_cli_entry | cli_asterisk_shutdown [] |
Shutdown Asterisk CLI commands. More... | |
static struct ast_threadstorage | console_state = { .once = PTHREAD_ONCE_INIT , .key_init = __init_console_state , .custom_init = console_state_init , } |
struct console | consoles [AST_MAX_CONNECTS] |
static pthread_t | consolethread = AST_PTHREADT_NULL |
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 |
static struct profile_data * | prof_data |
static struct ast_str * | prompt = NULL |
static char | randompool [256] |
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, 0} } |
static struct sigaction | safe_system_prev_handler |
static int | shutdown_pending |
static shutdown_nice_t | shuttingdown = NOT_SHUTTING_DOWN |
static int | sig_alert_pipe [2] = { -1, -1 } |
struct { | |
unsigned int need_el_end:1 | |
unsigned int need_quit:1 | |
unsigned int need_quit_handler:1 | |
unsigned int need_reload:1 | |
} | sig_flags |
static struct thread_list | thread_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
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 COPYRIGHT_TAG "Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others." |
Displayed copyright tag
Definition at line 300 of file asterisk.c.
enum shutdown_nice_t |
Definition at line 359 of file asterisk.c.
|
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 1711 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 802 of file asterisk.c.
References ast_calloc, ast_realloc, and ast_strdup.
int ast_cancel_shutdown | ( | void | ) |
Cancel an existing shutdown and return to normal operation.
Definition at line 1881 of file asterisk.c.
References NOT_SHUTTING_DOWN, SHUTDOWN_FAST, and shutdown_pending.
void ast_console_puts_mutable | ( | const char * | string, |
int | level | ||
) |
log the string to the root console, and all attached network console clients
log the string to the console, and all attached console clients
Definition at line 1316 of file asterisk.c.
References ast_console_puts_mutable_full().
Referenced by init_logger_chain().
void ast_console_puts_mutable_full | ( | const char * | message, |
int | level, | ||
int | sublevel | ||
) |
log the string to the console, and all attached console clients
message | The message to write to the console |
sublevel | If the log level supports it, the sub-level of the message |
level | The log level of the message |
Definition at line 1323 of file asterisk.c.
References ast_network_puts_mutable().
Referenced by ast_console_puts_mutable(), and logger_print_normal().
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 1251 of file asterisk.c.
References console::levels.
int ast_pbx_uuid_get | ( | char * | pbx_uuid, |
int | length | ||
) |
Retrieve the PBX UUID.
pbx_uuid | A buffer of at least AST_UUID_STR_LEN (36 + 1) size to receive the UUID |
length | The buffer length |
Definition at line 976 of file asterisk.c.
References ast_db_get().
Referenced by handle_show_settings().
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 1054 of file asterisk.c.
int ast_register_cleanup | ( | void(*)(void) | func | ) |
Register a function to be executed before Asterisk gracefully exits.
func | The callback function to use. |
0 | on success. |
-1 | on error. |
Definition at line 1059 of file asterisk.c.
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 1104 of file asterisk.c.
Referenced by safe_exec_prep().
int ast_safe_execvp | ( | int | dualfork, |
const char * | file, | ||
char *const | argv[] | ||
) |
Safely spawn an external program while closing file descriptors.
dualfork | Non-zero to simulate running the program in the background by forking twice. The option provides similar functionality to the '&' in the OS shell command "cmd &". The option allows Asterisk to run a reaper loop to watch the first fork which immediately exits after spaning the second fork. The actual program is run in the second fork. |
file | execvp(file, argv) file parameter |
argv | execvp(file, argv) argv parameter |
Definition at line 1222 of file asterisk.c.
References safe_exec_prep(), and safe_exec_wait().
Referenced by run_externnotify().
int ast_safe_system | ( | const char * | s | ) |
Safely spawn an OS shell command while closing file descriptors.
s | - OS shell command string to execute. |
Definition at line 1235 of file asterisk.c.
References safe_exec_prep(), and safe_exec_wait().
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 1841 of file asterisk.c.
Referenced by main(), safe_exec_prep(), and set_priority_all().
int ast_shutdown_final | ( | void | ) |
The server is releasing resources and unloading modules. It won't be long now.
Definition at line 1871 of file asterisk.c.
References SHUTTING_DOWN_FINAL.
Referenced by load_resource().
int ast_shutting_down | ( | void | ) |
The server is preventing new channel creation in preparation for shutdown and may actively be releasing resources. The shutdown process may be canceled by ast_cancel_shutdown() if it is not too late.
Definition at line 1876 of file asterisk.c.
References shutdown_pending.
Referenced by __ast_channel_alloc_ap(), ast_cli_command_full(), ast_unregister_translator(), confbridge_exec(), and process_message().
void ast_unregister_atexit | ( | void(*)(void) | func | ) |
Unregister a function registered with ast_register_atexit().
func | The callback function to unregister. |
Definition at line 1064 of file asterisk.c.
References AST_LIST_LOCK, and AST_LIST_UNLOCK.
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 1119 of file asterisk.c.
References safe_system_level.
Referenced by safe_exec_wait().
|
static |
Give an overview of core settings.
Definition at line 470 of file asterisk.c.
References ast_active_channels(), ast_cdr_is_enabled(), ast_eid_default, ast_eid_to_str(), ast_get_build_opts(), ast_get_build_opts_all(), ast_get_version(), ast_language_is_prefix, ast_localtime(), ast_manager_check_enabled(), AST_OPT_FLAG_EXEC_INCLUDES, AST_OPT_FLAG_GENERIC_PLC, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS, AST_OPT_FLAG_TRANSCODE_VIA_SLIN, AST_OPT_FLAG_TRANSMIT_SILENCE, ast_option_maxcalls, ast_option_maxfiles, ast_option_maxload, ast_pbx_uuid_get(), ast_realtime_enabled(), AST_RTP_MAX_PT, AST_RTP_PT_FIRST_DYNAMIC, AST_RTP_PT_LAST_REASSIGN, ast_strftime(), ast_verb_console_get(), ast_webmanager_check_enabled(), ast_cli_entry::command, option_debug, option_dtmfminduration, option_minmemfree, option_trace, option_verbose, print_file(), S_OR, and ast_cli_entry::usage.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Check for options
Definition at line 3583 of file asterisk.c.
References ast_language_is_prefix, 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_HIGH_PRIORITY, AST_OPT_FLAG_INIT_KEYS, AST_OPT_FLAG_LIGHT_BACKGROUND, AST_OPT_FLAG_MUTE, AST_OPT_FLAG_NO_COLOR, AST_OPT_FLAG_NO_FORK, AST_OPT_FLAG_QUIET, AST_OPT_FLAG_RECONNECT, AST_OPT_FLAG_REMOTE, AST_OPT_FLAG_TIMESTAMP, ast_option_maxcalls, ast_option_maxload, ast_sd_get_fd_un(), ast_select(), ast_set_priority(), ast_socket_is_sd, ast_strdup, ast_term_init(), ast_verb_sys_level, option_debug, option_minmemfree, option_verbose, RAII_VAR, and SHUTDOWN_FAST.
|
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 1378 of file asterisk.c.
References console::gid, and console::uid.
|
static |
Called when exiting is certain.
Definition at line 2046 of file asterisk.c.
References ast_active_channels(), ast_alertpipe_close(), ast_consock, ast_debug, ast_json_pack(), ast_json_unref(), ast_manager_publish_event(), ast_sd_notify(), ast_socket, ast_socket_is_sd, clean_time_zones(), close_logger(), modules_shutdown(), and SHUTDOWN_NICE.
|
static |
UNIX Socket for controlling another asterisk
Definition at line 317 of file asterisk.c.
Referenced by really_quit().
|
static |
UNIX Socket for allowing remote control
Definition at line 315 of file asterisk.c.
Referenced by really_quit().
|
static |
Is socket activation responsible for ast_socket?
Definition at line 316 of file asterisk.c.
Referenced by main(), and really_quit().
|
static |
Definition at line 1759 of file asterisk.c.
|
static |
Shutdown Asterisk CLI commands.
Definition at line 2618 of file asterisk.c.
|
static |
Definition at line 1739 of file asterisk.c.
|
static |
Definition at line 1093 of file asterisk.c.
|
static |
Definition at line 1088 of file asterisk.c.
|
static |
Prevent new channel allocation for shutdown.
Definition at line 384 of file asterisk.c.
Referenced by ast_cancel_shutdown(), and ast_shutting_down().
|
static |
Definition at line 1716 of file asterisk.c.