From 2ab504386c324a382c83495c991cb60747d0950d Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Fri, 7 Mar 2003 07:17:26 +0000 Subject: whole timer loop was on the wrong side of connection close code git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@373 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_smtp.c | 53 +++++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index d8b90597..8c0a246e 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -79,7 +79,7 @@ int main (int argc, char **argv) { int sd; - int result; + int result = STATE_UNKNOWN; char buffer[MAX_INPUT_BUFFER] = ""; char *from_str = NULL; char *helocmd = NULL; @@ -114,20 +114,15 @@ main (int argc, char **argv) /* we connected, so close connection before exiting */ if (result == STATE_OK) { - /* watch for the SMTP connection string */ - result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); - - /* strip the buffer of carriage returns */ - strip (buffer); - + /* watch for the SMTP connection string and */ /* return a WARNING status if we couldn't read any data */ - if (result == -1) { + if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) == -1) { printf ("recv() failed\n"); result = STATE_WARNING; } - else { - + /* strip the buffer of carriage returns */ + strip (buffer); /* make sure we find the response we are looking for */ if (!strstr (buffer, server_expect)) { if (server_port == SMTP_PORT) @@ -137,32 +132,9 @@ main (int argc, char **argv) server_port); result = STATE_WARNING; } - - else { - - time (&end_time); - - result = STATE_OK; - - if (check_critical_time == TRUE - && (end_time - start_time) > critical_time) result = - STATE_CRITICAL; - else if (check_warning_time == TRUE - && (end_time - start_time) > warning_time) result = - STATE_WARNING; - - 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)); - } } - /* close the connection */ - - /* first send the HELO command */ + /* send the HELO command */ send(sd, helocmd, strlen(helocmd), 0); /* allow for response to helo command to reach us */ @@ -188,6 +160,19 @@ main (int argc, char **argv) /* reset the alarm */ alarm (0); + time (&end_time); + + if (check_critical_time == TRUE && (end_time - start_time) > critical_time) + result = STATE_CRITICAL; + else if (check_warning_time == TRUE && (end_time - start_time) > warning_time) + result = STATE_WARNING; + + 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)); + return result; } -- cgit v1.2.3-74-g34f1