From 24ce419d07892d5f4e8696cb96f04db9748f46b8 Mon Sep 17 00:00:00 2001
From: Charlie Root <root@almsta.yo>
Date: Sun, 29 Dec 2019 13:25:40 +0100
Subject: [PATCH] WIP libgtop & mate-system-monitor

---
 .../dragonfly/patch-sysdeps_freebsd_cpu.c     | 19 -----
 .../patch-sysdeps_freebsd_mountlist.c         | 10 +++
 .../patch-sysdeps_freebsd_proclist.c          | 75 ++++++++++++++-----
 .../dragonfly/patch-src_sysinfo.cpp           | 13 ++++
 4 files changed, 81 insertions(+), 36 deletions(-)
 delete mode 100644 devel/libgtop/dragonfly/patch-sysdeps_freebsd_cpu.c
 create mode 100644 devel/libgtop/dragonfly/patch-sysdeps_freebsd_mountlist.c
 create mode 100644 sysutils/mate-system-monitor/dragonfly/patch-src_sysinfo.cpp

diff --git a/devel/libgtop/dragonfly/patch-sysdeps_freebsd_cpu.c b/devel/libgtop/dragonfly/patch-sysdeps_freebsd_cpu.c
deleted file mode 100644
index 1d923b17f1c..00000000000
--- a/devel/libgtop/dragonfly/patch-sysdeps_freebsd_cpu.c
+++ /dev/null
@@ -1,19 +0,0 @@
---- sysdeps/freebsd/cpu.c.orig	2016-11-27 18:05:03 UTC
-+++ sysdeps/freebsd/cpu.c
-@@ -61,6 +61,10 @@ glibtop_get_cpu_s (glibtop *server, glib
- 
- 	memset (buf, 0, sizeof (glibtop_cpu));
- 
-+#ifdef __DragonFly__
-+	glibtop_warn_io_r (server, "sysctl (kern.cp_time)");
-+	return;
-+#else
- 	length = sizeof (cpts);
- 	if (sysctlbyname ("kern.cp_time", cpts, &length, NULL, 0)) {
- 		glibtop_warn_io_r (server, "sysctl (kern.cp_time)");
-@@ -130,4 +134,5 @@ glibtop_get_cpu_s (glibtop *server, glib
- 	if (ncpu > 1) {
- 		buf->flags |= _glibtop_sysdeps_cpu_smp;
- 	}
-+#endif
- }
diff --git a/devel/libgtop/dragonfly/patch-sysdeps_freebsd_mountlist.c b/devel/libgtop/dragonfly/patch-sysdeps_freebsd_mountlist.c
new file mode 100644
index 00000000000..1987c406bc1
--- /dev/null
+++ b/devel/libgtop/dragonfly/patch-sysdeps_freebsd_mountlist.c
@@ -0,0 +1,10 @@
+--- sysdeps/freebsd/mountlist.c~	2016-11-27 19:05:03.000000000 +0100
++++ sysdeps/freebsd/mountlist.c	2019-12-27 13:44:41.111316000 +0100
+@@ -99,6 +99,7 @@ static gboolean ignore_mount_entry(const
+ 		"mfs",
+ 		"none",
+ 		"nfs",
++		"null",
+ 		"nullfs",
+ 		"nwfs",
+ 		"portalfs",
diff --git a/devel/libgtop/dragonfly/patch-sysdeps_freebsd_proclist.c b/devel/libgtop/dragonfly/patch-sysdeps_freebsd_proclist.c
index 5005786927f..9f1d87a6bd7 100644
--- a/devel/libgtop/dragonfly/patch-sysdeps_freebsd_proclist.c
+++ b/devel/libgtop/dragonfly/patch-sysdeps_freebsd_proclist.c
@@ -1,20 +1,61 @@
---- sysdeps/freebsd/proclist.c.orig	2016-11-27 18:05:03 UTC
-+++ sysdeps/freebsd/proclist.c
-@@ -74,6 +74,11 @@ glibtop_get_proclist_p (glibtop *server,
+--- sysdeps/freebsd/proclist.c~	2016-11-27 19:05:03.000000000 +0100
++++ sysdeps/freebsd/proclist.c	2019-12-29 13:17:13.985482000 +0100
+@@ -94,7 +94,7 @@ glibtop_get_proclist_p (glibtop *server,
+ 	for (i = 0; i < len; i++) {
+ 		pid_t pid;
  
- 	memset (buf, 0, sizeof (glibtop_proclist));
+-		pid = (pid_t) pinfo[i].ki_pid;
++		pid = (pid_t) pinfo[i].kp_pid;
  
-+#ifdef __DragonFly__
-+	/* XXX uninplemented */
-+	glibtop_warn_io_r (server, "sysctl (kern.proc.all)");
-+	return NULL;
-+#else
- 	if (sysctlbyname ("kern.proc.all", NULL, &len, NULL, 0)) {
- 		glibtop_warn_io_r (server, "sysctl (kern.proc.all)");
- 		return NULL;
-@@ -162,4 +167,5 @@ glibtop_get_proclist_p (glibtop *server,
- 	buf->total = buf->number * buf->size;
+ 		/* If a process has many threads, kern.proc.all reports multiple
+ 		   times the same pid. So don't look twice at the same pid.
+@@ -115,41 +115,41 @@ glibtop_get_proclist_p (glibtop *server,
+ 					continue;
+ 				break;
+ 			case GLIBTOP_KERN_PROC_UID:
+-				if ((uid_t) arg != pinfo[i].ki_ruid)
++				if ((uid_t) arg != pinfo[i].kp_ruid)
+ 					continue;
+ 				break;
+ 			case GLIBTOP_KERN_PROC_PGRP:
+-				if ((pid_t) arg != pinfo[i].ki_pgid)
++				if ((pid_t) arg != pinfo[i].kp_pgid)
+ 					continue;
+ 				break;
+ 			case GLIBTOP_KERN_PROC_SESSION:
+-				if ((pid_t) arg != pinfo[i].ki_sid)
++				if ((pid_t) arg != pinfo[i].kp_sid)
+ 					continue;
+ 				break;
+ 			case GLIBTOP_KERN_PROC_TTY:
+-				if ((dev_t) arg != pinfo[i].ki_tdev)
++				if ((dev_t) arg != pinfo[i].kp_tdev)
+ 					continue;
+ 				break;
+ 			case GLIBTOP_KERN_PROC_RUID:
+-				if ((uid_t) arg != pinfo[i].ki_ruid)
++				if ((uid_t) arg != pinfo[i].kp_ruid)
+ 					continue;
+ 				break;
+ 			}
  
- 	return (pid_t *) g_array_free (pids, FALSE);
-+#endif
- }
+ 		if (which & GLIBTOP_EXCLUDE_NOTTY)
+-			if (pinfo[i].ki_tdev == (dev_t) -1) continue;
++			if (pinfo[i].kp_tdev == (dev_t) -1) continue;
+ 
+ 		if (which & GLIBTOP_EXCLUDE_IDLE) {
+ 			glibtop_get_proc_state_p (server, &procstate, pid);
+ 			if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
+ 				if (procstate.state != GLIBTOP_PROCESS_RUNNING) continue;
+ 
+-			if (pinfo[i].ki_ppid == 0 && !strcmp(pinfo[i].ki_comm, "idle"))
++			if (pinfo[i].kp_ppid == 0 && !strcmp(pinfo[i].kp_comm, "idle"))
+ 				continue;
+ 		}
+ 
+ 		if (which & GLIBTOP_EXCLUDE_SYSTEM)
+-			if (pinfo[i].ki_ruid == (uid_t) 0) continue;
++			if (pinfo[i].kp_ruid == (uid_t) 0) continue;
+ 
+ 		g_array_append_val (pids, pid);
+ 	}
diff --git a/sysutils/mate-system-monitor/dragonfly/patch-src_sysinfo.cpp b/sysutils/mate-system-monitor/dragonfly/patch-src_sysinfo.cpp
new file mode 100644
index 00000000000..04c07b84c99
--- /dev/null
+++ b/sysutils/mate-system-monitor/dragonfly/patch-src_sysinfo.cpp
@@ -0,0 +1,13 @@
+--- src/sysinfo.cpp~	2019-04-24 17:41:49.000000000 +0200
++++ src/sysinfo.cpp	2019-12-27 13:47:53.143199000 +0100
+@@ -280,7 +280,9 @@ namespace {
+ 
+             for (guint i = 0; i != mountlist.number; ++i) {
+                 if ((string(entries[i].mountdir).compare("/") == 0) && \
+-                    (string(entries[i].type).compare("zfs") == 0)) {
++                    ((string(entries[i].type).compare("zfs") == 0) || \
++		     (string(entries[i].type).compare("hammer") == 0) ||
++		     (string(entries[i].type).compare("hammer2") == 0))) {
+                     // Root filesystem is ZFS based: Calculate usage based on "/".
+                     glibtop_fsusage usage;
+                     glibtop_get_fsusage(&usage, "/");
-- 
2.23.0

