Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
asterisk.c File Reference

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_stringast_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_dataprof_data
 
static struct ast_strprompt = 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 []
 

Detailed Description

Top level source file for Asterisk - the Open Source PBX. Implementation of PBX core functions and CLI interface.

Definition in file asterisk.c.

Macro Definition Documentation

#define COPYRIGHT_TAG   "Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others."

Displayed copyright tag

Definition at line 300 of file asterisk.c.

Enumeration Type Documentation

Enumerator
NOT_SHUTTING_DOWN 

Normal operation

SHUTTING_DOWN_FINAL 

Committed to shutting down. Final phase

SHUTTING_DOWN 

Committed to shutting down. Initial phase

SHUTDOWN_FAST 

Valid values for quit_handler() niceness below. These shutdown/restart levels can be cancelled.

Remote console exit right now

SHUTDOWN_NORMAL 

core stop/restart now

SHUTDOWN_NICE 

core stop/restart gracefully

SHUTDOWN_REALLY_NICE 

core stop/restart when convenient

Definition at line 359 of file asterisk.c.

359  {
360  /*! Normal operation */
362  /*! Committed to shutting down. Final phase */
364  /*! Committed to shutting down. Initial phase */
366  /*!
367  * Valid values for quit_handler() niceness below.
368  * These shutdown/restart levels can be cancelled.
369  *
370  * Remote console exit right now
371  */
373  /*! core stop/restart now */
375  /*! core stop/restart gracefully */
377  /*! core stop/restart when convenient */
shutdown_nice_t
Definition: asterisk.c:359

Function Documentation

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 1711 of file asterisk.c.

1712 {
1713  return;
1714 }
int ast_add_profile ( const char *  name,
uint64_t  scale 
)

allocates a counter with a given name and scale.

support for event profiling

Returns
Returns the identifier of the counter.

Definition at line 802 of file asterisk.c.

References ast_calloc, ast_realloc, and ast_strdup.

803 {
804 #if !defined(LOW_MEMORY)
805  int l = sizeof(struct profile_data);
806  int n = 10; /* default entries */
807 
808  if (prof_data == NULL) {
809  prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
810  if (prof_data == NULL)
811  return -1;
812  prof_data->entries = 0;
813  prof_data->max_size = n;
814  }
815  if (prof_data->entries >= prof_data->max_size) {
816  void *p;
817  n = prof_data->max_size + 20;
818  p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
819  if (p == NULL)
820  return -1;
821  prof_data = p;
822  prof_data->max_size = n;
823  }
824  n = prof_data->entries++;
825  prof_data->e[n].name = ast_strdup(name);
826  prof_data->e[n].value = 0;
827  prof_data->e[n].events = 0;
828  prof_data->e[n].mark = 0;
829  prof_data->e[n].scale = scale;
830  return n;
831 #else /* if defined(LOW_MEMORY) */
832  return 0;
833 #endif
834 }
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:226
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
Definition: asterisk.c:782
int ast_cancel_shutdown ( void  )

Cancel an existing shutdown and return to normal operation.

Note
Shutdown can be cancelled while the server is waiting for any existing channels to be destroyed before shutdown becomes irreversible.
Returns
non-zero if shutdown cancelled.

Definition at line 1881 of file asterisk.c.

References NOT_SHUTTING_DOWN, SHUTDOWN_FAST, and shutdown_pending.

1882 {
1883  int shutdown_aborted = 0;
1884 
1885  ast_mutex_lock(&safe_system_lock);
1886  if (shuttingdown >= SHUTDOWN_FAST) {
1887  shuttingdown = NOT_SHUTTING_DOWN;
1888  shutdown_pending = 0;
1889  shutdown_aborted = 1;
1890  }
1891  ast_mutex_unlock(&safe_system_lock);
1892  return shutdown_aborted;
1893 }
static int shutdown_pending
Definition: asterisk.c:384
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().

1317 {
1318  ast_console_puts_mutable_full(string, level, 0);
1319 }
void ast_console_puts_mutable_full(const char *message, int level, int sublevel)
log the string to the console, and all attached console clients
Definition: asterisk.c:1323
void ast_console_puts_mutable_full ( const char *  message,
int  level,
int  sublevel 
)

log the string to the console, and all attached console clients

Since
14.0.0
Parameters
messageThe message to write to the console
sublevelIf the log level supports it, the sub-level of the message
levelThe 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().

1324 {
1325  /* Send to the root console */
1326  console_print(message);
1327 
1328  /* Wake up a poll()ing console */
1329  if (ast_opt_console && consolethread != AST_PTHREADT_NULL) {
1330  pthread_kill(consolethread, SIGURG);
1331  }
1332 
1333  /* Send to any network console clients */
1334  ast_network_puts_mutable(message, level, sublevel);
1335 }
static void ast_network_puts_mutable(const char *string, int level, int sublevel)
log the string to all attached network console clients
Definition: asterisk.c:1297
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.

1252 {
1253  int x;
1254 
1255  if (level >= NUMLOGLEVELS) {
1256  level = NUMLOGLEVELS - 1;
1257  }
1258 
1259  for (x = 0;x < AST_MAX_CONNECTS; x++) {
1260  if (fd == consoles[x].fd) {
1261  /*
1262  * Since the logging occurs when levels are false, set to
1263  * flipped iinput because this function accepts 0 as off and 1 as on
1264  */
1265  consoles[x].levels[level] = state ? 0 : 1;
1266  return;
1267  }
1268  }
1269 }
int levels[NUMLOGLEVELS]
Definition: asterisk.c:326
int ast_pbx_uuid_get ( char *  pbx_uuid,
int  length 
)

Retrieve the PBX UUID.

Parameters
pbx_uuidA buffer of at least AST_UUID_STR_LEN (36 + 1) size to receive the UUID
lengthThe buffer length

Definition at line 976 of file asterisk.c.

References ast_db_get().

Referenced by handle_show_settings().

977 {
978  return ast_db_get("pbx", "UUID", pbx_uuid, length);
979 }
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:427
int ast_register_atexit ( void(*)(void)  func)

Register a function to be executed before Asterisk exits.

Parameters
funcThe callback function to use.
Return values
0on success.
-1on error.
Note
This function should be rarely used in situations where something must be shutdown to avoid corruption, excessive data loss, or when external programs must be stopped. All other cleanup in the core should use ast_register_cleanup.

Definition at line 1054 of file asterisk.c.

1055 {
1056  return register_atexit(func, 0);
1057 }
int ast_register_cleanup ( void(*)(void)  func)

Register a function to be executed before Asterisk gracefully exits.

Since
11.9 If Asterisk is immediately shutdown (core stop now, or sending the TERM signal), the callback is not run. When the callbacks are run, they are run in sequence with ast_register_atexit() callbacks, in the reverse order of registration.
Parameters
funcThe callback function to use.
Return values
0on success.
-1on error.

Definition at line 1059 of file asterisk.c.

1060 {
1061  return register_atexit(func, 1);
1062 }
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().

1105 {
1106  unsigned int level;
1107 
1108  ast_mutex_lock(&safe_system_lock);
1109  level = safe_system_level++;
1110 
1111  /* only replace the handler if it has not already been done */
1112  if (level == 0) {
1113  sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
1114  }
1115 
1116  ast_mutex_unlock(&safe_system_lock);
1117 }
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
Definition: asterisk.c:1101
int ast_safe_execvp ( int  dualfork,
const char *  file,
char *const  argv[] 
)

Safely spawn an external program while closing file descriptors.

Note
This replaces the execvp call in all Asterisk modules
Parameters
dualforkNon-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.
fileexecvp(file, argv) file parameter
argvexecvp(file, argv) argv parameter

Definition at line 1222 of file asterisk.c.

References safe_exec_prep(), and safe_exec_wait().

Referenced by run_externnotify().

1223 {
1224  pid_t pid = safe_exec_prep(dualfork);
1225 
1226  if (pid == 0) {
1227  execvp(file, argv);
1228  _exit(1);
1229  /* noreturn from _exit */
1230  }
1231 
1232  return safe_exec_wait(pid);
1233 }
static pid_t safe_exec_prep(int dualfork)
fork and perform other preparations for spawning applications
Definition: asterisk.c:1135
static int safe_exec_wait(pid_t pid)
wait for spawned application to complete and unreplace sigchld
Definition: asterisk.c:1196
int ast_safe_system ( const char *  s)

Safely spawn an OS shell command while closing file descriptors.

Note
This replaces the system call in all Asterisk modules
Parameters
s- OS shell command string to execute.
Warning
Command injection can happen using this call if the passed in string is created using untrusted data from an external source. It is best not to use untrusted data. However, the caller could filter out dangerous characters to avoid command injection.

Definition at line 1235 of file asterisk.c.

References safe_exec_prep(), and safe_exec_wait().

1236 {
1237  pid_t pid = safe_exec_prep(0);
1238 
1239  if (pid == 0) {
1240  execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
1241  _exit(1);
1242  /* noreturn from _exit */
1243  }
1244 
1245  return safe_exec_wait(pid);
1246 }
static pid_t safe_exec_prep(int dualfork)
fork and perform other preparations for spawning applications
Definition: asterisk.c:1135
static int safe_exec_wait(pid_t pid)
wait for spawned application to complete and unreplace sigchld
Definition: asterisk.c:1196
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().

1842 {
1843  struct sched_param sched;
1844  memset(&sched, 0, sizeof(sched));
1845 #ifdef __linux__
1846  if (pri) {
1847  sched.sched_priority = 10;
1848  if (sched_setscheduler(0, SCHED_RR, &sched)) {
1849  return -1;
1850  }
1851  } else {
1852  sched.sched_priority = 0;
1853  /* According to the manpage, these parameters can never fail. */
1854  sched_setscheduler(0, SCHED_OTHER, &sched);
1855  }
1856 #else
1857  if (pri) {
1858  if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
1859  ast_log(LOG_WARNING, "Unable to set high priority\n");
1860  return -1;
1861  } else
1862  ast_verb(1, "Set to high priority\n");
1863  } else {
1864  /* According to the manpage, these parameters can never fail. */
1865  setpriority(PRIO_PROCESS, 0, 0);
1866  }
1867 #endif
1868  return 0;
1869 }
Definition: sched.c:76
int ast_shutdown_final ( void  )
Returns
non-zero if the server is actively shutting down.
Since
13.3.0

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().

