Update to 3.7.2 Fix IPC on OpenBSD (broken because it used /proc) Add OpenBSD support to module/memory
Index: Makefile =================================================================== RCS file: /cvs/ports/x11/polybar/Makefile,v diff -u -p -u -p -r1.32 Makefile --- Makefile 6 May 2024 12:24:17 -0000 1.32 +++ Makefile 2 Dec 2024 12:54:41 -0000 @@ -1,8 +1,7 @@ COMMENT = fast and easy-to-use status bar -V = 3.7.1 +V = 3.7.2 DISTNAME = polybar-$V CATEGORIES = x11 -REVISION = 0 HOMEPAGE = https://polybar.github.io/ MAINTAINER = Jasper Lievisse Adriaanse <jas...@openbsd.org> Index: distinfo =================================================================== RCS file: /cvs/ports/x11/polybar/distinfo,v diff -u -p -u -p -r1.11 distinfo --- distinfo 8 Dec 2023 12:07:21 -0000 1.11 +++ distinfo 2 Dec 2024 12:54:41 -0000 @@ -1,2 +1,2 @@ -SHA256 (polybar-3.7.1.tar.gz) = XeatOFugncRTpOXscFR0mkiCtbIaYsF65Av3yQYT/w8= -SIZE (polybar-3.7.1.tar.gz) = 495162 +SHA256 (polybar-3.7.2.tar.gz) = 4v6svQLnyUuu1/ULE7y/MH2V3wMlw+yuRDKJultWryk= +SIZE (polybar-3.7.2.tar.gz) = 494383 Index: patches/patch-src_modules_memory_cpp =================================================================== RCS file: patches/patch-src_modules_memory_cpp diff -N patches/patch-src_modules_memory_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-src_modules_memory_cpp 2 Dec 2024 12:54:41 -0000 @@ -0,0 +1,92 @@ +Index: src/modules/memory.cpp +--- src/modules/memory.cpp.orig ++++ src/modules/memory.cpp +@@ -2,6 +2,14 @@ + #include <iomanip> + #include <istream> + ++#ifdef __OpenBSD__ ++#include <sys/param.h> ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#include <sys/swap.h> ++#include <unistd.h> ++#endif ++ + #include "drawtypes/label.hpp" + #include "drawtypes/progressbar.hpp" + #include "drawtypes/ramp.hpp" +@@ -63,6 +71,64 @@ namespace modules { + unsigned long long kb_swap_total{0ULL}; + unsigned long long kb_swap_free{0ULL}; + ++#ifdef __OpenBSD__ ++ size_t size; ++ struct uvmexp uvmexp; ++ struct swapent *swdev = NULL; ++ int nswap, i; ++ int physmem_mib[] = {CTL_HW, HW_PHYSMEM64}; ++ int uvmexp_mib[] = {CTL_VM, VM_UVMEXP}; ++ int pagesize = sysconf(_SC_PAGESIZE); ++ ++ size = sizeof(kb_total); ++ if (sysctl(physmem_mib, 2, &kb_total, &size, NULL, 0) < 0) { ++ m_log.err("Failed to read memory values (what: sysctl %s)", strerror(errno)); ++ goto no_update; ++ } ++ ++ kb_total = kb_total / 1024; ++ ++ size = sizeof(uvmexp); ++ if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) { ++ m_log.err("Failed to read memory values (what: sysctl %s)", strerror(errno)); ++ goto no_update; ++ } ++ ++ kb_avail = (long long) uvmexp.free * pagesize / 1024; ++ ++ if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0) { ++ // no swap ! ++ goto no_update; ++ } ++ ++ if ((swdev = (struct swapent *)calloc(nswap, sizeof(*swdev))) == NULL) { ++ m_log.err("Failed to read memory values (what: calloc %s)", strerror(errno)); ++ goto no_update; ++ } ++ ++ if (swapctl(SWAP_STATS, swdev, nswap) == -1) { ++ m_log.err("Failed to read memory values (what: swapctl %s)", strerror(errno)); ++ free(swdev); ++ goto no_update; ++ } ++ ++ kb_swap_total = kb_swap_free = 0; ++ for (i = 0; i < nswap; i++) { ++ if (swdev[i].se_flags & SWF_ENABLE) { ++ kb_swap_free += (swdev[i].se_nblks - swdev[i].se_inuse); ++ kb_swap_total += swdev[i].se_nblks; ++ } ++ } ++ ++ free(swdev); ++ ++ kb_swap_total = kb_swap_total * DEV_BSIZE / 1024; ++ kb_swap_free = kb_swap_free * DEV_BSIZE / 1024; ++ ++no_update: ++ ++#else ++ + try { + std::ifstream meminfo(PATH_MEMORY_INFO); + std::map<std::string, unsigned long long int> parsed; +@@ -95,6 +161,8 @@ namespace modules { + } catch (const std::exception& err) { + m_log.err("Failed to read memory values (what: %s)", err.what()); + } ++ ++#endif + + m_perc_memfree = math_util::percentage(kb_avail, kb_total); + m_perc_memused = 100 - m_perc_memfree; Index: patches/patch-src_polybar-msg_cpp =================================================================== RCS file: patches/patch-src_polybar-msg_cpp diff -N patches/patch-src_polybar-msg_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-src_polybar-msg_cpp 2 Dec 2024 12:54:41 -0000 @@ -0,0 +1,56 @@ +Index: src/polybar-msg.cpp +--- src/polybar-msg.cpp.orig ++++ src/polybar-msg.cpp +@@ -1,6 +1,11 @@ + #include <fcntl.h> + #include <unistd.h> + ++#ifdef __OpenBSD__ ++#include <sys/types.h> ++#include <sys/sysctl.h> ++#endif ++ + #include <algorithm> + #include <cassert> + #include <cstdlib> +@@ -53,6 +58,22 @@ bool validate_type(const string& type) { + return (type == "action" || type == "cmd" || type == "hook"); + } + ++static bool process_exists(int pid) { ++#ifdef __OpenBSD__ ++ struct kinfo_proc kp; ++ size_t len = sizeof(kp); ++ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, (int)len, 1}; ++ ++ if (sysctl(mib, std::size(mib), &kp, &len, NULL, 0) == -1) { ++ return false; // Assume the PID does not exist ++ } ++ ++ return (len > 0); ++#else ++ return file_util::exists("/proc/" + to_string(pid)); ++#endif ++} ++ + static vector<string> get_sockets() { + auto sockets = file_util::glob(ipc::get_glob_socket_path()); + +@@ -63,7 +84,7 @@ static vector<string> get_sockets() { + return true; + } + +- if (!file_util::exists("/proc/" + to_string(pid))) { ++ if (!process_exists(pid)) { + remove_socket(path); + return true; + } +@@ -194,7 +215,7 @@ int run(int argc, char** argv) { + if (args.size() >= 2 && args[0].compare(0, 2, "-p") == 0) { + auto& pid_string = args[1]; + socket_path = ipc::get_socket_path(pid_string); +- if (!file_util::exists("/proc/" + pid_string)) { ++ if (!process_exists(std::stoi(pid_string))) { + error("No process with pid " + pid_string); + } else if (!file_util::exists(socket_path)) { + error("No channel available for pid " + pid_string);