[libgtop] Some OpenBSD cleaning: - decrease stack usage when retrieving memory stats - use consistent warnings



commit 32833323d9aba6698ae7a37a86ef92e297375de6
Author: Jasper Lievisse Adriaanse <jasper humppa nl>
Date:   Sun Jul 10 17:23:39 2011 +0200

    Some OpenBSD cleaning:
    - decrease stack usage when retrieving memory stats
    - use consistent warnings when failing sysctl(3) calls
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654344

 sysdeps/openbsd/cpu.c  |    6 +++---
 sysdeps/openbsd/mem.c  |   34 +++++++++++++++-------------------
 sysdeps/openbsd/swap.c |    4 ++--
 3 files changed, 20 insertions(+), 24 deletions(-)
---
diff --git a/sysdeps/openbsd/cpu.c b/sysdeps/openbsd/cpu.c
index 81b4cac..fdc11f4 100644
--- a/sysdeps/openbsd/cpu.c
+++ b/sysdeps/openbsd/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.6 2011/05/31 14:19:18 jasper Exp $	*/
+/* $OpenBSD: cpu.c,v 1.7 2011/07/10 15:23:01 jasper Exp $	*/
 
 /* Copyright (C) 1998 Joshua Sled
    This file is part of LibGTop 1.0.
@@ -70,14 +70,14 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
 
 	length = sizeof (cpts);
 	if (sysctl (mib2, mib_length, cpts, &length, NULL, 0)) {
-		glibtop_warn_io_r (server, "sysctl");
+		glibtop_warn_io_r (server, "sysctl (kern.cptime)");
 		return;
 	}
 
 	/* Get the clockrate data */
 	length = sizeof (struct clockinfo);
 	if (sysctl (mib, mib_length, &ci, &length, NULL, 0)) {
-		glibtop_warn_io_r (server, "sysctl");
+		glibtop_warn_io_r (server, "sysctl (kern.clockrate)");
 		return;
 	}
 
diff --git a/sysdeps/openbsd/mem.c b/sysdeps/openbsd/mem.c
index 6fe8c6b..b0b0ed1 100644
--- a/sysdeps/openbsd/mem.c
+++ b/sysdeps/openbsd/mem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mem.c,v 1.10 2011/07/10 14:42:39 jasper Exp $	*/
+/* $OpenBSD: mem.c,v 1.11 2011/07/10 15:23:01 jasper Exp $	*/
 
 /* Copyright (C) 1998 Joshua Sled
    This file is part of LibGTop 1.0.
@@ -35,12 +35,10 @@
 #include <uvm/uvm_param.h>
 
 static const unsigned long _glibtop_sysdeps_mem =
-(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
-(1L << GLIBTOP_MEM_FREE) +
-(1L << GLIBTOP_MEM_SHARED) +
-(1L << GLIBTOP_MEM_BUFFER) +
-(1L << GLIBTOP_MEM_CACHED) +
-(1L << GLIBTOP_MEM_USER) + (1L << GLIBTOP_MEM_LOCKED);
+(1L << GLIBTOP_MEM_TOTAL)  + (1L << GLIBTOP_MEM_USED) +
+(1L << GLIBTOP_MEM_FREE)   + (1L << GLIBTOP_MEM_SHARED) +
+(1L << GLIBTOP_MEM_BUFFER) + (1L << GLIBTOP_MEM_CACHED) +
+(1L << GLIBTOP_MEM_USER)   + (1L << GLIBTOP_MEM_LOCKED);
 
 #ifndef LOG1024
 #define LOG1024		10
@@ -93,14 +91,12 @@ void
 glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
 {
 	struct vmtotal vmt;
-	size_t length_vmt;
 	struct uvmexp uvmexp;
-	size_t length_uvmexp;
 	struct bcachestats bcstats;
-	size_t length_bcstats;
 	u_int v_used_count;
 	u_int v_total_count;
 	u_int v_free_count;
+	size_t length;
 
 	glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MEM), 0);
 
@@ -110,24 +106,24 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
 		return;
 
 	/* Get the data from sysctl */
-	length_vmt = sizeof (vmt);
-	if (sysctl (vmmeter_mib, 2, &vmt, &length_vmt, NULL, 0)) {
+	length = sizeof (vmt);
+	if (sysctl (vmmeter_mib, 2, &vmt, &length, NULL, 0)) {
 		glibtop_warn_io_r (server, "sysctl (vm.vmmeter)");
-		bzero(&vmt, sizeof(length_vmt));
+		bzero(&vmt, sizeof(length));
 		return;
 	}
 
-	length_uvmexp = sizeof (uvmexp);
-	if (sysctl (uvmexp_mib, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
+	length = sizeof (uvmexp);
+	if (sysctl (uvmexp_mib, 2, &uvmexp, &length, NULL, 0)) {
 		glibtop_warn_io_r (server, "sysctl (vm.uvmexp)");
-		bzero(&uvmexp, sizeof(length_uvmexp));
+		bzero(&uvmexp, sizeof(length));
 		return;
 	}
 
-	length_bcstats = sizeof (bcstats);
-	if (sysctl (bcstats_mib, 3, &bcstats, &length_bcstats, NULL, 0)) {
+	length = sizeof (bcstats);
+	if (sysctl (bcstats_mib, 3, &bcstats, &length, NULL, 0)) {
 		glibtop_warn_io_r (server, "sysctl (vfs.generic.bcstats)");
-		bzero(&bcstats, sizeof(length_bcstats));
+		bzero(&bcstats, sizeof(length));
 		return;
 	}
 
diff --git a/sysdeps/openbsd/swap.c b/sysdeps/openbsd/swap.c
index 7f24365..4d46133 100644
--- a/sysdeps/openbsd/swap.c
+++ b/sysdeps/openbsd/swap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: swap.c,v 1.6 2011/05/25 10:44:34 jasper Exp $	*/
+/* $OpenBSD: swap.c,v 1.7 2011/07/10 15:23:01 jasper Exp $	*/
 
 /* Copyright (C) 1998-99 Martin Baulig
    This file is part of LibGTop 1.0.
@@ -79,7 +79,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
 
 	length_uvmexp = sizeof (uvmexp);
 	if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
-		glibtop_warn_io_r (server, "sysctl (uvmexp)");
+		glibtop_warn_io_r (server, "sysctl (vm.uvmexp)");
 		return;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]