summaryrefslogtreecommitdiffstats
path: root/src/detection/swap/swap_obsd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/detection/swap/swap_obsd.c')
-rw-r--r--src/detection/swap/swap_obsd.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/detection/swap/swap_obsd.c b/src/detection/swap/swap_obsd.c
new file mode 100644
index 0000000..1296aeb
--- /dev/null
+++ b/src/detection/swap/swap_obsd.c
@@ -0,0 +1,35 @@
+#include "swap.h"
+#include "common/FFlist.h"
+#include "common/mallocHelper.h"
+
+#include <sys/types.h>
+#include <sys/swap.h>
+#include <sys/param.h>
+#include <unistd.h>
+
+const char* ffDetectSwap(FFlist* result) {
+ int nswap = swapctl(SWAP_NSWAP, 0, 0);
+ if (nswap < 0) {
+ return "swapctl(SWAP_NSWAP) failed";
+ }
+ if (nswap == 0) {
+ return NULL;
+ }
+
+ FF_AUTO_FREE struct swapent* swdev = malloc((uint32_t) nswap * sizeof(*swdev));
+
+ if (swapctl(SWAP_STATS, swdev, nswap) < 0) {
+ return "swapctl(SWAP_STATS) failed";
+ }
+
+ for (int i = 0; i < nswap; i++) {
+ if (swdev[i].se_flags & SWF_ENABLE) {
+ FFSwapResult* swap = FF_LIST_ADD(FFSwapResult, *result);
+ ffStrbufInitS(&swap->name, swdev[i].se_path);
+ swap->bytesUsed = (uint64_t) swdev[i].se_inuse * DEV_BSIZE;
+ swap->bytesTotal = (uint64_t) swdev[i].se_nblks * DEV_BSIZE;
+ }
+ }
+
+ return NULL;
+}