[users at i-scream] *BSD TODO items

Jens Rehsack rehsack at googlemail.com
Fri Jun 14 14:48:30 BST 2013


Hi Tim,

> 4) DragonflyBSD & NetBSD testing
>    Dragonfly 3.4 - no network traffic showing

I added some debug code to dump the if_data structure - everything
is 0 there. But 
http://leaf.dragonflybsd.org/cgi/web-man?command=getifaddrs&section=ANY
says we're doing he right thing (tm). So I would leave it as it is
and wait what the D'flyers tell us ;)

Other opinions?

>    Dragonfly 3.4 - no user list

Cannot confirm. I see myself ;)

>    NetBSD - all ok?

I hope so - I'm searching for testers, but noone reacted. But some
helping the floodwaters victims (is the translation right?).

> 5) FreeBSD memory stats; totals don't add up
>    should we include cache in free memory?
>    so: free=free+inactive+cache, used=total-free ?

	mem_stats_buf->cache = (size_t)cache_count;
	mem_stats_buf->cache *= (size_t)pagesize;
	mem_stats_buf->total = (size_t)total_count;
	mem_stats_buf->total *= (size_t)pagesize;
	mem_stats_buf->free = (size_t)free_count + inactive_count;
	mem_stats_buf->free *= (size_t)pagesize;
	mem_stats_buf->used = mem_stats_buf->total - mem_stats_buf->free;

I didn't put the cache into free - to avoid confusing between
disk buffers and free memory. But that should be easy to change,
shouldn't it?

> 8) OpenBSD 5.3 - process stats missing
>    Failed to get process snapshot: sysctl failed (Invalid argument: CTL_KERN.KERN_PROC.KERN_PROC_ALL)

Fixed by attached patch - but it needs approval on more BSD's
before I commit it. I don't know - but maybe it'll break either
older OpenBSD's (then we need a way to check which way to use)
or any other (Dragonfly - maybe an ancient one, ...)

> 9) Should sg_destroy_globals be wrapped inside one of the thread-related
>    #ifdefs in globals.c?
>    Some testing should be done with threads disabled and warnings
>    turned on to see what other things crop up.
>    globals.c:447:1: warning: 'sg_destroy_globals' defined but not used [-Wunused-function]

Well, that seems to be an error - at least the glob_stats for the 
main-thread of the process must be freed. I analyse it and fix it.
Thank you very much for the hint.

Cheers,
Jens
-------------- next part --------------
diff --git a/src/libstatgrab/process_stats.c b/src/libstatgrab/process_stats.c
index 0ac6765..e063ed5 100644
--- a/src/libstatgrab/process_stats.c
+++ b/src/libstatgrab/process_stats.c
@@ -797,7 +797,10 @@ print_kernel_proctitle:
 	i = 4;
 #else
 	mib[2] = KERN_PROC_ALL;
-	i = 3;
+	mib[3] = 0;
+	mib[4] = sizeof(*kp_stats);
+	mib[5] = 0;
+	i = 6;
 #endif
 
 	if( NULL == (proctitle = sg_malloc( ARG_MAX * sizeof(*proctitle) ) ) ) {
@@ -816,6 +819,7 @@ again:
 	}
 
 	kp_stats = tmp;
+	mib[5] = nprocs = size / sizeof(*kp_stats);
 	if( -1 == (rc = sysctl(mib, (unsigned)i, kp_stats, &size, NULL, (size_t)0) ) ) {
 		if( errno == ENOMEM ) {
 			goto again;
@@ -824,7 +828,6 @@ again:
 	}
 
 	proc_items = 0;
-	nprocs = size / sizeof(*kp_stats);
 
 #undef VECTOR_UPDATE_ERROR_CLEANUP
 #define VECTOR_UPDATE_ERROR_CLEANUP free(kp_stats); free(proctitle);
@@ -1051,11 +1054,11 @@ again:
 			*proctitle = '\0';
 			mib[0] = CTL_KERN;
 #  if defined(KERN_PROC_ARGS)
-			mib[2] = KERN_PROC;
-			mib[2] = KERN_PROC_ARGS;
-			mib[3] = ((int)proc_stats_ptr[i].pid);
+			mib[1] = KERN_PROC_ARGS;
+			mib[2] = ((int)proc_stats_ptr[i].pid);
+			mib[3] = KERN_PROC_ARGV;
 			rc = 4;
-			p = "CTL_KERN.KERN_PROC.KERN_PROC_ARGS";
+			p = "CTL_KERN.KERN_PROC_ARGS.KERN_PROC_ARGV";
 #  elif defined(KERN_PROCARGS2)
 			mib[1] = KERN_PROCARGS2;
 			mib[2] = ((int)proc_stats_ptr[i].pid);
@@ -1063,12 +1066,11 @@ again:
 			p = "CTL_KERN.KERN_PROCARGS2";
 #  endif
 			if( -1 == ( rc = sysctl(mib, rc, proctitle, &size, NULL, 0) ) ) {
-				long failing_pid = (long)proc_stats_ptr[i].pid;
 #  if defined(KERN_PROCARGS2)
 				if( EINVAL == errno )
 					goto print_kernel_proctitle;
 #  endif
-				RETURN_WITH_SET_ERROR_WITH_ERRNO("process", SG_ERROR_SYSCTL, "%s for pid=%ld", p, failing_pid);
+				RETURN_WITH_SET_ERROR_WITH_ERRNO("process", SG_ERROR_SYSCTL, "%s for pid=" FMT_PID_T, p, proc_stats_ptr[i].pid);
 			}
 
 			if( size > 1 ) {


More information about the users mailing list