Date: Fri, 1 Jul 2022 13:10:01 GMT From: Baptiste Daroussin <bapt@FreeBSD.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org Subject: git: 48b8fc0b56fc - main - deskutils/i3status: fix looking up for network devices and memory Message-ID: <202207011310.261DA1t9010547@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/ports/commit/?id=48b8fc0b56fcce527fc8bdbc1568c63f9d5d7318 commit 48b8fc0b56fcce527fc8bdbc1568c63f9d5d7318 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2022-07-01 13:08:57 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2022-07-01 13:09:37 +0000 deskutils/i3status: fix looking up for network devices and memory --- deskutils/i3status/Makefile | 1 + .../files/patch-src_first__network__device.c | 57 +++++++++++ deskutils/i3status/files/patch-src_print__mem.c | 104 +++++++++++++++++++++ 3 files changed, 162 insertions(+) diff --git a/deskutils/i3status/Makefile b/deskutils/i3status/Makefile index b67848bc4bf8..cfa7da61a734 100644 --- a/deskutils/i3status/Makefile +++ b/deskutils/i3status/Makefile @@ -1,5 +1,6 @@ PORTNAME= i3status PORTVERSION= 2.14 +PORTREVISION= 1 CATEGORIES= deskutils MASTER_SITES= http://i3wm.org/i3status/ diff --git a/deskutils/i3status/files/patch-src_first__network__device.c b/deskutils/i3status/files/patch-src_first__network__device.c new file mode 100644 index 000000000000..a49a77e8e25f --- /dev/null +++ b/deskutils/i3status/files/patch-src_first__network__device.c @@ -0,0 +1,57 @@ +--- src/first_network_device.c.orig 2022-07-01 12:29:14 UTC ++++ src/first_network_device.c +@@ -4,13 +4,13 @@ + #include <sys/stat.h> + #include <stdlib.h> + #include <ifaddrs.h> +-#if defined(__OpenBSD__) || defined(__DragonFly__) ++#if defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) + #include <sys/types.h> + #include <sys/sockio.h> + #include <sys/ioctl.h> + #include <net/if.h> + #endif +-#if defined(__OpenBSD__) ++#if defined(__OpenBSD__) || defined(__FreeBSD__) + #include <net80211/ieee80211.h> + #include <net80211/ieee80211_ioctl.h> + #elif defined(__DragonFly__) +@@ -83,17 +83,17 @@ static net_type_t iface_type(const char *ifname) { + struct ifreq ifr; + struct ieee80211_bssid bssid; + struct ieee80211_nwid nwid; +-#elif defined(__DragonFly__) ++#elif defined(__DragonFly__) || defined(__FreeBSD__) + struct ieee80211req ifr; + #endif +-#if defined(__OpenBSD__) || defined(__DragonFly__) ++#if defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) + struct ifmediareq ifmr; + int s; + #endif + #if defined(__OpenBSD__) + int ibssid, inwid; + #endif +-#if defined(__OpenBSD__) || defined(__DragonFly__) ++#if defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + return NET_TYPE_OTHER; + +@@ -112,7 +112,7 @@ static net_type_t iface_type(const char *ifname) { + close(s); + return NET_TYPE_WIRELESS; + } +-#elif defined(__DragonFly__) ++#elif defined(__DragonFly__) || defined(__FreeBSD__) + (void)strlcpy(ifr.i_name, ifname, sizeof(ifr.i_name)); + ifr.i_type = IEEE80211_IOC_NUMSSIDS; + if (ioctl(s, SIOCG80211, &ifr) == 0) { +@@ -120,7 +120,7 @@ static net_type_t iface_type(const char *ifname) { + return NET_TYPE_WIRELESS; + } + #endif +-#if defined(__OpenBSD__) || defined(__DragonFly__) ++#if defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) + (void)memset(&ifmr, 0, sizeof(ifmr)); + (void)strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); + diff --git a/deskutils/i3status/files/patch-src_print__mem.c b/deskutils/i3status/files/patch-src_print__mem.c new file mode 100644 index 000000000000..50ef72f255b6 --- /dev/null +++ b/deskutils/i3status/files/patch-src_print__mem.c @@ -0,0 +1,104 @@ +--- src/print_mem.c.orig 2021-11-09 07:27:11 UTC ++++ src/print_mem.c +@@ -7,17 +7,21 @@ + #include <yajl/yajl_version.h> + #include "i3status.h" + ++#if defined(__FreeBSD__) ++#include <sys/sysctl.h> ++#endif ++ + #define MAX_DECIMALS 4 + #define STRING_SIZE ((sizeof "1023. TiB") + MAX_DECIMALS) + + #define BINARY_BASE 1024UL + +-#if defined(__linux__) ++#if defined(__linux__) || defined(__FreeBSD__) + static const char *const iec_symbols[] = {"B", "KiB", "MiB", "GiB", "TiB"}; + #define MAX_EXPONENT ((sizeof iec_symbols / sizeof *iec_symbols) - 1) + #endif + +-#if defined(__linux__) ++#if defined(__linux__) || defined(__FreeBSD__) + /* + * Prints the given amount of bytes in a human readable manner. + * +@@ -42,7 +46,7 @@ static int print_percentage(char *outwalk, float perce + } + #endif + +-#if defined(__linux__) ++#if defined(__linux__) || defined(__FreeBSD__) + /* + * Convert a string to its absolute representation based on the total + * memory of `mem_total`. +@@ -89,11 +93,10 @@ void print_memory(memory_ctx_t *ctx) { + void print_memory(memory_ctx_t *ctx) { + char *outwalk = ctx->buf; + +-#if defined(__linux__) ++#if defined(__linux__) || defined(__FreeBSD__) + const char *selected_format = ctx->format; + const char *output_color = NULL; + +- int unread_fields = 6; + unsigned long ram_total; + unsigned long ram_free; + unsigned long ram_available; +@@ -101,6 +104,8 @@ void print_memory(memory_ctx_t *ctx) { + unsigned long ram_cached; + unsigned long ram_shared; + ++#if defined(__linux__) ++ int unread_fields = 6; + FILE *file = fopen("/proc/meminfo", "r"); + if (!file) { + goto error; +@@ -130,7 +135,7 @@ void print_memory(memory_ctx_t *ctx) { + if (unread_fields > 0) { + goto error; + } +- ++ + // Values are in kB, convert them to B. + ram_total *= 1024UL; + ram_free *= 1024UL; +@@ -138,6 +143,25 @@ void print_memory(memory_ctx_t *ctx) { + ram_buffers *= 1024UL; + ram_cached *= 1024UL; + ram_shared *= 1024UL; ++#endif ++#if defined(__FreeBSD__) ++ size_t len; ++ unsigned long active_mem; ++ len = sizeof(unsigned long); ++ ram_total = ram_free = ram_cached = ram_buffers = ram_shared = 0; ++ sysctlbyname("hw.physmem", &ram_total, &len, NULL, 0); ++ sysctlbyname("hw.usermem", &ram_available, &len, NULL, 0); ++ int page_size = getpagesize(); ++ sysctlbyname("vm.stats.vm.v_cache_count", &ram_cached, &len, NULL, 0); ++ sysctlbyname("vm.stats.vm.v_buffer_count", &ram_buffers, &len, NULL, 0); ++ sysctlbyname("vm.stats.vm.v_wire_count", &ram_shared, &len, NULL, 0); ++ sysctlbyname("vm.stats.vm.v_active_count", &active_mem, &len, NULL, 0); ++ sysctlbyname("vm.stats.vm.v_free_count", &ram_free, &len, NULL, 0); ++ ram_cached *= page_size; ++ ram_buffers *= page_size; ++ ram_shared *= page_size; ++ ram_free *= page_size; ++#endif + + unsigned long ram_used; + if (BEGINS_WITH(ctx->memory_used_method, "memavailable")) { +@@ -211,9 +235,11 @@ void print_memory(memory_ctx_t *ctx) { + OUTPUT_FULL_TEXT(ctx->buf); + + return; ++#if defined(__linux__) + error: + OUTPUT_FULL_TEXT("can't read memory"); + fputs("i3status: Cannot read system memory using /proc/meminfo\n", stderr); ++#endif + #else + OUTPUT_FULL_TEXT(""); + fputs("i3status: Memory status information is not supported on this system\n", stderr);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207011310.261DA1t9010547>