[Asterisk-Dev] bug in remote console?

Jared Smith jsmith at drgutah.com
Mon Sep 15 08:25:40 MST 2003


Could you please post this as a "feature" along with the patch to
bugs.digium.com?  You'll also need to fax a disclaimer to Digium so that
they can incorporate the change into their software.


(It'll serve two purposes:  One, it'll make the patch easier to find. 
Two, it'll have a better chance of making it into CVS.)

Jared Smith

On Sun, 2003-09-14 at 20:41, Jason Ferrara wrote:
> 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
> 
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev




More information about the asterisk-dev mailing list