diff --git a/src/detection/swap/swap_apple.c b/src/detection/swap/swap_apple.c index c550d6a25..acfb734f9 100644 --- a/src/detection/swap/swap_apple.c +++ b/src/detection/swap/swap_apple.c @@ -1,7 +1,7 @@ #include "swap.h" +#include "common/sysctl.h" #include -#include const char* ffDetectSwap(FFlist* result) { struct xsw_usage xsw; @@ -10,6 +10,12 @@ const char* ffDetectSwap(FFlist* result) { return "Failed to read vm.swapusage"; } + if (xsw.xsu_total == 0) { + if (ffSysctlGetInt("vm.compressor_mode", 4) <= 2) { + return NULL; // Swap is disabled + } + } + FFSwapResult* swap = ffListAdd(result); ffStrbufInitStatic(&swap->name, xsw.xsu_encrypted ? "Encrypted" : "Normal"); swap->bytesTotal = xsw.xsu_total; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index ff48980ef..ee58521ad 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -6,7 +6,7 @@ #include "detection/swap/swap.h" #include "modules/swap/swap.h" -void printSwap(FFSwapOptions* options, uint8_t index, FFSwapResult* storage) { +void printSwap(FFSwapOptions* options, uint8_t index, uint32_t totalCount, FFSwapResult* storage) { FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); if (options->moduleArgs.key.length == 0) { @@ -45,7 +45,7 @@ void printSwap(FFSwapOptions* options, uint8_t index, FFSwapResult* storage) { ffStrbufAppendC(&str, ' '); } if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) { - ffStrbufAppendS(&str, "Disabled"); + ffStrbufAppendS(&str, totalCount ? "Unused" : "Disabled"); } else { ffPercentAppendNum(&str, 0, options->percent, str.length > 0, &options->moduleArgs); } @@ -94,11 +94,11 @@ bool ffPrintSwap(FFSwapOptions* options) { return false; } - if (options->separate) { + if (options->separate && result.length > 0) { uint8_t index = 0; FF_LIST_FOR_EACH (FFSwapResult, storage, result) { ++index; - printSwap(options, index, storage); + printSwap(options, index, result.length, storage); } } else { FFSwapResult total = { @@ -108,7 +108,7 @@ bool ffPrintSwap(FFSwapOptions* options) { total.bytesUsed += storage->bytesUsed; total.bytesTotal += storage->bytesTotal; } - printSwap(options, 0, &total); + printSwap(options, 0, result.length, &total); ffStrbufDestroy(&total.name); }