ports/151668: [maintainer-update] conky bugfix for the kvm_getprocs crash
Nikos Ntarmos
ntarmos at cs.uoi.gr
Sun Oct 24 00:30:11 UTC 2010
>Number: 151668
>Category: ports
>Synopsis: [maintainer-update] conky bugfix for the kvm_getprocs crash
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: maintainer-update
>Submitter-Id: current-users
>Arrival-Date: Sun Oct 24 00:30:10 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: Nikos Ntarmos
>Release: 8.1-RELEASE
>Organization:
Computer Science Dept., U. of Ioannina, Greece
>Environment:
FreeBSD umbriel.bsd.nix 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:55:53 UTC 2010 root at almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
>Description:
After 1.8.0 was released, I've been getting reports of conky crashing shortly after it is started. I've tried to reproduce the issue for some time but to no avail. I recently managed to get my hands on a proper core file and gdb backtrace with the help of an anonymous user and had a more in-depth look. It turns out the crashes were caused by kvm_getprocs(3) being called simultaneously by multiple threads within conky.
>How-To-Repeat:
Run conky>=1.8.0 with $processes or $running_processes in ~/.conkyrc and wait...
>Fix:
The attached patch uses a mutex to synchronize accesses to the locally allocated kinfo_proc structure, a pointer to which is returned by kvm_getprocs(3).
Patch attached with submission follows:
--- Makefile.orig
+++ Makefile
@@ -7,6 +7,7 @@
PORTNAME= conky
PORTVERSION= 1.8.1
+PORTREVISION= 1
CATEGORIES= sysutils
MASTER_SITES= SF
--- files/patch-src-conky.c.orig
+++ files/patch-src-conky.c
@@ -28,7 +28,23 @@
#endif /* AUDACIOUS */
#ifdef BMPX
-@@ -6007,7 +6011,7 @@
+@@ -5716,6 +5720,7 @@
+ "kvm_open")) == NULL) {
+ CRIT_ERR(NULL, NULL, "cannot read kvm");
+ }
++ pthread_mutex_init(&kvm_proc_mutex, NULL);
+ #endif
+
+ while (1) {
+@@ -5999,6 +6004,7 @@
+
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ kvm_close(kd);
++ pthread_mutex_destroy(&kvm_proc_mutex);
+ #endif
+
+ return 0;
+@@ -6007,7 +6013,7 @@
void alarm_handler(void) {
if(childpid > 0) {
--- files/patch-src-freebsd.c.orig
+++ files/patch-src-freebsd.c
@@ -0,0 +1,44 @@
+--- src/freebsd.c.orig 2010-10-24 03:14:05.000000000 +0300
++++ src/freebsd.c 2010-10-24 03:13:05.000000000 +0300
+@@ -266,7 +266,9 @@
+ {
+ int n_processes;
+
++ pthread_mutex_lock(&kvm_proc_mutex);
+ kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
++ pthread_mutex_unlock(&kvm_proc_mutex);
+
+ info.procs = n_processes;
+ return 0;
+@@ -278,6 +280,7 @@
+ int n_processes;
+ int i, cnt = 0;
+
++ pthread_mutex_lock(&kvm_proc_mutex);
+ p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
+ for (i = 0; i < n_processes; i++) {
+ #if (__FreeBSD__ < 5) && (__FreeBSD_kernel__ < 5)
+@@ -288,6 +291,7 @@
+ cnt++;
+ }
+ }
++ pthread_mutex_unlock(&kvm_proc_mutex);
+
+ info.run_procs = cnt;
+ return 0;
+@@ -748,6 +752,7 @@
+ CRIT_ERR(NULL, NULL, "Cannot read sysctl \"vm.stats.vm.v_page_count\"");
+ }
+
++ pthread_mutex_lock(&kvm_proc_mutex);
+ p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);
+ processes = malloc(n_processes * sizeof(struct process));
+
+@@ -764,6 +769,7 @@
+ j++;
+ }
+ }
++ pthread_mutex_unlock(&kvm_proc_mutex);
+
+ qsort(processes, j - 1, sizeof(struct process), comparemem);
+ for (i = 0; i < 10 && i < n_processes; i++) {
--- files/patch-src-freebsd.h.orig
+++ files/patch-src-freebsd.h
@@ -0,0 +1,16 @@
+--- src/freebsd.h.orig 2010-10-24 03:14:11.000000000 +0300
++++ src/freebsd.h 2010-10-24 03:13:05.000000000 +0300
+@@ -9,11 +9,13 @@
+ #include <sys/ucred.h>
+ #include <fcntl.h>
+ #include <kvm.h>
++#include <pthread.h>
+ #if (defined(i386) || defined(__i386__))
+ #include <machine/apm_bios.h>
+ #endif /* i386 || __i386__ */
+
+ kvm_t *kd;
++pthread_mutex_t kvm_proc_mutex;
+
+ int get_entropy_avail(unsigned int *);
+ int get_entropy_poolsize(unsigned int *);
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list