[asterisk-dev] Bug in logger.c

Paul Hewlett paul at gccs.co.za
Fri Jan 26 07:07:51 MST 2007


Can someone confirm a (minor) bug in logger.c.

It is in both 1.2.13 and trunk.

In function make_logchannel() there is a compound if statement that tests the 
'channel' var against 'console' ,'syslog', 'queue_log' and a default else 
clause. The following code is in the else clause
o========================================================================
               if (channel[0] == '/') {
                        if(!ast_strlen_zero(hostname)) {
                                snprintf(chan->filename, 
sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
                        } else {
                                ast_copy_string(chan->filename, channel, 
sizeof(chan->filename));
                        }
                }

                if(!ast_strlen_zero(hostname)) {
                        snprintf(chan->filename, 
sizeof(chan->filename), "%s/%s.%s", ast_config_AST_LOG_DIR, channel, 
hostname);
                } else {
                        snprintf(chan->filename, 
sizeof(chan->filename), "%s/%s", ast_config_AST_LOG_DIR, channel);
                }

o==========================================================================
The second if statement overrides the first one unconditionally - should it 
not be
o==========================================================================
               if (channel[0] == '/') {
                        if(!ast_strlen_zero(hostname)) {
                                snprintf(chan->filename, 
sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
                        } else {
                                ast_copy_string(chan->filename, channel, 
sizeof(chan->filename));
                        }
                }
		else {
                     if(!ast_strlen_zero(hostname)) {
                        snprintf(chan->filename, 
sizeof(chan->filename), "%s/%s.%s", ast_config_AST_LOG_DIR, channel, 
hostname);
                     } else {
                        snprintf(chan->filename, 
sizeof(chan->filename), "%s/%s", ast_config_AST_LOG_DIR, channel);
                    }
                }
o========================================================================

i.e. a missing 'else'

Also why in the first clause is there a '-1' for the length parameter - this 
is unnecessary surely...

Additionally there is a small enhancement I would propose that enables one to 
direct the log output to an unused console much like syslog outputs to the 
console on F12 viz:
==========================================================================                                                                       
char access[2] = "a";
                if (channel[0] == '/') {
                        if(!ast_strlen_zero(hostname)) {
                                snprintf(chan->filename, 
sizeof(chan->filename),"%s.%s", channel, hostname);
                        } else {
                                ast_copy_string(chan->filename, channel, 
sizeof(chan->filename));
                        }
                } else if (!strncasecmp(channel,"tty",3)) {
                        access[0] = 'w';
                        snprintf(chan->filename, 
sizeof(chan->filename),"/dev/%s", channel);
                } else {
                        if(!ast_strlen_zero(hostname)) {
                                snprintf(chan->filename, 
sizeof(chan->filename), "%s/%s.%s",(char *)ast_config_AST_LOG_DIR, channel, 
hostname);
                        } else {
                                snprintf(chan->filename, 
sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel);
                        }
                }
                chan->fileptr = fopen(chan->filename, access);

===========================================================================

-- 
Paul Hewlett  Technical Director 
Global Call Center Solutions Ltd, 2nd Floor, Milnerton Mall
Cnr Loxton & Koeberg Roads, 7435 Milnerton
paul at gccs.co.za  www.gccs.co.za
Tel: +27 86 111 3433 Fax: +27 86 111 3520 Cel: +27 76 072 7906
Gizmo: 1 747 659 6171



More information about the asterisk-dev mailing list