pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bsdfetch: portability fixes for NetBSD.



Module Name:	pkgsrc-wip
Committed By:	Paolo Vincenzo Olivo <vms%retrobsd.ddns.net@localhost>
Pushed By:	vms
Date:		Tue Nov 29 21:10:20 2022 +0100
Changeset:	fce98b6e8f5822d4e1ee1bb87eb2326e1e7c2959

Modified Files:
	bsdfetch/distinfo
Added Files:
	bsdfetch/patches/patch-bsdfetch.c

Log Message:
bsdfetch: portability fixes for NetBSD.

* Improve CPU model name detection on NetBSD.
* Fix uptime count and re-enable it (previously disabled by default on
  NetBSD)

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=fce98b6e8f5822d4e1ee1bb87eb2326e1e7c2959

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 bsdfetch/distinfo                 |  1 +
 bsdfetch/patches/patch-bsdfetch.c | 87 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)

diffs:
diff --git a/bsdfetch/distinfo b/bsdfetch/distinfo
index 07e3427728..754d62d436 100644
--- a/bsdfetch/distinfo
+++ b/bsdfetch/distinfo
@@ -4,3 +4,4 @@ BLAKE2s (bsdfetch-20221123/bsdfetch-20221123-c75e286bec960d00f71cb166e59c2af7a71
 SHA512 (bsdfetch-20221123/bsdfetch-20221123-c75e286bec960d00f71cb166e59c2af7a71c8835.tar.gz) = a5060c5484252b224daa9e352f2dc27c13ffa937846788b0531bc41b88221deee21696985802b7ede368d08d927449974e2b45aaccef87289ac461c9a700ae44
 Size (bsdfetch-20221123/bsdfetch-20221123-c75e286bec960d00f71cb166e59c2af7a71c8835.tar.gz) = 6592 bytes
 SHA1 (patch-Makefile) = 62812c29b42d05ad9a9b1b9cc263ec309a7a4771
+SHA1 (patch-bsdfetch.c) = 86c0e3e45a7ffbafdd935c985672c021ff585e95
diff --git a/bsdfetch/patches/patch-bsdfetch.c b/bsdfetch/patches/patch-bsdfetch.c
new file mode 100644
index 0000000000..f2942f6575
--- /dev/null
+++ b/bsdfetch/patches/patch-bsdfetch.c
@@ -0,0 +1,87 @@
+$NetBSD$
+
+* Improve CPU model name detection on NetBSD.
+* Fix uptime count on NetBSD and re-enable it.
+
+--- bsdfetch.c.orig	2022-11-23 13:22:36.000000000 +0000
++++ bsdfetch.c
+@@ -17,19 +17,20 @@
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include <time.h>
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/sysctl.h>
+ #include <sys/utsname.h>
+ #include <dlfcn.h>
+ #if defined(__FreeBSD__) || defined(__DragonFly__)
++#include <sys/time.h>
+ #include <sys/vmmeter.h>
+ #include <vm/vm_param.h>
++#elif defined(__NetBSD__) || defined(__OpenBSD__)
++#include <sys/time.h>
+ #endif
+ #ifdef __OpenBSD__
+ #include "sysctlbyname.h"
+-#include <sys/time.h>
+ #include <sys/sensors.h>
+ #endif
+ 
+@@ -103,7 +104,6 @@ static void get_user() {
+ 
+ static void get_cpu() {
+ 	size_t num_cpu_size = 0;
+-	size_t cpu_type_size = 0;
+ 	uint num_cpu = 0;
+ 	char cpu_type[200] = {0};
+ 	char tmp[100] = {0};
+@@ -113,11 +113,24 @@ static void get_cpu() {
+ 	if(sysctlbyname("hw.ncpu", &num_cpu, &num_cpu_size, NULL, 0) == -1)
+ 		die(errno, __LINE__);
+ 
+-	cpu_type_size = sizeof(char) * 200;
++#if defined(__NetBSD__)
++	FILE *fc = NULL;
+ 
+-	if(sysctlbyname("hw.model", &cpu_type, &cpu_type_size, NULL, 0) == -1)
++	fc = popen("awk 'BEGIN{FS=\":\"} /model name/ { print $2; exit }' "
++                   "/proc/cpuinfo | sed -e 's/ @//' -e 's/^ *//g' -e 's/ *$//g' "
++                   "| head -1 | tr -d '\\n'",
++                   "r");
++	if (fc == NULL)
+ 		die(errno, __LINE__);
+ 
++	fgets(cpu_type, sizeof(cpu_type), fc);
++	pclose(fc);
++#else
++	size_t cpu_type_size = 0;
++	cpu_type_size = sizeof(char) * 200;
++	if(sysctlbyname("hw.model", &cpu_type, &cpu_type_size, NULL, 0) == -1)
++		die(errno, __LINE__);
++#endif
+ 	show("CPU", cpu_type);
+ 
+ 	_SILENT sprintf(tmp, "%d", num_cpu);
+@@ -284,10 +297,8 @@ static void get_uptime() {
+ 	int minutes = 0;
+ 	struct timespec t;
+ 
+-// NetBSD kernel doesn't implement CLOCK_UPTIME, to assume we've we'll set CLOCK_UPTIME to CLOCK_REALTIME
+-// More easily we can also use value 5 instead CLOCK_UPTIME, since it's only for FreeBSD
+ #ifndef CLOCK_UPTIME
+-#define CLOCK_UPTIME 0
++#define CLOCK_UPTIME CLOCK_MONOTONIC 
+ #endif
+ 	ret = clock_gettime(CLOCK_UPTIME, &t);
+ 	if(ret == -1)
+@@ -413,9 +424,7 @@ int main(int argc, char **argv) {
+ 	get_shell();
+ 	get_user();
+ 	get_packages();
+-#ifndef __NetBSD__
+ 	get_uptime();
+-#endif
+ 	get_memory();
+ 	get_loadavg();
+ 	get_cpu();


Home | Main Index | Thread Index | Old Index