[Pkg-wmaker-commits] [wmmemload] 81/103: debian/patches: (sysctl_swap.patch) Use sysctl to get swap usage information for GNU/kFreeBSD.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 03:11:48 UTC 2015


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

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

commit dffaddf2242f3e18cb3b09e2b8a4f704a50f4bf1
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Mon Oct 13 14:34:04 2014 -0500

    debian/patches: (sysctl_swap.patch) Use sysctl to get swap usage information for
    GNU/kFreeBSD.
    
    Remove debian/patches/fix-unused-result.patch, as the affected code was removed
    by sysctl_swap.patch.
---
 debian/patches/fix-unused-result.patch | 49 -------------------
 debian/patches/series                  |  2 +-
 debian/patches/sysctl_swap.patch       | 87 ++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 50 deletions(-)

diff --git a/debian/patches/fix-unused-result.patch b/debian/patches/fix-unused-result.patch
deleted file mode 100644
index 556c4b8..0000000
--- a/debian/patches/fix-unused-result.patch
+++ /dev/null
@@ -1,49 +0,0 @@
-Description: Fix unused result compiler warning.
- Fix the following compiler warnings, which appear when -D_FORTIFY_SOURCE=2 is
- passed to gcc:
- .
- mem_freebsd.c: In function ‘mem_init’:
- mem_freebsd.c:38:2: warning: ignoring return value of ‘seteuid’, declared with
- attribute warn_unused_result [-Wunused-result]
-  seteuid(getuid());
-  ^
- mem_freebsd.c:39:2: warning: ignoring return value of ‘setegid’, declared with
- attribute warn_unused_result [-Wunused-result]
-  setegid(getgid());
-  ^
-Author: Doug Torrance <dtorrance at monmouthcollege.edu>
-Last-Update: 2014-10-10
-
---- a/src/mem_freebsd.c
-+++ b/src/mem_freebsd.c
-@@ -27,6 +27,8 @@
- /* initialize function */
- void mem_init(void)
- {
-+	int s;
-+
- 	kvm_data = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
- 
- 	if (kvm_data == NULL) {
-@@ -35,8 +37,19 @@
- 	}
- 
- 	/* drop setgid & setuid (the latter should not be there really) */
--	seteuid(getuid());
--	setegid(getgid());
-+	s = seteuid(getuid());
-+	if (s == -1) {
-+		fprintf(stderr, "seteuid(getuid()) failed: %s\n",
-+			strerror(errno));
-+		exit(1);
-+	}
-+
-+	s = setegid(getgid());
-+	if (s == -1) {
-+		fprintf(stderr, "setegid(getgid()) failed: %s\n",
-+			strerror(errno));
-+		exit(1);
-+	}
- 
- 	if (geteuid() != getuid() || getegid() != getgid()) {
- 		fprintf(stderr, "unable to drop privileges");
diff --git a/debian/patches/series b/debian/patches/series
index 3609eb9..d1ac254 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1 @@
-fix-unused-result.patch
+sysctl_swap.patch
diff --git a/debian/patches/sysctl_swap.patch b/debian/patches/sysctl_swap.patch
new file mode 100644
index 0000000..ce1d41d
--- /dev/null
+++ b/debian/patches/sysctl_swap.patch
@@ -0,0 +1,87 @@
+Description: Use sysctl for swap usage information in GNU/kFreeBSD.
+ Use sysctl instead of kvm_getswapinfo() to read the swap usage information in
+ GNU/kFreeBSD.  This removes the need for a Build-Depends on libkvm-dev and
+ having a setgid binary.
+Author: Doug Torrance <dtorrance at monmouthcollege.edu>
+Last-Update: 2014-10-13
+
+--- a/src/mem_freebsd.c
++++ b/src/mem_freebsd.c
+@@ -11,38 +11,18 @@
+ #endif
+ 
+ #include <stdio.h>
+-#include <unistd.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "mem.h"
+ 
+-#include <kvm.h>
+-#include <fcntl.h>
++#include <vm/vm_param.h>
+ #include <sys/errno.h>
+ #include <sys/sysctl.h>
+ #include <time.h>
+ 
+-static kvm_t *kvm_data;
+-
+ /* initialize function */
+ void mem_init(void)
+ {
+-	kvm_data = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
+-
+-	if (kvm_data == NULL) {
+-		fprintf(stderr, "can't open kernel virtual memory");
+-		exit(1);
+-	}
+-
+-	/* drop setgid & setuid (the latter should not be there really) */
+-	seteuid(getuid());
+-	setegid(getgid());
+-
+-	if (geteuid() != getuid() || getegid() != getgid()) {
+-		fprintf(stderr, "unable to drop privileges");
+-		exit(1);
+-	}
+-
+ 	return;
+ }
+ 
+@@ -101,17 +81,30 @@
+ 	if (swap_firsttime ||
+ 	    (((new_swappgsin > swappgsin) || (new_swappgsout > swappgsout))
+ 	     && cur_time > last_time_swap + 1)) {
+-
+-		struct kvm_swap swap;
+-		int n;
++		int mib[2], n;
++		size_t mibsize, size;
++		struct xswdev xsw;
++
++		mibsize = sizeof(mib) / sizeof(mib[0]);
++		if (sysctlnametomib("vm.swap_info", mib, &mibsize) == -1) {
++			fprintf(stderr, "sysctlnametomib() failed: %s\n", strerror(errno));
++			exit(1);
++		}
+ 
+ 		swapmax = 0;
+ 		swapused = 0;
+ 
+-		n = kvm_getswapinfo(kvm_data, &swap, 1, 0);
+-		if (n >= 0 && swap.ksw_total != 0) {
+-			swapmax = swap.ksw_total;
+-			swapused = swap.ksw_used;
++		for (n = 0; ; n++) {
++			mib[mibsize] = n;
++			size = sizeof(xsw);
++			if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, 0) == -1) {
++				if (errno == ENOENT)
++					break;
++				fprintf(stderr, "sysctl() failed: %s\n", strerror(errno));
++				exit(1);
++			}
++			swapmax += xsw.xsw_nblks;
++			swapused += xsw.xsw_used;
+ 		}
+ 
+ 		swap_firsttime = 0;

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



More information about the Pkg-wmaker-commits mailing list