154#undef sched_setscheduler
163#include <sys/resource.h>
167#if defined(HAVE_SYSINFO)
168#include <sys/sysinfo.h>
169#elif defined(HAVE_SYSCTL)
170#include <sys/param.h>
171#include <sys/sysctl.h>
172#include <sys/vmmeter.h>
173#if defined(__FreeBSD__) || defined(__DragonFly__)
174#include <vm/vm_param.h>
176#if defined(HAVE_SWAPCTL)
185#include <sys/loadavg.h>
189#include <sys/prctl.h>
191#include <sys/capability.h>
247#include "../defaults.h"
292#define AF_LOCAL AF_UNIX
293#define PF_LOCAL PF_UNIX
296#define AST_MAX_CONNECTS 128
300#define COPYRIGHT_TAG "Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others."
303#define WELCOME_MESSAGE \
304 ast_verbose("Asterisk %s, " COPYRIGHT_TAG "\n" \
305 "Created by Mark Spencer <markster@digium.com>\n" \
306 "Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.\n" \
307 "This is free software, with components licensed under the GNU General Public\n" \
308 "License version 2 and other licenses; you are welcome to redistribute it under\n" \
309 "certain conditions. Type 'core show license' for details.\n" \
310 "=========================================================================\n", ast_get_version()) \
352static void asterisk_daemon(
int isroot,
const char *runuser,
const char *rungroup);
393static cap_t child_cap;
404#if !defined(LOW_MEMORY)
422 new->id = pthread_self();
436 if ((
void *) x->id ==
id) {
454 if (!(f = fopen(filename,
"r"))) {
458 while ((
c = fgetc(f)) != EOF) {
474#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
480 e->
command =
"core show settings";
481 e->
usage =
"Usage: core show settings\n"
482 " Show core misc settings";
491 ast_cli(
a->fd,
"\nPBX Core settings\n");
492 ast_cli(
a->fd,
"-----------------\n");
499 ast_cli(
a->fd,
" Maximum calls: Not set\n");
501 if (getrlimit(RLIMIT_NOFILE, &
limits)) {
502 ast_cli(
a->fd,
" Maximum open file handles: Error because of %s\n", strerror(
errno));
503 }
else if (
limits.rlim_cur == RLIM_INFINITY) {
504 ast_cli(
a->fd,
" Maximum open file handles: Unlimited\n");
508 ast_cli(
a->fd,
" Maximum open file handles: %d\n", (
int)
limits.rlim_cur);
516 print_file(
a->fd,
" Core dump file: ",
"/proc/sys/kernel/core_pattern");
518#if defined(HAVE_SYSINFO)
531 ast_cli(
a->fd,
" Entity ID: %s\n", eid_str);
532 ast_cli(
a->fd,
" PBX UUID: %s\n", pbx_uuid);
536#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
537#if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS)
538#define eaccess euidaccess
540 if (!getcwd(dir,
sizeof(dir))) {
541 if (eaccess(dir, R_OK | X_OK | F_OK)) {
542 ast_cli(
a->fd,
" Running directory: %s\n",
"Unable to access");
544 ast_cli(
a->fd,
" Running directory: %s (%s)\n", dir,
"Unable to access");
547 ast_cli(
a->fd,
" Running directory: %s\n", dir);
558#if !defined(LOW_MEMORY)
564 ast_cli(
a->fd,
" RTP dynamic payload types: %u,%u-%u\n",
568 ast_cli(
a->fd,
" RTP dynamic payload types: %u-%u,%u-%u\n",
572 ast_cli(
a->fd,
" RTP dynamic payload types: %u-%u\n",
585 ast_cli(
a->fd,
"\n* Directories\n");
610 e->
command =
"core show threads";
612 "Usage: core show threads\n"
613 " List threads currently active in the system.\n";
621 ast_cli(
a->fd,
"%p %d %s\n", (
void *)cur->id, cur->lwp, cur->name);
625 ast_cli(
a->fd,
"%d threads listed.\n", count);
629#if defined (HAVE_SYSCTL) && defined(HAVE_SWAPCTL)
634static int swapmode(
int *used,
int *
total)
636 struct swapent *swdev;
637 int nswap, rnswap, i;
639 nswap = swapctl(SWAP_NSWAP, 0, 0);
647 rnswap = swapctl(SWAP_STATS, swdev, nswap);
657 for (i = 0; i < nswap; i++) {
658 if (swdev[i].se_flags & SWF_ENABLE) {
659 *used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
660 *
total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
668#if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL)
672 uint64_t physmem, freeram;
673#if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL)
675 uint64_t freeswap = 0;
679#if defined(HAVE_SYSINFO)
680 struct sysinfo sys_info;
681#elif defined(HAVE_SYSCTL)
682 static int pageshift;
683 struct vmtotal vmtotal;
684 struct timeval boottime;
686 int mib[2], pagesize;
687#if defined(HAVE_SWAPCTL)
695 e->
command =
"core show sysinfo";
697 "Usage: core show sysinfo\n"
698 " List current system information.\n";
704#if defined(HAVE_SYSINFO)
706 uptime = sys_info.uptime / 3600;
707 physmem = sys_info.totalram * sys_info.mem_unit;
708 freeram = (sys_info.freeram * sys_info.mem_unit) / 1024;
709 totalswap = (sys_info.totalswap * sys_info.mem_unit) / 1024;
710 freeswap = (sys_info.freeswap * sys_info.mem_unit) / 1024;
711 nprocs = sys_info.procs;
712#elif defined(HAVE_SYSCTL)
716 mib[1] = KERN_BOOTTIME;
717 len =
sizeof(boottime);
718 if (sysctl(mib, 2, &boottime, &
len,
NULL, 0) != -1) {
719 uptime = now - boottime.tv_sec;
721 uptime = uptime/3600;
724#if defined(HW_PHYSMEM64)
725 mib[1] = HW_PHYSMEM64;
729 len =
sizeof(physmem);
730 sysctl(mib, 2, &physmem, &
len,
NULL, 0);
732 pagesize = getpagesize();
734 while (pagesize > 1) {
745 len =
sizeof(vmtotal);
746 sysctl(mib, 2, &vmtotal, &
len,
NULL, 0);
747 freeram = (vmtotal.t_free << pageshift);
749#if defined(HAVE_SWAPCTL)
750 swapmode(&usedswap, &totalswap);
751 freeswap = (totalswap - usedswap);
754#if defined(__OpenBSD__)
756 mib[1] = KERN_NPROCS;
757 len =
sizeof(nprocs);
758 sysctl(mib, 2, &nprocs, &
len,
NULL, 0);
762 ast_cli(
a->fd,
"\nSystem Statistics\n");
763 ast_cli(
a->fd,
"-----------------\n");
764 ast_cli(
a->fd,
" System Uptime: %ld hours\n", uptime);
765 ast_cli(
a->fd,
" Total RAM: %" PRIu64
" KiB\n", physmem / 1024);
766 ast_cli(
a->fd,
" Free RAM: %" PRIu64
" KiB\n", freeram);
767#if defined(HAVE_SYSINFO)
768 ast_cli(
a->fd,
" Buffer RAM: %" PRIu64
" KiB\n", ((uint64_t) sys_info.bufferram * sys_info.mem_unit) / 1024);
770#if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL)
771 ast_cli(
a->fd,
" Total Swap Space: %d KiB\n", totalswap);
772 ast_cli(
a->fd,
" Free Swap Space: %" PRIu64
" KiB\n\n", freeswap);
774 ast_cli(
a->fd,
" Number of Processes: %d \n\n", nprocs);
801#if !defined(LOW_MEMORY)
835#if !defined(LOW_MEMORY)
848#if !defined(LOW_MEMORY)
852#if defined ( __i686__) && (defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux))
853#if defined(__FreeBSD__)
854#include <machine/cpufunc.h>
855#elif defined(__NetBSD__) || defined(linux)
856static __inline uint64_t
861 __asm __volatile(
".byte 0x0f, 0x31" :
"=A" (rv));
866static __inline uint64_t
876#if !defined(LOW_MEMORY)
894#if !defined(LOW_MEMORY)
895#define DEFINE_PROFILE_MIN_MAX_VALUES min = 0; \
896 max = prof_data->entries;\
898 if (isdigit(a->argv[3][0])) { \
899 min = atoi(a->argv[3]); \
900 if (a->argc == 5 && strcmp(a->argv[4], "-")) \
901 max = atoi(a->argv[4]); \
903 search = a->argv[3]; \
905 if (max > prof_data->entries) \
906 max = prof_data->entries;
911 const char *search =
NULL;
914 e->command =
"core show profile";
915 e->usage =
"Usage: core show profile\n"
916 " show profile information";
926 ast_cli(
a->fd,
"profile values (%d, allocated %d)\n-------------------\n",
928 ast_cli(
a->fd,
"%6s %8s %10s %12s %12s %s\n",
"ID",
"Scale",
"Events",
929 "Value",
"Average",
"Name");
930 for (i =
min; i <
max; i++) {
932 if (!search || strstr(
entry->name, search))
933 ast_cli(
a->fd,
"%6d: [%8ld] %10ld %12lld %12lld %s\n",
946 const char *search =
NULL;
949 e->
command =
"core clear profile";
950 e->
usage =
"Usage: core clear profile\n"
951 " clear profile information";
961 for (i=
min; i <
max; i++) {
969#undef DEFINE_PROFILE_MIN_MAX_VALUES
975 return ast_db_get(
"pbx",
"UUID", pbx_uuid, length);
982 int lastreloaded = 0;
988 uptime = (int)
tmp.tv_sec;
993 lastreloaded = (int)
tmp.tv_sec;
997 "Status",
"Fully Booted",
999 "LastReload", lastreloaded);
1071 return write(fd, s, strlen(s) + 1);
1077 return write(fd, s, strlen(s));
1087 .sa_flags = SA_RESTART,
1091 .sa_handler = SIG_IGN,
1136#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
1139#ifdef HAVE_WORKING_FORK
1147 cap_set_proc(child_cap);
1149#ifdef HAVE_WORKING_FORK
1157#ifdef HAVE_WORKING_FORK
1197#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
1202 res = waitpid(pid, &
status, 0);
1207 if (
errno != EINTR) {
1237 execl(
"/bin/sh",
"/bin/sh",
"-c", s, (
char *)
NULL);
1279 ast_cli(fd,
"Console is not muted anymore.\n");
1283 ast_cli(fd,
"Console is muted.\n");
1288 ast_cli(fd,
"Couldn't find remote console.\n");
1356 fputs(
string, stdout);
1377#if defined(SO_PEERCRED)
1378#ifdef HAVE_STRUCT_SOCKPEERCRED_UID
1379#define HAVE_STRUCT_UCRED_UID
1380 struct sockpeercred cred;
1384 socklen_t
len =
sizeof(cred);
1386#if defined(HAVE_GETPEEREID)
1394 result = read(fd, buffer, size);
1399#if defined(SO_PEERCRED) && (defined(HAVE_STRUCT_UCRED_UID) || defined(HAVE_STRUCT_UCRED_CR_UID))
1400 if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &
len)) {
1403#if defined(HAVE_STRUCT_UCRED_UID)
1411#elif defined(HAVE_GETPEEREID)
1412 if (getpeereid(fd, &uid, &gid)) {
1427 struct console *con = vconsole;
1431 const char *
const end_buf =
inbuf +
sizeof(
inbuf);
1432 char *start_read =
inbuf;
1434 struct pollfd fds[2];
1442 fds[0].fd = con->
fd;
1443 fds[0].events = POLLIN;
1445 fds[1].fd = con->
p[0];
1446 fds[1].events = POLLIN;
1455 if (fds[0].revents) {
1456 int cmds_read, bytes_read;
1457 if ((bytes_read =
read_credentials(con->
fd, start_read, end_buf - start_read, con)) < 1) {
1461 if (strncmp(
inbuf,
"cli quit after ", 15) == 0) {
1470 if (start_read + bytes_read < end_buf) {
1471 start_read += bytes_read;
1478 if (start_read[bytes_read - 1] ==
'\0') {
1486 while (cmds_read-- && (start_read = strchr(start_read,
'\0'))) {
1489 memmove(
inbuf, start_read, end_buf - start_read);
1490 start_read = end_buf - start_read +
inbuf;
1492 if (fds[1].revents) {
1498 res = write(con->
fd, outbuf, res);
1505 ast_verb(3,
"Remote UNIX connection disconnected\n");
1517 struct sockaddr_un sunaddr;
1522 struct pollfd fds[1];
1529 fds[0].events = POLLIN;
1530 poll_result =
ast_poll(fds, 1, -1);
1531 pthread_testcancel();
1532 if (poll_result < 0) {
1533 if (
errno != EINTR) {
1538 len =
sizeof(sunaddr);
1544#if defined(SO_PASSCRED)
1547 if (setsockopt(s, SOL_SOCKET, SO_PASSCRED, &sckopt,
sizeof(sckopt)) < 0) {
1559 fdprint(s,
"Server failed to create pipe\n");
1577 fdprint(s,
"Server failed to spawn thread\n");
1583 fdprint(s,
"No more connections allowed\n");
1587 ast_verb(3,
"Remote UNIX connection\n");
1597 struct sockaddr_un sunaddr;
1619 memset(&sunaddr, 0,
sizeof(sunaddr));
1622 res = bind(
ast_socket, (
struct sockaddr *)&sunaddr,
sizeof(sunaddr));
1683 struct sockaddr_un sunaddr;
1687 fprintf(stderr,
"Unable to create socket: %s\n", strerror(
errno));
1690 memset(&sunaddr, 0,
sizeof(sunaddr));
1693 res = connect(
ast_consock, (
struct sockaddr *)&sunaddr,
sizeof(sunaddr));
1719 int save_errno =
errno;
1728 printf(
"Received HUP signal -- Reloading configs\n");
1731 fprintf(stderr,
"hup_handler: write() failed: %s\n", strerror(
errno));
1738 .sa_flags = SA_RESTART,
1749 for (n = 0; waitpid(-1, &
status, WNOHANG) > 0; n++)
1752 printf(
"Huh? Child handler, but nobody there?\n");
1758 .sa_flags = SA_RESTART,
1764 if (getenv(
"TERM") && strstr(getenv(
"TERM"),
"xterm"))
1765 fprintf(stdout,
"\033]2;%s\007",
text);
1770 if (getenv(
"TERM") && strstr(getenv(
"TERM"),
"xterm"))
1771 fprintf(stdout,
"\033]1;%s\007",
text);
1782 return sched_getscheduler(0);
1790 return (getpriority(PRIO_PROCESS, 0) < 0);
1797#if !defined(__linux__)
1800#elif defined(LOW_MEMORY)
1805 struct sched_param
sched;
1806 char const *policy_str;
1812 policy_str =
"realtime";
1813 sched.sched_priority = 10;
1815 policy = SCHED_OTHER;
1816 policy_str =
"regular";
1817 sched.sched_priority = 0;
1820 ast_log(
LOG_WARNING,
"Unable to set %s thread priority on main thread\n", policy_str);
1823 ast_verb(1,
"Setting %s thread priority on all threads\n", policy_str);
1840 struct sched_param
sched;
1844 sched.sched_priority = 10;
1849 sched.sched_priority = 0;
1859 ast_verb(1,
"Set to high priority\n");
1880 int shutdown_aborted = 0;
1886 shutdown_aborted = 1;
1889 return shutdown_aborted;
1917#define SHUTDOWN_TIMEOUT 15
1948 if (seconds < (now - start)) {
1969 ast_verbose(
"Ignoring asterisk %s request, already in progress.\n", restart ?
"restart" :
"shutdown");
1992 ast_verb(0,
"Beginning asterisk %s....\n", restart ?
"restart" :
"shutdown");
2001 ast_verb(0,
"Waiting for inactivity to perform %s...\n", restart ?
"restart" :
"halt");
2012 ast_verb(0,
"Asterisk %s cancelled.\n", restart ?
"restart" :
"shutdown");
2045 int active_channels;
2050 ast_verb(0,
"Some modules could not be unloaded, switching to fast shutdown\n");
2067 }
else if (!restart) {
2078 "Shutdown", active_channels ?
"Uncleanly" :
"Cleanly",
2079 "Restart", restart ?
"True" :
"False");
2084 ast_verb(0,
"Asterisk %s ending (%d).\n",
2085 active_channels ?
"uncleanly" :
"cleanly", num);
2087 ast_verb(0,
"Executing last minute cleanups\n");
2090 ast_debug(1,
"Asterisk ending (%d).\n", num);
2098 pthread_kill(
lthread, SIGURG);
2109 ast_verb(0,
"Preparing for Asterisk restart...\n");
2111 for (i = 3; i < 32768; i++) {
2112 fcntl(i, F_SETFD, FD_CLOEXEC);
2114 ast_verb(0,
"Asterisk is now restarting...\n");
2143 fprintf(stderr,
"quit_handler: write() failed: %s\n", strerror(
errno));
2191 snprintf(outbuf, maxout,
"%s%s%s%s%s%s",
2207 state->verbose_line_level = 0;
2221 unsigned int newline;
2240 if ((s = strchr(
c,
'\n'))) {
2244 s = strchr(
c,
'\0');
2260 if (fwrite(
c,
sizeof(
char), num, stdout) < num) {
2274 state->verbose_line_level = 0;
2321 while (isspace(*s)) {
2332 }
else if ((strncasecmp(s,
"quit", 4) == 0 || strncasecmp(s,
"exit", 4) == 0) &&
2333 (s[4] ==
'\0' || isspace(s[4]))) {
2345 e->
command =
"core show version";
2347 "Usage: core show version\n"
2348 " Shows Asterisk version information.\n";
2356 ast_cli(
a->fd,
"Asterisk %s built by %s @ %s on a %s running %s on %s\n",
2368 "Usage: core stop now\n"
2369 " Shuts down a running Asterisk immediately, hanging up all active calls .\n";
2376 if (
a->argc != e->
args)
2386 e->
command =
"core stop gracefully";
2388 "Usage: core stop gracefully\n"
2389 " Causes Asterisk to not accept new calls, and exit when all\n"
2390 " active calls have terminated normally.\n";
2397 if (
a->argc != e->
args)
2407 e->
command =
"core stop when convenient";
2409 "Usage: core stop when convenient\n"
2410 " Causes Asterisk to perform a shutdown when all active calls have ended.\n";
2417 if (
a->argc != e->
args)
2419 ast_cli(
a->fd,
"Waiting for inactivity to perform halt\n");
2428 e->
command =
"core restart now";
2430 "Usage: core restart now\n"
2431 " Causes Asterisk to hangup all calls and exec() itself performing a cold\n"
2439 if (
a->argc != e->
args)
2449 e->
command =
"core restart gracefully";
2451 "Usage: core restart gracefully\n"
2452 " Causes Asterisk to stop accepting new calls and exec() itself performing a cold\n"
2453 " restart when all active calls have ended.\n";
2460 if (
a->argc != e->
args)
2470 e->
command =
"core restart when convenient";
2472 "Usage: core restart when convenient\n"
2473 " Causes Asterisk to perform a cold restart when all active calls have ended.\n";
2480 if (
a->argc != e->
args)
2482 ast_cli(
a->fd,
"Waiting for inactivity to perform restart\n");
2491 e->
command =
"core abort shutdown";
2493 "Usage: core abort shutdown\n"
2494 " Causes Asterisk to abort an executing shutdown or restart, and resume normal\n"
2495 " call operations.\n";
2502 if (
a->argc != e->
args)
2516 "Usage: !<command>\n"
2517 " Executes a given shell command\n";
2529 "BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
2530 "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"
2531 "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
2532 "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
2533 "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
2534 "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"
2535 "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"
2536 "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
2537 "REPAIR OR CORRECTION.\n"
2539 "IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
2540 "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
2541 "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
2542 "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
2543 "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
2544 "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
2545 "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
2546 "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
2547 "POSSIBILITY OF SUCH DAMAGES.\n"
2554 e->
command =
"core show warranty";
2556 "Usage: core show warranty\n"
2557 " Shows the warranty (if any) for this copy of Asterisk.\n";
2570 "This program is free software; you can redistribute it and/or modify\n"
2571 "it under the terms of the GNU General Public License version 2 as\n"
2572 "published by the Free Software Foundation.\n"
2574 "This program also contains components licensed under other licenses.\n"
2577 "This program is distributed in the hope that it will be useful,\n"
2578 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
2579 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
2580 "GNU General Public License for more details.\n"
2582 "You should have received a copy of the GNU General Public License\n"
2583 "along with this program; if not, write to the Free Software\n"
2584 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
2591 e->
command =
"core show license";
2593 "Usage: core show license\n"
2594 " Shows the license(s) for this copy of Asterisk.\n";
2605#define ASTERISK_PROMPT "*CLI> "
2630#if !defined(LOW_MEMORY)
2632#if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL)
2665 printf(
"log and verbose output currently muted ('logger mute' to unmute)\n");
2669#ifdef HAVE_LIBEDIT_IS_UNICODE
2670#define CHAR_T_LIBEDIT wchar_t
2671#define CHAR_TO_LIBEDIT(c) btowc(c)
2673#define CHAR_T_LIBEDIT char
2674#define CHAR_TO_LIBEDIT(c) c
2681 struct pollfd fds[2];
2684#define EL_BUF_SIZE 512
2690 fds[0].events = POLLIN;
2692 fds[1].fd = STDIN_FILENO;
2693 fds[1].events = POLLIN;
2701 if (
errno == EINTR) {
2704 fprintf(stderr,
"poll failed: %s\n", strerror(
errno));
2711 num_read = read(STDIN_FILENO, &
c, 1);
2721 if (fds[0].revents) {
2725 fprintf(stderr,
"\nDisconnected from Asterisk server\n");
2730 int reconnects_per_second = 20;
2732 fprintf(stderr,
"Attempting to reconnect for 30 seconds\n");
2733 for (tries = 0; tries < 30 * reconnects_per_second; tries++) {
2735 fprintf(stderr,
"Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries);
2742 usleep(1000000 / reconnects_per_second);
2744 if (tries >= 30 * reconnects_per_second) {
2745 fprintf(stderr,
"Failed to reconnect for 30 seconds. Quitting.\n");
2756 if (write(STDOUT_FILENO,
"\r␛[0K", 5) < 0) {
2762 if ((res <
EL_BUF_SIZE - 1) && ((
buf[res-1] ==
'\n') || (res >= 2 &&
buf[res-2] ==
'\n'))) {
2783 static int cli_prompt_changes = 0;
2789 }
else if (!cli_prompt_changes) {
2795 if ((pfmt = getenv(
"ASTERISK_PROMPT"))) {
2798 while (*t !=
'\0') {
2802 struct ast_tm tm = { 0, };
2809 if (sscanf(t,
"%30d;%30d%n", &fgcolor, &bgcolor, &i) == 2) {
2812 }
else if (sscanf(t,
"%30d%n", &fgcolor, &i) == 1) {
2824 cli_prompt_changes++;
2828 if ((gr = getgrgid(getgid()))) {
2842 if ((dotptr = strchr(
hostname,
'.'))) {
2850#ifdef HAVE_GETLOADAVG
2853 if (sscanf(t,
"%30d", &which) == 1 && which > 0 && which <= 3) {
2857 cli_prompt_changes++;
2868 cli_prompt_changes++;
2872 if ((pw = getpwuid(getuid()))) {
2921 goto vector_cleanup;
2926 goto vector_cleanup;
2951 for (numoutputline = 0; numoutputline < limit && idx <
AST_VECTOR_SIZE(matches); idx++) {
2956 if (!numoutputline) {
2960 fprintf(stdout,
"\n");
2974 LineInfo *lf = (LineInfo *)el_line(editline);
2976 savechr = *(
char *)lf->cursor;
2977 *(
char *)lf->cursor =
'\0';
2978 ptr = (
char *)lf->cursor;
2980 while (ptr > lf->buffer) {
2981 if (isspace(*ptr)) {
2989 len = lf->cursor - ptr;
2992#define CMD_MATCHESARRAY "_COMMAND MATCHESARRAY \"%s\" \"%s\""
2998 if (maxmbuf == -1) {
2999 *((
char *) lf->cursor) = savechr;
3001 return (
char *)(CC_ERROR);
3010 if (mlen + 1024 > maxmbuf) {
3012 maxmbuf = mlen + 1024;
3016 *((
char *) lf->cursor) = savechr;
3018 return (
char *)(CC_ERROR);
3025 if (!strncmp(mbuf,
"Usage:", 6)) {
3056 int maxlen, match_len;
3060 el_deletestr(editline, (
int)
len);
3061 el_insertstr(editline, best_match);
3067 el_insertstr(editline,
" ");
3073 if (match_len > maxlen) {
3078 fprintf(stdout,
"\n");
3086 *((
char *) lf->cursor) = savechr;
3088 return (
char *)(long)
retval;
3094 char *editor, *editrc = getenv(
"EDITRC");
3096 if (!(editor = getenv(
"AST_EDITMODE"))) {
3097 if (!(editor = getenv(
"AST_EDITOR"))) {
3107 el = el_init(
"asterisk", stdin, stdout, stderr);
3110 el_set(
el, EL_EDITMODE, 1);
3111 el_set(
el, EL_EDITOR, editor);
3117 history(
el_hist, &ev, H_SETSIZE, 100);
3121 el_set(
el, EL_ADDFN,
"ed-complete",
"Complete argument",
cli_complete);
3123 el_set(
el, EL_BIND,
"^I",
"ed-complete",
NULL);
3125 el_set(
el, EL_BIND,
"?",
"ed-complete",
NULL);
3127 el_set(
el, EL_BIND,
"^D",
"ed-redisplay",
NULL);
3129 el_set(
el, EL_BIND,
"\\e[3~",
"ed-delete-next-char",
NULL);
3131 el_set(
el, EL_BIND,
"\\e[1~",
"ed-move-to-beg",
NULL);
3132 el_set(
el, EL_BIND,
"\\e[4~",
"ed-move-to-end",
NULL);
3134 el_set(
el, EL_BIND,
"\\eOC",
"vi-next-word",
NULL);
3135 el_set(
el, EL_BIND,
"\\eOD",
"vi-prev-word",
NULL);
3138 el_source(
el, editrc);
3144#define MAX_HISTORY_COMMAND_LENGTH 256
3161 if (!history(
el_hist, &ev, H_FIRST) && strcmp(ev.str, stripped_buf) == 0) {
3165 return history(
el_hist, &ev, H_ENTER, stripped_buf);
3175 return (history(
el_hist, &ev, H_SAVE, filename));
3186 if (access(filename, F_OK) == 0) {
3187 return history(
el_hist, &ev, H_LOAD, filename);
3196 struct passwd *pw = getpwuid(geteuid());
3201 ast_log(
LOG_ERROR,
"Unable to determine home directory. History read/write disabled.\n");
3207 ast_log(
LOG_ERROR,
"Unable to create history file name. History read/write disabled.\n");
3211 ret = readwrite(
name);
3239 char *stringp =
NULL;
3258 char prefix[] =
"cli quit after ";
3270 cpid =
strsep(&stringp,
"/");
3273 version =
"<Version Unknown>";
3285 int linefull = 1, prev_linefull = 1, prev_line_verbose = 0;
3288 fds.events = POLLIN;
3291 while (
ast_poll(&fds, 1, 60000) > 0) {
3292 char buffer[512] =
"", *curline = buffer, *nextline;
3293 int not_written = 1;
3299 if (read(
ast_consock, buffer,
sizeof(buffer) - 1) <= 0) {
3304 prev_linefull = linefull;
3305 if ((nextline = strchr(curline,
'\n'))) {
3310 nextline = strchr(curline,
'\0');
3324 if ((!prev_linefull && !prev_line_verbose) || (prev_linefull && *curline > 0)) {
3325 prev_line_verbose = 0;
3327 if (write(STDOUT_FILENO, curline, nextline - curline) < 0) {
3331 prev_line_verbose = 1;
3355 ebuf = (
char *)el_gets(
el, &num);
3361 if (!ebuf && write(1,
"", 1) < 0)
3365 if (ebuf[strlen(ebuf)-1] ==
'\n')
3366 ebuf[strlen(ebuf)-1] =
'\0';
3376 printf(
"\nDisconnected from Asterisk server\n");
3388 printf(
"Usage: asterisk [OPTIONS]\n");
3389 printf(
"Valid Options:\n");
3390 printf(
" -V Display version number and exit\n");
3391 printf(
" -C <configfile> Use an alternate configuration file\n");
3392 printf(
" -G <group> Run as a group other than the caller\n");
3393 printf(
" -U <user> Run as a user other than the caller\n");
3394 printf(
" -c Provide console CLI\n");
3395 printf(
" -d Increase debugging (multiple d's = more debugging)\n");
3396#if HAVE_WORKING_FORK
3397 printf(
" -f Do not fork\n");
3398 printf(
" -F Always fork\n");
3400 printf(
" -g Dump core in case of a crash\n");
3401 printf(
" -h This help screen\n");
3402 printf(
" -i Initialize crypto keys at startup\n");
3403 printf(
" -L <load> Limit the maximum load average before rejecting new calls\n");
3404 printf(
" -M <value> Limit the maximum number of calls to the specified value\n");
3405 printf(
" -m Mute debugging and console output on the console\n");
3406 printf(
" -n Disable console colorization. Can be used only at startup.\n");
3407 printf(
" -p Run as pseudo-realtime thread\n");
3408 printf(
" -q Quiet mode (suppress output)\n");
3409 printf(
" -r Connect to Asterisk on this machine\n");
3410 printf(
" -R Same as -r, except attempt to reconnect if disconnected\n");
3411 printf(
" -s <socket> Connect to Asterisk via socket <socket> (only valid with -r)\n");
3412 printf(
" -t Record soundfiles in /var/tmp and move them where they\n");
3413 printf(
" belong after they are done\n");
3414 printf(
" -T Display the time in [Mmm dd hh:mm:ss] format for each line\n");
3415 printf(
" of output to the CLI. Cannot be used with remote console mode.\n\n");
3416 printf(
" -v Increase verbosity (multiple v's = more verbose)\n");
3417 printf(
" -x <cmd> Execute command <cmd> (implies -r)\n");
3418 printf(
" -X Enable use of #exec in asterisk.conf\n");
3419 printf(
" -W Adjust terminal colors to compensate for a light background\n");
3442 if (!strcasecmp(v->
name,
"log_level")) {
3450 }
else if (!strcasecmp(v->
name,
"cache_pools")) {
3485 struct stat canary_stat;
3493 if (stat(
canary_filename, &canary_stat) || now.tv_sec > canary_stat.st_mtime + 60) {
3495 "The canary is no more. He has ceased to be! "
3496 "He's expired and gone to meet his maker! "
3497 "He's a stiff! Bereft of life, he rests in peace. "
3498 "His metabolic processes are now history! He's off the twig! "
3499 "He's kicked the bucket. He's shuffled off his mortal coil, "
3500 "run down the curtain, and joined the bleeding choir invisible!! "
3501 "THIS is an EX-CANARY. (Reducing priority)\n");
3535 fd = open(
"/dev/null", O_RDWR);
3570 ast_verbose(
"Running under group '%s'\n", rungroup);
3584 int isroot = 1, rundir_exists = 0;
3589 static const char *getopt_settings =
"BC:cde:FfG:ghIiL:M:mnpqRrs:TtU:VvWXx:";
3593 fprintf(stderr,
"Truncating argument size to %d\n", (
int)
ARRAY_LEN(
_argv) - 1);
3596 for (x = 0; x < argc; x++)
3604 if (argv[0] && (strstr(argv[0],
"rasterisk")) !=
NULL) {
3610 while ((
c = getopt(argc, argv, getopt_settings)) != -1) {
3655 while ((
c = getopt(argc, argv, getopt_settings)) != -1) {
3676#if defined(HAVE_SYSINFO)
3683#if HAVE_WORKING_FORK
3702 "NOTICE: The -I option is no longer needed.\n"
3703 " It will always be enabled if you have a timing module loaded.\n");
3776 while ((
c = getopt(argc, argv, getopt_settings)) != -1) {
3813 fprintf(stderr,
"'%c' option is not compatible with remote console mode and has no effect.\n",
c);
3818 fprintf(stderr,
"\n");
3826 strcpy(argv[0],
"rasterisk");
3827 for (x = 1; x < argc; x++) {
3828 argv[x] = argv[0] + 10;
3833 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 fprintf(stderr,
"'alwaysfork' is not compatible with console or remote console mode; ignored\n");
3842 memset(&l, 0,
sizeof(l));
3843 l.rlim_cur = RLIM_INFINITY;
3844 l.rlim_max = RLIM_INFINITY;
3845 if (setrlimit(RLIMIT_CORE, &l)) {
3846 fprintf(stderr,
"Unable to disable core size resource limit: %s\n", strerror(
errno));
3850 if (getrlimit(RLIMIT_NOFILE, &l)) {
3851 fprintf(stderr,
"Unable to check file descriptor limit: %s\n", strerror(
errno));
3854#if !defined(CONFIGURE_RAN_AS_ROOT)
3859 struct timeval tv = { 0, };
3861 if (l.rlim_cur <= FD_SETSIZE) {
3867 if (!(fd = open(
"/dev/null", O_RDONLY))) {
3868 fprintf(stderr,
"Cannot open a file descriptor at boot? %s\n", strerror(
errno));
3872 fd2 = ((l.rlim_cur >
sizeof(readers) * 8) ?
sizeof(readers) * 8 : l.rlim_cur) - 1;
3873 if (dup2(fd, fd2) < 0) {
3874 fprintf(stderr,
"Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(
errno));
3882 fprintf(stderr,
"Maximum select()able file descriptor is %d\n", FD_SETSIZE);
3888#elif defined(HAVE_VARIABLE_FDSET)
3905 if (
errno == EEXIST) {
3908 fprintf(stderr,
"Unable to create socket file directory. Remote consoles will not be able to connect! (%s)\n", strerror(x));
3918 if (isroot && rungroup) {
3920 gr = getgrnam(rungroup);
3922 fprintf(stderr,
"No such group '%s'!\n", rungroup);
3926 fprintf(stderr,
"Unable to chgrp run directory to %d (%s)\n", (
int) gr->gr_gid, rungroup);
3928 if (setgid(gr->gr_gid)) {
3929 fprintf(stderr,
"Unable to setgid to %d (%s)\n", (
int)gr->gr_gid, rungroup);
3932 if (setgroups(0,
NULL)) {
3933 fprintf(stderr,
"Unable to drop unneeded groups\n");
3943 pw = getpwnam(runuser);
3945 fprintf(stderr,
"No such user '%s'!\n", runuser);
3949 fprintf(stderr,
"Unable to chown run directory to %d (%s)\n", (
int) pw->pw_uid, runuser);
3952 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
3957 if (!isroot && pw->pw_uid != geteuid()) {
3958 fprintf(stderr,
"Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
3962 if (setgid(pw->pw_gid)) {
3963 fprintf(stderr,
"Unable to setgid to %d!\n", (
int)pw->pw_gid);
3966 if (isroot && initgroups(pw->pw_name, pw->pw_gid)) {
3967 fprintf(stderr,
"Unable to init groups for '%s'\n", runuser);
3971 if (setuid(pw->pw_uid)) {
3972 fprintf(stderr,
"Unable to setuid to %d (%s)\n", (
int)pw->pw_uid, runuser);
3979 cap = cap_from_text(
"cap_net_admin=eip");
3981 if (cap_set_proc(cap)) {
3982 fprintf(stderr,
"Unable to install capabilities.\n");
3984 if (cap_free(cap)) {
3985 fprintf(stderr,
"Unable to drop capabilities.\n");
3995 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
3996 fprintf(stderr,
"Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(
errno));
4002#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
4004 if (!getcwd(dir,
sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) {
4005 fprintf(stderr,
"Unable to access the running directory (%s). Changing to '/' for compatibility.\n", strerror(
errno));
4010 fprintf(stderr,
"chdir(\"/\") failed?!! %s\n", strerror(
errno));
4017 fprintf(stderr,
"Unable to chdir(\"/\") ?!! %s\n", strerror(
errno));
4049 fprintf(stderr,
"Asterisk already running on %s. Use 'asterisk -r' to connect.\n",
ast_config_AST_SOCKET);
4060 child_cap = cap_from_text(
"cap_net_admin-eip");
4065 cap_free(child_cap);
4076 fprintf(stderr,
"%s initialization failed. ASTERISK EXITING!\n%s",
name,
term_quit());
4079 exit(init_result == -2 ? 2 : 1);
4099#if HAVE_WORKING_FORK
4101#ifndef HAVE_SBIN_LAUNCHD
4102 if (daemon(1, 0) < 0) {
4103 fprintf(stderr,
"daemon() failed: %s\n", strerror(
errno));
4108 fprintf(stderr,
"Mac OS X detected. Use 'launchctl load /Library/LaunchDaemon/org.asterisk.asterisk.plist'.\n");
4137 char canary_binary[
PATH_MAX], ppid[12];
4140 signal(SIGCHLD, SIG_DFL);
4141 signal(SIGPIPE, SIG_DFL);
4145 snprintf(ppid,
sizeof(ppid),
"%d", (
int)
ast_mainpid);
4154 pthread_t dont_care;
4205 ast_verb(0,
"PBX UUID: %s\n", pbx_uuid);
4221#ifdef TEST_FRAMEWORK
4240 (void) sigemptyset(&sigs);
4241 (void) sigaddset(&sigs, SIGHUP);
4242 (void) sigaddset(&sigs, SIGTERM);
4243 (void) sigaddset(&sigs, SIGINT);
4244 (void) sigaddset(&sigs, SIGPIPE);
4245 (void) sigaddset(&sigs, SIGWINCH);
4246 pthread_sigmask(SIG_BLOCK, &sigs,
NULL);
4256 srand((
unsigned int) getpid() + (
unsigned int) time(
NULL));
4325 pthread_sigmask(SIG_UNBLOCK, &sigs,
NULL);
4353 snprintf(title,
sizeof(title),
"Asterisk Console on '%s' (pid %ld)",
hostname, (
long)
ast_mainpid);
4369 buf = (
char *) el_gets(
el, &num);
4371 if (!
buf && write(1,
"", 1) < 0)
4375 if (
buf[strlen(
buf)-1] ==
'\n')
4376 buf[strlen(
buf)-1] =
'\0';
Prototypes for public functions only of internal interest,.
int load_pbx_variables(void)
void threadstorage_init(void)
void ast_process_pending_reloads(void)
Process reload requests received during startup.
int modules_shutdown(void)
int ast_bridging_init(void)
Initialize the bridging system.
void dnsmgr_start_refresh(void)
int ast_timing_init(void)
int ast_device_state_engine_init(void)
Initialize the device state engine in separate thread.
void ast_cli_channels_init(void)
void ast_msg_shutdown(void)
void logger_queue_start(void)
Start the ast_queue_log() logger.
void load_asterisk_conf(void)
void ast_stun_init(void)
Initialize the STUN system in Asterisk.
void set_asterisk_conf_path(const char *path)
int load_pbx_functions_cli(void)
void load_astmm_phase_2(void)
Initialize malloc debug phase 2.
int load_pbx_hangup_handler(void)
int ast_local_init(void)
Initialize the local proxy channel.
int load_pbx_builtins(void)
int load_pbx_switch(void)
int ast_rtp_engine_init(void)
initializes the rtp engine arrays
int ast_xmldoc_load_documentation(void)
Load XML documentation. Provided by xmldoc.c.
int ast_named_locks_init(void)
int ast_channels_init(void)
void clean_time_zones(void)
void load_astmm_phase_1(void)
Initialize malloc debug phase 1.
void ast_builtins_init(void)
initialize the _full_cmd string in * each of the builtins.
void ast_autoservice_init(void)
int ast_endpoint_init(void)
Endpoint support initialization.
int ast_dns_system_resolver_init(void)
Initializes the resolver.
int ast_cli_perms_init(int reload)
void set_socket_path(const char *path)
int ast_parking_stasis_init(void)
initializes the rtp engine arrays
Access Control of various sorts.
A-Law to Signed linear conversion.
void ast_alaw_init(void)
To init the alaw to slinear conversion stuff, this needs to be run.
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
ssize_t ast_alertpipe_write(int alert_pipe[2])
Write an event to an alert pipe.
int ast_alertpipe_init(int alert_pipe[2])
Initialize an alert pipe.
ast_alert_status_t ast_alertpipe_read(int alert_pipe[2])
Read an event from an alert pipe.
Generic Advice of Charge encode and decode routines.
int ast_aoc_cli_init(void)
enable aoc cli options
Asterisk version information.
const char * ast_get_build_opts(void)
const char * ast_get_version(void)
Retrieve the Asterisk version string.
const char * ast_get_build_opts_all(void)
Persistent data storage (akin to *doze registry)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
static int ast_el_add_history(const char *)
static char * remotehostname
static char * handle_stop_gracefully(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void __ast_unregister_atexit(void(*func)(void))
static char * cli_complete(EditLine *editline, int ch)
int64_t ast_mark(int i, int startstop)
int main(int argc, char *argv[])
static int ast_socket_is_sd
int ast_shutdown_final(void)
static void canary_exit(void)
static shutdown_nice_t shuttingdown
static void check_init(int init_result, const char *name)
static void __remote_quit_handler(int num)
static void _urg_handler(int num)
Urgent handler.
static char * show_license(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_threads(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void ast_run_atexits(int run_cleanups)
static int console_state_init(void *ptr)
static struct profile_data * prof_data
static char * handle_stop_when_convenient(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int remoteconsolehandler(const char *s)
static struct ast_str * prompt
static void publish_fully_booted(void)
static int show_version(void)
static void main_atexit(void)
static int safe_exec_wait(pid_t pid)
wait for spawned application to complete and unreplace sigchld
int ast_add_profile(const char *name, uint64_t scale)
allocates a counter with a given name and scale.
static void ast_cli_display_match_list(struct ast_vector_string *matches, int max)
static void _hup_handler(int num)
static char * handle_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
static void ast_network_puts_mutable(const char *string, int level, int sublevel)
log the string to all attached network console clients
static char randompool[256]
static char * handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Give an overview of system statistics.
#define WELCOME_MESSAGE
Welcome message when starting a CLI interface.
int ast_safe_execvp(int dualfork, const char *file, char *const argv[])
Safely spawn an external program while closing file descriptors.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
static void set_header(char *outbuf, int maxout, char level)
static int ast_el_read_char(EditLine *editline, CHAR_T_LIBEDIT *cp)
static char * handle_stop_now(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char canary_filename[128]
static __inline uint64_t rdtsc(void)
static struct sigaction child_handler
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...
static void asterisk_daemon(int isroot, const char *runuser, const char *rungroup)
void ast_console_toggle_loglevel(int fd, int level, int state)
enable or disable a logging level to a specified console
static char * handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Give an overview of core settings.
static int has_priority(void)
Check whether we were set to high(er) priority.
void ast_console_toggle_mute(int fd, int silent)
mute or unmute a console from logging
static void send_rasterisk_connect_commands(void)
static struct sigaction safe_system_prev_handler
static char * handle_bang(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct sigaction hup_handler
static pthread_t mon_sig_flags
static int fdprint(int fd, const char *s)
static pthread_t consolethread
static void * netconsole(void *vconsole)
static int ast_el_initialize(void)
static int set_priority_all(int pri)
Set priority on all known threads.
static void ast_begin_shutdown(void)
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 int ast_el_read_history(const char *)
static char * handle_abort_shutdown(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_shutting_down(void)
static void _child_handler(int sig)
void ast_console_puts_mutable(const char *string, int level)
log the string to the root console, and all attached network console clients
int ast_pbx_uuid_get(char *pbx_uuid, int length)
Retrieve the PBX UUID.
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
int ast_cancel_shutdown(void)
Cancel an existing shutdown and return to normal operation.
static void ast_network_puts(const char *string)
write the string to all attached console clients
static int read_credentials(int fd, char *buffer, size_t size, struct console *con)
read() function supporting the reception of user credentials.
#define CHAR_TO_LIBEDIT(c)
static int shutdown_pending
static void _null_sig_handler(int sig)
NULL handler so we can collect the child exit status.
static void process_histfile(int(*readwrite)(const char *filename))
static struct @297 sig_flags
static int sig_alert_pipe[2]
struct timeval ast_lastreloadtime
static const char warranty_lines[]
void ast_console_puts(const char *string)
write the string to the root console, and all attached network console clients
void ast_unregister_atexit(void(*func)(void))
Unregister a function registered with ast_register_atexit().
static int console_print(const char *s)
static void quit_handler(int num, shutdown_nice_t niceness, int restart)
static char * handle_restart_gracefully(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void * monitor_sig_flags(void *unused)
static char * show_warranty(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define MAX_HISTORY_COMMAND_LENGTH
void ast_register_thread(char *name)
static void ast_remotecontrol(char *data)
static int print_file(int fd, char *desc, const char *filename)
Print the contents of a file.
void ast_unregister_thread(void *id)
static void consolehandler(const char *s)
static struct ast_cli_entry cli_asterisk_shutdown[]
Shutdown Asterisk CLI commands.
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
static ast_mutex_t safe_system_lock
static pid_t safe_exec_prep(int dualfork)
fork and perform other preparations for spawning applications
int ast_safe_system(const char *s)
Safely spawn an OS shell command while closing file descriptors.
static int ast_all_zeros(const char *s)
static int can_safely_quit(shutdown_nice_t niceness, int restart)
static char * cli_prompt(EditLine *editline)
static void set_title(char *text)
Set an X-term or screen title.
static int register_atexit(void(*func)(void), int is_cleanup)
static char * handle_clear_profile(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)
static struct ast_threadstorage console_state
static int ast_makesocket(void)
#define DEFINE_PROFILE_MIN_MAX_VALUES
unsigned int need_quit_handler
static int ast_tryconnect(void)
static void * canary_thread(void *unused)
static void * listener(void *unused)
static struct ast_cli_entry cli_asterisk[]
static int fdsend(int fd, const char *s)
static int ast_el_write_history(const char *)
static void run_startup_commands(void)
static int show_cli_help(void)
static void ast_el_read_default_histfile(void)
static char * handle_show_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void env_init(void)
struct timeval ast_startuptime
static void read_pjproject_startup_options(void)
static const char license_lines[]
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
static void really_quit(int num, shutdown_nice_t niceness, int restart)
static void ast_el_write_default_histfile(void)
static int multi_thread_safe
static struct ast_vector_string * ast_el_strtoarr(char *buf)
static void __quit_handler(int num)
void ast_console_puts_mutable_full(const char *message, int level, int sublevel)
log the string to the console, and all attached console clients
static void set_icon(char *text)
static void print_intro_message(const char *runuser, const char *rungroup)
static struct sigaction ignore_sig_handler
static struct sigaction null_sig_handler
struct console consoles[AST_MAX_CONNECTS]
int64_t ast_profile(int i, int64_t delta)
static struct sigaction urg_handler
Asterisk main include file. File version handling, generic pbx functions.
#define sched_setscheduler
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_realloc(p, len)
A wrapper for realloc()
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
void ast_free_ptr(void *ptr)
free() wrapper
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_bucket_init(void)
Initialize bucket support.
const char * ast_build_os
const char * ast_build_machine
const char * ast_build_hostname
const char * ast_build_user
const char * ast_build_date
const char * ast_build_kernel
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
void callerid_init(void)
CallerID Initialization.
int ast_cdr_is_enabled(void)
Return TRUE if CDR subsystem is enabled.
void ast_cdr_engine_term(void)
static char version[AST_MAX_EXTENSION]
General Asterisk PBX channel definitions.
void ast_softhangup_all(void)
Soft hangup all active channels.
int ast_undestroyed_channels(void)
int ast_active_channels(void)
returns number of active/allocated channels
Standard Command Line Interface.