[Nagiosplug-devel] BUG Report with Patch (check_smtp)

Stephen Carpenter scarpe01 at usg.tufts.edu
Tue Mar 4 14:13:09 CET 2003


Ok...well I guess I can browse the bugs through the sourceforge
interface but I am not 37337 enough to actually file bugs. Fine...
well I found one and I fixed it. 

Anyway... there is a race condition in check_smtp

Here goes... check_smtp connects to the server and gets the banner.
At this point it sends back its OK and sets its return code to
be STATE_OK...

Then it procedes to close down the connection. However the alarm
signal counter is still counting down. So if the HELO takes too 
long, then the signal handler wins the race and exits with 
a 2 (note the 2...look at the signal handler code... naughty 
not following your own coding standards its hard coded as a 2 :P )
and a message that says "SMTP OK"

I solved this by moving the print statment down to the end
AFTER the "alarm(0)" that resets the alarm counter, thus removing
the race condition.

I chose to solve it this way because it catches the condition of the
mail server being horked but still giving a banner (at least for some
definitions of horked) we actually had this problem recently.

The diff is attached

-Steve
-- 
"The Creation of the Universe was made possible by a grant from Texas 
Instruments. "
                -- PBS 
-------------- next part --------------
Index: check_smtp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_smtp.c,v
retrieving revision 1.9
diff -r1.9 check_smtp.c
154,159d153
<                               if (verbose == TRUE)
<                                       printf ("SMTP %s - %d sec. response time, %s\n",
<                                                                       state_text (result), (int) (end_time - start_time), buffer);
<                               else
<                                       printf ("SMTP %s - %d second response time\n", state_text (result),
<                                                                       (int) (end_time - start_time));
189a184,189
>       if (verbose == TRUE)
>               printf ("SMTP %s - %d sec. response time, %s\n",
>                                               state_text (result), (int) (end_time - start_time), buffer);
>       else
>               printf ("SMTP %s - %d second response time\n", state_text (result),
>                                               (int) (end_time - start_time));


More information about the Devel mailing list