]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
feat: Add NetBSD memory usage support
authorCursor Agent <cursoragent@cursor.com>
Tue, 4 Nov 2025 10:24:00 +0000 (10:24 +0000)
committerCursor Agent <cursoragent@cursor.com>
Tue, 4 Nov 2025 10:24:00 +0000 (10:24 +0000)
Co-authored-by: v <v@rspamd.com>
src/lua/lua_util.c

index 12323f5dad6478e477d6c68432622c1a4d53e26f..14d95a20f1c005b1b88ad439ca112317d7a6f32f 100644 (file)
@@ -34,6 +34,9 @@
 #ifdef __FreeBSD__
 #include <sys/user.h>
 #endif
+#ifdef __NetBSD__
+#include <sys/param.h>
+#endif
 #endif
 #ifdef __APPLE__
 #include <mach/mach.h>
@@ -2532,7 +2535,21 @@ lua_util_get_memory_usage(lua_State *L)
                lua_pushinteger(L, info.virtual_size);
                lua_settable(L, -3);
        }
-#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+#elif defined(__NetBSD__)
+       struct kinfo_proc2 kp;
+       size_t len = sizeof(kp);
+       int mib[6] = {CTL_KERN, KERN_PROC2, KERN_PROC_PID, getpid(), sizeof(struct kinfo_proc2), 1};
+
+       if (sysctl(mib, 6, &kp, &len, NULL, 0) == 0) {
+               lua_pushstring(L, "rss");
+               lua_pushinteger(L, kp.p_vm_rssize * getpagesize());
+               lua_settable(L, -3);
+
+               lua_pushstring(L, "vsize");
+               lua_pushinteger(L, kp.p_vm_vsize);
+               lua_settable(L, -3);
+       }
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
        struct kinfo_proc kp;
        size_t len = sizeof(kp);
        int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};