#include <asterisk/ulaw.h>
#include <asterisk/callerid.h>
#include <asterisk/module.h>
+#include <asterisk/image.h>
+#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <sched.h>
}
if (FD_ISSET(con->fd, &rfds)) {
res = read(con->fd, tmp, sizeof(tmp));
- if (res < 1)
+ if (res < 1) {
break;
+ }
tmp[res] = 0;
ast_cli_command(con->fd, tmp);
}
int s;
int len;
int x;
+ int flags;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
} else {
for (x=0;x<AST_MAX_CONNECTS;x++) {
if (consoles[x].fd < 0) {
- if (pipe(consoles[x].p)) {
+ if (socketpair(AF_LOCAL, SOCK_STREAM, 0, consoles[x].p)) {
ast_log(LOG_ERROR, "Unable to create pipe: %s\n", strerror(errno));
consoles[x].fd = -1;
fdprint(s, "Server failed to create pipe\n");
close(s);
break;
}
+ flags = fcntl(consoles[x].p[1], F_GETFL);
+ fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
consoles[x].fd = s;
if (pthread_create(&consoles[x].t, &attr, netconsole, &consoles[x])) {
ast_log(LOG_ERROR, "Unable to spawn thread to handle connection\n");
exit(1);
if (init_logger())
exit(1);
+ if (ast_image_init())
+ exit(1);
if (load_pbx())
exit(1);
if (load_modules())
exit(1);
+ if (init_framer())
+ exit(1);
/* We might have the option of showing a console, but for now just
do nothing... */
if (option_console && !option_verbose)
{
if (argc != 2)
return RESULT_SHOWUSAGE;
- ast_cli(fd, VERSION_INFO);
+ ast_cli(fd, "%s\n", VERSION_INFO);
return RESULT_SUCCESS;
}
static int handle_chanlist(int fd, int argc, char *argv[])
{ { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help },
{ { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch },
{ { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help },
- { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },
+ { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },
+ { { "show", "version", NULL }, handle_version, "Display version info", version_help },
{ { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch },
{ { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
- { { "version", NULL }, handle_version, "Display version info", version_help },
{ { NULL }, NULL, NULL, NULL }
};
ast_pthread_mutex_lock(&clilock);
join2(fulle, sizeof(fulle), e->cmda);
if (find_cli(e->cmda, -1)) {
- ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
ast_pthread_mutex_unlock(&clilock);
+ ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
return -1;
}
cur = helpers;
join(fullcmd2, sizeof(fullcmd2), e2->cmda);
if (e1->cmda[0])
join(fullcmd1, sizeof(fullcmd1), e1->cmda);
- if (!e1->cmda ||
+ if (!e1->cmda[0] ||
(e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
/* Use e2 */
e = e2;