[Pkg-wmaker-commits] [wmcube] 40/67: debian/patches: (freebsd_sysctl.patch): Use sysctl instead of kvm to get cpu stats on kfreebsd.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Tue Aug 25 03:22:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmcube.

commit 0df83336c463f1e115f183399d5bb27fbc7730db
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Tue Jan 13 18:07:52 2015 -0600

    debian/patches: (freebsd_sysctl.patch): Use sysctl instead of kvm to get cpu
    stats on kfreebsd.
---
 debian/patches/freebsd_sysctl.patch | 92 +++++++++++++++++++++++++++++++++++++
 debian/patches/series               |  1 +
 2 files changed, 93 insertions(+)

diff --git a/debian/patches/freebsd_sysctl.patch b/debian/patches/freebsd_sysctl.patch
new file mode 100644
index 0000000..084ee48
--- /dev/null
+++ b/debian/patches/freebsd_sysctl.patch
@@ -0,0 +1,92 @@
+Description: Use sysctl instead of kvm to get cpu stats on kfreebsd.
+ This lets avoids avoid a setgid binary and a dependency on libkvm.  Based on
+ similar patches for wmbubble [1,2].
+ .
+ [1] https://github.com/rnjacobs/wmbubble/commit/19794d2
+ [2] https://github.com/rnjacobs/wmbubble/commit/3e74615
+Author: Doug Torrance <dtorrance at monmouthcollege.edu>
+Last-Update: 2015-01-14
+
+--- a/wmcube/wmcube.c
++++ b/wmcube/wmcube.c
+@@ -58,7 +58,9 @@
+ #include <X11/extensions/shape.h>
+ 
+ #ifdef FREEBSD
+-#include <kvm.h>
++#include <sys/resource.h>
++#include <sys/sysctl.h>
++#include <errno.h>
+ #endif
+ 
+ #include "../wmgeneral/wmgeneral.h"
+@@ -143,11 +145,6 @@
+ 
+ float	lum_vector[3] = { 0, 0, 100 };  // Lightsource vector
+ 
+-#ifdef FREEBSD
+-static kvm_t            *kd;
+-static struct nlist     nlst[] = { {"_cp_time"}, {0} };
+-#endif
+-
+ 	char	obj_filename[256];
+ 	char	*plugin = {""};
+ 
+@@ -1311,26 +1308,28 @@
+ }
+ 
+ #elif defined FREEBSD
+-#include <nlist.h>
+-#include <fcntl.h>
+-#include <sys/dkstat.h>
+ 
+ int init_calc_cpu()
+ {
++        return 0;
++}
+ 
+-        if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
+-        {
+-                printf("\nError: unable to open kvm\n\n");
+-                exit(0);
+-        }
+-        kvm_nlist(kd, nlst);
+-        if (nlst[0].n_type == 0) 
+-        {
+-                printf("\nError: unable to get nlist\n\n");
+-                exit(1);
+-        }
++#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
+ 
+-        return 0;
++static void getsysctl(const char *name, void *ptr, size_t len)
++{
++	size_t nlen = len;
++
++	if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
++		fprintf(stderr, "sysctl(%s...) failed: %s\n", name,
++			strerror(errno));
++		exit(1);
++	}
++	if (nlen != len) {
++		fprintf(stderr, "sysctl(%s...) expected %lu, got %lu\n",
++			name, (unsigned long)len, (unsigned long)nlen);
++		exit(1);
++	}
+ }
+ 
+ int calc_cpu_total() {
+@@ -1339,12 +1338,7 @@
+         int cpu,nice,system,idle;
+         unsigned long int cpu_time[CPUSTATES];
+ 
+-        if (kvm_read(kd, nlst[0].n_value, &cpu_time, sizeof(cpu_time))
+-                != sizeof(cpu_time))
+-        {
+-                printf("\nError reading kvm\n\n");
+-                exit(0);
+-        }
++        GETSYSCTL("kern.cp_time", cpu_time);
+ 
+         cpu = cpu_time[CP_USER];
+         nice = cpu_time[CP_NICE];
diff --git a/debian/patches/series b/debian/patches/series
index 8d38ace..94f3d01 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@
 40_bts-357072_long_uptime_fix.patch
 update_makefile.patch
 fix_-Wunused-result.patch
+freebsd_sysctl.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmcube.git



More information about the Pkg-wmaker-commits mailing list