summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/negate.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/plugins/negate.c b/plugins/negate.c
index 82a5548..7e52fe6 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -41,10 +41,8 @@ const char *email = "devel@monitoring-plugins.org";
41 41
42#include <ctype.h> 42#include <ctype.h>
43 43
44/* char *command_line; */ 44static const char **process_arguments(int /*argc*/, char ** /*argv*/);
45 45static void validate_arguments(char ** /*command_line*/);
46static const char **process_arguments(int, char **);
47static void validate_arguments(char **);
48static void print_help(void); 46static void print_help(void);
49void print_usage(void); 47void print_usage(void);
50static bool subst_text = false; 48static bool subst_text = false;
@@ -57,18 +55,13 @@ static int state[4] = {
57}; 55};
58 56
59int main(int argc, char **argv) { 57int main(int argc, char **argv) {
60 int result = STATE_UNKNOWN;
61 char *sub;
62 char **command_line;
63 output chld_out, chld_err;
64
65 setlocale(LC_ALL, ""); 58 setlocale(LC_ALL, "");
66 bindtextdomain(PACKAGE, LOCALEDIR); 59 bindtextdomain(PACKAGE, LOCALEDIR);
67 textdomain(PACKAGE); 60 textdomain(PACKAGE);
68 61
69 timeout_interval = DEFAULT_TIMEOUT; 62 timeout_interval = DEFAULT_TIMEOUT;
70 63
71 command_line = (char **)process_arguments(argc, argv); 64 char **command_line = (char **)process_arguments(argc, argv);
72 65
73 /* Set signal handling and alarm */ 66 /* Set signal handling and alarm */
74 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) 67 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR)
@@ -76,6 +69,10 @@ int main(int argc, char **argv) {
76 69
77 (void)alarm((unsigned)timeout_interval); 70 (void)alarm((unsigned)timeout_interval);
78 71
72 int result = STATE_UNKNOWN;
73 output chld_out;
74 output chld_err;
75
79 /* catch when the command is quoted */ 76 /* catch when the command is quoted */
80 if (command_line[1] == NULL) { 77 if (command_line[1] == NULL) {
81 result = cmd_run(command_line[0], &chld_out, &chld_err, 0); 78 result = cmd_run(command_line[0], &chld_out, &chld_err, 0);
@@ -92,6 +89,7 @@ int main(int argc, char **argv) {
92 if (chld_out.lines == 0) 89 if (chld_out.lines == 0)
93 die(max_state_alt(result, STATE_UNKNOWN), _("No data returned from command\n")); 90 die(max_state_alt(result, STATE_UNKNOWN), _("No data returned from command\n"));
94 91
92 char *sub;
95 for (size_t i = 0; i < chld_out.lines; i++) { 93 for (size_t i = 0; i < chld_out.lines; i++) {
96 if (subst_text && result >= 0 && result <= 4 && result != state[result]) { 94 if (subst_text && result >= 0 && result <= 4 && result != state[result]) {
97 /* Loop over each match found */ 95 /* Loop over each match found */
@@ -115,23 +113,21 @@ int main(int argc, char **argv) {
115 113
116/* process command-line arguments */ 114/* process command-line arguments */
117static const char **process_arguments(int argc, char **argv) { 115static const char **process_arguments(int argc, char **argv) {
118 int c;
119 bool permute = true;
120
121 int option = 0;
122 static struct option longopts[] = {{"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, 116 static struct option longopts[] = {{"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'},
123 {"timeout", required_argument, 0, 't'}, {"timeout-result", required_argument, 0, 'T'}, 117 {"timeout", required_argument, 0, 't'}, {"timeout-result", required_argument, 0, 'T'},
124 {"ok", required_argument, 0, 'o'}, {"warning", required_argument, 0, 'w'}, 118 {"ok", required_argument, 0, 'o'}, {"warning", required_argument, 0, 'w'},
125 {"critical", required_argument, 0, 'c'}, {"unknown", required_argument, 0, 'u'}, 119 {"critical", required_argument, 0, 'c'}, {"unknown", required_argument, 0, 'u'},
126 {"substitute", no_argument, 0, 's'}, {0, 0, 0, 0}}; 120 {"substitute", no_argument, 0, 's'}, {0, 0, 0, 0}};
127 121
128 while (1) { 122 bool permute = true;
129 c = getopt_long(argc, argv, "+hVt:T:o:w:c:u:s", longopts, &option); 123 while (true) {
124 int option = 0;
125 int option_char = getopt_long(argc, argv, "+hVt:T:o:w:c:u:s", longopts, &option);
130 126
131 if (c == -1 || c == EOF) 127 if (option_char == -1 || option_char == EOF)
132 break; 128 break;
133 129
134 switch (c) { 130 switch (option_char) {
135 case '?': /* help */ 131 case '?': /* help */
136 usage5(); 132 usage5();
137 break; 133 break;