[monitoring-plugins] Revert to poor man's logic

RincewindsHat git at monitoring-plugins.org
Sun Oct 3 13:40:11 CEST 2021


 Module: monitoring-plugins
 Branch: master
 Commit: 46c5327e348540ab04dc37d42f6d1c5408179fa6
 Author: RincewindsHat <12514511+RincewindsHat at users.noreply.github.com>
   Date: Sat Oct  2 23:37:12 2021 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=46c5327

Revert to poor man's logic

---

 plugins/check_swap.c | 13 ++++++-------
 plugins/utils.c      | 16 ++++++++--------
 plugins/utils.h      |  5 ++---
 3 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 4d124a3..685c2cc 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -37,7 +37,6 @@ const char *email = "devel at monitoring-plugins.org";
 #include <string.h>
 #include <math.h>
 #include <libintl.h>
-#include <stdbool.h>
 
 #ifdef HAVE_DECL_SWAPCTL
 # ifdef HAVE_SYS_PARAM_H
@@ -56,7 +55,7 @@ const char *email = "devel at monitoring-plugins.org";
 #endif
 
 typedef struct {
-	bool is_percentage;
+	int is_percentage;
 	uint64_t value;
 } threshold_t;
 
@@ -69,7 +68,7 @@ void print_help (void);
 threshold_t warn;
 threshold_t crit;
 int verbose;
-bool allswaps;
+int allswaps;
 int no_swap_state = STATE_CRITICAL;
 
 int
@@ -467,7 +466,7 @@ process_arguments (int argc, char **argv)
 
 				if (optarg[length - 1] == '%') {
 					/* It's percentage */
-					warn.is_percentage = true;
+					warn.is_percentage = 1;
 					optarg[length - 1] = '\0';
 					if (is_uint64(optarg, &warn.value)) {
 						if (warn.value > 100) {
@@ -478,7 +477,7 @@ process_arguments (int argc, char **argv)
 					}
 				} else {
 					/* It's Bytes */
-					warn.is_percentage = false;
+					warn.is_percentage = 0;
 					if (is_uint64(optarg, &warn.value)) {
 						break;
 					} else {
@@ -498,7 +497,7 @@ process_arguments (int argc, char **argv)
 
 				if (optarg[length - 1] == '%') {
 					/* It's percentage */
-					crit.is_percentage = true;
+					crit.is_percentage = 1;
 					optarg[length - 1] = '\0';
 					if (is_uint64(optarg, &crit.value)) {
 						if (crit.value> 100) {
@@ -509,7 +508,7 @@ process_arguments (int argc, char **argv)
 					}
 				} else {
 					/* It's Bytes */
-					crit.is_percentage = false;
+					crit.is_percentage = 0;
 					if (is_uint64(optarg, &crit.value)) {
 						break;
 					} else {
diff --git a/plugins/utils.c b/plugins/utils.c
index 011f715..f7f8952 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -246,19 +246,19 @@ is_intnonneg (char *number)
  * On success the number will be written to the _target_ address, if _target_ is not set
  * to NULL.
  */
-bool is_int64(char *number, int64_t *target) {
+int is_int64(char *number, int64_t *target) {
 	errno = 0;
 	uint64_t tmp = strtoll(number, NULL, 10);
 	if (errno != 0) {
-		return false;
+		return 0;
 	}
 	if (tmp < INT64_MIN || tmp > INT64_MAX) {
-		return false;
+		return 0;
 	}
 	if (target != NULL) {
 		*target = tmp;
 	}
-	return true;
+	return 1;
 }
 
 /*
@@ -266,19 +266,19 @@ bool is_int64(char *number, int64_t *target) {
  * On success the number will be written to the _target_ address, if _target_ is not set
  * to NULL.
  */
-bool is_uint64(char *number, uint64_t *target) {
+int is_uint64(char *number, uint64_t *target) {
 	errno = 0;
 	uint64_t tmp = strtoll(number, NULL, 10);
 	if (errno != 0) {
-		return false;
+		return 0;
 	}
 	if (tmp < 0 || tmp > UINT64_MAX) {
-		return false;
+		return 0;
 	}
 	if (target != NULL) {
 		*target = tmp;
 	}
-	return true;
+	return 1;
 }
 
 int
diff --git a/plugins/utils.h b/plugins/utils.h
index 91a9c3f..5b54da3 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -17,8 +17,6 @@ suite of plugins. */
 #include "utils_base.h"
 
 
-#include <stdbool.h>
-
 #ifdef NP_EXTRA_OPTS
 /* Include extra-opts functions if compiled in */
 #include "extra_opts.h"
@@ -41,7 +39,8 @@ int is_intpos (char *);
 int is_intneg (char *);
 int is_intnonneg (char *);
 int is_intpercent (char *);
-bool is_uint64(char *number, uint64_t *target);
+int is_uint64(char *number, uint64_t *target);
+int is_int64(char *number, int64_t *target);
 
 int is_numeric (char *);
 int is_positive (char *);



More information about the Commits mailing list