1872 {
1873  return shuttingdown == SHUTTING_DOWN_FINAL;
1874 }
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.

Note
The preparation to shutdown phase can be quite lengthy if we are gracefully shutting down. How long existing calls will last is not up to us.
Returns
non-zero if the server is preparing to or actively shutting down.

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().

1877 {
1878  return shutdown_pending;
1879 }
static int shutdown_pending
Definition: asterisk.c:384
void ast_unregister_atexit ( void(*)(void)  func)

Unregister a function registered with ast_register_atexit().

Parameters
funcThe callback function to unregister.

Definition at line 1064 of file asterisk.c.

References AST_LIST_LOCK, and AST_LIST_UNLOCK.

1065 {
1067  __ast_unregister_atexit(func);
1069 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
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().

1120 {
1121  unsigned int level;
1122 
1123  ast_mutex_lock(&safe_system_lock);
1124  level = --safe_system_level;
1125 
1126  /* only restore the handler if we are the last one */
1127  if (level == 0) {
1128  sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
1129  }
1130 
1131  ast_mutex_unlock(&safe_system_lock);
1132 }
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
Definition: asterisk.c:1101
static char* handle_show_settings ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Give an overview of core settings.

Todo:
we could check musiconhold, voicemail, smdi, adsi, queues

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.

471 {
472  char buf[BUFSIZ];
473  struct ast_tm tm;
474  char eid_str[128];
475  struct rlimit limits;
476  char pbx_uuid[AST_UUID_STR_LEN];
477 #if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
478  char dir[PATH_MAX];
479 #endif
480 
481  switch (cmd) {
482  case CLI_INIT:
483  e->command = "core show settings";
484  e->usage = "Usage: core show settings\n"
485  " Show core misc settings";
486  return NULL;
487  case CLI_GENERATE:
488  return NULL;
489  }
490 
491  ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default);
492  ast_pbx_uuid_get(pbx_uuid, sizeof(pbx_uuid));
493 
494  ast_cli(a->fd, "\nPBX Core settings\n");
495  ast_cli(a->fd, "-----------------\n");
496  ast_cli(a->fd, " Version: %s\n", ast_get_version());
497  ast_cli(a->fd, " ABI related Build Options: %s\n", S_OR(ast_get_build_opts(), "(none)"));
498  ast_cli(a->fd, " All Build Options: %s\n", S_OR(ast_get_build_opts_all(), "(none)"));
500  ast_cli(a->fd, " Maximum calls: %d (Current %d)\n", ast_option_maxcalls, ast_active_channels());
501  else
502  ast_cli(a->fd, " Maximum calls: Not set\n");
503 
504  if (getrlimit(RLIMIT_NOFILE, &limits)) {
505  ast_cli(a->fd, " Maximum open file handles: Error because of %s\n", strerror(errno));
506  } else if (limits.rlim_cur == RLIM_INFINITY) {
507  ast_cli(a->fd, " Maximum open file handles: Unlimited\n");
508  } else if (limits.rlim_cur < ast_option_maxfiles) {
509  ast_cli(a->fd, " Maximum open file handles: %d (is) %d (requested)\n", (int) limits.rlim_cur, ast_option_maxfiles);
510  } else {
511  ast_cli(a->fd, " Maximum open file handles: %d\n", (int) limits.rlim_cur);
512  }
513 
514  ast_cli(a->fd, " Root console verbosity: %d\n", option_verbose);
515  ast_cli(a->fd, " Current console verbosity: %d\n", ast_verb_console_get());
516  ast_cli(a->fd, " Debug level: %d\n", option_debug);
517  ast_cli(a->fd, " Trace level: %d\n", option_trace);
518  ast_cli(a->fd, " Dump core on crash: %s\n", ast_opt_dump_core ? "Yes" : "No");
519  print_file(a->fd, " Core dump file: ", "/proc/sys/kernel/core_pattern");
520  ast_cli(a->fd, " Maximum load average: %lf\n", ast_option_maxload);
521 #if defined(HAVE_SYSINFO)
522  ast_cli(a->fd, " Minimum free memory: %ld MB\n", option_minmemfree);
523 #endif
524  if (ast_localtime(&ast_startuptime, &tm, NULL)) {
525  ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
526  ast_cli(a->fd, " Startup time: %s\n", buf);
527  }
528  if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) {
529  ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
530  ast_cli(a->fd, " Last reload time: %s\n", buf);
531  }
532  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);
533  ast_cli(a->fd, " System name: %s\n", ast_config_AST_SYSTEM_NAME);
534  ast_cli(a->fd, " Entity ID: %s\n", eid_str);
535  ast_cli(a->fd, " PBX UUID: %s\n", pbx_uuid);
536  ast_cli(a->fd, " Default language: %s\n", ast_defaultlanguage);
537  ast_cli(a->fd, " Language prefix: %s\n", ast_language_is_prefix ? "Enabled" : "Disabled");
538  ast_cli(a->fd, " User name and group: %s/%s\n", ast_config_AST_RUN_USER, ast_config_AST_RUN_GROUP);
539 #if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
540 #if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS)
541 #define eaccess euidaccess
542 #endif
543  if (!getcwd(dir, sizeof(dir))) {
544  if (eaccess(dir, R_OK | X_OK | F_OK)) {
545  ast_cli(a->fd, " Running directory: %s\n", "Unable to access");
546  } else {
547  ast_cli(a->fd, " Running directory: %s (%s)\n", dir, "Unable to access");
548  }
549  } else {
550  ast_cli(a->fd, " Running directory: %s\n", dir);
551  }
552 #endif /* defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) */
553  ast_cli(a->fd, " Executable includes: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES) ? "Enabled" : "Disabled");
554  ast_cli(a->fd, " Transcode via SLIN: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled");
555  ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled");
556  ast_cli(a->fd, " Generic PLC: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) ? "Enabled" : "Disabled");
557  ast_cli(a->fd, " Generic PLC on equal codecs: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS) ? "Enabled" : "Disabled");
558  ast_cli(a->fd, " Hide Msg Chan AMI events: %s\n", ast_opt_hide_messaging_ami_events ? "Enabled" : "Disabled");
559  ast_cli(a->fd, " Sounds search custom dir: %s\n", ast_opt_sounds_search_custom ? "Enabled" : "Disabled");
560  ast_cli(a->fd, " Min DTMF duration:: %u\n", option_dtmfminduration);
561 #if !defined(LOW_MEMORY)
562  ast_cli(a->fd, " Cache media frames: %s\n", ast_opt_cache_media_frames ? "Enabled" : "Disabled");
563 #endif
564  ast_cli(a->fd, " RTP use dynamic payloads: %u\n", ast_option_rtpusedynamic);
565 
566  if (ast_option_rtpptdynamic == AST_RTP_PT_LAST_REASSIGN) {
567  ast_cli(a->fd, " RTP dynamic payload types: %u,%u-%u\n",
568  ast_option_rtpptdynamic,
570  } else if (ast_option_rtpptdynamic < AST_RTP_PT_LAST_REASSIGN) {
571  ast_cli(a->fd, " RTP dynamic payload types: %u-%u,%u-%u\n",
572  ast_option_rtpptdynamic, AST_RTP_PT_LAST_REASSIGN,
574  } else {
575  ast_cli(a->fd, " RTP dynamic payload types: %u-%u\n",
577  }
578 
579  ast_cli(a->fd, "\n* Subsystems\n");
580  ast_cli(a->fd, " -------------\n");
581  ast_cli(a->fd, " Manager (AMI): %s\n", ast_manager_check_enabled() ? "Enabled" : "Disabled");
582  ast_cli(a->fd, " Web Manager (AMI/HTTP): %s\n", ast_webmanager_check_enabled() ? "Enabled" : "Disabled");
583  ast_cli(a->fd, " Call data records: %s\n", ast_cdr_is_enabled() ? "Enabled" : "Disabled");
584  ast_cli(a->fd, " Realtime Architecture (ARA): %s\n", ast_realtime_enabled() ? "Enabled" : "Disabled");
585 
586  /*! \todo we could check musiconhold, voicemail, smdi, adsi, queues */
587 
588  ast_cli(a->fd, "\n* Directories\n");
589  ast_cli(a->fd, " -------------\n");
590  ast_cli(a->fd, " Configuration file: %s\n", ast_config_AST_CONFIG_FILE);
591  ast_cli(a->fd, " Configuration directory: %s\n", ast_config_AST_CONFIG_DIR);
592  ast_cli(a->fd, " Module directory: %s\n", ast_config_AST_MODULE_DIR);
593  ast_cli(a->fd, " Spool directory: %s\n", ast_config_AST_SPOOL_DIR);
594  ast_cli(a->fd, " Log directory: %s\n", ast_config_AST_LOG_DIR);
595  ast_cli(a->fd, " Run/Sockets directory: %s\n", ast_config_AST_RUN_DIR);
596  ast_cli(a->fd, " PID file: %s\n", ast_config_AST_PID);
597  ast_cli(a->fd, " VarLib directory: %s\n", ast_config_AST_VAR_DIR);
598  ast_cli(a->fd, " Data directory: %s\n", ast_config_AST_DATA_DIR);
599  ast_cli(a->fd, " ASTDB: %s\n", ast_config_AST_DB);
600  ast_cli(a->fd, " IAX2 Keys directory: %s\n", ast_config_AST_KEY_DIR);
601  ast_cli(a->fd, " AGI Scripts directory: %s\n", ast_config_AST_AGI_DIR);
602  ast_cli(a->fd, " Cache directory: %s\n", ast_config_AST_CACHE_DIR);
603  ast_cli(a->fd, "\n\n");
604  return CLI_SUCCESS;
605 }
int ast_option_maxfiles
Definition: options.c:81
unsigned int option_dtmfminduration
Definition: options.c:83
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition: utils.c:2839
int option_debug
Definition: options.c:69
int ast_manager_check_enabled(void)
Check if AMI is enabled.
Definition: manager.c:2109
const char * ast_get_version(void)
Retrieve the Asterisk version string.
Definition: version.c:18
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
const char * ast_get_build_opts(void)
Definition: version.c:28
int option_verbose
Definition: options.c:67
int ast_verb_console_get(void)
Get this thread's console verbosity level.
Definition: logger.c:2673
double ast_option_maxload
Definition: options.c:77
#define AST_RTP_PT_FIRST_DYNAMIC
Definition: rtp_engine.h:92
int ast_option_maxcalls
Definition: options.c:79
const char * ast_get_build_opts_all(void)
Definition: version.c:33
int ast_realtime_enabled(void)
Check if there's any realtime engines loaded.
Definition: main/config.c:3544
int ast_webmanager_check_enabled(void)
Check if AMI/HTTP is enabled.
Definition: manager.c:2114
int ast_cdr_is_enabled(void)
Return TRUE if CDR subsystem is enabled.
Definition: cdr.c:2923
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
long option_minmemfree
Definition: options.c:86
int ast_language_is_prefix
The following variable controls the layout of localized sound files. If 0, use the historical layout ...
Definition: file.c:67
int ast_pbx_uuid_get(char *pbx_uuid, int length)
Retrieve the PBX UUID.
Definition: asterisk.c:976
static int print_file(int fd, char *desc, const char *filename)
Print the contents of a file.
Definition: asterisk.c:453
char * command
Definition: cli.h:186
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
const char * usage
Definition: cli.h:177
struct ast_eid ast_eid_default
Global EID.
Definition: options.c:93
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
#define AST_RTP_PT_LAST_REASSIGN
Definition: rtp_engine.h:95
int ast_active_channels(void)
returns number of active/allocated channels
Definition: channel.c:499
int option_trace
Definition: options.c:71
int main ( int  argc,
char *  argv[] 
)

Check for options

Todo:
Document these options
Note
Please keep the ordering here to alphabetical, capital letters first. This will make it easier in the future to select unused option flags for new features.
The q option is never used anywhere, only defined
Can ONLY be used with remote console

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.

3584 {
3585  int c;
3586  int x;
3587  int isroot = 1, rundir_exists = 0;
3588  RAII_VAR(char *, runuser, NULL, ast_free);
3589  RAII_VAR(char *, rungroup, NULL, ast_free);
3590  RAII_VAR(char *, xarg, NULL, ast_free);
3591  struct rlimit l;
3592  static const char *getopt_settings = "BC:cde:FfG:ghIiL:M:mnpqRrs:TtU:VvWXx:";
3593 
3594  /* Remember original args for restart */
3595  if (argc > ARRAY_LEN(_argv) - 1) {
3596  fprintf(stderr, "Truncating argument size to %d\n", (int)ARRAY_LEN(_argv) - 1);
3597  argc = ARRAY_LEN(_argv) - 1;
3598  }
3599  for (x = 0; x < argc; x++)
3600  _argv[x] = argv[x];
3601  _argv[x] = NULL;
3602 
3603  if (geteuid() != 0)
3604  isroot = 0;
3605 
3606  /* if the progname is rasterisk consider it a remote console */
3607  if (argv[0] && (strstr(argv[0], "rasterisk")) != NULL) {
3608  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
3609  }
3610  ast_mainpid = getpid();
3611 
3612  /* Process command-line options that affect asterisk.conf load. */
3613  while ((c = getopt(argc, argv, getopt_settings)) != -1) {
3614  switch (c) {
3615  case 'X':
3616  ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES);
3617  break;
3618  case 'C':
3619  set_asterisk_conf_path(optarg);
3620  break;
3621  case 'd':
3622  option_debug++;
3623  break;
3624  case 'h':
3625  show_cli_help();
3626  exit(0);
3627  case 'R':
3628  case 'r':
3629  case 'x':
3630  /* ast_opt_remote is checked during config load. This is only part of what
3631  * these options do, see the second loop for the rest of the actions. */
3632  ast_set_flag(&ast_options, AST_OPT_FLAG_REMOTE);
3633  break;
3634  case 'V':
3635  show_version();
3636  exit(0);
3637  case 'v':
3638  option_verbose++;
3639  break;
3640  case '?':
3641  exit(1);
3642  }
3643  }
3644 
3645  /* Initialize env so it is available if #exec is used in asterisk.conf. */
3646  env_init();
3647 
3648  load_asterisk_conf();
3649 
3650  /* Update env to include any systemname that was set. */
3651  env_init();
3652 
3653  /*! \brief Check for options
3654  *
3655  * \todo Document these options
3656  */
3657  optind = 1;
3658  while ((c = getopt(argc, argv, getopt_settings)) != -1) {
3659  /*!\note Please keep the ordering here to alphabetical, capital letters
3660  * first. This will make it easier in the future to select unused
3661  * option flags for new features. */
3662  switch (c) {
3663  case 'B': /* Force black background */
3664  ast_set_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
3665  ast_clear_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
3666  break;
3667  case 'X':
3668  /* The command-line -X option enables #exec for asterisk.conf only. */
3669  break;
3670  case 'C':
3671  /* already processed. */
3672  break;
3673  case 'c':
3674  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
3675  break;
3676  case 'd':
3677  /* already processed. */
3678  break;
3679 #if defined(HAVE_SYSINFO)
3680  case 'e':
3681  if ((sscanf(&optarg[1], "%30ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) {
3682  option_minmemfree = 0;
3683  }
3684  break;
3685 #endif
3686 #if HAVE_WORKING_FORK
3687  case 'F':
3688  ast_set_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
3689  break;
3690  case 'f':
3691  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
3692  break;
3693 #endif
3694  case 'G':
3695  rungroup = ast_strdup(optarg);
3696  break;
3697  case 'g':
3698  ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
3699  break;
3700  case 'h':
3701  /* already processed. */
3702  break;
3703  case 'I':
3704  fprintf(stderr,
3705  "NOTICE: The -I option is no longer needed.\n"
3706  " It will always be enabled if you have a timing module loaded.\n");
3707  break;
3708  case 'i':
3709  ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
3710  break;
3711  case 'L':
3712  if ((sscanf(optarg, "%30lf", &ast_option_maxload) != 1) || (ast_option_maxload < 0.0)) {
3713  ast_option_maxload = 0.0;
3714  }
3715  break;
3716  case 'M':
3717  if ((sscanf(optarg, "%30d", &ast_option_maxcalls) != 1) || (ast_option_maxcalls < 0)) {
3718  ast_option_maxcalls = 0;
3719  }
3720  break;
3721  case 'm':
3722  ast_set_flag(&ast_options, AST_OPT_FLAG_MUTE);
3723  break;
3724  case 'n':
3725  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
3726  break;
3727  case 'p':
3728  ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
3729  break;
3730  case 'q':
3731  ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET);
3732  break;
3733  case 'R':
3734  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
3735  break;
3736  case 'r':
3737  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
3738  break;
3739  case 's':
3740  if (ast_opt_remote) {
3741  set_socket_path(optarg);
3742  }
3743  break;
3744  case 'T':
3745  ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
3746  break;
3747  case 't':
3748  ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
3749  break;
3750  case 'U':
3751  runuser = ast_strdup(optarg);
3752  break;
3753  case 'V':
3754  case 'v':
3755  /* already processed. */
3756  break;
3757  case 'W': /* White background */
3758  ast_set_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
3759  ast_clear_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
3760  break;
3761  case 'x':
3762  /* -r is implied by -x so set the flags -r sets as well. */
3763  ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
3764 
3765  ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC | AST_OPT_FLAG_NO_COLOR);
3766  xarg = ast_strdup(optarg);
3767  break;
3768  case '?':
3769  /* already processed. */
3770  break;
3771  }
3772  }
3773 
3774  if (ast_opt_remote) {
3775  int didwarn = 0;
3776  optind = 1;
3777 
3778  /* Not all options can be used with remote console. Warn if they're used. */
3779  while ((c = getopt(argc, argv, getopt_settings)) != -1) {
3780  switch (c) {
3781  /* okay to run with remote console */
3782  case 'B': /* force black background */
3783  case 'C': /* set config path */
3784  case 'd': /* debug */
3785  case 'h': /* help */
3786  case 'I': /* obsolete timing option: warning already thrown if used */
3787  case 'L': /* max load */
3788  case 'M': /* max calls */
3789  case 'm': /* mute */
3790  /*! \note The q option is never used anywhere, only defined */
3791  case 'q': /* quiet */
3792  case 'R': /* reconnect */
3793  case 'r': /* remote */
3794  /*! \note Can ONLY be used with remote console */
3795  case 's': /* set socket path */
3796  case 'T': /* timestamp */
3797  case 'V': /* version */
3798  case 'v': /* verbose */
3799  case 'W': /* white background */
3800  case 'x': /* remote execute */
3801  case '?': /* ? */
3802  break;
3803  /* can only be run when Asterisk is starting */
3804  case 'X': /* enables #exec for asterisk.conf only. */
3805  case 'c': /* foreground console */
3806  case 'e': /* minimum memory free */
3807  case 'F': /* always fork */
3808  case 'f': /* no fork */
3809  case 'G': /* run group */
3810  case 'g': /* dump core */
3811  case 'i': /* init keys */
3812  case 'n': /* no color */
3813  case 'p': /* high priority */
3814  case 't': /* cache record files */
3815  case 'U': /* run user */
3816  fprintf(stderr, "'%c' option is not compatible with remote console mode and has no effect.\n", c);
3817  didwarn = 1;
3818  }
3819  }
3820  if (didwarn) {
3821  fprintf(stderr, "\n"); /* if any warnings print out, make them stand out */
3822  }
3823  }
3824 
3825  /* For remote connections, change the name of the remote connection.
3826  * We do this for the benefit of init scripts (which need to know if/when
3827  * the main asterisk process has died yet). */
3828  if (ast_opt_remote) {
3829  strcpy(argv[0], "rasterisk");
3830  for (x = 1; x < argc; x++) {
3831  argv[x] = argv[0] + 10;
3832  }
3833  }
3834 
3835  if (!ast_language_is_prefix && !ast_opt_remote) {
3836  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");
3837  }
3838 
3839  if (ast_opt_always_fork && (ast_opt_remote || ast_opt_console)) {
3840  fprintf(stderr, "'alwaysfork' is not compatible with console or remote console mode; ignored\n");
3841  ast_clear_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
3842  }
3843 
3844  if (ast_opt_dump_core) {
3845  memset(&l, 0, sizeof(l));
3846  l.rlim_cur = RLIM_INFINITY;
3847  l.rlim_max = RLIM_INFINITY;
3848  if (setrlimit(RLIMIT_CORE, &l)) {
3849  fprintf(stderr, "Unable to disable core size resource limit: %s\n", strerror(errno));
3850  }
3851  }
3852 
3853  if (getrlimit(RLIMIT_NOFILE, &l)) {
3854  fprintf(stderr, "Unable to check file descriptor limit: %s\n", strerror(errno));
3855  }
3856 
3857 #if !defined(CONFIGURE_RAN_AS_ROOT)
3858  /* Check if select(2) will run with more file descriptors */
3859  do {
3860  int fd, fd2;
3861  ast_fdset readers;
3862  struct timeval tv = { 0, };
3863 
3864  if (l.rlim_cur <= FD_SETSIZE) {
3865  /* The limit of select()able FDs is irrelevant, because we'll never
3866  * open one that high. */
3867  break;
3868  }
3869 
3870  if (!(fd = open("/dev/null", O_RDONLY))) {
3871  fprintf(stderr, "Cannot open a file descriptor at boot? %s\n", strerror(errno));
3872  break; /* XXX Should we exit() here? XXX */
3873  }
3874 
3875  fd2 = ((l.rlim_cur > sizeof(readers) * 8) ? sizeof(readers) * 8 : l.rlim_cur) - 1;
3876  if (dup2(fd, fd2) < 0) {
3877  fprintf(stderr, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno));
3878  close(fd);
3879  break;
3880  }
3881 
3882  FD_ZERO(&readers);
3883  FD_SET(fd2, &readers);
3884  if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) {
3885  fprintf(stderr, "Maximum select()able file descriptor is %d\n", FD_SETSIZE);
3886  }
3887  ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur;
3888  close(fd);
3889  close(fd2);
3890  } while (0);
3891 #elif defined(HAVE_VARIABLE_FDSET)
3892  ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur;
3893 #endif /* !defined(CONFIGURE_RAN_AS_ROOT) */
3894 
3895  if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))
3896  rungroup = ast_strdup(ast_config_AST_RUN_GROUP);
3897  if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER))
3898  runuser = ast_strdup(ast_config_AST_RUN_USER);
3899 
3900  /* Must install this signal handler up here to ensure that if the canary
3901  * fails to execute that it doesn't kill the Asterisk process.
3902  */
3903  sigaction(SIGCHLD, &child_handler, NULL);
3904 
3905  /* It's common on some platforms to clear /var/run at boot. Create the
3906  * socket file directory before we drop privileges. */
3907  if (mkdir(ast_config_AST_RUN_DIR, 0755)) {
3908  if (errno == EEXIST) {
3909  rundir_exists = 1;
3910  } else {
3911  fprintf(stderr, "Unable to create socket file directory. Remote consoles will not be able to connect! (%s)\n", strerror(x));
3912  }
3913  }
3914 
3915 #ifndef __CYGWIN__
3916 
3917  if (isroot) {
3918  ast_set_priority(ast_opt_high_priority);
3919  }
3920 
3921  if (isroot && rungroup) {
3922  struct group *gr;
3923  gr = getgrnam(rungroup);
3924  if (!gr) {
3925  fprintf(stderr, "No such group '%s'!\n", rungroup);
3926  exit(1);
3927  }
3928  if (!rundir_exists && chown(ast_config_AST_RUN_DIR, -1, gr->gr_gid)) {
3929  fprintf(stderr, "Unable to chgrp run directory to %d (%s)\n", (int) gr->gr_gid, rungroup);
3930  }
3931  if (setgid(gr->gr_gid)) {
3932  fprintf(stderr, "Unable to setgid to %d (%s)\n", (int)gr->gr_gid, rungroup);
3933  exit(1);
3934  }
3935  if (setgroups(0, NULL)) {
3936  fprintf(stderr, "Unable to drop unneeded groups\n");
3937  exit(1);
3938  }
3939  }
3940 
3941  if (runuser && !ast_test_flag(&ast_options, AST_OPT_FLAG_REMOTE)) {
3942 #ifdef HAVE_CAP
3943  int has_cap = 1;
3944 #endif /* HAVE_CAP */
3945  struct passwd *pw;
3946  pw = getpwnam(runuser);
3947  if (!pw) {
3948  fprintf(stderr, "No such user '%s'!\n", runuser);
3949  exit(1);
3950  }
3951  if (chown(ast_config_AST_RUN_DIR, pw->pw_uid, -1)) {
3952  fprintf(stderr, "Unable to chown run directory to %d (%s)\n", (int) pw->pw_uid, runuser);
3953  }
3954 #ifdef HAVE_CAP
3955  if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
3956  ast_log(LOG_WARNING, "Unable to keep capabilities.\n");
3957  has_cap = 0;
3958  }
3959 #endif /* HAVE_CAP */
3960  if (!isroot && pw->pw_uid != geteuid()) {
3961  fprintf(stderr, "Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
3962  exit(1);
3963  }
3964  if (!rungroup) {
3965  if (setgid(pw->pw_gid)) {
3966  fprintf(stderr, "Unable to setgid to %d!\n", (int)pw->pw_gid);
3967  exit(1);
3968  }
3969  if (isroot && initgroups(pw->pw_name, pw->pw_gid)) {
3970  fprintf(stderr, "Unable to init groups for '%s'\n", runuser);
3971  exit(1);
3972  }
3973  }
3974  if (setuid(pw->pw_uid)) {
3975  fprintf(stderr, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
3976  exit(1);
3977  }
3978 #ifdef HAVE_CAP
3979  if (has_cap) {
3980  cap_t cap;
3981 
3982  cap = cap_from_text("cap_net_admin=eip");
3983 
3984  if (cap_set_proc(cap)) {
3985  fprintf(stderr, "Unable to install capabilities.\n");
3986  }
3987  if (cap_free(cap)) {
3988  fprintf(stderr, "Unable to drop capabilities.\n");
3989  }
3990  }
3991 #endif /* HAVE_CAP */
3992  }
3993 
3994 #endif /* __CYGWIN__ */
3995 
3996 #ifdef linux
3997  if (geteuid() && ast_opt_dump_core) {
3998  if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
3999  fprintf(stderr, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno));
4000  }
4001  }
4002 #endif
4003 
4004  {
4005 #if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
4006  char dir[PATH_MAX];
4007  if (!getcwd(dir, sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) {
4008  fprintf(stderr, "Unable to access the running directory (%s). Changing to '/' for compatibility.\n", strerror(errno));
4009  /* If we cannot access the CWD, then we couldn't dump core anyway,
4010  * so chdir("/") won't break anything. */
4011  if (chdir("/")) {
4012  /* chdir(/) should never fail, so this ends up being a no-op */
4013  fprintf(stderr, "chdir(\"/\") failed?!! %s\n", strerror(errno));
4014  }
4015  } else
4016 #endif /* defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) */
4017  if (!ast_opt_no_fork && !ast_opt_dump_core) {
4018  /* Backgrounding, but no cores, so chdir won't break anything. */
4019  if (chdir("/")) {
4020  fprintf(stderr, "Unable to chdir(\"/\") ?!! %s\n", strerror(errno));
4021  }
4022  }
4023  }
4024 
4025  /* Initial value of the maximum active system verbosity level. */
4027 
4028  if (ast_sd_get_fd_un(SOCK_STREAM, ast_config_AST_SOCKET) > 0) {
4029  ast_socket_is_sd = 1;
4030  }
4031 
4032  /* DO NOT perform check for existing daemon if systemd has CLI socket activation */
4033  if (!ast_socket_is_sd && ast_tryconnect()) {
4034  /* One is already running */
4035  if (ast_opt_remote) {
4036  multi_thread_safe = 1;
4037  if (ast_opt_exec) {
4038  ast_remotecontrol(xarg);
4039  quit_handler(0, SHUTDOWN_FAST, 0);
4040  exit(0);
4041  }
4042  ast_term_init();
4043  printf("%s", term_end());
4044  fflush(stdout);
4045 
4046  print_intro_message(runuser, rungroup);
4047  printf("%s", term_quit());
4048  ast_remotecontrol(NULL);
4049  quit_handler(0, SHUTDOWN_FAST, 0);
4050  exit(0);
4051  } else {
4052  fprintf(stderr, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET);
4053  printf("%s", term_quit());
4054  exit(1);
4055  }
4056  } else if (ast_opt_remote || ast_opt_exec) {
4057  fprintf(stderr, "Unable to connect to remote asterisk (does %s exist?)\n", ast_config_AST_SOCKET);
4058  printf("%s", term_quit());
4059  exit(1);
4060  }
4061 
4062 #ifdef HAVE_CAP
4063  child_cap = cap_from_text("cap_net_admin-eip");
4064 #endif
4065  /* Not a remote console? Start the daemon. */
4066  asterisk_daemon(isroot, runuser, rungroup);
4067 #ifdef HAS_CAP
4068  cap_free(child_cap);
4069 #endif
4070  return 0;
4071 }
int ast_sd_get_fd_un(int type, const char *path)
Find a listening AF_LOCAL file descriptor provided by socket activation.
Definition: io.c:454
int option_debug
Definition: options.c:69
int option_verbose
Definition: options.c:67
double ast_option_maxload
Definition: options.c:77
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
int ast_option_maxcalls
Definition: options.c:79
int ast_term_init(void)
Definition: term.c:165
long option_minmemfree
Definition: options.c:86
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 ac...
Definition: asterisk.c:1841
int ast_language_is_prefix
The following variable controls the layout of localized sound files. If 0, use the historical layout ...
Definition: file.c:67
static int ast_select(int nfds, ast_fdset *rfds, ast_fdset *wfds, ast_fdset *efds, struct timeval *tvp)
Waits for activity on a group of channels.
Definition: select.h:79
int ast_verb_sys_level
Definition: options.c:64
static int ast_socket_is_sd
Definition: asterisk.c:316
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
static int read_credentials ( int  fd,
char *  buffer,
size_t  size,
struct console con 
)
static

