summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 16:21:31 (GMT)
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 16:21:31 (GMT)
commitddbabaa3b659bed9dcf5c5a2bfc430fb816277c7 (patch)
tree0d0980d41f95385cc0137ec86e7a1cea0065e04c /lib/utils_base.c
parent4b9d90f31c700298185aa4c7b20fe1c5e8bf19c2 (diff)
downloadmonitoring-plugins-ddbabaa3b659bed9dcf5c5a2bfc430fb816277c7.tar.gz
Replace all old school booleans in lib witch C99 onesrefs/pull/1937/head
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index eabcd7e..3c7221c 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -40,7 +40,7 @@ monitoring_plugin *this_monitoring_plugin=NULL;
40unsigned int timeout_state = STATE_CRITICAL; 40unsigned int timeout_state = STATE_CRITICAL;
41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; 41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
42 42
43int _np_state_read_file(FILE *); 43bool _np_state_read_file(FILE *);
44 44
45void np_init( char *plugin_name, int argc, char **argv ) { 45void np_init( char *plugin_name, int argc, char **argv ) {
46 if (this_monitoring_plugin==NULL) { 46 if (this_monitoring_plugin==NULL) {
@@ -105,12 +105,12 @@ die (int result, const char *fmt, ...)
105 105
106void set_range_start (range *this, double value) { 106void set_range_start (range *this, double value) {
107 this->start = value; 107 this->start = value;
108 this->start_infinity = FALSE; 108 this->start_infinity = false;
109} 109}
110 110
111void set_range_end (range *this, double value) { 111void set_range_end (range *this, double value) {
112 this->end = value; 112 this->end = value;
113 this->end_infinity = FALSE; 113 this->end_infinity = false;
114} 114}
115 115
116range 116range
@@ -124,9 +124,9 @@ range
124 124
125 /* Set defaults */ 125 /* Set defaults */
126 temp_range->start = 0; 126 temp_range->start = 0;
127 temp_range->start_infinity = FALSE; 127 temp_range->start_infinity = false;
128 temp_range->end = 0; 128 temp_range->end = 0;
129 temp_range->end_infinity = TRUE; 129 temp_range->end_infinity = true;
130 temp_range->alert_on = OUTSIDE; 130 temp_range->alert_on = OUTSIDE;
131 temp_range->text = strdup(str); 131 temp_range->text = strdup(str);
132 132
@@ -138,7 +138,7 @@ range
138 end_str = index(str, ':'); 138 end_str = index(str, ':');
139 if (end_str != NULL) { 139 if (end_str != NULL) {
140 if (str[0] == '~') { 140 if (str[0] == '~') {
141 temp_range->start_infinity = TRUE; 141 temp_range->start_infinity = true;
142 } else { 142 } else {
143 start = strtod(str, NULL); /* Will stop at the ':' */ 143 start = strtod(str, NULL); /* Will stop at the ':' */
144 set_range_start(temp_range, start); 144 set_range_start(temp_range, start);
@@ -152,8 +152,8 @@ range
152 set_range_end(temp_range, end); 152 set_range_end(temp_range, end);
153 } 153 }
154 154
155 if (temp_range->start_infinity == TRUE || 155 if (temp_range->start_infinity == true ||
156 temp_range->end_infinity == TRUE || 156 temp_range->end_infinity == true ||
157 temp_range->start <= temp_range->end) { 157 temp_range->start <= temp_range->end) {
158 return temp_range; 158 return temp_range;
159 } 159 }
@@ -223,31 +223,30 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) {
223 printf("\n"); 223 printf("\n");
224} 224}
225 225
226/* Returns TRUE if alert should be raised based on the range */ 226/* Returns true if alert should be raised based on the range */
227int 227bool check_range(double value, range *my_range)
228check_range(double value, range *my_range)
229{ 228{
230 int no = FALSE; 229 bool no = false;
231 int yes = TRUE; 230 bool yes = true;
232 231
233 if (my_range->alert_on == INSIDE) { 232 if (my_range->alert_on == INSIDE) {
234 no = TRUE; 233 no = true;
235 yes = FALSE; 234 yes = false;
236 } 235 }
237 236
238 if (my_range->end_infinity == FALSE && my_range->start_infinity == FALSE) { 237 if (my_range->end_infinity == false && my_range->start_infinity == false) {
239 if ((my_range->start <= value) && (value <= my_range->end)) { 238 if ((my_range->start <= value) && (value <= my_range->end)) {
240 return no; 239 return no;
241 } else { 240 } else {
242 return yes; 241 return yes;
243 } 242 }
244 } else if (my_range->start_infinity == FALSE && my_range->end_infinity == TRUE) { 243 } else if (my_range->start_infinity == false && my_range->end_infinity == true) {
245 if (my_range->start <= value) { 244 if (my_range->start <= value) {
246 return no; 245 return no;
247 } else { 246 } else {
248 return yes; 247 return yes;
249 } 248 }
250 } else if (my_range->start_infinity == TRUE && my_range->end_infinity == FALSE) { 249 } else if (my_range->start_infinity == true && my_range->end_infinity == false) {
251 if (value <= my_range->end) { 250 if (value <= my_range->end) {
252 return no; 251 return no;
253 } else { 252 } else {
@@ -263,12 +262,12 @@ int
263get_status(double value, thresholds *my_thresholds) 262get_status(double value, thresholds *my_thresholds)
264{ 263{
265 if (my_thresholds->critical != NULL) { 264 if (my_thresholds->critical != NULL) {
266 if (check_range(value, my_thresholds->critical) == TRUE) { 265 if (check_range(value, my_thresholds->critical) == true) {
267 return STATE_CRITICAL; 266 return STATE_CRITICAL;
268 } 267 }
269 } 268 }
270 if (my_thresholds->warning != NULL) { 269 if (my_thresholds->warning != NULL) {
271 if (check_range(value, my_thresholds->warning) == TRUE) { 270 if (check_range(value, my_thresholds->warning) == true) {
272 return STATE_WARNING; 271 return STATE_WARNING;
273 } 272 }
274 } 273 }
@@ -465,7 +464,7 @@ char* _np_state_calculate_location_prefix(){
465 464
466 /* Do not allow passing MP_STATE_PATH in setuid plugins 465 /* Do not allow passing MP_STATE_PATH in setuid plugins
467 * for security reasons */ 466 * for security reasons */
468 if (mp_suid() == FALSE) { 467 if (!mp_suid()) {
469 env_dir = getenv("MP_STATE_PATH"); 468 env_dir = getenv("MP_STATE_PATH");
470 if(env_dir && env_dir[0] != '\0') 469 if(env_dir && env_dir[0] != '\0')
471 return env_dir; 470 return env_dir;
@@ -541,7 +540,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
541state_data *np_state_read() { 540state_data *np_state_read() {
542 state_data *this_state_data=NULL; 541 state_data *this_state_data=NULL;
543 FILE *statefile; 542 FILE *statefile;
544 int rc = FALSE; 543 bool rc = false;
545 544
546 if(this_monitoring_plugin==NULL) 545 if(this_monitoring_plugin==NULL)
547 die(STATE_UNKNOWN, _("This requires np_init to be called")); 546 die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -563,7 +562,7 @@ state_data *np_state_read() {
563 fclose(statefile); 562 fclose(statefile);
564 } 563 }
565 564
566 if(rc==FALSE) { 565 if(!rc) {
567 _cleanup_state_data(); 566 _cleanup_state_data();
568 } 567 }
569 568
@@ -573,8 +572,8 @@ state_data *np_state_read() {
573/* 572/*
574 * Read the state file 573 * Read the state file
575 */ 574 */
576int _np_state_read_file(FILE *f) { 575bool _np_state_read_file(FILE *f) {
577 int status=FALSE; 576 bool status = false;
578 size_t pos; 577 size_t pos;
579 char *line; 578 char *line;
580 int i; 579 int i;
@@ -628,7 +627,7 @@ int _np_state_read_file(FILE *f) {
628 if(this_monitoring_plugin->state->state_data->data==NULL) 627 if(this_monitoring_plugin->state->state_data->data==NULL)
629 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 628 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
630 expected=STATE_DATA_END; 629 expected=STATE_DATA_END;
631 status=TRUE; 630 status=true;
632 break; 631 break;
633 case STATE_DATA_END: 632 case STATE_DATA_END:
634 ; 633 ;