|
|
@@ -53,32 +53,44 @@ socket_timeout_alarm_handler (int sig)
|
|
|
exit (socket_timeout_state);
|
|
|
}
|
|
|
|
|
|
+void
|
|
|
+set_socket_timeout_state (char *state) {
|
|
|
+ if ((socket_timeout_state = translate_state(state)) == ERROR)
|
|
|
+ usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
|
|
+}
|
|
|
+
|
|
|
int
|
|
|
parse_socket_timeout_string (char *timeout_str)
|
|
|
{
|
|
|
- char *seperated_str;
|
|
|
- int timeout_value;
|
|
|
- if ( strstr(timeout_str, ":") == NULL) {
|
|
|
- return atoi(timeout_str);
|
|
|
+ char *seperated_str;
|
|
|
+ char *timeout_val = "";
|
|
|
+ char *timeout_sta;
|
|
|
+ if ( strstr(timeout_str, ":" ) == NULL) {
|
|
|
+ timeout_val = timeout_str;
|
|
|
+ } else if ( strncmp(timeout_str, ":", 1 ) == 0) {
|
|
|
+ seperated_str = strtok(timeout_str, ":");
|
|
|
+ if ( seperated_str != NULL ) {
|
|
|
+ timeout_sta = seperated_str;
|
|
|
+ }
|
|
|
} else {
|
|
|
- seperated_str = strtok(timeout_str, ":");
|
|
|
- timeout_value = atoi(seperated_str);
|
|
|
+ seperated_str = strtok(timeout_str, ":");
|
|
|
+ timeout_val = seperated_str;
|
|
|
seperated_str = strtok(NULL, ":");
|
|
|
-
|
|
|
if (seperated_str != NULL) {
|
|
|
- set_socket_timeout_state(seperated_str);
|
|
|
- }
|
|
|
-
|
|
|
- if (timeout_value != NULL) {
|
|
|
- return timeout_value;
|
|
|
+ timeout_sta = seperated_str;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-void
|
|
|
-set_socket_timeout_state (char *state) {
|
|
|
- if ((socket_timeout_state = translate_state(state)) == ERROR)
|
|
|
- usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
|
|
+ if ( timeout_sta != NULL ) {
|
|
|
+ set_socket_timeout_state(timeout_sta);
|
|
|
+ }
|
|
|
+ if (( timeout_val == NULL ) || ( timeout_val[0] == '\0' )) {
|
|
|
+ return socket_timeout;
|
|
|
+ } else if (is_intpos(timeout_val)) {
|
|
|
+ return atoi(timeout_val);
|
|
|
+ } else {
|
|
|
+ usage4 (_("Socket timeout value must be a positive integer"));
|
|
|
+ exit (STATE_UNKNOWN);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* connects to a host on a specified tcp port, sends a string, and gets a
|