aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_tcp.c
diff options
context:
space:
mode:
authorGravatar Sven Nierlein <sven@nierlein.de> 2013-09-15 20:49:36 +0200
committerGravatar Sven Nierlein <sven@nierlein.de> 2013-09-15 20:49:36 +0200
commitcb8390aec94e7e44180780b6e315d5363082dfef (patch)
treedfba0d3844e6322ff78110451ec0803fcc34015d /plugins/check_tcp.c
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.
Diffstat (limited to 'plugins/check_tcp.c')
-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 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";
#include "utils.h"
#include "utils_tcp.h"
+#include <sys/select.h>
+
#ifdef HAVE_SSL
static int check_cert = FALSE;
static int days_till_exp_warn, days_till_exp_crit;
@@ -60,6 +62,7 @@ static char *SEND = NULL;
static char *QUIT = NULL;
static int PROTOCOL = IPPROTO_TCP; /* most common is default */
static int PORT = 0;
+static int READ_TIMEOUT = 2;
static int server_port = 0;
static char *server_address = NULL;
@@ -98,8 +101,12 @@ main (int argc, char **argv)
int i;
char *status = NULL;
struct timeval tv;
+ struct timeval timeout;
size_t len;
int match = -1;
+ fd_set rfds;
+
+ FD_ZERO(&rfds);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@@ -288,6 +295,13 @@ main (int argc, char **argv)
server_expect_count,
match_flags)) != NP_MATCH_RETRY)
break;
+
+ /* some protocols wait for further input, so make sure we don't wait forever */
+ FD_SET(sd, &rfds);
+ timeout.tv_sec = READ_TIMEOUT;
+ timeout.tv_usec = 0;
+ if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0)
+ break;
}
if (match == NP_MATCH_RETRY)
match = NP_MATCH_FAILURE;