--- projects/libstatgrab/src/libstatgrab/process_stats.c 2004/04/05 18:10:11 1.53 +++ projects/libstatgrab/src/libstatgrab/process_stats.c 2004/04/05 19:55:27 1.54 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * - * $Id: process_stats.c,v 1.53 2004/04/05 18:10:11 ats Exp $ + * $Id: process_stats.c,v 1.54 2004/04/05 19:55:27 ats Exp $ */ #ifdef HAVE_CONFIG_H @@ -264,6 +264,7 @@ sg_process_stats *sg_get_process_stats(int *entries){ if(kp_stats == NULL) { return NULL; } + memset(kp_stats, 0, size); if(sysctl(mib, 3, kp_stats, &size, NULL, 0) < 0) { free(kp_stats); @@ -276,6 +277,15 @@ sg_process_stats *sg_get_process_stats(int *entries){ for (i = 0; i < procs; i++) { const char *name; + + if (kp_stats[i].ki_stat == 0) { + /* FreeBSD 5 deliberately overallocates the array that + * the sysctl returns, so we'll get a few junk + * processes on the end that we have to ignore. (Search + * for "overestimate by 5 procs" in + * src/sys/kern/kern_proc.c for more details.) */ + continue; + } if (VECTOR_RESIZE(proc_state, proc_state_size + 1) < 0) { return NULL;