read() function supporting the reception of user credentials.

Parameters
fdSocket file descriptor.
bufferReceive buffer.
size'buffer' size.
conConsole structure to set received credentials
Return values
-1on error
thenumber of bytes received on success.

Definition at line 1378 of file asterisk.c.

References console::gid, and console::uid.

1379 {
1380 #if defined(SO_PEERCRED)
1381 #ifdef HAVE_STRUCT_SOCKPEERCRED_UID
1382 #define HAVE_STRUCT_UCRED_UID
1383  struct sockpeercred cred;
1384 #else
1385  struct ucred cred;
1386 #endif
1387  socklen_t len = sizeof(cred);
1388 #endif
1389 #if defined(HAVE_GETPEEREID)
1390  uid_t uid;
1391  gid_t gid;
1392 #else
1393  int uid, gid;
1394 #endif
1395  int result;
1396 
1397  result = read(fd, buffer, size);
1398  if (result < 0) {
1399  return result;
1400  }
1401 
1402 #if defined(SO_PEERCRED) && (defined(HAVE_STRUCT_UCRED_UID) || defined(HAVE_STRUCT_UCRED_CR_UID))
1403  if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len)) {
1404  return result;
1405  }
1406 #if defined(HAVE_STRUCT_UCRED_UID)
1407  uid = cred.uid;
1408  gid = cred.gid;
1409 #else /* defined(HAVE_STRUCT_UCRED_CR_UID) */
1410  uid = cred.cr_uid;
1411  gid = cred.cr_gid;
1412 #endif /* defined(HAVE_STRUCT_UCRED_UID) */
1413 
1414 #elif defined(HAVE_GETPEEREID)
1415  if (getpeereid(fd, &uid, &gid)) {
1416  return result;
1417  }
1418 #else
1419  return result;
1420 #endif
1421  con->uid = uid;
1422  con->gid = gid;
1423 
1424  return result;
1425 }
int uid
Definition: asterisk.c:324
int gid
Definition: asterisk.c:325
static void really_quit ( int  num,
shutdown_nice_t  niceness,
int  restart 
)
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.

