summaryrefslogtreecommitdiff
path: root/main/asterisk.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c129
1 files changed, 43 insertions, 86 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 0026b36d7..01107e217 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -795,12 +795,35 @@ static int swapmode(int *used, int *total)
static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
uint64_t physmem, freeram;
+#if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL)
uint64_t freeswap = 0;
+#endif
int nprocs = 0;
long uptime = 0;
int totalswap = 0;
#if defined(HAVE_SYSINFO)
struct sysinfo sys_info;
+#elif defined(HAVE_SYSCTL)
+ static int pageshift;
+ struct vmtotal vmtotal;
+ struct timeval boottime;
+ time_t now;
+ int mib[2], pagesize, usedswap = 0;
+ size_t len;
+#endif
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show sysinfo";
+ e->usage =
+ "Usage: core show sysinfo\n"
+ " List current system information.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+#if defined(HAVE_SYSINFO)
sysinfo(&sys_info);
uptime = sys_info.uptime / 3600;
physmem = sys_info.totalram * sys_info.mem_unit;
@@ -809,12 +832,6 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
freeswap = (sys_info.freeswap * sys_info.mem_unit) / 1024;
nprocs = sys_info.procs;
#elif defined(HAVE_SYSCTL)
- static int pageshift;
- struct vmtotal vmtotal;
- struct timeval boottime;
- time_t now;
- int mib[2], pagesize, usedswap = 0;
- size_t len;
/* calculate the uptime by looking at boottime */
time(&now);
mib[0] = CTL_KERN;
@@ -862,17 +879,6 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
#endif
#endif
- switch (cmd) {
- case CLI_INIT:
- e->command = "core show sysinfo";
- e->usage =
- "Usage: core show sysinfo\n"
- " List current system information.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
-
ast_cli(a->fd, "\nSystem Statistics\n");
ast_cli(a->fd, "-----------------\n");
ast_cli(a->fd, " System Uptime: %ld hours\n", uptime);
@@ -881,7 +887,7 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
#if defined(HAVE_SYSINFO)
ast_cli(a->fd, " Buffer RAM: %" PRIu64 " KiB\n", ((uint64_t) sys_info.bufferram * sys_info.mem_unit) / 1024);
#endif
-#if defined(HAVE_SWAPCTL) || defined(HAVE_SYSINFO)
+#if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL)
ast_cli(a->fd, " Total Swap Space: %d KiB\n", totalswap);
ast_cli(a->fd, " Free Swap Space: %" PRIu64 " KiB\n\n", freeswap);
#endif
@@ -1691,18 +1697,21 @@ static void *listener(void *unused)
int s;
socklen_t len;
int x;
- int flags;
+ int poll_result;
struct pollfd fds[1];
+
for (;;) {
- if (ast_socket < 0)
+ if (ast_socket < 0) {
return NULL;
+ }
fds[0].fd = ast_socket;
fds[0].events = POLLIN;
- s = ast_poll(fds, 1, -1);
+ poll_result = ast_poll(fds, 1, -1);
pthread_testcancel();
- if (s < 0) {
- if (errno != EINTR)
+ if (poll_result < 0) {
+ if (errno != EINTR) {
ast_log(LOG_WARNING, "poll returned error: %s\n", strerror(errno));
+ }
continue;
}
len = sizeof(sunaddr);
@@ -1716,6 +1725,7 @@ static void *listener(void *unused)
/* turn on socket credentials passing. */
if (setsockopt(s, SOL_SOCKET, SO_PASSCRED, &sckopt, sizeof(sckopt)) < 0) {
ast_log(LOG_WARNING, "Unable to turn on socket credentials passing\n");
+ close(s);
} else
#endif
{
@@ -1729,8 +1739,7 @@ static void *listener(void *unused)
close(s);
break;
}
- flags = fcntl(consoles[x].p[1], F_GETFL);
- fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
+ ast_fd_set_flags(consoles[x].p[1], O_NONBLOCK);
consoles[x].mute = 1; /* Default is muted, we will un-mute if necessary */
/* Default uid and gid to -2, so then in cli.c/cli_has_permissions() we will be able
to know if the user didn't send the credentials. */
@@ -2517,52 +2526,6 @@ static int remoteconsolehandler(const char *s)
(s[4] == '\0' || isspace(s[4]))) {
quit_handler(0, SHUTDOWN_FAST, 0);
ret = 1;
- } else if (s[0]) {
- char *shrunk = ast_strdupa(s);
- char *cur;
- char *prev;
-
- /*
- * Remove duplicate spaces from shrunk for matching purposes.
- *
- * shrunk has at least one character in it to start with or we
- * couldn't get here.
- */
- for (prev = shrunk, cur = shrunk + 1; *cur; ++cur) {
- if (*prev == ' ' && *cur == ' ') {
- /* Skip repeated space delimiter. */
- continue;
- }
- *++prev = *cur;
- }
- *++prev = '\0';
-
- if (strncasecmp(shrunk, "core set verbose ", 17) == 0) {
- /*
- * We need to still set the rasterisk option_verbose in case we are
- * talking to an earlier version which doesn't prefilter verbose
- * levels. This is really a compromise as we should always take
- * whatever the server sends.
- */
-
- if (!strncasecmp(shrunk + 17, "off", 3)) {
- ast_verb_console_set(0);
- } else {
- int verbose_new;
- int atleast;
-
- atleast = 8;
- if (strncasecmp(shrunk + 17, "atleast ", atleast)) {
- atleast = 0;
- }
-
- if (sscanf(shrunk + 17 + atleast, "%30d", &verbose_new) == 1) {
- if (!atleast || ast_verb_console_get() < verbose_new) {
- ast_verb_console_set(verbose_new);
- }
- }
- }
- }
}
return ret;
@@ -2887,6 +2850,9 @@ static void send_rasterisk_connect_commands(void)
fdsend(ast_consock, buf);
}
+ /* Leave verbose filtering to the server. */
+ option_verbose = INT_MAX;
+
if (!ast_opt_mute) {
fdsend(ast_consock, "logger mute silent");
} else {
@@ -3236,20 +3202,10 @@ static char *cli_complete(EditLine *editline, int ch)
#define CMD_MATCHESARRAY "_COMMAND MATCHESARRAY \"%s\" \"%s\""
char *mbuf;
char *new_mbuf;
- int mlen = 0, maxmbuf = 2048;
-
- /* Start with a 2048 byte buffer */
- mbuf = ast_malloc(maxmbuf);
-
- /* This will run snprintf twice at most. */
- while (mbuf && (mlen = snprintf(mbuf, maxmbuf, CMD_MATCHESARRAY, lf->buffer, ptr)) > maxmbuf) {
- /* Return value does not include space for NULL terminator. */
- maxmbuf = mlen + 1;
- ast_free(mbuf);
- mbuf = ast_malloc(maxmbuf);
- }
+ int mlen = 0;
+ int maxmbuf = ast_asprintf(&mbuf, CMD_MATCHESARRAY, lf->buffer, ptr);
- if (!mbuf) {
+ if (maxmbuf == -1) {
*((char *) lf->cursor) = savechr;
return (char *)(CC_ERROR);
@@ -3262,9 +3218,9 @@ static char *cli_complete(EditLine *editline, int ch)
while (!strstr(mbuf, AST_CLI_COMPLETE_EOF) && res != -1) {
if (mlen + 1024 > maxmbuf) {
- /* Expand buffer to the next 1024 byte increment. */
+ /* Expand buffer to the next 1024 byte increment plus a NULL terminator. */
maxmbuf = mlen + 1024;
- new_mbuf = ast_realloc(mbuf, maxmbuf);
+ new_mbuf = ast_realloc(mbuf, maxmbuf + 1);
if (!new_mbuf) {
ast_free(mbuf);
*((char *) lf->cursor) = savechr;
@@ -3277,6 +3233,7 @@ static char *cli_complete(EditLine *editline, int ch)
res = read(ast_consock, mbuf + mlen, 1024);
if (res > 0) {
mlen += res;
+ mbuf[mlen] = '\0';
}
}
mbuf[mlen] = '\0';