From 9679551b20acdc8306a11e6c7d9dbc4f15e90967 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:37:19 +0100 Subject: check_swap: stricter error handling --- plugins/check_swap.d/swap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'plugins/check_swap.d/swap.c') diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c index 17c4f73b..6c94b33a 100644 --- a/plugins/check_swap.d/swap.c +++ b/plugins/check_swap.d/swap.c @@ -1,6 +1,7 @@ #include "./check_swap.d/check_swap.h" #include "../popen.h" #include "../utils.h" +#include "common.h" extern int verbose; @@ -66,7 +67,7 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) { meminfo_file_ptr = fopen(proc_meminfo, "r"); swap_result result = {0}; - result.statusCode = STATE_OK; + result.errorcode = STATE_UNKNOWN; uint64_t swap_total = 0; uint64_t swap_used = 0; @@ -91,6 +92,9 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) { result.metrics.used += swap_used; result.metrics.free += swap_free; + // Set error + result.errorcode = STATE_OK; + /* * The following sscanf call looks for lines looking like: * "SwapTotal: 123" and "SwapFree: 123" This format exists at least @@ -113,6 +117,8 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) { } else if (strcmp("Cached", str) == 0) { swap_free = swap_free + tmp_KB * 1024; } + + result.errorcode = STATE_OK; } } -- cgit v1.2.3-74-g34f1