Index | Thread | Search

From:
Rafael Sadowski <rafael@sizeofvoid.org>
Subject:
Re: kinfocenter: replace sysconf with sysctl
To:
ports@openbsd.org
Date:
Sun, 28 Dec 2025 15:02:56 +0100

Download raw body.

Thread
On Sun Dec 28, 2025 at 01:14:16PM +0000, Stuart Henderson wrote:
> On 2025/12/28 13:55, Rafael Sadowski wrote:
> > Simple diff to replace sysconf with sysctl in
> > MemoryEntry::calculateAvailableRam() and MemoryEntry::calculateTotalRam().
> 
> why?
> 

Oops, that diff was stale. Updated version uses uvmexp for
calculateAvailableRam() and replaces sysconf with sysctl in
calculateTotalRam() - consistent with FreeBSD/NetBSD in all other KDE
parts

Rafael

Index: Makefile
===================================================================
RCS file: /cvs/ports/x11/kde-plasma/kinfocenter/Makefile,v
diff -u -p -r1.10 Makefile
--- Makefile	22 Feb 2025 14:34:43 -0000	1.10
+++ Makefile	28 Dec 2025 13:55:44 -0000
@@ -1,5 +1,6 @@
 COMMENT =	core components for the KDE Activity concept
 DISTNAME =	kinfocenter-${VERSION}
+REVISION =	0
 
 WANTLIB += ${COMPILER_LIBCXX} GL KF6AuthCore KF6ColorScheme KF6Completion
 WANTLIB += KF6ConfigCore KF6ConfigGui KF6ConfigWidgets KF6CoreAddons
Index: patches/patch-Modules_about-distro_src_MemoryEntry_cpp
===================================================================
RCS file: /cvs/ports/x11/kde-plasma/kinfocenter/patches/patch-Modules_about-distro_src_MemoryEntry_cpp,v
diff -u -p -r1.5 patch-Modules_about-distro_src_MemoryEntry_cpp
--- patches/patch-Modules_about-distro_src_MemoryEntry_cpp	4 Jul 2025 05:47:07 -0000	1.5
+++ patches/patch-Modules_about-distro_src_MemoryEntry_cpp	28 Dec 2025 13:55:44 -0000
@@ -12,15 +12,34 @@ Index: kcms/about-distro/src/MemoryEntry
  #include <sys/types.h>
  #include <sys/sysctl.h>
  // clang-format on
-@@ -58,6 +59,11 @@ std::optional<qlonglong> MemoryEntry::calculateTotalRa
+@@ -58,6 +59,13 @@ std::optional<qlonglong> MemoryEntry::calculateTotalRa
      }
  
      return totalBytes;
 +#elif defined(Q_OS_OPENBSD)
-+    long phys_pages = sysconf(_SC_PHYS_PAGES);
-+    long pagesize = sysconf(_SC_PAGESIZE);
-+    if (phys_pages != -1 && pagesize != -1)
-+        return ((uint64_t)phys_pages * (uint64_t)pagesize);
++    int64_t memSize = 0;
++    int mib[] = {CTL_HW, HW_PHYSMEM64};
++    size_t sz = sizeof(memSize);
++    if (sysctl(mib, 2, &memSize, &sz, NULL, 0) == 0) {
++        return memSize;
++    }
  #endif
  
      /*
+@@ -79,6 +87,16 @@ std::optional<qlonglong> MemoryEntry::calculateAvailab
+         // manpage: "sizes are given as multiples of mem_unit bytes"
+         return qlonglong(info.totalram) * info.mem_unit;
+     }
++#elif defined(Q_OS_OPENBSD)
++    struct uvmexp uvmexp;
++    int mib[] = {CTL_VM, VM_UVMEXP};
++    size_t sz = sizeof(uvmexp);
++    if (sysctl(mib, 2, &uvmexp, &sz, NULL, 0) == 0) {
++        int64_t pagesize = uvmexp.pagesize;
++        int64_t available = (int64_t)(uvmexp.free + uvmexp.inactive) * pagesize;
++        return available;
++    }
++
+ #elif defined(Q_OS_FREEBSD)
+     /* Stuff for sysctl */
+     unsigned long memory;