ssf

Owner: IIIlllIIIllI URL: git@git.0x00nyx.xyz:seb/ssf.git

dropped the problematic <uvm/uvm_extern.h> include so userland builds no longer pull in kernel-only types

Commit b3841b09265a9b4ea0ed8f898a876fe227db1f11 by SM <seb.michalk@gmail.com> on 2025-09-23 15:31:50 +0200
diff --git a/ssf.c b/ssf.c
index 805f46f..6b86d4a 100644
--- a/ssf.c
+++ b/ssf.c
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
+#include <sys/types.h>
 #include <sys/utsname.h>
 #include <time.h>
 #include <unistd.h>
@@ -17,7 +18,6 @@
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <sys/time.h>
-#include <uvm/uvm_extern.h>
 #endif
 
 #include "ascii"
@@ -246,17 +246,26 @@ memory(struct Info *i)
 		UNKNOWN(i->memory);
 	}
 #elif defined(__OpenBSD__)
-	struct uvmexp u;
-	size_t len = sizeof(u);
-	int mib[2] = { CTL_VM, VM_UVMEXP };
+	long pagesize = 0;
+	u_int pagecount = 0, freecount = 0;
 	unsigned long long total, freep, used;
+	size_t len;
 
-	if (sysctl(mib, 2, &u, &len, NULL, 0) < 0 || !u.pagesize || !u.npages) {
+	len = sizeof(pagesize);
+	if (sysctlbyname("hw.pagesize", &pagesize, &len, NULL, 0) == -1 || pagesize <= 0) {
+		UNKNOWN(i->memory);
+		return;
+	}
+	len = sizeof(pagecount);
+	if (sysctlbyname("vm.stats.vm.v_page_count", &pagecount, &len, NULL, 0) == -1 || !pagecount) {
 		UNKNOWN(i->memory);
 		return;
 	}
-	total = (unsigned long long)u.npages * (unsigned long long)u.pagesize;
-	freep = (unsigned long long)u.free * (unsigned long long)u.pagesize;
+	len = sizeof(freecount);
+	if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &len, NULL, 0) == -1)
+		freecount = 0;
+	total = (unsigned long long)pagecount * (unsigned long long)pagesize;
+	freep = (unsigned long long)freecount * (unsigned long long)pagesize;
 	used = total > freep ? total - freep : 0;
 	snprintf(i->memory, sizeof(i->memory), "%llu/%llu MB",
 	    used / (1024ULL * 1024ULL), total / (1024ULL * 1024ULL));