Subject: patch for Thorsten Lockert's m_netbsd.c/top-3.3beta
To: None <current-users@netbsd.org>
From: Jarle F. Greipsland <jarle@ed.unit.no>
List: current-users
Date: 11/11/1994 20:53:37
What follows is a patch against Thorsten Lockert's m_netbsd.c for
top-3.3beta, NetBSD/i386.  I apologize if someone has submitted a patch for
this one already, I just haven't noticed it yet ....

At some rare occasions the sysctl-call that reads out the wchan and wmesg
stuff gets a wchan without a wmesg.  The original version then bombs out
trying to print the value of the pointer by casting it to a string
..... This one sprintfs it instead.

						-jarle

*** machine/m_netbsd.c.orig	Wed Nov  9 21:49:30 1994
--- machine/m_netbsd.c	Wed Nov  9 22:03:17 1994
***************
*** 383,386 ****
--- 383,388 ----
      register double pct;
      struct handle *hp;
+     char waddr[sizeof(void *) * 2 + 3];	/* Hexify void pointer */
+     char *p_wait;
  
      /* find and remember the next proc structure */
***************
*** 411,414 ****
--- 413,427 ----
      pct = pctdouble(PP(pp, p_pctcpu));
  
+     if (PP(pp, p_wchan))
+         if (PP(pp, p_wmesg))
+ 	    p_wait = EP(pp, e_wmesg);
+ 	else {
+ 	    sprintf(waddr, "%x", 
+ 		(unsigned long)(PP(pp, p_wchan)) & ~KERNBASE);
+ 	    p_wait = waddr;
+         }
+     else
+ 	p_wait = "-";
+ 	    
      /* format this entry */
      sprintf(fmt,
***************
*** 421,428 ****
  	    format_k(pagetok(VP(pp, vm_rssize))),
  	    state_abbrev[(unsigned char) PP(pp, p_stat)],
! 	    PP(pp, p_wchan) ?
! 				PP(pp, p_wmesg) ? EP(pp, e_wmesg) :
! 						  (char *)((int)PP(pp, p_wchan) &~ KERNBASE) :
! 				"-",
  	    format_time(cputime),
  	    100.0 * pct,
--- 434,438 ----
  	    format_k(pagetok(VP(pp, vm_rssize))),
  	    state_abbrev[(unsigned char) PP(pp, p_stat)],
! 	    p_wait,
  	    format_time(cputime),
  	    100.0 * pct,