diff options
Diffstat (limited to 'plugins/check_tcp.c')
-rw-r--r-- | plugins/check_tcp.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index a1a14b4..01dd35e 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -70,7 +70,7 @@ static char *server_send = NULL; | |||
70 | static char *server_quit = NULL; | 70 | static char *server_quit = NULL; |
71 | static char **server_expect; | 71 | static char **server_expect; |
72 | static size_t server_expect_count = 0; | 72 | static size_t server_expect_count = 0; |
73 | static size_t maxbytes = 0; | 73 | static ssize_t maxbytes = 0; |
74 | static char **warn_codes = NULL; | 74 | static char **warn_codes = NULL; |
75 | static size_t warn_codes_count = 0; | 75 | static size_t warn_codes_count = 0; |
76 | static char **crit_codes = NULL; | 76 | static char **crit_codes = NULL; |
@@ -102,11 +102,9 @@ int | |||
102 | main (int argc, char **argv) | 102 | main (int argc, char **argv) |
103 | { | 103 | { |
104 | int result = STATE_UNKNOWN; | 104 | int result = STATE_UNKNOWN; |
105 | int i; | ||
106 | char *status = NULL; | 105 | char *status = NULL; |
107 | struct timeval tv; | 106 | struct timeval tv; |
108 | struct timeval timeout; | 107 | struct timeval timeout; |
109 | size_t len; | ||
110 | int match = -1; | 108 | int match = -1; |
111 | fd_set rfds; | 109 | fd_set rfds; |
112 | 110 | ||
@@ -121,10 +119,10 @@ main (int argc, char **argv) | |||
121 | if(progname != NULL) progname++; | 119 | if(progname != NULL) progname++; |
122 | else progname = argv[0]; | 120 | else progname = argv[0]; |
123 | 121 | ||
124 | len = strlen(progname); | 122 | size_t prog_name_len = strlen(progname); |
125 | if(len > 6 && !memcmp(progname, "check_", 6)) { | 123 | if(prog_name_len > 6 && !memcmp(progname, "check_", 6)) { |
126 | SERVICE = strdup(progname + 6); | 124 | SERVICE = strdup(progname + 6); |
127 | for(i = 0; i < len - 6; i++) | 125 | for(size_t i = 0; i < prog_name_len - 6; i++) |
128 | SERVICE[i] = toupper(SERVICE[i]); | 126 | SERVICE[i] = toupper(SERVICE[i]); |
129 | } | 127 | } |
130 | 128 | ||
@@ -275,19 +273,21 @@ main (int argc, char **argv) | |||
275 | printf("Quit string: %s\n", server_quit); | 273 | printf("Quit string: %s\n", server_quit); |
276 | } | 274 | } |
277 | printf("server_expect_count: %d\n", (int)server_expect_count); | 275 | printf("server_expect_count: %d\n", (int)server_expect_count); |
278 | for(i = 0; i < server_expect_count; i++) | 276 | for(size_t i = 0; i < server_expect_count; i++) |
279 | printf("\t%d: %s\n", i, server_expect[i]); | 277 | printf("\t%zd: %s\n", i, server_expect[i]); |
280 | } | 278 | } |
281 | 279 | ||
282 | /* if(len) later on, we know we have a non-NULL response */ | 280 | /* if(len) later on, we know we have a non-NULL response */ |
283 | len = 0; | 281 | ssize_t len = 0; |
282 | |||
284 | if (server_expect_count) { | 283 | if (server_expect_count) { |
284 | ssize_t received = 0; | ||
285 | 285 | ||
286 | /* watch for the expect string */ | 286 | /* watch for the expect string */ |
287 | while ((i = my_recv(buffer, sizeof(buffer))) > 0) { | 287 | while ((received = my_recv(buffer, sizeof(buffer))) > 0) { |
288 | status = realloc(status, len + i + 1); | 288 | status = realloc(status, len + received + 1); |
289 | memcpy(&status[len], buffer, i); | 289 | memcpy(&status[len], buffer, received); |
290 | len += i; | 290 | len += received; |
291 | status[len] = '\0'; | 291 | status[len] = '\0'; |
292 | 292 | ||
293 | /* stop reading if user-forced */ | 293 | /* stop reading if user-forced */ |
@@ -307,6 +307,7 @@ main (int argc, char **argv) | |||
307 | if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0) | 307 | if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0) |
308 | break; | 308 | break; |
309 | } | 309 | } |
310 | |||
310 | if (match == NP_MATCH_RETRY) | 311 | if (match == NP_MATCH_RETRY) |
311 | match = NP_MATCH_FAILURE; | 312 | match = NP_MATCH_FAILURE; |
312 | 313 | ||