Skip to content

Commit 52c7f9f

Browse files
committed
Swap (macOS): display Unused instead of Disabled for 0/0
Fixes #2248
1 parent e0eba8c commit 52c7f9f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/detection/swap/swap_apple.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "swap.h"
22

3+
#include "common/sysctl.h"
34
#include <mach/mach.h>
4-
#include <sys/sysctl.h>
55

66
const char* ffDetectSwap(FFlist* result) {
77
struct xsw_usage xsw;
@@ -10,6 +10,12 @@ const char* ffDetectSwap(FFlist* result) {
1010
return "Failed to read vm.swapusage";
1111
}
1212

13+
if (xsw.xsu_total == 0) {
14+
if (ffSysctlGetInt("vm.compressor_mode", 4) <= 2) {
15+
return NULL; // Swap is disabled
16+
}
17+
}
18+
1319
FFSwapResult* swap = ffListAdd(result);
1420
ffStrbufInitStatic(&swap->name, xsw.xsu_encrypted ? "Encrypted" : "Normal");
1521
swap->bytesTotal = xsw.xsu_total;

src/modules/swap/swap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "detection/swap/swap.h"
77
#include "modules/swap/swap.h"
88

9-
void printSwap(FFSwapOptions* options, uint8_t index, FFSwapResult* storage) {
9+
void printSwap(FFSwapOptions* options, uint8_t index, uint32_t totalCount, FFSwapResult* storage) {
1010
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
1111

1212
if (options->moduleArgs.key.length == 0) {
@@ -45,7 +45,7 @@ void printSwap(FFSwapOptions* options, uint8_t index, FFSwapResult* storage) {
4545
ffStrbufAppendC(&str, ' ');
4646
}
4747
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) {
48-
ffStrbufAppendS(&str, "Disabled");
48+
ffStrbufAppendS(&str, totalCount ? "Unused" : "Disabled");
4949
} else {
5050
ffPercentAppendNum(&str, 0, options->percent, str.length > 0, &options->moduleArgs);
5151
}
@@ -94,11 +94,11 @@ bool ffPrintSwap(FFSwapOptions* options) {
9494
return false;
9595
}
9696

97-
if (options->separate) {
97+
if (options->separate && result.length > 0) {
9898
uint8_t index = 0;
9999
FF_LIST_FOR_EACH (FFSwapResult, storage, result) {
100100
++index;
101-
printSwap(options, index, storage);
101+
printSwap(options, index, result.length, storage);
102102
}
103103
} else {
104104
FFSwapResult total = {
@@ -108,7 +108,7 @@ bool ffPrintSwap(FFSwapOptions* options) {
108108
total.bytesUsed += storage->bytesUsed;
109109
total.bytesTotal += storage->bytesTotal;
110110
}
111-
printSwap(options, 0, &total);
111+
printSwap(options, 0, result.length, &total);
112112
ffStrbufDestroy(&total.name);
113113
}
114114

0 commit comments

Comments
 (0)