154 #undef sched_setscheduler 156 #include <sys/time.h> 161 #include <sys/wait.h> 163 #include <sys/resource.h> 166 #include <sys/stat.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) 177 #include <sys/swap.h> 181 #include <histedit.h> 184 int daemon(
int,
int);
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 - 2021, Sangoma Technologies Corporation and others." 303 #define WELCOME_MESSAGE \ 304 ast_verbose("Asterisk %s, " COPYRIGHT_TAG "\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()) \ 352 static void asterisk_daemon(
int isroot,
const char *runuser,
const char *rungroup);
404 #if !defined(LOW_MEMORY) 422 new->id = pthread_self();
436 if ((
void *) x->id ==
id) {
455 struct rlimit limits;
460 e->
command =
"core show settings";
461 e->
usage =
"Usage: core show settings\n" 462 " Show core misc settings";
478 ast_cli(a->
fd,
" Maximum calls: Not set\n");
480 if (getrlimit(RLIMIT_NOFILE, &limits)) {
481 ast_cli(a->
fd,
" Maximum open file handles: Error because of %s\n", strerror(
errno));
482 }
else if (limits.rlim_cur == RLIM_INFINITY) {
483 ast_cli(a->
fd,
" Maximum open file handles: Unlimited\n");
487 ast_cli(a->
fd,
" Maximum open file handles: %d\n", (
int) limits.rlim_cur);
495 #if defined(HAVE_SYSINFO) 500 ast_cli(a->
fd,
" Startup time: %s\n", buf);
504 ast_cli(a->
fd,
" Last reload time: %s\n", buf);
508 ast_cli(a->
fd,
" Entity ID: %s\n", eid_str);
509 ast_cli(a->
fd,
" PBX UUID: %s\n", pbx_uuid);
520 #if !defined(LOW_MEMORY) 526 ast_cli(a->
fd,
" RTP dynamic payload types: %u,%u-%u\n",
530 ast_cli(a->
fd,
" RTP dynamic payload types: %u-%u,%u-%u\n",
534 ast_cli(a->
fd,
" RTP dynamic payload types: %u-%u\n",
571 e->
command =
"core show threads";
573 "Usage: core show threads\n" 574 " List threads currently active in the system.\n";
582 ast_cli(a->
fd,
"%p %d %s\n", (
void *)cur->id, cur->lwp, cur->name);
586 ast_cli(a->
fd,
"%d threads listed.\n", count);
590 #if defined (HAVE_SYSCTL) && defined(HAVE_SWAPCTL) 595 static int swapmode(
int *used,
int *
total)
597 struct swapent *swdev;
598 int nswap, rnswap, i;
600 nswap = swapctl(SWAP_NSWAP, 0, 0);
608 rnswap = swapctl(SWAP_STATS, swdev, nswap);
618 for (i = 0; i < nswap; i++) {
619 if (swdev[i].se_flags & SWF_ENABLE) {
620 *used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
621 *total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
629 #if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL) 633 uint64_t physmem, freeram;
634 #if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL) 636 uint64_t freeswap = 0;
640 #if defined(HAVE_SYSINFO) 641 struct sysinfo sys_info;
642 #elif defined(HAVE_SYSCTL) 643 static int pageshift;
644 struct vmtotal vmtotal;
645 struct timeval boottime;
647 int mib[2], pagesize;
648 #if defined(HAVE_SWAPCTL) 656 e->
command =
"core show sysinfo";
658 "Usage: core show sysinfo\n" 659 " List current system information.\n";
665 #if defined(HAVE_SYSINFO) 667 uptime = sys_info.uptime / 3600;
668 physmem = sys_info.totalram * sys_info.mem_unit;
669 freeram = (sys_info.freeram * sys_info.mem_unit) / 1024;
670 totalswap = (sys_info.totalswap * sys_info.mem_unit) / 1024;
671 freeswap = (sys_info.freeswap * sys_info.mem_unit) / 1024;
672 nprocs = sys_info.procs;
673 #elif defined(HAVE_SYSCTL) 677 mib[1] = KERN_BOOTTIME;
678 len =
sizeof(boottime);
679 if (sysctl(mib, 2, &boottime, &len,
NULL, 0) != -1) {
680 uptime = now - boottime.tv_sec;
682 uptime = uptime/3600;
685 #if defined(HW_PHYSMEM64) 686 mib[1] = HW_PHYSMEM64;
690 len =
sizeof(physmem);
691 sysctl(mib, 2, &physmem, &len,
NULL, 0);
693 pagesize = getpagesize();
695 while (pagesize > 1) {
706 len =
sizeof(vmtotal);
707 sysctl(mib, 2, &vmtotal, &len,
NULL, 0);
708 freeram = (vmtotal.t_free << pageshift);
710 #if defined(HAVE_SWAPCTL) 711 swapmode(&usedswap, &totalswap);
712 freeswap = (totalswap - usedswap);
715 #if defined(__OpenBSD__) 717 mib[1] = KERN_NPROCS;
718 len =
sizeof(nprocs);
719 sysctl(mib, 2, &nprocs, &len,
NULL, 0);
725 ast_cli(a->
fd,
" System Uptime: %ld hours\n", uptime);
726 ast_cli(a->
fd,
" Total RAM: %" PRIu64
" KiB\n", physmem / 1024);
727 ast_cli(a->
fd,
" Free RAM: %" PRIu64
" KiB\n", freeram);
728 #if defined(HAVE_SYSINFO) 729 ast_cli(a->
fd,
" Buffer RAM: %" PRIu64
" KiB\n", ((uint64_t) sys_info.bufferram * sys_info.mem_unit) / 1024);
731 #if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL) 732 ast_cli(a->
fd,
" Total Swap Space: %d KiB\n", totalswap);
733 ast_cli(a->
fd,
" Free Swap Space: %" PRIu64
" KiB\n\n", freeswap);
735 ast_cli(a->
fd,
" Number of Processes: %d \n\n", nprocs);
762 #if !defined(LOW_MEMORY) 766 if (prof_data ==
NULL) {
768 if (prof_data ==
NULL)
784 prof_data->
e[n].
value = 0;
786 prof_data->
e[n].
mark = 0;
787 prof_data->
e[n].
scale = scale;
796 #if !defined(LOW_MEMORY) 797 if (!prof_data || i < 0 || i > prof_data->
entries)
799 if (prof_data->
e[i].
scale > 1)
800 delta /= prof_data->
e[i].
scale;
801 prof_data->
e[i].
value += delta;
803 return prof_data->
e[i].
value;
809 #if !defined(LOW_MEMORY) 813 #if defined ( __i686__) && (defined(__FreeBSD__) || defined(linux)) 814 #if defined(__FreeBSD__) 815 #include <machine/cpufunc.h> 817 static __inline uint64_t
822 __asm __volatile(
".byte 0x0f, 0x31" :
"=A" (rv));
827 static __inline uint64_t
837 #if !defined(LOW_MEMORY) 838 if (!prof_data || i < 0 || i > prof_data->
entries)
844 if (prof_data->
e[i].
scale > 1)
849 return prof_data->
e[i].
mark;
855 #if !defined(LOW_MEMORY) 856 #define DEFINE_PROFILE_MIN_MAX_VALUES min = 0; \ 857 max = prof_data->entries;\ 859 if (isdigit(a->argv[3][0])) { \ 860 min = atoi(a->argv[3]); \ 861 if (a->argc == 5 && strcmp(a->argv[4], "-")) \ 862 max = atoi(a->argv[4]); \ 864 search = a->argv[3]; \ 866 if (max > prof_data->entries) \ 867 max = prof_data->entries; 872 const char *search =
NULL;
875 e->
command =
"core show profile";
876 e->
usage =
"Usage: core show profile\n" 877 " show profile information";
883 if (prof_data ==
NULL)
887 ast_cli(a->
fd,
"profile values (%d, allocated %d)\n-------------------\n",
889 ast_cli(a->
fd,
"%6s %8s %10s %12s %12s %s\n",
"ID",
"Scale",
"Events",
890 "Value",
"Average",
"Name");
891 for (i = min; i <
max; i++) {
893 if (!search || strstr(entry->
name, search))
894 ast_cli(a->
fd,
"%6d: [%8ld] %10ld %12lld %12lld %s\n",
907 const char *search =
NULL;
910 e->
command =
"core clear profile";
911 e->
usage =
"Usage: core clear profile\n" 912 " clear profile information";
918 if (prof_data ==
NULL)
922 for (i= min; i <
max; i++) {
923 if (!search || strstr(prof_data->
e[i].
name, search)) {
924 prof_data->
e[i].
value = 0;
930 #undef DEFINE_PROFILE_MIN_MAX_VALUES 936 return ast_db_get(
"pbx",
"UUID", pbx_uuid, length);
943 int lastreloaded = 0;
949 uptime = (int) tmp.tv_sec;
954 lastreloaded = (int) tmp.tv_sec;
958 "Status",
"Fully Booted",
960 "LastReload", lastreloaded);
1032 return write(fd, s, strlen(s) + 1);
1038 return write(fd, s, strlen(s));
1048 .sa_flags = SA_RESTART,
1052 .sa_handler = SIG_IGN,
1067 level = safe_system_level++;
1097 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) 1100 #ifdef HAVE_WORKING_FORK 1110 #ifdef HAVE_WORKING_FORK 1118 #ifdef HAVE_WORKING_FORK 1158 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) 1163 res = waitpid(pid, &status, 0);
1168 if (
errno != EINTR) {
1198 execl(
"/bin/sh",
"/bin/sh",
"-c", s, (
char *)
NULL);
1240 ast_cli(fd,
"Console is not muted anymore.\n");
1244 ast_cli(fd,
"Console is muted.\n");
1249 ast_cli(fd,
"Couldn't find remote console.\n");
1317 fputs(
string, stdout);
1338 #if defined(SO_PEERCRED) 1339 #ifdef HAVE_STRUCT_SOCKPEERCRED_UID 1340 #define HAVE_STRUCT_UCRED_UID 1341 struct sockpeercred cred;
1345 socklen_t
len =
sizeof(cred);
1347 #if defined(HAVE_GETPEEREID) 1355 result = read(fd, buffer, size);
1360 #if defined(SO_PEERCRED) && (defined(HAVE_STRUCT_UCRED_UID) || defined(HAVE_STRUCT_UCRED_CR_UID)) 1361 if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len)) {
1364 #if defined(HAVE_STRUCT_UCRED_UID) 1372 #elif defined(HAVE_GETPEEREID) 1373 if (getpeereid(fd, &uid, &gid)) {
1388 struct console *con = vconsole;
1392 const char *
const end_buf = inbuf +
sizeof(
inbuf);
1393 char *start_read =
inbuf;
1395 struct pollfd fds[2];
1397 if (gethostname(hostname,
sizeof(hostname)-1))
1403 fds[0].fd = con->
fd;
1404 fds[0].events = POLLIN;
1406 fds[1].fd = con->
p[0];
1407 fds[1].events = POLLIN;
1416 if (fds[0].revents) {
1417 int cmds_read, bytes_read;
1418 if ((bytes_read =
read_credentials(con->
fd, start_read, end_buf - start_read, con)) < 1) {
1422 if (strncmp(inbuf,
"cli quit after ", 15) == 0) {
1431 if (start_read + bytes_read < end_buf) {
1432 start_read += bytes_read;
1439 if (start_read[bytes_read - 1] ==
'\0') {
1447 while (cmds_read-- && (start_read = strchr(start_read,
'\0'))) {
1450 memmove(inbuf, start_read, end_buf - start_read);
1451 start_read = end_buf - start_read +
inbuf;
1453 if (fds[1].revents) {
1459 res = write(con->
fd, outbuf, res);
1466 ast_verb(3,
"Remote UNIX connection disconnected\n");
1478 struct sockaddr_un sunaddr;
1483 struct pollfd fds[1];
1490 fds[0].events = POLLIN;
1491 poll_result =
ast_poll(fds, 1, -1);
1492 pthread_testcancel();
1493 if (poll_result < 0) {
1494 if (
errno != EINTR) {
1499 len =
sizeof(sunaddr);
1500 s = accept(
ast_socket, (
struct sockaddr *)&sunaddr, &len);
1505 #if defined(SO_PASSCRED) 1508 if (setsockopt(s, SOL_SOCKET, SO_PASSCRED, &sckopt,
sizeof(sckopt)) < 0) {
1520 fdprint(s,
"Server failed to create pipe\n");
1538 fdprint(s,
"Server failed to spawn thread\n");
1543 if (x >= AST_MAX_CONNECTS) {
1544 fdprint(s,
"No more connections allowed\n");
1548 ast_verb(3,
"Remote UNIX connection\n");
1558 struct sockaddr_un sunaddr;
1580 memset(&sunaddr, 0,
sizeof(sunaddr));
1583 res = bind(
ast_socket, (
struct sockaddr *)&sunaddr,
sizeof(sunaddr));
1644 struct sockaddr_un sunaddr;
1648 fprintf(stderr,
"Unable to create socket: %s\n", strerror(
errno));
1651 memset(&sunaddr, 0,
sizeof(sunaddr));
1654 res = connect(
ast_consock, (
struct sockaddr *)&sunaddr,
sizeof(sunaddr));
1680 int save_errno =
errno;
1689 printf(
"Received HUP signal -- Reloading configs\n");
1692 fprintf(stderr,
"hup_handler: write() failed: %s\n", strerror(
errno));
1699 .sa_flags = SA_RESTART,
1710 for (n = 0; waitpid(-1, &status, WNOHANG) > 0; n++)
1713 printf(
"Huh? Child handler, but nobody there?\n");
1719 .sa_flags = SA_RESTART,
1725 if (getenv(
"TERM") && strstr(getenv(
"TERM"),
"xterm"))
1726 fprintf(stdout,
"\033]2;%s\007", text);
1731 if (getenv(
"TERM") && strstr(getenv(
"TERM"),
"xterm"))
1732 fprintf(stdout,
"\033]1;%s\007", text);
1743 return sched_getscheduler(0);
1751 return (getpriority(PRIO_PROCESS, 0) < 0);
1758 #if !defined(__linux__) 1761 #elif defined(LOW_MEMORY) 1766 struct sched_param sched;
1767 char const *policy_str;
1770 memset(&sched, 0,
sizeof(sched));
1773 policy_str =
"realtime";
1774 sched.sched_priority = 10;
1776 policy = SCHED_OTHER;
1777 policy_str =
"regular";
1778 sched.sched_priority = 0;
1781 ast_log(
LOG_WARNING,
"Unable to set %s thread priority on main thread\n", policy_str);
1784 ast_verb(1,
"Setting %s thread priority on all threads\n", policy_str);
1801 struct sched_param sched;
1802 memset(&sched, 0,
sizeof(sched));
1805 sched.sched_priority = 10;
1810 sched.sched_priority = 0;
1820 ast_verb(1,
"Set to high priority\n");
1841 int shutdown_aborted = 0;
1847 shutdown_aborted = 1;
1850 return shutdown_aborted;
1878 #define SHUTDOWN_TIMEOUT 15 1909 if (seconds < (now - start)) {
1930 ast_verbose(
"Ignoring asterisk %s request, already in progress.\n", restart ?
"restart" :
"shutdown");
1953 ast_verb(0,
"Beginning asterisk %s....\n", restart ?
"restart" :
"shutdown");
1962 ast_verb(0,
"Waiting for inactivity to perform %s...\n", restart ?
"restart" :
"halt");
1973 ast_verb(0,
"Asterisk %s cancelled.\n", restart ?
"restart" :
"shutdown");
2006 int active_channels;
2011 ast_verb(0,
"Some modules could not be unloaded, switching to fast shutdown\n");
2028 }
else if (!restart) {
2039 "Shutdown", active_channels ?
"Uncleanly" :
"Cleanly",
2040 "Restart", restart ?
"True" :
"False");
2045 ast_verb(0,
"Asterisk %s ending (%d).\n",
2046 active_channels ?
"uncleanly" :
"cleanly", num);
2048 ast_verb(0,
"Executing last minute cleanups\n");
2051 ast_debug(1,
"Asterisk ending (%d).\n", num);
2053 pthread_cancel(lthread);
2059 pthread_kill(lthread, SIGURG);
2060 pthread_join(lthread,
NULL);
2070 ast_verb(0,
"Preparing for Asterisk restart...\n");
2072 for (i = 3; i < 32768; i++) {
2073 fcntl(i, F_SETFD, FD_CLOEXEC);
2075 ast_verb(0,
"Asterisk is now restarting...\n");
2104 fprintf(stderr,
"quit_handler: write() failed: %s\n", strerror(
errno));
2140 snprintf(outbuf, maxout,
"%s%s%s%s%s%s",
2170 unsigned int newline;
2189 if ((s = strchr(c,
'\n'))) {
2193 s = strchr(c,
'\0');
2205 fputs(prefix, stdout);
2209 if (fwrite(c,
sizeof(
char), num, stdout) < num) {
2270 while (isspace(*s)) {
2281 }
else if ((strncasecmp(s,
"quit", 4) == 0 || strncasecmp(s,
"exit", 4) == 0) &&
2282 (s[4] ==
'\0' || isspace(s[4]))) {
2294 e->
command =
"core show version";
2296 "Usage: core show version\n" 2297 " Shows Asterisk version information.\n";
2305 ast_cli(a->
fd,
"Asterisk %s built by %s @ %s on a %s running %s on %s\n",
2317 "Usage: core stop now\n" 2318 " Shuts down a running Asterisk immediately, hanging up all active calls .\n";
2335 e->
command =
"core stop gracefully";
2337 "Usage: core stop gracefully\n" 2338 " Causes Asterisk to not accept new calls, and exit when all\n" 2339 " active calls have terminated normally.\n";
2356 e->
command =
"core stop when convenient";
2358 "Usage: core stop when convenient\n" 2359 " Causes Asterisk to perform a shutdown when all active calls have ended.\n";
2368 ast_cli(a->
fd,
"Waiting for inactivity to perform halt\n");
2377 e->
command =
"core restart now";
2379 "Usage: core restart now\n" 2380 " Causes Asterisk to hangup all calls and exec() itself performing a cold\n" 2398 e->
command =
"core restart gracefully";
2400 "Usage: core restart gracefully\n" 2401 " Causes Asterisk to stop accepting new calls and exec() itself performing a cold\n" 2402 " restart when all active calls have ended.\n";
2419 e->
command =
"core restart when convenient";
2421 "Usage: core restart when convenient\n" 2422 " Causes Asterisk to perform a cold restart when all active calls have ended.\n";
2431 ast_cli(a->
fd,
"Waiting for inactivity to perform restart\n");
2440 e->
command =
"core abort shutdown";
2442 "Usage: core abort shutdown\n" 2443 " Causes Asterisk to abort an executing shutdown or restart, and resume normal\n" 2444 " call operations.\n";
2465 "Usage: !<command>\n" 2466 " Executes a given shell command\n";
2478 "BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n" 2479 "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n" 2480 "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n" 2481 "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n" 2482 "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n" 2483 "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n" 2484 "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n" 2485 "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n" 2486 "REPAIR OR CORRECTION.\n" 2488 "IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n" 2489 "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n" 2490 "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n" 2491 "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n" 2492 "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n" 2493 "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n" 2494 "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n" 2495 "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n" 2496 "POSSIBILITY OF SUCH DAMAGES.\n" 2503 e->
command =
"core show warranty";
2505 "Usage: core show warranty\n" 2506 " Shows the warranty (if any) for this copy of Asterisk.\n";
2519 "This program is free software; you can redistribute it and/or modify\n" 2520 "it under the terms of the GNU General Public License version 2 as\n" 2521 "published by the Free Software Foundation.\n" 2523 "This program also contains components licensed under other licenses.\n" 2526 "This program is distributed in the hope that it will be useful,\n" 2527 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 2528 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 2529 "GNU General Public License for more details.\n" 2531 "You should have received a copy of the GNU General Public License\n" 2532 "along with this program; if not, write to the Free Software\n" 2533 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n" 2540 e->
command =
"core show license";
2542 "Usage: core show license\n" 2543 " Shows the license(s) for this copy of Asterisk.\n";
2554 #define ASTERISK_PROMPT "*CLI> " 2579 #if !defined(LOW_MEMORY) 2581 #if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL) 2599 snprintf(buf,
sizeof(buf),
"core set verbose atleast %d silent",
option_verbose);
2604 snprintf(buf,
sizeof(buf),
"core set debug atleast %d",
option_debug);
2614 printf(
"log and verbose output currently muted ('logger mute' to unmute)\n");
2618 #ifdef HAVE_LIBEDIT_IS_UNICODE 2619 #define CHAR_T_LIBEDIT wchar_t 2620 #define CHAR_TO_LIBEDIT(c) btowc(c) 2622 #define CHAR_T_LIBEDIT char 2623 #define CHAR_TO_LIBEDIT(c) c 2630 struct pollfd fds[2];
2633 #define EL_BUF_SIZE 512 2639 fds[0].events = POLLIN;
2641 fds[1].fd = STDIN_FILENO;
2642 fds[1].events = POLLIN;
2650 if (
errno == EINTR) {
2653 fprintf(stderr,
"poll failed: %s\n", strerror(
errno));
2660 num_read = read(STDIN_FILENO, &c, 1);
2670 if (fds[0].revents) {
2674 fprintf(stderr,
"\nDisconnected from Asterisk server\n");
2679 int reconnects_per_second = 20;
2681 fprintf(stderr,
"Attempting to reconnect for 30 seconds\n");
2682 for (tries = 0; tries < 30 * reconnects_per_second; tries++) {
2684 fprintf(stderr,
"Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries);
2691 usleep(1000000 / reconnects_per_second);
2693 if (tries >= 30 * reconnects_per_second) {
2694 fprintf(stderr,
"Failed to reconnect for 30 seconds. Quitting.\n");
2705 if (write(STDOUT_FILENO,
"\r[0K", 5) < 0) {
2711 if ((res <
EL_BUF_SIZE - 1) && ((buf[res-1] ==
'\n') || (res >= 2 && buf[res-2] ==
'\n'))) {
2732 static int cli_prompt_changes = 0;
2736 if (prompt ==
NULL) {
2738 }
else if (!cli_prompt_changes) {
2744 if ((pfmt = getenv(
"ASTERISK_PROMPT"))) {
2747 while (*t !=
'\0') {
2751 struct ast_tm tm = { 0, };
2758 if (sscanf(t,
"%30d;%30d%n", &fgcolor, &bgcolor, &i) == 2) {
2761 }
else if (sscanf(t,
"%30d%n", &fgcolor, &i) == 1) {
2773 cli_prompt_changes++;
2777 if ((gr = getgrgid(getgid()))) {
2782 if (!gethostname(hostname,
sizeof(hostname) - 1)) {
2789 if (!gethostname(hostname,
sizeof(hostname) - 1)) {
2791 if ((dotptr = strchr(hostname,
'.'))) {
2799 #ifdef HAVE_GETLOADAVG 2802 if (sscanf(t,
"%30d", &which) == 1 && which > 0 && which <= 3) {
2806 cli_prompt_changes++;
2817 cli_prompt_changes++;
2821 if ((pw = getpwuid(getuid()))) {
2856 struct ast_vector_string *vec =
ast_calloc(1,
sizeof(*vec));
2862 while ((retstr =
strsep(&buf,
" "))) {
2870 goto vector_cleanup;
2875 goto vector_cleanup;
2900 for (numoutputline = 0; numoutputline < limit && idx <
AST_VECTOR_SIZE(matches); idx++) {
2905 if (!numoutputline) {
2909 fprintf(stdout,
"\n");
2918 struct ast_vector_string *matches;
2923 LineInfo *lf = (LineInfo *)el_line(editline);
2925 savechr = *(
char *)lf->cursor;
2926 *(
char *)lf->cursor =
'\0';
2927 ptr = (
char *)lf->cursor;
2929 while (ptr > lf->buffer) {
2930 if (isspace(*ptr)) {
2938 len = lf->cursor - ptr;
2941 #define CMD_MATCHESARRAY "_COMMAND MATCHESARRAY \"%s\" \"%s\"" 2947 if (maxmbuf == -1) {
2948 *((
char *) lf->cursor) = savechr;
2950 return (
char *)(CC_ERROR);
2959 if (mlen + 1024 > maxmbuf) {
2961 maxmbuf = mlen + 1024;
2965 *((
char *) lf->cursor) = savechr;
2967 return (
char *)(CC_ERROR);
2988 int maxlen, match_len;
2992 el_deletestr(editline, (
int) len);
2993 el_insertstr(editline, best_match);
2994 retval = CC_REFRESH;
2999 el_insertstr(editline,
" ");
3000 retval = CC_REFRESH;
3005 if (match_len > maxlen) {
3010 fprintf(stdout,
"\n");
3012 retval = CC_REDISPLAY;
3018 *((
char *) lf->cursor) = savechr;
3020 return (
char *)(long)retval;
3026 char *editor, *editrc = getenv(
"EDITRC");
3028 if (!(editor = getenv(
"AST_EDITMODE"))) {
3029 if (!(editor = getenv(
"AST_EDITOR"))) {
3039 el = el_init(
"asterisk", stdin, stdout, stderr);
3042 el_set(
el, EL_EDITMODE, 1);
3043 el_set(
el, EL_EDITOR, editor);
3049 history(
el_hist, &ev, H_SETSIZE, 100);
3053 el_set(
el, EL_ADDFN,
"ed-complete",
"Complete argument",
cli_complete);
3055 el_set(
el, EL_BIND,
"^I",
"ed-complete",
NULL);
3057 el_set(
el, EL_BIND,
"?",
"ed-complete",
NULL);
3059 el_set(
el, EL_BIND,
"^D",
"ed-redisplay",
NULL);
3061 el_set(
el, EL_BIND,
"\\e[3~",
"ed-delete-next-char",
NULL);
3063 el_set(
el, EL_BIND,
"\\e[1~",
"ed-move-to-beg",
NULL);
3064 el_set(
el, EL_BIND,
"\\e[4~",
"ed-move-to-end",
NULL);
3066 el_set(
el, EL_BIND,
"\\eOC",
"vi-next-word",
NULL);
3067 el_set(
el, EL_BIND,
"\\eOD",
"vi-prev-word",
NULL);
3070 el_source(
el, editrc);
3076 #define MAX_HISTORY_COMMAND_LENGTH 256 3093 if (!history(
el_hist, &ev, H_FIRST) && strcmp(ev.str, stripped_buf) == 0) {
3097 return history(
el_hist, &ev, H_ENTER, stripped_buf);
3107 return (history(
el_hist, &ev, H_SAVE, filename));
3118 return history(
el_hist, &ev, H_LOAD, filename);
3123 char histfile[80] =
"";
3124 const char *home = getenv(
"HOME");
3127 snprintf(histfile,
sizeof(histfile),
"%s/.asterisk_history", home);
3134 char histfile[80] =
"";
3135 const char *home = getenv(
"HOME");
3138 snprintf(histfile,
sizeof(histfile),
"%s/.asterisk_history", home);
3151 char *stringp =
NULL;
3165 if (read(
ast_consock, buf,
sizeof(buf) - 1) < 0) {
3170 char prefix[] =
"cli quit after ";
3172 sprintf(tmp,
"%s%s", prefix, data);
3173 if (write(
ast_consock, tmp, strlen(tmp) + 1) < 0) {
3181 hostname =
strsep(&stringp,
"/");
3182 cpid =
strsep(&stringp,
"/");
3183 version =
strsep(&stringp,
"\n");
3185 version =
"<Version Unknown>";
3197 int linefull = 1, prev_linefull = 1, prev_line_verbose = 0;
3200 fds.events = POLLIN;
3203 while (
ast_poll(&fds, 1, 60000) > 0) {
3204 char buffer[512] =
"", *curline = buffer, *nextline;
3205 int not_written = 1;
3211 if (read(
ast_consock, buffer,
sizeof(buffer) - 1) <= 0) {
3216 prev_linefull = linefull;
3217 if ((nextline = strchr(curline,
'\n'))) {
3222 nextline = strchr(curline,
'\0');
3236 if ((!prev_linefull && !prev_line_verbose) || (prev_linefull && *curline > 0)) {
3237 prev_line_verbose = 0;
3239 if (write(STDOUT_FILENO, curline, nextline - curline) < 0) {
3243 prev_line_verbose = 1;
3256 ast_verbose(
"Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
3267 ebuf = (
char *)el_gets(
el, &num);
3273 if (!ebuf && write(1,
"", 1) < 0)
3277 if (ebuf[strlen(ebuf)-1] ==
'\n')
3278 ebuf[strlen(ebuf)-1] =
'\0';
3288 printf(
"\nDisconnected from Asterisk server\n");
3300 printf(
"Usage: asterisk [OPTIONS]\n");
3301 printf(
"Valid Options:\n");
3302 printf(
" -V Display version number and exit\n");
3303 printf(
" -C <configfile> Use an alternate configuration file\n");
3304 printf(
" -G <group> Run as a group other than the caller\n");
3305 printf(
" -U <user> Run as a user other than the caller\n");
3306 printf(
" -c Provide console CLI\n");
3307 printf(
" -d Increase debugging (multiple d's = more debugging)\n");
3308 #if HAVE_WORKING_FORK 3309 printf(
" -f Do not fork\n");
3310 printf(
" -F Always fork\n");
3312 printf(
" -g Dump core in case of a crash\n");
3313 printf(
" -h This help screen\n");
3314 printf(
" -i Initialize crypto keys at startup\n");
3315 printf(
" -L <load> Limit the maximum load average before rejecting new calls\n");
3316 printf(
" -M <value> Limit the maximum number of calls to the specified value\n");
3317 printf(
" -m Mute debugging and console output on the console\n");
3318 printf(
" -n Disable console colorization\n");
3319 printf(
" -p Run as pseudo-realtime thread\n");
3320 printf(
" -q Quiet mode (suppress output)\n");
3321 printf(
" -r Connect to Asterisk on this machine\n");
3322 printf(
" -R Same as -r, except attempt to reconnect if disconnected\n");
3323 printf(
" -s <socket> Connect to Asterisk via socket <socket> (only valid with -r)\n");
3324 printf(
" -t Record soundfiles in /var/tmp and move them where they\n");
3325 printf(
" belong after they are done\n");
3326 printf(
" -T Display the time in [Mmm dd hh:mm:ss] format for each line\n");
3327 printf(
" of output to the CLI\n");
3328 printf(
" -v Increase verbosity (multiple v's = more verbose)\n");
3329 printf(
" -x <cmd> Execute command <cmd> (implies -r)\n");
3330 printf(
" -X Enable use of #exec in asterisk.conf\n");
3331 printf(
" -W Adjust terminal colors to compensate for a light background\n");
3354 if (!strcasecmp(v->
name,
"log_level")) {
3362 }
else if (!strcasecmp(v->
name,
"cache_pools")) {
3397 struct stat canary_stat;
3405 if (stat(
canary_filename, &canary_stat) || now.tv_sec > canary_stat.st_mtime + 60) {
3407 "The canary is no more. He has ceased to be! " 3408 "He's expired and gone to meet his maker! " 3409 "He's a stiff! Bereft of life, he rests in peace. " 3410 "His metabolic processes are now history! He's off the twig! " 3411 "He's kicked the bucket. He's shuffled off his mortal coil, " 3412 "run down the curtain, and joined the bleeding choir invisible!! " 3413 "THIS is an EX-CANARY. (Reducing priority)\n");
3447 fd = open(
"/dev/null", O_RDWR);
3482 ast_verbose(
"Running under group '%s'\n", rungroup);
3496 int isroot = 1, rundir_exists = 0;
3501 static const char *getopt_settings =
"BC:cde:FfG:ghIiL:M:mnpqRrs:TtU:VvWXx:";
3505 fprintf(stderr,
"Truncating argument size to %d\n", (
int)
ARRAY_LEN(
_argv) - 1);
3508 for (x = 0; x < argc; x++)
3516 if (argv[0] && (strstr(argv[0],
"rasterisk")) !=
NULL) {
3522 while ((c = getopt(argc, argv, getopt_settings)) != -1) {
3567 while ((c = getopt(argc, argv, getopt_settings)) != -1) {
3588 #if defined(HAVE_SYSINFO) 3595 #if HAVE_WORKING_FORK 3614 "NOTICE: The -I option is no longer needed.\n" 3615 " It will always be enabled if you have a timing module loaded.\n");
3687 strcpy(argv[0],
"rasterisk");
3688 for (x = 1; x < argc; x++) {
3689 argv[x] = argv[0] + 10;
3694 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");
3698 fprintf(stderr,
"'alwaysfork' is not compatible with console or remote console mode; ignored\n");
3703 memset(&l, 0,
sizeof(l));
3704 l.rlim_cur = RLIM_INFINITY;
3705 l.rlim_max = RLIM_INFINITY;
3706 if (setrlimit(RLIMIT_CORE, &l)) {
3707 fprintf(stderr,
"Unable to disable core size resource limit: %s\n", strerror(
errno));
3711 if (getrlimit(RLIMIT_NOFILE, &l)) {
3712 fprintf(stderr,
"Unable to check file descriptor limit: %s\n", strerror(
errno));
3715 #if !defined(CONFIGURE_RAN_AS_ROOT) 3720 struct timeval tv = { 0, };
3722 if (l.rlim_cur <= FD_SETSIZE) {
3728 if (!(fd = open(
"/dev/null", O_RDONLY))) {
3729 fprintf(stderr,
"Cannot open a file descriptor at boot? %s\n", strerror(
errno));
3733 fd2 = ((l.rlim_cur >
sizeof(readers) * 8) ?
sizeof(readers) * 8 : l.rlim_cur) - 1;
3734 if (dup2(fd, fd2) < 0) {
3735 fprintf(stderr,
"Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(
errno));
3743 fprintf(stderr,
"Maximum select()able file descriptor is %d\n", FD_SETSIZE);
3749 #elif defined(HAVE_VARIABLE_FDSET) 3761 sigaction(SIGCHLD, &child_handler,
NULL);
3766 if (
errno == EEXIST) {
3769 fprintf(stderr,
"Unable to create socket file directory. Remote consoles will not be able to connect! (%s)\n", strerror(x));
3779 if (isroot && rungroup) {
3781 gr = getgrnam(rungroup);
3783 fprintf(stderr,
"No such group '%s'!\n", rungroup);
3787 fprintf(stderr,
"Unable to chgrp run directory to %d (%s)\n", (
int) gr->gr_gid, rungroup);
3789 if (setgid(gr->gr_gid)) {
3790 fprintf(stderr,
"Unable to setgid to %d (%s)\n", (
int)gr->gr_gid, rungroup);
3793 if (setgroups(0,
NULL)) {
3794 fprintf(stderr,
"Unable to drop unneeded groups\n");
3804 pw = getpwnam(runuser);
3806 fprintf(stderr,
"No such user '%s'!\n", runuser);
3810 fprintf(stderr,
"Unable to chown run directory to %d (%s)\n", (
int) pw->pw_uid, runuser);
3813 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
3818 if (!isroot && pw->pw_uid != geteuid()) {
3819 fprintf(stderr,
"Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
3823 if (setgid(pw->pw_gid)) {
3824 fprintf(stderr,
"Unable to setgid to %d!\n", (
int)pw->pw_gid);
3827 if (isroot && initgroups(pw->pw_name, pw->pw_gid)) {
3828 fprintf(stderr,
"Unable to init groups for '%s'\n", runuser);
3832 if (setuid(pw->pw_uid)) {
3833 fprintf(stderr,
"Unable to setuid to %d (%s)\n", (
int)pw->pw_uid, runuser);
3840 cap = cap_from_text(
"cap_net_admin=eip");
3842 if (cap_set_proc(cap)) {
3843 fprintf(stderr,
"Unable to install capabilities.\n");
3845 if (cap_free(cap)) {
3846 fprintf(stderr,
"Unable to drop capabilities.\n");
3856 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
3857 fprintf(stderr,
"Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(
errno));
3863 #if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) 3864 #if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS) 3865 #define eaccess euidaccess 3868 if (!getcwd(dir,
sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) {
3869 fprintf(stderr,
"Unable to access the running directory (%s). Changing to '/' for compatibility.\n", strerror(
errno));
3874 fprintf(stderr,
"chdir(\"/\") failed?!! %s\n", strerror(
errno));
3881 fprintf(stderr,
"Unable to chdir(\"/\") ?!! %s\n", strerror(
errno));
3913 fprintf(stderr,
"Asterisk already running on %s. Use 'asterisk -r' to connect.\n",
ast_config_AST_SOCKET);
3924 child_cap = cap_from_text(
"cap_net_admin-eip");
3940 fprintf(stderr,
"%s initialization failed. ASTERISK EXITING!\n%s", name,
term_quit());
3943 exit(init_result == -2 ? 2 : 1);
3963 #if HAVE_WORKING_FORK 3965 #ifndef HAVE_SBIN_LAUNCHD 3966 if (daemon(1, 0) < 0) {
3967 fprintf(stderr,
"daemon() failed: %s\n", strerror(
errno));
3972 fprintf(stderr,
"Mac OS X detected. Use 'launchctl load /Library/LaunchDaemon/org.asterisk.asterisk.plist'.\n");
3997 sigaction(SIGPIPE, &ignore_sig_handler,
NULL);
4001 char canary_binary[
PATH_MAX], ppid[12];
4004 signal(SIGCHLD, SIG_DFL);
4005 signal(SIGPIPE, SIG_DFL);
4009 snprintf(ppid,
sizeof(ppid),
"%d", (
int)
ast_mainpid);
4018 pthread_t dont_care;
4069 ast_verb(0,
"PBX UUID: %s\n", pbx_uuid);
4085 #ifdef TEST_FRAMEWORK 4104 (void) sigemptyset(&sigs);
4105 (void) sigaddset(&sigs, SIGHUP);
4106 (void) sigaddset(&sigs, SIGTERM);
4107 (void) sigaddset(&sigs, SIGINT);
4108 (void) sigaddset(&sigs, SIGPIPE);
4109 (void) sigaddset(&sigs, SIGWINCH);
4110 pthread_sigmask(SIG_BLOCK, &sigs,
NULL);
4111 sigaction(SIGURG, &urg_handler,
NULL);
4114 sigaction(SIGHUP, &hup_handler,
NULL);
4115 sigaction(SIGPIPE, &ignore_sig_handler,
NULL);
4120 srand((
unsigned int) getpid() + (
unsigned int) time(
NULL));
4187 pthread_sigmask(SIG_UNBLOCK, &sigs,
NULL);
4208 if (gethostname(hostname,
sizeof(hostname) - 1)) {
4215 snprintf(title,
sizeof(title),
"Asterisk Console on '%s' (pid %ld)", hostname, (
long)
ast_mainpid);
4231 buf = (
char *) el_gets(
el, &num);
4233 if (!buf && write(1,
"", 1) < 0)
4237 if (buf[strlen(buf)-1] ==
'\n')
4238 buf[strlen(buf)-1] =
'\0';
int load_pbx_variables(void)
const char * term_quit(void)
static void __ast_unregister_atexit(void(*func)(void))
static int sig_alert_pipe[2]
static char * handle_restart_gracefully(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
A-Law to Signed linear conversion.
static char * handle_restart_now(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
struct ast_variable * next
const char * ast_config_AST_KEY_DIR
static int show_version(void)
static void * canary_thread(void *unused)
int ast_codec_builtin_init(void)
Initialize built-in codecs within the core.
#define AST_CLI_DEFINE(fn, txt,...)
int stasis_init(void)
Initialize the Stasis subsystem.
int ast_stasis_system_init(void)
Initialize the stasis system topic and message types.
#define AST_LIST_LOCK(head)
Locks a list.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static char * handle_bang(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_named_locks_init(void)
#define ast_realloc(p, len)
A wrapper for realloc()
static void canary_exit(void)
const char * ast_build_user
int ast_pickup_init(void)
Initialize pickup.
static struct ast_vector_string * ast_el_strtoarr(char *buf)
static char * handle_restart_when_convenient(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Security Event Reporting API.
#define AST_CLI_COMPLETE_EOF
void ast_autoservice_init(void)
static int ast_makesocket(void)
int ast_image_init(void)
Initialize image stuff Initializes all the various image stuff. Basically just registers the cli stuf...
static struct sigaction ignore_sig_handler
static const char license_lines[]
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
unsigned int option_dtmfminduration
int ast_translate_init(void)
Initialize the translation matrix and index to format conversion table.
static void check_init(int init_result, const char *name)
void ast_builtins_init(void)
initialize the _full_cmd string in * each of the builtins.
static struct ast_cli_entry cli_asterisk[]
static char * handle_stop_now(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
const char * ast_config_AST_DB
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
const char * ast_config_AST_SBIN_DIR
#define ast_pthread_create_detached(a, b, c, d)
static struct sigaction urg_handler
Asterisk version information.
void set_socket_path(const char *path)
static ast_mutex_t safe_system_lock
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
static char * handle_abort_shutdown(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_sd_get_fd_un(int type, const char *path)
Find a listening AF_LOCAL file descriptor provided by socket activation.
static char * show_warranty(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int ast_all_zeros(const char *s)
#define ast_test_flag(p, flag)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Support for translation of data formats. translate.c.
int ast_manager_check_enabled(void)
Check if AMI is enabled.
int register_config_cli(void)
Exposed initialization method for core process.
static char * handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Give an overview of system statistics.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
const char * ast_config_AST_MODULE_DIR
const char * ast_get_version(void)
Retrieve the Asterisk version string.
static char * handle_show_threads(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int ast_el_read_char(EditLine *editline, CHAR_T_LIBEDIT *cp)
static int wait_for_channels_to_die(shutdown_nice_t niceness, int seconds)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define DEFAULT_PJ_LOG_MAX_LEVEL
#define ast_set_flag(p, flag)
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
int mwi_init(void)
Initialize the mwi core.
descriptor for a cli entry.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
int ast_endpoint_init(void)
Endpoint support initialization.
int ast_verb_console_get(void)
Get this thread's console verbosity level.
static int console_print(const char *s)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static char * cli_complete(EditLine *editline, int ch)
void load_astmm_phase_1(void)
Initialize malloc debug phase 1.
#define CONFIG_STATUS_FILEINVALID
static int multi_thread_safe
int load_pbx_switch(void)
void set_asterisk_conf_path(const char *path)
const char * ast_logger_get_dateformat(void)
Get the logger configured date format.
#define WELCOME_MESSAGE
Welcome message when starting a CLI interface.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
static void __remote_quit_handler(int num)
const char * ast_build_date
const char * ast_get_build_opts(void)
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
static struct sigaction safe_system_prev_handler
static int ast_el_write_history(const char *)
int ast_presence_state_engine_init(void)
Universally unique identifier support.
const char * ast_build_os
int ast_bucket_init(void)
Initialize bucket support.
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
Append a color sequence to an ast_str.
void load_asterisk_conf(void)
static void _hup_handler(int num)
static void ast_el_read_default_histfile(void)
static struct profile_data * prof_data
static void read_pjproject_startup_options(void)
static int ast_el_add_history(const char *)
int ast_bridging_init(void)
Initialize the bridging system.
int ast_xmldoc_load_documentation(void)
Load XML documentation. Provided by xmldoc.c.
int ast_security_stasis_init(void)
initializes stasis topic/event types for ast_security_topic and ast_security_event_type ...
static int show_cli_help(void)
int ast_endpoint_stasis_init(void)
Initialization function for endpoint stasis support.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define DEFAULT_PJPROJECT_CACHE_POOLS
static char * cli_prompt(EditLine *editline)
static void _null_sig_handler(int sig)
NULL handler so we can collect the child exit status.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int ast_dns_system_resolver_init(void)
Initializes the resolver.
const char * ast_config_AST_RUN_DIR
void ast_alaw_init(void)
To init the alaw to slinear conversion stuff, this needs to be run.
#define ast_mutex_lock(a)
double ast_option_maxload
const char * ast_config_AST_RUN_USER
void ast_verbose(const char *fmt,...)
#define ast_strdup(str)
A wrapper for strdup()
static void ast_cli_display_match_list(struct ast_vector_string *matches, int max)
struct timeval ast_lastreloadtime
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
void ast_init_logger_for_socket_console(void)
load logger.conf configuration for console socket connections
int ast_add_profile(const char *name, uint64_t scale)
allocates a counter with a given name and scale.
#define AST_RTP_PT_FIRST_DYNAMIC
int ast_cancel_shutdown(void)
Cancel an existing shutdown and return to normal operation.
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
I/O Management (derived from Cheops-NG)
void ast_cli(int fd, const char *fmt,...)
struct ast_atexit::@338 list
void ast_unregister_thread(void *id)
void ast_console_puts_mutable(const char *string, int level)
log the string to the root console, and all attached network console clients
static int ast_tryconnect(void)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
UTF-8 information and validation functions.
void ast_free_ptr(void *ptr)
free() wrapper
#define ast_pthread_create_detached_background(a, b, c, d)
#define ast_verb(level,...)
#define ast_opt_reconnect
const char * term_end(void)
int modules_shutdown(void)
const char * ast_build_hostname
int ast_sorcery_init(void)
Initialize the sorcery API.
int ast_get_termcols(int fd)
#define COLORIZE(fg, bg, str)
int ast_codec_init(void)
Initialize codec support within the core.
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
int args
This gets set in ast_cli_register()
const char * ast_build_kernel
#define ast_strlen_zero(foo)
int ast_realtime_enabled(void)
Check if there's any realtime engines loaded.
int ast_webmanager_check_enabled(void)
Check if AMI/HTTP is enabled.
static void quit_handler(int num, shutdown_nice_t niceness, int restart)
void ast_verb_console_register(int *level)
Register this thread's console verbosity level pointer.
#define ast_pthread_create_background(a, b, c, d)
const char * ast_config_AST_SYSTEM_NAME
static char * handle_stop_when_convenient(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void _urg_handler(int num)
Urgent handler.
ssize_t ast_alertpipe_write(int alert_pipe[2])
Write an event to an alert pipe.
int ast_cdr_is_enabled(void)
Return TRUE if CDR subsystem is enabled.
const char * ast_config_AST_RUN_GROUP
void ast_console_toggle_loglevel(int fd, int level, int state)
enable or disable a logging level to a specified console
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
static void env_init(void)
static void _child_handler(int sig)
Configuration File Parser.
int load_pbx_hangup_handler(void)
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
const char * ast_build_machine
#define AST_RWLIST_INSERT_HEAD
const char * ast_config_AST_CONFIG_FILE
struct timeval ast_startuptime
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
#define EVENT_FLAG_SYSTEM
static int shutdown_pending
#define ast_debug(level,...)
Log a DEBUG message.
static pthread_t mon_sig_flags
static char * handle_stop_gracefully(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
General Asterisk channel definitions for image handling.
u-Law to Signed linear conversion
Generic Advice of Charge encode and decode routines.
#define ast_opt_hide_messaging_ami_events
static void * listener(void *unused)
void ast_console_puts_mutable_full(const char *message, int level, int sublevel)
log the string to the console, and all attached console clients
struct ast_vector_string * ast_cli_completion_vector(const char *text, const char *word)
Generates a vector of strings for CLI completion.
void callerid_init(void)
CallerID Initialization.
General Asterisk PBX channel definitions.
Asterisk JSON abstraction layer.
#define ast_opt_timestamp
static void __quit_handler(int num)
Asterisk file paths, configured in asterisk.conf.
#define ast_opt_cache_media_frames
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_sd_notify(const char *state)
a wrapper for sd_notify(): notify systemd of any state changes.
const char * ast_config_AST_AGI_DIR
int ast_get_tid(void)
Get current thread ID.
struct profile_entry e[0]
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...
#define AST_PTHREADT_NULL
#define ast_poll(a, b, c)
static void set_title(char *text)
Set an X-term or screen title.
Access Control of various sorts.
const char * ast_config_AST_PID
void ast_softhangup_all(void)
Soft hangup all active channels.
int ast_language_is_prefix
The following variable controls the layout of localized sound files. If 0, use the historical layout ...
char ast_defaultlanguage[]
#define AST_RWLIST_TRAVERSE
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Scheduler Routines (derived from cheops)
static struct sigaction hup_handler
int ast_utf8_init(void)
Register UTF-8 tests.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
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.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
int devstate_init(void)
Initialize the device state core.
#define AST_RWLIST_REMOVE_CURRENT
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_option_pjproject_log_level
static const char warranty_lines[]
static void publish_fully_booted(void)
const char * ast_config_AST_CTL_GROUP
int ast_alertpipe_init(int alert_pipe[2])
Initialize an alert pipe.
A set of macros to manage forward-linked lists.
ast_cli_command
calling arguments for new-style handlers.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
struct console consoles[AST_MAX_CONNECTS]
int ast_aoc_cli_init(void)
enable aoc cli options
int ast_cli_allow_at_shutdown(struct ast_cli_entry *e)
Core PBX routines and definitions.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
static void send_rasterisk_connect_commands(void)
static shutdown_nice_t shuttingdown
#define CONFIG_STATUS_FILEUNCHANGED
Wrapper for network related headers, masking differences between various operating systems...
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
const char * ast_config_AST_DATA_DIR
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
static pthread_t consolethread
void ast_cdr_engine_term(void)
static int console_state_init(void *ptr)
static char canary_filename[128]
int ast_device_state_engine_init(void)
Initialize the device state engine in separate thread.
static int set_priority_all(int pri)
Set priority on all known threads.
Presence state management.
static void ast_el_write_default_histfile(void)
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
void ast_ulaw_init(void)
Set up mu-law conversion table.
void ast_uuid_init(void)
Initialize the UUID system.
static void run_startup_commands(void)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
ast_alert_status_t ast_alertpipe_read(int alert_pipe[2])
Read an event from an alert pipe.
void ast_stun_init(void)
Initialize the STUN system in Asterisk.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static int fdsend(int fd, const char *s)
int ast_option_pjproject_cache_pools
static char randompool[256]
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 ast_el_read_history(const char *)
const char * ast_config_AST_CONFIG_DIR
TTY/TDD Generation support.
int ast_pbx_uuid_get(char *pbx_uuid, int length)
Retrieve the PBX UUID.
unsigned int ast_FD_SETSIZE
static struct ast_threadstorage console_state
int ast_parking_stasis_init(void)
initializes the rtp engine arrays
int ast_local_init(void)
Initialize the local proxy channel.
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_verb_console_unregister(void)
Unregister this thread's console verbosity level.
int ast_is_logger_initialized(void)
Test if logger is initialized.
#define VERBOSE_HASMAGIC(x)
static void * netconsole(void *vconsole)
#define DEFINE_PROFILE_MIN_MAX_VALUES
const char * ast_config_AST_LOG_DIR
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
static void ast_begin_shutdown(void)
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
static char * remotehostname
static char version[AST_MAX_EXTENSION]
static void set_icon(char *text)
static void ast_remotecontrol(char *data)
void ast_console_puts(const char *string)
write the string to the root console, and all attached network console clients
static pid_t safe_exec_prep(int dualfork)
fork and perform other preparations for spawning applications
#define ast_calloc(num, len)
A wrapper for calloc()
static int read_credentials(int fd, char *buffer, size_t size, struct console *con)
read() function supporting the reception of user credentials.
static char * handle_clear_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
const char * ast_term_reset(void)
Returns the terminal reset code.
static void asterisk_daemon(int isroot, const char *runuser, const char *rungroup)
static char * handle_show_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
int ast_shutdown_final(void)
Asterisk XML Documentation API.
int ast_rtp_engine_init(void)
initializes the rtp engine arrays
Prototypes for public functions only of internal interest,.
const char * ast_config_AST_SPOOL_DIR
#define ast_opt_always_fork
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...
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
static struct sigaction child_handler
void logger_queue_start(void)
Start the ast_queue_log() logger.
static void main_atexit(void)
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
#define AST_VECTOR_PTR_FREE(vec)
Deallocates this vector pointer.
Structure used to handle boolean flags.
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
#define ast_clear_flag(p, flag)
#define AST_THREADSTORAGE_CUSTOM(a, b, c)
Define a thread storage variable, with custom initialization and cleanup.
#define CONFIG_STATUS_FILEMISSING
struct ast_eid ast_eid_default
Global EID.
#define sched_setscheduler
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
void load_astmm_phase_2(void)
Initialize malloc debug phase 2.
void clean_time_zones(void)
int ast_cli_command_multiple_full(int uid, int gid, int fd, size_t size, const char *s)
Executes multiple CLI commands Interpret strings separated by NULL and execute each one...
#define MAX_PJ_LOG_MAX_LEVEL
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
#define VERBOSE_MAGIC2LEVEL(x)
struct ast_flags ast_options
char * strsep(char **str, const char *delims)
void ast_console_toggle_mute(int fd, int silent)
mute or unmute a console from logging
static void set_header(char *outbuf, int maxout, char level)
void threadstorage_init(void)
static int fdprint(int fd, const char *s)
Standard Command Line Interface.
static int ast_el_initialize(void)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_json_init(void)
Initialize the JSON library.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static int register_atexit(void(*func)(void), int is_cleanup)
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
int ast_safe_execvp(int dualfork, const char *file, char *const argv[])
Safely spawn an external program while closing file descriptors.
const char * ast_config_AST_SOCKET
void dnsmgr_start_refresh(void)
#define MAX_HISTORY_COMMAND_LENGTH
int ast_shutting_down(void)
static int can_safely_quit(shutdown_nice_t niceness, int restart)
int ast_safe_system(const char *s)
Safely spawn an OS shell command while closing file descriptors.
#define AST_RTP_PT_LAST_REASSIGN
static struct ast_str * hostname
static int ast_socket_is_sd
int getloadavg(double *list, int nelem)
int ast_option_rtpusedynamic
Abstract JSON element (object, array, string, int, ...).
static char * handle_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Options provided by main asterisk program.
void ast_unregister_atexit(void(*func)(void))
Unregister a function registered with ast_register_atexit().
#define CHAR_TO_LIBEDIT(c)
static void consolehandler(const char *s)
static int has_priority(void)
Check whether we were set to high(er) priority.
#define WEXITSTATUS(status)
Handy terminal functions for vt* terms.
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
int setenv(const char *name, const char *value, int overwrite)
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
int ast_timing_init(void)
static struct sigaction null_sig_handler
int ast_undestroyed_channels(void)
static int remoteconsolehandler(const char *s)
int load_pbx_functions_cli(void)
static char * show_license(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct ast_str * prompt
unsigned int need_quit_handler
void ast_msg_shutdown(void)
int main(int argc, char *argv[])
static int safe_exec_wait(pid_t pid)
wait for spawned application to complete and unreplace sigchld
static struct @337 sig_flags
static void ast_network_puts(const char *string)
write the string to all attached console clients
Pluggable RTP Architecture.
#define ast_opt_hide_connect
Asterisk module definitions.
const char * ast_config_AST_VAR_DIR
int ast_channels_init(void)
static struct ast_cli_entry cli_asterisk_shutdown[]
Shutdown Asterisk CLI commands.
int load_pbx_builtins(void)
int ast_active_channels(void)
returns number of active/allocated channels
Persistant data storage (akin to *doze registry)
#define WIFEXITED(status)
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static void ast_network_puts_mutable(const char *string, int level, int sublevel)
log the string to all attached network console clients
#define ast_opt_dump_core
static void print_intro_message(const char *runuser, const char *rungroup)
unsigned int ast_option_rtpptdynamic
void ast_register_thread(char *name)
#define AST_RWLIST_TRAVERSE_SAFE_END
void ast_process_pending_reloads(void)
Process reload requests received during startup.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
static void really_quit(int num, shutdown_nice_t niceness, int restart)
#define AST_MUTEX_DEFINE_STATIC(mutex)
int64_t ast_profile(int i, int64_t delta)
static void * monitor_sig_flags(void *unused)
int ast_cli_perms_init(int reload)
int app_init(void)
Initialize the application core.
int64_t ast_mark(int i, int startstop)
static void ast_run_atexits(int run_cleanups)
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
Publish an event to AMI.
#define ast_opt_high_priority
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Sorcery Data Access Layer API.
#define ast_mutex_unlock(a)
static __inline uint64_t rdtsc(void)
const char * ast_config_AST_CTL_PERMISSIONS
static char prefix[MAX_PREFIX]
const char * ast_config_AST_CTL_OWNER