#include "asterisk.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <sched.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/resource.h>
#include <grp.h>
#include <pwd.h>
#include <sys/stat.h>
#include <regex.h>
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/channel.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/image.h"
#include "asterisk/tdd.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/cdr.h"
#include "asterisk/pbx.h"
#include "asterisk/enum.h"
#include "asterisk/rtp.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/version.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
#include "asterisk/module.h"
#include "asterisk/doxyref.h"
#include "../defaults.h"
Include dependency graph for asterisk.c:

Go to the source code of this file.
Data Structures | |
| struct | ast_atexit |
| struct | console |
| struct | file_version |
| struct | profile_data |
| struct | profile_entry |
| struct | thread_list_t |
Defines | |
| #define | AF_LOCAL AF_UNIX |
| #define | AST_MAX_CONNECTS 128 |
| #define | ASTERISK_PROMPT "*CLI> " |
| #define | ASTERISK_PROMPT2 "%s*CLI> " |
| #define | EL_BUF_SIZE 512 |
| #define | FORMAT "%-25.25s %-40.40s\n" |
| #define | FORMAT "%-25.25s %-40.40s\n" |
| #define | NUM_MSGS 64 |
| #define | PF_LOCAL PF_UNIX |
| #define | WELCOME_MESSAGE |
| Welcome message when starting a CLI interface. | |
Functions | |
| static void | __quit_handler (int num) |
| int | ast_add_profile (const char *name, uint64_t scale) |
| support for event profiling | |
| static int | ast_all_zeros (char *s) |
| static int | ast_cli_display_match_list (char **matches, int len, int max) |
| void | ast_console_puts (const char *string) |
| void | ast_console_puts_mutable (const char *string) |
| log the string to the console, and all attached console clients | |
| 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 *el, 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 *) |
| static | AST_LIST_HEAD_STATIC (thread_list, thread_list_t) |
| static | AST_LIST_HEAD_STATIC (file_versions, file_version) |
| static | AST_LIST_HEAD_STATIC (atexits, ast_atexit) |
| static int | ast_makesocket (void) |
| int64_t | ast_mark (int i, int startstop) |
| AST_MUTEX_DEFINE_STATIC (safe_system_lock) | |
| 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) |
| 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) |
| 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 void | child_handler (int sig) |
| static char * | cli_complete (EditLine *el, int ch) |
| static char * | cli_prompt (EditLine *el) |
| static char * | complete_show_version_files (const char *line, const char *word, int pos, int state) |
| static char * | complete_show_version_files_deprecated (const char *line, const char *word, int pos, int state) |
| static void | console_verboser (const char *s) |
| static void | consolehandler (char *s) |
| 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 int | handle_abort_halt (int fd, int argc, char *argv[]) |
| static int | handle_bang (int fd, int argc, char *argv[]) |
| static int | handle_restart_gracefully (int fd, int argc, char *argv[]) |
| static int | handle_restart_now (int fd, int argc, char *argv[]) |
| static int | handle_restart_when_convenient (int fd, int argc, char *argv[]) |
| static int | handle_show_profile (int fd, int argc, char *argv[]) |
| static int | handle_show_profile_deprecated (int fd, int argc, char *argv[]) |
| static int | handle_show_threads (int fd, int argc, char *argv[]) |
| static int | handle_show_version_files (int fd, int argc, char *argv[]) |
| static int | handle_show_version_files_deprecated (int fd, int argc, char *argv[]) |
| CLI command to list module versions. | |
| static int | handle_shutdown_gracefully (int fd, int argc, char *argv[]) |
| static int | handle_shutdown_now (int fd, int argc, char *argv[]) |
| static int | handle_shutdown_when_convenient (int fd, int argc, char *argv[]) |
| static int | handle_version (int fd, int argc, char *argv[]) |
| static int | handle_version_deprecated (int fd, int argc, char *argv[]) |
| static void | hup_handler (int num) |
| static void * | listener (void *unused) |
| int | main (int argc, char *argv[]) |
| static void * | monitor_sig_flags (void *unused) |
| static void * | netconsole (void *vconsole) |
| static void | network_verboser (const char *s) |
| static void | null_sig_handler (int signal) |
| NULL handler so we can collect the child exit status. | |
| static void | quit_handler (int num, int nice, int safeshutdown, int restart) |
| static __inline uint64_t | rdtsc (void) |
| static int | remoteconsolehandler (char *s) |
| static void | set_icon (char *text) |
| static void | set_title (char *text) |
| Set an X-term or screen title. | |
| static int | show_cli_help (void) |
| static int | show_license (int fd, int argc, char *argv[]) |
| static int | show_version (void) |
| static int | show_warranty (int fd, int argc, char *argv[]) |
| static void | urg_handler (int num) |
| Urgent handler. | |
Variables | |
| static char * | _argv [256] |
| static enum dahdi_chan_modes | _dahdi_chan_mode = CHAN_DAHDI_PLUS_ZAP_MODE |
| static char | _dahdi_chan_name [AST_CHANNEL_NAME] = "DAHDI" |
| static size_t | _dahdi_chan_name_len = 5 |
| static char | abort_halt_help [] |
| const char * | ast_build_date |
| const char * | ast_build_hostname |
| const char * | ast_build_kernel |
| const char * | ast_build_machine |
| const char * | ast_build_os |
| const char * | ast_build_user |
| char | ast_config_AST_AGI_DIR [PATH_MAX] |
| char | ast_config_AST_CONFIG_DIR [PATH_MAX] |
| char | ast_config_AST_CONFIG_FILE [PATH_MAX] |
| char | ast_config_AST_CTL [PATH_MAX] = "asterisk.ctl" |
| char | ast_config_AST_CTL_GROUP [PATH_MAX] = "\0" |
| char | ast_config_AST_CTL_OWNER [PATH_MAX] = "\0" |
| char | ast_config_AST_CTL_PERMISSIONS [PATH_MAX] |
| char | ast_config_AST_DATA_DIR [PATH_MAX] |
| char | ast_config_AST_DB [PATH_MAX] |
| char | ast_config_AST_KEY_DIR [PATH_MAX] |
| char | ast_config_AST_LOG_DIR [PATH_MAX] |
| char | ast_config_AST_MODULE_DIR [PATH_MAX] |
| char | ast_config_AST_MONITOR_DIR [PATH_MAX] |
| char | ast_config_AST_PID [PATH_MAX] |
| char | ast_config_AST_RUN_DIR [PATH_MAX] |
| char | ast_config_AST_RUN_GROUP [PATH_MAX] |
| char | ast_config_AST_RUN_USER [PATH_MAX] |
| char | ast_config_AST_SOCKET [PATH_MAX] |
| char | ast_config_AST_SPOOL_DIR [PATH_MAX] |
| char | ast_config_AST_SYSTEM_NAME [20] = "" |
| char | ast_config_AST_VAR_DIR [PATH_MAX] |
| time_t | ast_lastreloadtime |
| ast_flags | ast_options = { AST_DEFAULT_OPTIONS } |
| time_t | ast_startuptime |
| static char | bang_help [] |
| static struct ast_cli_entry | cli_asterisk [] |
| static struct ast_cli_entry | cli_clear_profile_deprecated |
| static struct ast_cli_entry | cli_show_profile_deprecated |
| static struct ast_cli_entry | cli_show_version_deprecated |
| static struct ast_cli_entry | cli_show_version_files_deprecated |
| console | consoles [AST_MAX_CONNECTS] |
| static pthread_t | consolethread = AST_PTHREADT_NULL |
| const char * | dahdi_chan_name |
| const size_t * | dahdi_chan_name_len |
| char | debug_filename [AST_FILENAME_MAX] = "" |
| char | defaultlanguage [MAX_LANGUAGE] = DEFAULT_LANGUAGE |
| static EditLine * | el |
| static History * | el_hist |
| static const char * | license_lines [] |
| static pthread_t | lthread |
| int | option_debug |
| int | option_maxcalls |
| double | option_maxload |
| int | option_verbose |
| static struct profile_data * | prof_data |
| static char | randompool [256] |
| char | record_cache_dir [AST_CACHE_DIR_LEN] = AST_TMP_DIR |
| static char * | remotehostname |
| static char | restart_gracefully_help [] |
| static char | restart_now_help [] |
| static char | restart_when_convenient_help [] |
| 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 void * | safe_system_prev_handler |
| static char | show_license_help [] |
| static char | show_threads_help [] |
| static char | show_version_files_help [] |
| static char | show_warranty_help [] |
| static char | shutdown_gracefully_help [] |
| static char | shutdown_now_help [] |
| static char | shutdown_when_convenient_help [] |
| static int | shuttingdown |
| static int | sig_alert_pipe [2] = { -1, -1 } |
| struct { | |
| unsigned int need_quit:1 | |
| unsigned int need_reload:1 | |
| } | sig_flags |
| static char | version_help [] |
| static const char * | warranty_lines [] |
Definition in file asterisk.c.
| #define AF_LOCAL AF_UNIX |
Definition at line 132 of file asterisk.c.
Referenced by ast_makesocket(), ast_tryconnect(), listener(), and NBScat_exec().
| #define AST_MAX_CONNECTS 128 |
Definition at line 136 of file asterisk.c.
Referenced by ast_console_toggle_mute(), ast_makesocket(), ast_network_puts(), ast_network_puts_mutable(), and listener().
| #define ASTERISK_PROMPT "*CLI> " |
| #define ASTERISK_PROMPT2 "%s*CLI> " |
| #define EL_BUF_SIZE 512 |
Referenced by ast_el_read_char().
| #define FORMAT "%-25.25s %-40.40s\n" |
| #define FORMAT "%-25.25s %-40.40s\n" |
Referenced by __iax2_show_peers(), __sip_show_channels(), _sip_show_peers(), dahdi_show_channels(), dahdi_show_status(), dundi_show_mappings(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), gtalk_show_channels(), handle_show_version_files(), handle_show_version_files_deprecated(), iax2_show_channels(), iax2_show_firmware(), iax2_show_registry(), iax2_show_users(), show_channeltypes(), show_file_formats(), show_file_formats_deprecated(), show_image_formats(), show_image_formats_deprecated(), sip_show_domains(), sip_show_inuse(), sip_show_registry(), and sip_show_users().
| #define NUM_MSGS 64 |
Definition at line 137 of file asterisk.c.
| #define PF_LOCAL PF_UNIX |
| #define WELCOME_MESSAGE |
Welcome message when starting a CLI interface.
Definition at line 140 of file asterisk.c.
Referenced by ast_el_read_char(), and main().
| static void __quit_handler | ( | int | num | ) | [static] |
Definition at line 1350 of file asterisk.c.
References sig_flags.
Referenced by main().
01351 { 01352 int a = 0; 01353 sig_flags.need_quit = 1; 01354 if (sig_alert_pipe[1] != -1) 01355 write(sig_alert_pipe[1], &a, sizeof(a)); 01356 /* There is no need to restore the signal handler here, since the app 01357 * is going to exit */ 01358 }
| int ast_add_profile | ( | const char * | name, | |
| uint64_t | scale | |||
| ) |
support for event profiling
Definition at line 380 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().
00381 { 00382 int l = sizeof(struct profile_data); 00383 int n = 10; /* default entries */ 00384 00385 if (prof_data == NULL) { 00386 prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry)); 00387 if (prof_data == NULL) 00388 return -1; 00389 prof_data->entries = 0; 00390 prof_data->max_size = n; 00391 } 00392 if (prof_data->entries >= prof_data->max_size) { 00393 void *p; 00394 n = prof_data->max_size + 20; 00395 p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry)); 00396 if (p == NULL) 00397 return -1; 00398 prof_data = p; 00399 prof_data->max_size = n; 00400 } 00401 n = prof_data->entries++; 00402 prof_data->e[n].name = ast_strdup(name); 00403 prof_data->e[n].value = 0; 00404 prof_data->e[n].events = 0; 00405 prof_data->e[n].mark = 0; 00406 prof_data->e[n].scale = scale; 00407 return n; 00408 }
| static int ast_all_zeros | ( | char * | s | ) | [static] |
Definition at line 1402 of file asterisk.c.
Referenced by ast_el_read_history(), consolehandler(), and remoteconsolehandler().
01403 { 01404 while (*s) { 01405 if (*s > 32) 01406 return 0; 01407 s++; 01408 } 01409 return 1; 01410 }
| static int ast_cli_display_match_list | ( | char ** | matches, | |
| int | len, | |||
| int | max | |||
| ) | [static] |
Definition at line 2036 of file asterisk.c.
References ast_el_sort_compare(), ast_get_termcols(), and free.
Referenced by cli_complete().
02037 { 02038 int i, idx, limit, count; 02039 int screenwidth = 0; 02040 int numoutput = 0, numoutputline = 0; 02041 02042 screenwidth = ast_get_termcols(STDOUT_FILENO); 02043 02044 /* find out how many entries can be put on one line, with two spaces between strings */ 02045 limit = screenwidth / (max + 2); 02046 if (limit == 0) 02047 limit = 1; 02048 02049 /* how many lines of output */ 02050 count = len / limit; 02051 if (count * limit < len) 02052 count++; 02053 02054 idx = 1; 02055 02056 qsort(&matches[0], (size_t)(len), sizeof(char *), ast_el_sort_compare); 02057 02058 for (; count > 0; count--) { 02059 numoutputline = 0; 02060 for (i=0; i < limit && matches[idx]; i++, idx++) { 02061 02062 /* Don't print dupes */ 02063 if ( (matches[idx+1] != NULL && strcmp(matches[idx], matches[idx+1]) == 0 ) ) { 02064 i--; 02065 free(matches[idx]); 02066 matches[idx] = NULL; 02067 continue; 02068 } 02069 02070 numoutput++; 02071 numoutputline++; 02072 fprintf(stdout, "%-*s ", max, matches[idx]); 02073 free(matches[idx]); 02074 matches[idx] = NULL; 02075 } 02076 if (numoutputline > 0) 02077 fprintf(stdout, "\n"); 02078 } 02079 02080 return numoutput; 02081 }
| void ast_console_puts | ( | const char * | string | ) |
write the string to the console, and all attached console clients
Definition at line 915 of file asterisk.c.
References ast_network_puts().
Referenced by chan_misdn_log().
00916 { 00917 fputs(string, stdout); 00918 fflush(stdout); 00919 ast_network_puts(string); 00920 }
| void ast_console_puts_mutable | ( | const char * | string | ) |
log the string to the console, and all attached console clients
Definition at line 892 of file asterisk.c.
References ast_network_puts_mutable().
Referenced by ast_log().
00893 { 00894 fputs(string, stdout); 00895 fflush(stdout); 00896 ast_network_puts_mutable(string); 00897 }
| void ast_console_toggle_mute | ( | int | fd, | |
| int | silent | |||
| ) |
mute or unmute a console from logging
Definition at line 855 of file asterisk.c.
References ast_cli(), AST_MAX_CONNECTS, consoles, and console::mute.
Referenced by handle_logger_mute().
00855 { 00856 int x; 00857 for (x = 0;x < AST_MAX_CONNECTS; x++) { 00858 if (fd == consoles[x].fd) { 00859 if (consoles[x].mute) { 00860 consoles[x].mute = 0; 00861 if (!silent) 00862 ast_cli(fd, "Console is not muted anymore.\n"); 00863 } else { 00864 consoles[x].mute = 1; 00865 if (!silent) 00866 ast_cli(fd, "Console is muted.\n"); 00867 } 00868 return; 00869 } 00870 } 00871 ast_cli(fd, "Couldn't find remote console.\n"); 00872 }
| static int ast_el_add_history | ( | char * | ) | [static] |
Definition at line 2230 of file asterisk.c.
References ast_el_initialize().
Referenced by ast_el_read_history(), consolehandler(), and remoteconsolehandler().
02231 { 02232 HistEvent ev; 02233 02234 if (el_hist == NULL || el == NULL) 02235 ast_el_initialize(); 02236 if (strlen(buf) > 256) 02237 return 0; 02238 return (history(el_hist, &ev, H_ENTER, buf)); 02239 }
| static int ast_el_initialize | ( | void | ) | [static] |
Definition at line 2195 of file asterisk.c.
References cli_complete(), and cli_prompt().
Referenced by ast_el_add_history(), ast_el_read_history(), ast_el_write_history(), ast_remotecontrol(), and main().
02196 { 02197 HistEvent ev; 02198 char *editor = getenv("AST_EDITOR"); 02199 02200 if (el != NULL) 02201 el_end(el); 02202 if (el_hist != NULL) 02203 history_end(el_hist); 02204 02205 el = el_init("asterisk", stdin, stdout, stderr); 02206 el_set(el, EL_PROMPT, cli_prompt); 02207 02208 el_set(el, EL_EDITMODE, 1); 02209 el_set(el, EL_EDITOR, editor ? editor : "emacs"); 02210 el_hist = history_init(); 02211 if (!el || !el_hist) 02212 return -1; 02213 02214 /* setup history with 100 entries */ 02215 history(el_hist, &ev, H_SETSIZE, 100); 02216 02217 el_set(el, EL_HIST, history, el_hist); 02218 02219 el_set(el, EL_ADDFN, "ed-complete", "Complete argument", cli_complete); 02220 /* Bind <tab> to command completion */ 02221 el_set(el, EL_BIND, "^I", "ed-complete", NULL); 02222 /* Bind ? to command completion */ 02223 el_set(el, EL_BIND, "?", "ed-complete", NULL); 02224 /* Bind ^D to redisplay */ 02225 el_set(el, EL_BIND, "^D", "ed-redisplay", NULL); 02226 02227 return 0; 02228 }
| static int ast_el_read_char | ( | EditLine * | el, | |
| char * | cp | |||
| ) | [static] |
Definition at line 1748 of file asterisk.c.
References ast_log(), ast_opt_exec, ast_opt_mute, ast_opt_reconnect, ast_tryconnect(), EL_BUF_SIZE, errno, pollfd::events, pollfd::fd, fdsend(), LOG_ERROR, poll(), POLLIN, quit_handler(), pollfd::revents, term_quit(), and WELCOME_MESSAGE.
Referenced by ast_remotecontrol().
01749 { 01750 int num_read = 0; 01751 int lastpos = 0; 01752 struct pollfd fds[2]; 01753 int res; 01754 int max; 01755 #define EL_BUF_SIZE 512 01756 char buf[EL_BUF_SIZE]; 01757 01758 for (;;) { 01759 max = 1; 01760 fds[0].fd = ast_consock; 01761 fds[0].events = POLLIN; 01762 if (!ast_opt_exec) { 01763 fds[1].fd = STDIN_FILENO; 01764 fds[1].events = POLLIN; 01765 max++; 01766 } 01767 res = poll(fds, max, -1); 01768 if (res < 0) { 01769 if (errno == EINTR) 01770 continue; 01771 ast_log(LOG_ERROR, "poll failed: %s\n", strerror(errno)); 01772 break; 01773 } 01774 01775 if (!ast_opt_exec && fds[1].revents) { 01776 num_read = read(STDIN_FILENO, cp, 1); 01777 if (num_read < 1) { 01778 break; 01779 } else 01780 return (num_read); 01781 } 01782 if (fds[0].revents) { 01783 char *tmp; 01784 res = read(ast_consock, buf, sizeof(buf) - 1); 01785 /* if the remote side disappears exit */ 01786 if (res < 1) { 01787 fprintf(stderr, "\nDisconnected from Asterisk server\n"); 01788 if (!ast_opt_reconnect) { 01789 quit_handler(0, 0, 0, 0); 01790 } else { 01791 int tries; 01792 int reconnects_per_second = 20; 01793 fprintf(stderr, "Attempting to reconnect for 30 seconds\n"); 01794 for (tries=0; tries < 30 * reconnects_per_second; tries++) { 01795 if (ast_tryconnect()) { 01796 fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries); 01797 printf(term_quit()); 01798 WELCOME_MESSAGE; 01799 if (!ast_opt_mute) 01800 fdsend(ast_consock, "logger mute silent"); 01801 else 01802 printf("log and verbose output currently muted ('logger mute' to unmute)\n"); 01803 break; 01804 } else { 01805 usleep(1000000 / reconnects_per_second); 01806 } 01807 } 01808 if (tries >= 30 * reconnects_per_second) { 01809 fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n"); 01810 quit_handler(0, 0, 0, 0); 01811 } 01812 } 01813 } 01814 01815 buf[res] = '\0'; 01816 01817 /* Strip preamble from asynchronous events, too */ 01818 for (tmp = buf; *tmp; tmp++) { 01819 if (*tmp == 127) { 01820 memmove(tmp, tmp + 1, strlen(tmp)); 01821 tmp--; 01822 } 01823 } 01824 01825 /* Write over the CLI prompt */ 01826 if (!ast_opt_exec && !lastpos) 01827 write(STDOUT_FILENO, "\r", 1); 01828 write(STDOUT_FILENO, buf, res); 01829 if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (buf[res-2] == '\n'))) { 01830 *cp = CC_REFRESH; 01831 return(1); 01832 } else { 01833 lastpos = 1; 01834 } 01835 } 01836 } 01837 01838 *cp = '\0'; 01839 return (0); 01840 }
| static int ast_el_read_history | ( | char * | ) | [static] |
Definition at line 2251 of file asterisk.c.
References ast_all_zeros(), ast_el_add_history(), ast_el_initialize(), and f.
Referenced by ast_remotecontrol(), and main().
02252 { 02253 char buf[256]; 02254 FILE *f; 02255 int ret = -1; 02256 02257 if (el_hist == NULL || el == NULL) 02258 ast_el_initialize(); 02259 02260 if ((f = fopen(filename, "r")) == NULL) 02261 return ret; 02262 02263 while (!feof(f)) { 02264 fgets(buf, sizeof(buf), f); 02265 if (!strcmp(buf, "_HiStOrY_V2_\n")) 02266 continue; 02267 if (ast_all_zeros(buf)) 02268 continue; 02269 if ((ret = ast_el_add_history(buf)) == -1) 02270 break; 02271 } 02272 fclose(f); 02273 02274 return ret; 02275 }
| static int ast_el_sort_compare | ( | const void * | i1, | |
| const void * | i2 | |||
| ) | [static] |
Definition at line 2026 of file asterisk.c.
Referenced by ast_cli_display_match_list().
02027 { 02028 char *s1, *s2; 02029 02030 s1 = ((char **)i1)[0]; 02031 s2 = ((char **)i2)[0]; 02032 02033 return strcasecmp(s1, s2); 02034 }
| static char** ast_el_strtoarr | ( | char * | buf | ) | [static] |
Definition at line 1991 of file asterisk.c.
References AST_CLI_COMPLETE_EOF, ast_realloc, strdup, and strsep().
Referenced by cli_complete().
01992 { 01993 char **match_list = NULL, *retstr; 01994 size_t match_list_len; 01995 int matches = 0; 01996 01997 match_list_len = 1; 01998 while ( (retstr = strsep(&buf, " ")) != NULL) { 01999 02000 if (!strcmp(retstr, AST_CLI_COMPLETE_EOF)) 02001 break; 02002 if (matches + 1 >= match_list_len) { 02003 match_list_len <<= 1; 02004 if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(char *)))) { 02005 /* TODO: Handle memory allocation failure */ 02006 } 02007 } 02008 02009 match_list[matches++] = strdup(retstr); 02010 } 02011 02012 if (!match_list) 02013 return (char **) NULL; 02014 02015 if (matches >= match_list_len) { 02016 if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) { 02017 /* TODO: Handle memory allocation failure */ 02018 } 02019 } 02020 02021 match_list[matches] = (char *) NULL; 02022 02023 return match_list; 02024 }
| static int ast_el_write_history | ( | char * | ) | [static] |
Definition at line 2241 of file asterisk.c.
References ast_el_initialize().
Referenced by quit_handler().
02242 { 02243 HistEvent ev; 02244 02245 if (el_hist == NULL || el == NULL) 02246 ast_el_initialize(); 02247 02248 return (history(el_hist, &ev, H_SAVE, filename)); 02249 }
| static AST_LIST_HEAD_STATIC | ( | thread_list | , | |
| thread_list_t | ||||
| ) | [static] |
| static AST_LIST_HEAD_STATIC | ( | file_versions | , | |
| file_version | ||||
| ) | [static] |
| static AST_LIST_HEAD_STATIC | ( | atexits | , | |
| ast_atexit | ||||
| ) | [static] |
| static int ast_makesocket | ( | void | ) | [static] |
Definition at line 1050 of file asterisk.c.
References AF_LOCAL, ast_log(), AST_MAX_CONNECTS, ast_pthread_create_background, ast_register_verbose(), ast_strlen_zero(), consoles, errno, group, listener(), LOG_WARNING, network_verboser(), and PF_LOCAL.
Referenced by main().
01051 { 01052 struct sockaddr_un sunaddr; 01053 int res; 01054 int x; 01055 uid_t uid = -1; 01056 gid_t gid = -1; 01057 01058 for (x = 0; x < AST_MAX_CONNECTS; x++) 01059 consoles[x].fd = -1; 01060 unlink(ast_config_AST_SOCKET); 01061 ast_socket = socket(PF_LOCAL, SOCK_STREAM, 0); 01062 if (ast_socket < 0) { 01063 ast_log(LOG_WARNING, "Unable to create control socket: %s\n", strerror(errno)); 01064 return -1; 01065 } 01066 memset(&sunaddr, 0, sizeof(sunaddr)); 01067 sunaddr.sun_family = AF_LOCAL; 01068 ast_copy_string(sunaddr.sun_path, ast_config_AST_SOCKET, sizeof(sunaddr.sun_path)); 01069 res = bind(ast_socket, (struct sockaddr *)&sunaddr, sizeof(sunaddr)); 01070 if (res) { 01071 ast_log(LOG_WARNING, "Unable to bind socket to %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01072 close(ast_socket); 01073 ast_socket = -1; 01074 return -1; 01075 } 01076 res = listen(ast_socket, 2); 01077 if (res < 0) { 01078 ast_log(LOG_WARNING, "Unable to listen on socket %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01079 close(ast_socket); 01080 ast_socket = -1; 01081 return -1; 01082 } 01083 ast_register_verbose(network_verboser); 01084 ast_pthread_create_background(<hread, NULL, listener, NULL); 01085 01086 if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) { 01087 struct passwd *pw; 01088 if ((pw = getpwnam(ast_config_AST_CTL_OWNER)) == NULL) { 01089 ast_log(LOG_WARNING, "Unable to find uid of user %s\n", ast_config_AST_CTL_OWNER); 01090 } else { 01091 uid = pw->pw_uid; 01092 } 01093 } 01094 01095 if (!ast_strlen_zero(ast_config_AST_CTL_GROUP)) { 01096 struct group *grp; 01097 if ((grp = getgrnam(ast_config_AST_CTL_GROUP)) == NULL) { 01098 ast_log(LOG_WARNING, "Unable to find gid of group %s\n", ast_config_AST_CTL_GROUP); 01099 } else { 01100 gid = grp->gr_gid; 01101 } 01102 } 01103 01104 if (chown(ast_config_AST_SOCKET, uid, gid) < 0) 01105 ast_log(LOG_WARNING, "Unable to change ownership of %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01106 01107 if (!ast_strlen_zero(ast_config_AST_CTL_PERMISSIONS)) { 01108 int p1; 01109 mode_t p; 01110 sscanf(ast_config_AST_CTL_PERMISSIONS, "%o", &p1); 01111 p = p1; 01112 if ((chmod(ast_config_AST_SOCKET, p)) < 0) 01113 ast_log(LOG_WARNING, "Unable to change file permissions of %s: %s\n", ast_config_AST_SOCKET, strerror(errno)); 01114 } 01115 01116 return 0; 01117 }
| int64_t ast_mark | ( | int | i, | |
| int | startstop | |||
| ) |
Definition at line 445 of file asterisk.c.
References profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, prof_data, rdtsc(), profile_entry::scale, and