2047 {
2048  int active_channels;
2049  struct ast_json *json_object = NULL;
2050  int run_cleanups = niceness >= SHUTDOWN_NICE;
2051 
2052  if (run_cleanups && modules_shutdown()) {
2053  ast_verb(0, "Some modules could not be unloaded, switching to fast shutdown\n");
2054  run_cleanups = 0;
2055  }
2056 
2057  if (!restart && !ast_opt_remote) {
2058  ast_sd_notify("STOPPING=1");
2059  }
2060  if (ast_opt_console || (ast_opt_remote && !ast_opt_exec)) {
2061  ast_el_write_default_histfile();
2062  if (consolethread == AST_PTHREADT_NULL || consolethread == pthread_self()) {
2063  /* Only end if we are the consolethread, otherwise there's a race with that thread. */
2064  if (el != NULL) {
2065  el_end(el);
2066  }
2067  if (el_hist != NULL) {
2068  history_end(el_hist);
2069  }
2070  } else if (!restart) {
2071  sig_flags.need_el_end = 1;
2072  pthread_kill(consolethread, SIGURG);
2073  }
2074  }
2075  active_channels = ast_active_channels();
2076  /* Don't publish messages if we're a remote console - we won't have all of the Stasis
2077  * topics or message types
2078  */
2079  if (!ast_opt_remote) {
2080  json_object = ast_json_pack("{s: s, s: s}",
2081  "Shutdown", active_channels ? "Uncleanly" : "Cleanly",
2082  "Restart", restart ? "True" : "False");
2083  ast_manager_publish_event("Shutdown", EVENT_FLAG_SYSTEM, json_object);
2084  ast_json_unref(json_object);
2085  json_object = NULL;
2086  }
2087  ast_verb(0, "Asterisk %s ending (%d).\n",
2088  active_channels ? "uncleanly" : "cleanly", num);
2089 
2090  ast_verb(0, "Executing last minute cleanups\n");
2091  ast_run_atexits(run_cleanups);
2092 
2093  ast_debug(1, "Asterisk ending (%d).\n", num);
2094  if (ast_socket > -1) {
2095  pthread_cancel(lthread);
2096  close(ast_socket);
2097  ast_socket = -1;
2098  if (!ast_socket_is_sd) {
2099  unlink(ast_config_AST_SOCKET);
2100  }
2101  pthread_kill(lthread, SIGURG);
2102  pthread_join(lthread, NULL);
2103  }
2104  if (ast_consock > -1)
2105  close(ast_consock);
2106  if (!ast_opt_remote)
2107  unlink(ast_config_AST_PID);
2108  ast_alertpipe_close(sig_alert_pipe);
2109  printf("%s", term_quit());
2110  if (restart) {
2111  int i;
2112  ast_verb(0, "Preparing for Asterisk restart...\n");
2113  /* Mark all FD's for closing on exec */
2114  for (i = 3; i < 32768; i++) {
2115  fcntl(i, F_SETFD, FD_CLOEXEC);
2116  }
2117  ast_verb(0, "Asterisk is now restarting...\n");
2118  restartnow = 1;
2119 
2120  /* close logger */
2121  close_logger();
2122  clean_time_zones();
2123 
2124  /* If there is a consolethread running send it a SIGHUP
2125  so it can execvp, otherwise we can do it ourselves */
2126  if ((consolethread != AST_PTHREADT_NULL) && (consolethread != pthread_self())) {
2127  pthread_kill(consolethread, SIGHUP);
2128  /* Give the signal handler some time to complete */
2129  sleep(2);
2130  } else
2131  execvp(_argv[0], _argv);
2132 
2133  } else {
2134  /* close logger */
2135  close_logger();
2136  clean_time_zones();
2137  }
2138 
2139  exit(0);
2140 }
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
Definition: alertpipe.c:79
int modules_shutdown(void)
Definition: loader.c:1172
void close_logger(void)
Definition: logger.c:2245
int ast_sd_notify(const char *state)
a wrapper for sd_notify(): notify systemd of any state changes.
Definition: io.c:392
#define ast_debug(level,...)
Log a DEBUG message.
static int ast_socket
Definition: asterisk.c:315
static int ast_consock
Definition: asterisk.c:317
void clean_time_zones(void)
Definition: localtime.c:1590
static int ast_socket_is_sd
Definition: asterisk.c:316
Abstract JSON element (object, array, string, int, ...).
int ast_active_channels(void)
returns number of active/allocated channels
Definition: channel.c:499
void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
Publish an event to AMI.
Definition: manager.c:2063

