diff options
author | Anders Kaseorg <andersk@mit.edu> | 2012-06-29 00:57:48 -0400 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2012-06-29 13:39:11 +0200 |
commit | 028d50d6f99e647a325a0a68303016382c4bbdc9 (patch) | |
tree | 1d9a14635602169d137409becfa108cd6bdb371c /plugins/check_ups.c | |
parent | 9976876584e5a1df6e1c9315212c3d274df7a12e (diff) | |
download | monitoring-plugins-028d50d6f99e647a325a0a68303016382c4bbdc9.tar.gz |
Die when asprintf fails
Fixes many instances of
warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Diffstat (limited to 'plugins/check_ups.c')
-rw-r--r-- | plugins/check_ups.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 30c9357a..59dcc264 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -136,56 +136,56 @@ main (int argc, char **argv) | |||
136 | result = STATE_OK; | 136 | result = STATE_OK; |
137 | 137 | ||
138 | if (status & UPSSTATUS_OFF) { | 138 | if (status & UPSSTATUS_OFF) { |
139 | asprintf (&ups_status, "Off"); | 139 | xasprintf (&ups_status, "Off"); |
140 | result = STATE_CRITICAL; | 140 | result = STATE_CRITICAL; |
141 | } | 141 | } |
142 | else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) == | 142 | else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) == |
143 | (UPSSTATUS_OB | UPSSTATUS_LB)) { | 143 | (UPSSTATUS_OB | UPSSTATUS_LB)) { |
144 | asprintf (&ups_status, _("On Battery, Low Battery")); | 144 | xasprintf (&ups_status, _("On Battery, Low Battery")); |
145 | result = STATE_CRITICAL; | 145 | result = STATE_CRITICAL; |
146 | } | 146 | } |
147 | else { | 147 | else { |
148 | if (status & UPSSTATUS_OL) { | 148 | if (status & UPSSTATUS_OL) { |
149 | asprintf (&ups_status, "%s%s", ups_status, _("Online")); | 149 | xasprintf (&ups_status, "%s%s", ups_status, _("Online")); |
150 | } | 150 | } |
151 | if (status & UPSSTATUS_OB) { | 151 | if (status & UPSSTATUS_OB) { |
152 | asprintf (&ups_status, "%s%s", ups_status, _("On Battery")); | 152 | xasprintf (&ups_status, "%s%s", ups_status, _("On Battery")); |
153 | result = STATE_WARNING; | 153 | result = STATE_WARNING; |
154 | } | 154 | } |
155 | if (status & UPSSTATUS_LB) { | 155 | if (status & UPSSTATUS_LB) { |
156 | asprintf (&ups_status, "%s%s", ups_status, _(", Low Battery")); | 156 | xasprintf (&ups_status, "%s%s", ups_status, _(", Low Battery")); |
157 | result = STATE_WARNING; | 157 | result = STATE_WARNING; |
158 | } | 158 | } |
159 | if (status & UPSSTATUS_CAL) { | 159 | if (status & UPSSTATUS_CAL) { |
160 | asprintf (&ups_status, "%s%s", ups_status, _(", Calibrating")); | 160 | xasprintf (&ups_status, "%s%s", ups_status, _(", Calibrating")); |
161 | } | 161 | } |
162 | if (status & UPSSTATUS_RB) { | 162 | if (status & UPSSTATUS_RB) { |
163 | asprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery")); | 163 | xasprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery")); |
164 | result = STATE_WARNING; | 164 | result = STATE_WARNING; |
165 | } | 165 | } |
166 | if (status & UPSSTATUS_BYPASS) { | 166 | if (status & UPSSTATUS_BYPASS) { |
167 | asprintf (&ups_status, "%s%s", ups_status, _(", On Bypass")); | 167 | xasprintf (&ups_status, "%s%s", ups_status, _(", On Bypass")); |
168 | } | 168 | } |
169 | if (status & UPSSTATUS_OVER) { | 169 | if (status & UPSSTATUS_OVER) { |
170 | asprintf (&ups_status, "%s%s", ups_status, _(", Overload")); | 170 | xasprintf (&ups_status, "%s%s", ups_status, _(", Overload")); |
171 | } | 171 | } |
172 | if (status & UPSSTATUS_TRIM) { | 172 | if (status & UPSSTATUS_TRIM) { |
173 | asprintf (&ups_status, "%s%s", ups_status, _(", Trimming")); | 173 | xasprintf (&ups_status, "%s%s", ups_status, _(", Trimming")); |
174 | } | 174 | } |
175 | if (status & UPSSTATUS_BOOST) { | 175 | if (status & UPSSTATUS_BOOST) { |
176 | asprintf (&ups_status, "%s%s", ups_status, _(", Boosting")); | 176 | xasprintf (&ups_status, "%s%s", ups_status, _(", Boosting")); |
177 | } | 177 | } |
178 | if (status & UPSSTATUS_CHRG) { | 178 | if (status & UPSSTATUS_CHRG) { |
179 | asprintf (&ups_status, "%s%s", ups_status, _(", Charging")); | 179 | xasprintf (&ups_status, "%s%s", ups_status, _(", Charging")); |
180 | } | 180 | } |
181 | if (status & UPSSTATUS_DISCHRG) { | 181 | if (status & UPSSTATUS_DISCHRG) { |
182 | asprintf (&ups_status, "%s%s", ups_status, _(", Discharging")); | 182 | xasprintf (&ups_status, "%s%s", ups_status, _(", Discharging")); |
183 | } | 183 | } |
184 | if (status & UPSSTATUS_UNKOWN) { | 184 | if (status & UPSSTATUS_UNKOWN) { |
185 | asprintf (&ups_status, "%s%s", ups_status, _(", Unknown")); | 185 | xasprintf (&ups_status, "%s%s", ups_status, _(", Unknown")); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | asprintf (&message, "%sStatus=%s ", message, ups_status); | 188 | xasprintf (&message, "%sStatus=%s ", message, ups_status); |
189 | } | 189 | } |
190 | 190 | ||
191 | /* get the ups utility voltage if possible */ | 191 | /* get the ups utility voltage if possible */ |
@@ -197,7 +197,7 @@ main (int argc, char **argv) | |||
197 | supported_options |= UPS_UTILITY; | 197 | supported_options |= UPS_UTILITY; |
198 | 198 | ||
199 | ups_utility_voltage = atof (temp_buffer); | 199 | ups_utility_voltage = atof (temp_buffer); |
200 | asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); | 200 | xasprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); |
201 | 201 | ||
202 | if (ups_utility_voltage > 120.0) | 202 | if (ups_utility_voltage > 120.0) |
203 | ups_utility_deviation = 120.0 - ups_utility_voltage; | 203 | ups_utility_deviation = 120.0 - ups_utility_voltage; |
@@ -211,13 +211,13 @@ main (int argc, char **argv) | |||
211 | else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { | 211 | else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { |
212 | result = max_state (result, STATE_WARNING); | 212 | result = max_state (result, STATE_WARNING); |
213 | } | 213 | } |
214 | asprintf (&data, "%s", | 214 | xasprintf (&data, "%s", |
215 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", | 215 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", |
216 | check_warn, (long)(1000*warning_value), | 216 | check_warn, (long)(1000*warning_value), |
217 | check_crit, (long)(1000*critical_value), | 217 | check_crit, (long)(1000*critical_value), |
218 | TRUE, 0, FALSE, 0)); | 218 | TRUE, 0, FALSE, 0)); |
219 | } else { | 219 | } else { |
220 | asprintf (&data, "%s", | 220 | xasprintf (&data, "%s", |
221 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", | 221 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", |
222 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | 222 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); |
223 | } | 223 | } |
@@ -231,7 +231,7 @@ main (int argc, char **argv) | |||
231 | else { | 231 | else { |
232 | supported_options |= UPS_BATTPCT; | 232 | supported_options |= UPS_BATTPCT; |
233 | ups_battery_percent = atof (temp_buffer); | 233 | ups_battery_percent = atof (temp_buffer); |
234 | asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); | 234 | xasprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); |
235 | 235 | ||
236 | if (check_variable == UPS_BATTPCT) { | 236 | if (check_variable == UPS_BATTPCT) { |
237 | if (check_crit==TRUE && ups_battery_percent <= critical_value) { | 237 | if (check_crit==TRUE && ups_battery_percent <= critical_value) { |
@@ -240,13 +240,13 @@ main (int argc, char **argv) | |||
240 | else if (check_warn==TRUE && ups_battery_percent<=warning_value) { | 240 | else if (check_warn==TRUE && ups_battery_percent<=warning_value) { |
241 | result = max_state (result, STATE_WARNING); | 241 | result = max_state (result, STATE_WARNING); |
242 | } | 242 | } |
243 | asprintf (&data, "%s %s", data, | 243 | xasprintf (&data, "%s %s", data, |
244 | perfdata ("battery", (long)ups_battery_percent, "%", | 244 | perfdata ("battery", (long)ups_battery_percent, "%", |
245 | check_warn, (long)(1000*warning_value), | 245 | check_warn, (long)(1000*warning_value), |
246 | check_crit, (long)(1000*critical_value), | 246 | check_crit, (long)(1000*critical_value), |
247 | TRUE, 0, TRUE, 100)); | 247 | TRUE, 0, TRUE, 100)); |
248 | } else { | 248 | } else { |
249 | asprintf (&data, "%s %s", data, | 249 | xasprintf (&data, "%s %s", data, |
250 | perfdata ("battery", (long)ups_battery_percent, "%", | 250 | perfdata ("battery", (long)ups_battery_percent, "%", |
251 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); | 251 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); |
252 | } | 252 | } |
@@ -260,7 +260,7 @@ main (int argc, char **argv) | |||
260 | else { | 260 | else { |
261 | supported_options |= UPS_LOADPCT; | 261 | supported_options |= UPS_LOADPCT; |
262 | ups_load_percent = atof (temp_buffer); | 262 | ups_load_percent = atof (temp_buffer); |
263 | asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); | 263 | xasprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); |
264 | 264 | ||
265 | if (check_variable == UPS_LOADPCT) { | 265 | if (check_variable == UPS_LOADPCT) { |
266 | if (check_crit==TRUE && ups_load_percent>=critical_value) { | 266 | if (check_crit==TRUE && ups_load_percent>=critical_value) { |
@@ -269,13 +269,13 @@ main (int argc, char **argv) | |||
269 | else if (check_warn==TRUE && ups_load_percent>=warning_value) { | 269 | else if (check_warn==TRUE && ups_load_percent>=warning_value) { |
270 | result = max_state (result, STATE_WARNING); | 270 | result = max_state (result, STATE_WARNING); |
271 | } | 271 | } |
272 | asprintf (&data, "%s %s", data, | 272 | xasprintf (&data, "%s %s", data, |
273 | perfdata ("load", (long)ups_load_percent, "%", | 273 | perfdata ("load", (long)ups_load_percent, "%", |
274 | check_warn, (long)(1000*warning_value), | 274 | check_warn, (long)(1000*warning_value), |
275 | check_crit, (long)(1000*critical_value), | 275 | check_crit, (long)(1000*critical_value), |
276 | TRUE, 0, TRUE, 100)); | 276 | TRUE, 0, TRUE, 100)); |
277 | } else { | 277 | } else { |
278 | asprintf (&data, "%s %s", data, | 278 | xasprintf (&data, "%s %s", data, |
279 | perfdata ("load", (long)ups_load_percent, "%", | 279 | perfdata ("load", (long)ups_load_percent, "%", |
280 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); | 280 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); |
281 | } | 281 | } |
@@ -291,12 +291,12 @@ main (int argc, char **argv) | |||
291 | if (temp_output_c) { | 291 | if (temp_output_c) { |
292 | tunits="degC"; | 292 | tunits="degC"; |
293 | ups_temperature = atof (temp_buffer); | 293 | ups_temperature = atof (temp_buffer); |
294 | asprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); | 294 | xasprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); |
295 | } | 295 | } |
296 | else { | 296 | else { |
297 | tunits="degF"; | 297 | tunits="degF"; |
298 | ups_temperature = (atof (temp_buffer) * 1.8) + 32; | 298 | ups_temperature = (atof (temp_buffer) * 1.8) + 32; |
299 | asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); | 299 | xasprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); |
300 | } | 300 | } |
301 | 301 | ||
302 | if (check_variable == UPS_TEMP) { | 302 | if (check_variable == UPS_TEMP) { |
@@ -306,13 +306,13 @@ main (int argc, char **argv) | |||
306 | else if (check_warn == TRUE && ups_temperature>=warning_value) { | 306 | else if (check_warn == TRUE && ups_temperature>=warning_value) { |
307 | result = max_state (result, STATE_WARNING); | 307 | result = max_state (result, STATE_WARNING); |
308 | } | 308 | } |
309 | asprintf (&data, "%s %s", data, | 309 | xasprintf (&data, "%s %s", data, |
310 | perfdata ("temp", (long)ups_temperature, tunits, | 310 | perfdata ("temp", (long)ups_temperature, tunits, |
311 | check_warn, (long)(1000*warning_value), | 311 | check_warn, (long)(1000*warning_value), |
312 | check_crit, (long)(1000*critical_value), | 312 | check_crit, (long)(1000*critical_value), |
313 | TRUE, 0, FALSE, 0)); | 313 | TRUE, 0, FALSE, 0)); |
314 | } else { | 314 | } else { |
315 | asprintf (&data, "%s %s", data, | 315 | xasprintf (&data, "%s %s", data, |
316 | perfdata ("temp", (long)ups_temperature, tunits, | 316 | perfdata ("temp", (long)ups_temperature, tunits, |
317 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | 317 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); |
318 | } | 318 | } |
@@ -321,7 +321,7 @@ main (int argc, char **argv) | |||
321 | /* if the UPS does not support any options we are looking for, report an error */ | 321 | /* if the UPS does not support any options we are looking for, report an error */ |
322 | if (supported_options == UPS_NONE) { | 322 | if (supported_options == UPS_NONE) { |
323 | result = STATE_CRITICAL; | 323 | result = STATE_CRITICAL; |
324 | asprintf (&message, _("UPS does not support any available options\n")); | 324 | xasprintf (&message, _("UPS does not support any available options\n")); |
325 | } | 325 | } |
326 | 326 | ||
327 | /* reset timeout */ | 327 | /* reset timeout */ |
@@ -595,7 +595,7 @@ void | |||
595 | print_help (void) | 595 | print_help (void) |
596 | { | 596 | { |
597 | char *myport; | 597 | char *myport; |
598 | asprintf (&myport, "%d", PORT); | 598 | xasprintf (&myport, "%d", PORT); |
599 | 599 | ||
600 | print_revision (progname, NP_VERSION); | 600 | print_revision (progname, NP_VERSION); |
601 | 601 | ||