summaryrefslogtreecommitdiffstats
path: root/plugins/negate.c
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-10-07 01:19:36 +0000
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-10-07 01:19:36 +0000
commit90b6597ce4c8f64b28d892960d95c8bf7ea71598 (patch)
tree9079249f09e399e08c26851a05c9a4c3004d3692 /plugins/negate.c
parent6839342c46bc0225a6b9f633551d76b567361558 (diff)
downloadmonitoring-plugins-90b6597ce4c8f64b28d892960d95c8bf7ea71598.tar.gz
use asprintf, inhibit splint warning
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@107 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/negate.c')
-rw-r--r--plugins/negate.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/plugins/negate.c b/plugins/negate.c
index b6effe39..a11558d5 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -120,17 +120,14 @@ main (int argc, char **argv)
120 usage ("Could not parse arguments"); 120 usage ("Could not parse arguments");
121 121
122 /* Set signal handling and alarm */ 122 /* Set signal handling and alarm */
123 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { 123 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR)
124 printf ("Cannot catch SIGALRM"); 124 terminate (STATE_UNKNOWN, "Cannot catch SIGALRM");
125 return STATE_UNKNOWN; 125
126 } 126 (void) alarm ((unsigned) timeout_interval);
127 alarm (timeout_interval);
128 127
129 child_process = spopen (command_line); 128 child_process = spopen (command_line);
130 if (child_process == NULL) { 129 if (child_process == NULL)
131 printf ("Could not open pipe: %s\n", command_line); 130 terminate (STATE_UNKNOWN, "Could not open pipe: %s\n", command_line);
132 exit (STATE_UNKNOWN);
133 }
134 131
135 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 132 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
136 if (child_stderr == NULL) { 133 if (child_stderr == NULL) {
@@ -139,7 +136,7 @@ main (int argc, char **argv)
139 136
140 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 137 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
141 found++; 138 found++;
142 if (index (input_buffer, '\n')) { 139 if (strchr (input_buffer, '\n')) {
143 input_buffer[strcspn (input_buffer, "\n")] = 0; 140 input_buffer[strcspn (input_buffer, "\n")] = 0;
144 printf ("%s\n", input_buffer); 141 printf ("%s\n", input_buffer);
145 } 142 }
@@ -148,11 +145,10 @@ main (int argc, char **argv)
148 } 145 }
149 } 146 }
150 147
151 if (!found) { 148 if (!found)
152 printf ("%s problem - No data recieved from host\nCMD: %s\n", argv[0], 149 terminate (STATE_UNKNOWN,\
153 command_line); 150 "%s problem - No data recieved from host\nCMD: %s\n",\
154 exit (STATE_UNKNOWN); 151 argv[0], command_line);
155 }
156 152
157 /* close the pipe */ 153 /* close the pipe */
158 result = spclose (child_process); 154 result = spclose (child_process);
@@ -165,11 +161,11 @@ main (int argc, char **argv)
165 (void) fclose (child_stderr); 161 (void) fclose (child_stderr);
166 162
167 if (result == STATE_OK) 163 if (result == STATE_OK)
168 return STATE_CRITICAL; 164 exit (STATE_CRITICAL);
169 else if (result == STATE_CRITICAL) 165 else if (result == STATE_CRITICAL)
170 return STATE_OK; 166 exit (EXIT_SUCCESS);
171 else 167 else
172 return result; 168 exit (result);
173} 169}
174 170
175 171
@@ -251,10 +247,10 @@ process_arguments (int argc, char **argv)
251 usage2 ("Unknown argument", optarg); 247 usage2 ("Unknown argument", optarg);
252 case 'h': /* help */ 248 case 'h': /* help */
253 print_help (); 249 print_help ();
254 exit (STATE_OK); 250 exit (EXIT_SUCCESS);
255 case 'V': /* version */ 251 case 'V': /* version */
256 print_revision (PROGNAME, REVISION); 252 print_revision (PROGNAME, REVISION);
257 exit (STATE_OK); 253 exit (EXIT_SUCCESS);
258 case 't': /* timeout period */ 254 case 't': /* timeout period */
259 if (!is_integer (optarg)) 255 if (!is_integer (optarg))
260 usage2 ("Timeout Interval must be an integer", optarg); 256 usage2 ("Timeout Interval must be an integer", optarg);
@@ -265,7 +261,7 @@ process_arguments (int argc, char **argv)
265 261
266 command_line = strscpy (command_line, argv[optind]); 262 command_line = strscpy (command_line, argv[optind]);
267 for (c = optind+1; c <= argc; c++) { 263 for (c = optind+1; c <= argc; c++) {
268 command_line = ssprintf (command_line, "%s %s", command_line, argv[c]); 264 asprintf (&command_line, "%s %s", command_line, argv[c]);
269 } 265 }
270 266
271 return validate_arguments (); 267 return validate_arguments ();
@@ -286,7 +282,7 @@ process_arguments (int argc, char **argv)
286int 282int
287validate_arguments () 283validate_arguments ()
288{ 284{
289 return OK; 285 return STATE_OK;
290} 286}
291 287
292 288