Variable Documentation

int ast_consock = -1
static

UNIX Socket for controlling another asterisk

Definition at line 317 of file asterisk.c.

Referenced by really_quit().

int ast_socket = -1
static

UNIX Socket for allowing remote control

Definition at line 315 of file asterisk.c.

Referenced by really_quit().

int ast_socket_is_sd = 0
static

Is socket activation responsible for ast_socket?

Definition at line 316 of file asterisk.c.

Referenced by main(), and really_quit().

struct sigaction child_handler
static
Initial value:
= {
.sa_handler = _child_handler,
.sa_flags = SA_RESTART,
}

Definition at line 1759 of file asterisk.c.

struct ast_cli_entry cli_asterisk_shutdown[]
static

Shutdown Asterisk CLI commands.

Note
These CLI commands cannot be unregistered at shutdown because one of them is likely the reason for the shutdown. The CLI generates a warning if a command is in-use when it is unregistered.

Definition at line 2618 of file asterisk.c.

struct sigaction hup_handler
static
Initial value:
= {
.sa_handler = _hup_handler,
.sa_flags = SA_RESTART,
}

Definition at line 1739 of file asterisk.c.

struct sigaction ignore_sig_handler
static
Initial value:
= {
.sa_handler = SIG_IGN,
}

Definition at line 1093 of file asterisk.c.

struct sigaction null_sig_handler
static
Initial value:
= {
.sa_handler = _null_sig_handler,
.sa_flags = SA_RESTART,
}
static void _null_sig_handler(int sig)
NULL handler so we can collect the child exit status.
Definition: asterisk.c:1084

Definition at line 1088 of file asterisk.c.

int shutdown_pending
static

Prevent new channel allocation for shutdown.

Definition at line 384 of file asterisk.c.

Referenced by ast_cancel_shutdown(), and ast_shutting_down().

struct sigaction urg_handler
static
Initial value:
= {
.sa_handler = _urg_handler,
}
static void _urg_handler(int num)
Urgent handler.
Definition: asterisk.c:1711

Definition at line 1716 of file asterisk.c.