summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2013-09-15 18:49:36 (GMT)
committerSven Nierlein <sven@nierlein.de>2013-09-15 18:49:36 (GMT)
commitcb8390aec94e7e44180780b6e315d5363082dfef (patch)
treedfba0d3844e6322ff78110451ec0803fcc34015d
parentc900ee2772b223c3ae8c29f752b8c1a6a8c10f92 (diff)
downloadmonitoring-plugins-cb8390aec94e7e44180780b6e315d5363082dfef.tar.gz
check_tcp: use receive timeout for checks that expect response
if check_imap expects a string that never occurs, it currently waits forever because thats how the imap protocoll works. Use a receive timeout in that case so we can exit early with a proper error message.
-rw-r--r--plugins/check_tcp.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index e7342f3..6ab8261 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -39,6 +39,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
39#include "utils.h" 39#include "utils.h"
40#include "utils_tcp.h" 40#include "utils_tcp.h"
41 41
42#include <sys/select.h>
43
42#ifdef HAVE_SSL 44#ifdef HAVE_SSL
43static int check_cert = FALSE; 45static int check_cert = FALSE;
44static int days_till_exp_warn, days_till_exp_crit; 46static int days_till_exp_warn, days_till_exp_crit;
@@ -60,6 +62,7 @@ static char *SEND = NULL;
60static char *QUIT = NULL; 62static char *QUIT = NULL;
61static int PROTOCOL = IPPROTO_TCP; /* most common is default */ 63static int PROTOCOL = IPPROTO_TCP; /* most common is default */
62static int PORT = 0; 64static int PORT = 0;
65static int READ_TIMEOUT = 2;
63 66
64static int server_port = 0; 67static int server_port = 0;
65static char *server_address = NULL; 68static char *server_address = NULL;
@@ -98,8 +101,12 @@ main (int argc, char **argv)
98 int i; 101 int i;
99 char *status = NULL; 102 char *status = NULL;
100 struct timeval tv; 103 struct timeval tv;
104 struct timeval timeout;
101 size_t len; 105 size_t len;
102 int match = -1; 106 int match = -1;
107 fd_set rfds;
108
109 FD_ZERO(&rfds);
103 110
104 setlocale (LC_ALL, ""); 111 setlocale (LC_ALL, "");
105 bindtextdomain (PACKAGE, LOCALEDIR); 112 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -288,6 +295,13 @@ main (int argc, char **argv)
288 server_expect_count, 295 server_expect_count,
289 match_flags)) != NP_MATCH_RETRY) 296 match_flags)) != NP_MATCH_RETRY)
290 break; 297 break;
298
299 /* some protocols wait for further input, so make sure we don't wait forever */
300 FD_SET(sd, &rfds);
301 timeout.tv_sec = READ_TIMEOUT;
302 timeout.tv_usec = 0;
303 if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0)
304 break;
291 } 305 }
292 if (match == NP_MATCH_RETRY) 306 if (match == NP_MATCH_RETRY)
293 match = NP_MATCH_FAILURE; 307 match = NP_MATCH_FAILURE;