|
|
@ -13,7 +13,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
|
|
|
|
#include <asterisk/logger.h>
|
|
|
|
#include <asterisk/logger.h>
|
|
|
|
#include <asterisk/options.h>
|
|
|
|
#include <asterisk/options.h>
|
|
|
|
#include <asterisk/cli.h>
|
|
|
|
#include <asterisk/cli.h>
|
|
|
@ -230,24 +229,26 @@ static void *netconsole(void *vconsole)
|
|
|
|
char hostname[256];
|
|
|
|
char hostname[256];
|
|
|
|
char tmp[512];
|
|
|
|
char tmp[512];
|
|
|
|
int res;
|
|
|
|
int res;
|
|
|
|
struct pollfd fds[2];
|
|
|
|
int max;
|
|
|
|
|
|
|
|
fd_set rfds;
|
|
|
|
|
|
|
|
|
|
|
|
if (gethostname(hostname, sizeof(hostname)))
|
|
|
|
if (gethostname(hostname, sizeof(hostname)))
|
|
|
|
strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
|
|
|
|
strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
|
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION);
|
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION);
|
|
|
|
fdprint(con->fd, tmp);
|
|
|
|
fdprint(con->fd, tmp);
|
|
|
|
for(;;) {
|
|
|
|
for(;;) {
|
|
|
|
fds[0].fd = con->fd;
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
FD_SET(con->fd, &rfds);
|
|
|
|
fds[1].fd = con->p[0];
|
|
|
|
FD_SET(con->p[0], &rfds);
|
|
|
|
fds[1].events = POLLIN;
|
|
|
|
max = con->fd;
|
|
|
|
|
|
|
|
if (con->p[0] > max)
|
|
|
|
res = poll(fds, 2, -1);
|
|
|
|
max = con->p[0];
|
|
|
|
|
|
|
|
res = ast_select(max + 1, &rfds, NULL, NULL, NULL);
|
|
|
|
if (res < 0) {
|
|
|
|
if (res < 0) {
|
|
|
|
ast_log(LOG_WARNING, "poll returned < 0: %s\n", strerror(errno));
|
|
|
|
ast_log(LOG_WARNING, "select returned < 0: %s\n", strerror(errno));
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fds[0].revents) {
|
|
|
|
if (FD_ISSET(con->fd, &rfds)) {
|
|
|
|
res = read(con->fd, tmp, sizeof(tmp));
|
|
|
|
res = read(con->fd, tmp, sizeof(tmp));
|
|
|
|
if (res < 1) {
|
|
|
|
if (res < 1) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -255,7 +256,7 @@ static void *netconsole(void *vconsole)
|
|
|
|
tmp[res] = 0;
|
|
|
|
tmp[res] = 0;
|
|
|
|
ast_cli_command(con->fd, tmp);
|
|
|
|
ast_cli_command(con->fd, tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fds[1].revents) {
|
|
|
|
if (FD_ISSET(con->p[0], &rfds)) {
|
|
|
|
res = read(con->p[0], tmp, sizeof(tmp));
|
|
|
|
res = read(con->p[0], tmp, sizeof(tmp));
|
|
|
|
if (res < 1) {
|
|
|
|
if (res < 1) {
|
|
|
|
ast_log(LOG_ERROR, "read returned %d\n", res);
|
|
|
|
ast_log(LOG_ERROR, "read returned %d\n", res);
|
|
|
@ -279,23 +280,23 @@ static void *netconsole(void *vconsole)
|
|
|
|
static void *listener(void *unused)
|
|
|
|
static void *listener(void *unused)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct sockaddr_un sun;
|
|
|
|
struct sockaddr_un sun;
|
|
|
|
|
|
|
|
fd_set fds;
|
|
|
|
int s;
|
|
|
|
int s;
|
|
|
|
int len;
|
|
|
|
int len;
|
|
|
|
int x;
|
|
|
|
int x;
|
|
|
|
int flags;
|
|
|
|
int flags;
|
|
|
|
struct pollfd fds[1];
|
|
|
|
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
for(;;) {
|
|
|
|
for(;;) {
|
|
|
|
if (ast_socket < 0)
|
|
|
|
if (ast_socket < 0)
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
fds[0].fd = ast_socket;
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
fds[0].events= POLLIN;
|
|
|
|
FD_SET(ast_socket, &fds);
|
|
|
|
s = poll(fds, 1, -1);
|
|
|
|
s = ast_select(ast_socket + 1, &fds, NULL, NULL, NULL);
|
|
|
|
if (s < 0) {
|
|
|
|
if (s < 0) {
|
|
|
|
if (errno != EINTR)
|
|
|
|
if (errno != EINTR)
|
|
|
|
ast_log(LOG_WARNING, "poll returned error: %s\n", strerror(errno));
|
|
|
|
ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = sizeof(sun);
|
|
|
|
len = sizeof(sun);
|
|
|
@ -396,7 +397,7 @@ static int ast_tryconnect(void)
|
|
|
|
|
|
|
|
|
|
|
|
static void urg_handler(int num)
|
|
|
|
static void urg_handler(int num)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Called by soft_hangup to interrupt the poll, read, or other
|
|
|
|
/* Called by soft_hangup to interrupt the select, read, or other
|
|
|
|
system call. We don't actually need to do anything though. */
|
|
|
|
system call. We don't actually need to do anything though. */
|
|
|
|
/* Cannot EVER ast_log from within a signal handler */
|
|
|
|
/* Cannot EVER ast_log from within a signal handler */
|
|
|
|
if (option_debug)
|
|
|
|
if (option_debug)
|
|
|
@ -627,7 +628,7 @@ static void console_verboser(const char *s, int pos, int replace, int complete)
|
|
|
|
fputs(s + pos,stdout);
|
|
|
|
fputs(s + pos,stdout);
|
|
|
|
fflush(stdout);
|
|
|
|
fflush(stdout);
|
|
|
|
if (complete)
|
|
|
|
if (complete)
|
|
|
|
/* Wake up a poll()ing console */
|
|
|
|
/* Wake up a select()ing console */
|
|
|
|
if (option_console && consolethread != AST_PTHREADT_NULL)
|
|
|
|
if (option_console && consolethread != AST_PTHREADT_NULL)
|
|
|
|
pthread_kill(consolethread, SIGURG);
|
|
|
|
pthread_kill(consolethread, SIGURG);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -820,38 +821,38 @@ static struct ast_cli_entry astbang = { { "!", NULL }, handle_bang, "Execute a s
|
|
|
|
|
|
|
|
|
|
|
|
static int ast_el_read_char(EditLine *el, char *cp)
|
|
|
|
static int ast_el_read_char(EditLine *el, char *cp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int num_read=0;
|
|
|
|
int num_read=0;
|
|
|
|
int lastpos=0;
|
|
|
|
int lastpos=0;
|
|
|
|
struct pollfd fds[2];
|
|
|
|
fd_set rfds;
|
|
|
|
int res;
|
|
|
|
int res;
|
|
|
|
int max;
|
|
|
|
int max;
|
|
|
|
char buf[512];
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
max = 1;
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
fds[0].fd = ast_consock;
|
|
|
|
FD_SET(ast_consock, &rfds);
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
max = ast_consock;
|
|
|
|
if (!option_exec) {
|
|
|
|
if (!option_exec) {
|
|
|
|
fds[1].fd = STDIN_FILENO;
|
|
|
|
FD_SET(STDIN_FILENO, &rfds);
|
|
|
|
fds[1].events = POLLIN;
|
|
|
|
if (STDIN_FILENO > max)
|
|
|
|
max++;
|
|
|
|
max = STDIN_FILENO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = poll(fds, max, -1);
|
|
|
|
res = ast_select(max+1, &rfds, NULL, NULL, NULL);
|
|
|
|
if (res < 0) {
|
|
|
|
if (res < 0) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
ast_log(LOG_ERROR, "poll failed: %s\n", strerror(errno));
|
|
|
|
ast_log(LOG_ERROR, "select failed: %s\n", strerror(errno));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!option_exec && fds[1].revents) {
|
|
|
|
if (FD_ISSET(STDIN_FILENO, &rfds)) {
|
|
|
|
num_read = read(STDIN_FILENO, cp, 1);
|
|
|
|
num_read = read(STDIN_FILENO, cp, 1);
|
|
|
|
if (num_read < 1) {
|
|
|
|
if (num_read < 1) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
return (num_read);
|
|
|
|
return (num_read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fds[0].revents) {
|
|
|
|
if (FD_ISSET(ast_consock, &rfds)) {
|
|
|
|
res = read(ast_consock, buf, sizeof(buf) - 1);
|
|
|
|
res = read(ast_consock, buf, sizeof(buf) - 1);
|
|
|
|
/* if the remote side disappears exit */
|
|
|
|
/* if the remote side disappears exit */
|
|
|
|
if (res < 1) {
|
|
|
|
if (res < 1) {
|
|
|
@ -1671,7 +1672,7 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
/* Do nothing */
|
|
|
|
/* Do nothing */
|
|
|
|
poll(NULL,0, -1);
|
|
|
|
ast_select(0,NULL,NULL,NULL,NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|