From owner-freebsd-ports-bugs@FreeBSD.ORG Sun Oct 24 00:30:11 2010 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 17AB8106566C for ; Sun, 24 Oct 2010 00:30:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E41B78FC0C for ; Sun, 24 Oct 2010 00:30:10 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o9O0UAJp062367 for ; Sun, 24 Oct 2010 00:30:10 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o9O0UAwc062363; Sun, 24 Oct 2010 00:30:10 GMT (envelope-from gnats) Resent-Date: Sun, 24 Oct 2010 00:30:10 GMT Resent-Message-Id: <201010240030.o9O0UAwc062363@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Nikos Ntarmos Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 742D81065675 for ; Sun, 24 Oct 2010 00:29:40 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 621B08FC17 for ; Sun, 24 Oct 2010 00:29:40 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o9O0TduX035243 for ; Sun, 24 Oct 2010 00:29:39 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o9O0TdUB035242; Sun, 24 Oct 2010 00:29:39 GMT (envelope-from nobody) Message-Id: <201010240029.o9O0TdUB035242@www.freebsd.org> Date: Sun, 24 Oct 2010 00:29:39 GMT From: Nikos Ntarmos To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: ports/151668: [maintainer-update] conky bugfix for the kvm_getprocs crash X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Oct 2010 00:30:11 -0000 >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@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 + #include + #include ++#include + #if (defined(i386) || defined(__i386__)) + #include + #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: