diff options
author | Sven Nierlein <sven@nierlein.de> | 2013-09-15 18:49:36 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2013-09-15 18:49:36 (GMT) |
commit | cb8390aec94e7e44180780b6e315d5363082dfef (patch) | |
tree | dfba0d3844e6322ff78110451ec0803fcc34015d | |
parent | c900ee2772b223c3ae8c29f752b8c1a6a8c10f92 (diff) | |
download | monitoring-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.c | 14 |
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 |
43 | static int check_cert = FALSE; | 45 | static int check_cert = FALSE; |
44 | static int days_till_exp_warn, days_till_exp_crit; | 46 | static int days_till_exp_warn, days_till_exp_crit; |
@@ -60,6 +62,7 @@ static char *SEND = NULL; | |||
60 | static char *QUIT = NULL; | 62 | static char *QUIT = NULL; |
61 | static int PROTOCOL = IPPROTO_TCP; /* most common is default */ | 63 | static int PROTOCOL = IPPROTO_TCP; /* most common is default */ |
62 | static int PORT = 0; | 64 | static int PORT = 0; |
65 | static int READ_TIMEOUT = 2; | ||
63 | 66 | ||
64 | static int server_port = 0; | 67 | static int server_port = 0; |
65 | static char *server_address = NULL; | 68 | static 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; |