[Asterisk-Dev] bug in remote console?

Jason Ferrara jason at discordia.org
Sun Sep 14 19:41:34 MST 2003


I found what appears to be a bug in the remote console code. I was 
trying to control asterisk
from another program via /var/run/asterisk.ctl, and found that if I 
sent two or more commands
in a row quickly, most of the commands would just sort of dissapear. 
The would not get
executed, and there would be no error message.

Looking in static void *netconsole(void *vconsole) in asterisk.c there 
is

		if (FD_ISSET(con->fd, &rfds)) {
			res = read(con->fd, tmp, sizeof(tmp));
			if (res < 1) {
				break;
			}
			tmp[res] = 0;
			ast_cli_command(con->fd, tmp);
		}

It appears that its assumed each read call will get one complete (and 
only one)
command. I don't believe thats a valid assumption. Should the code look 
more
like this?

		if (FD_ISSET(con->fd, &rfds)) {
			res = read(con->fd, tmp, sizeof(tmp));
			if (res < 1) {
				break;
			}
			j=0;
			while(j<res)
			{
				for(i=j; i<res; i++)
				{
					cmdbuf[cmdbufpos] = tmp[i];
					cmdbufpos++;
					if (cmdbuf[cmdbufpos-1]==0)
					{
						i++;
						break;
					}
				}
				j=i;
				if (cmdbuf[cmdbufpos-1]==0)
				{
					cmdbufpos = 0;
					ast_cli_command(con->fd, cmdbuf);
				}
			}
		}



If I make this change I can send commands to asterisk quickly without
them disappearing, and nothing else seems to break.

- Jason




More information about the asterisk-dev mailing list