diff options
-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 e7342f35..6ab82616 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; |