$NetBSD: patch-ab,v 1.7 2006/08/22 16:11:12 joerg Exp $

--- sysdeps/freebsd/proctime.c.orig	2006-04-04 22:01:43.000000000 +0200
+++ sysdeps/freebsd/proctime.c
@@ -32,6 +32,10 @@
 #include <osreldate.h>
 #endif
 
+#ifdef __NetBSD__
+#include <sys/resourcevar.h>
+#endif
+
 static const unsigned long _glibtop_sysdeps_proc_time =
 (1L << GLIBTOP_PROC_TIME_RTIME) + (1L << GLIBTOP_PROC_TIME_FREQUENCY);
 
@@ -58,7 +62,7 @@ glibtop_init_proc_time_p (glibtop *serve
  * system, and interrupt time usage.
  */
 
-#ifndef __FreeBSD__
+#if !defined(__FreeBSD__) && !defined(__DragonFly__)
 
 #ifndef __FreeBSD__
 static void
@@ -142,11 +146,15 @@ glibtop_get_proc_time_p (glibtop *server
 
 	/* Get the process information */
 	pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
-	if ((pinfo == NULL) || (count != 1))
-		glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
+	if ((pinfo == NULL) || (count != 1)) {
+		glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
+		return;
+	}
 
 #if defined(__FreeBSD__) && (__FreeBSD_version >= 500013)
 	buf->rtime = pinfo [0].ki_runtime;
+#elif defined(__DragonFly__)
+	buf->rtime = pinfo [0].kp_eproc.e_uticks / 100000;
 #elif (defined __FreeBSD__) && (__FreeBSD_version <= 500013)
 	buf->rtime = pinfo [0].kp_proc.p_runtime;
 #else
@@ -189,18 +197,26 @@ glibtop_get_proc_time_p (glibtop *server
        if ((pinfo [0].ki_flag & P_INMEM)) {
 #endif
            buf->utime = pinfo [0].ki_runtime;
-           buf->stime = 0; /* XXX */
+		   buf->stime = tv2sec (pinfo [0].ki_rusage.ru_stime);
            buf->cutime = tv2sec (pinfo [0].ki_childtime);
-           buf->cstime = 0; /* XXX */
+#if __FreeBSD_version >= 600000
+		   buf->cstime = tv2sec (pinfo [0].ki_rusage_ch.ru_stime);
+#else
+		   buf->cstime = 0;
+#endif
            buf->start_time = tv2sec (pinfo [0].ki_start);
            buf->flags = _glibtop_sysdeps_proc_time_user;
        }
 
 	glibtop_suid_enter (server);
 
-#elif (__FreeBSD_version <= 500013)
+#elif defined(__DragonFly__) || (defined(__FreeBSD__) || (__FreeBSD_version <= 500013))
 
+#if defined(__DragonFly__)
+        if ((pinfo [0].kp_proc.p_flag & P_SWAPPEDOUT) == 0 &&
+#else
         if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
+#endif
             kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
                        (unsigned long) &u_addr->u_stats,
                        (char *) &pstats, sizeof (pstats)) == sizeof (pstats))
@@ -210,13 +226,21 @@ glibtop_get_proc_time_p (glibtop *server
                        buf->stime = tv2sec (pinfo[0].kp_eproc.e_stats.p_ru.ru_stime);
                        buf->cutime = tv2sec (pinfo[0].kp_eproc.e_stats.p_cru.ru_utime);
                        buf->cstime = tv2sec (pinfo[0].kp_eproc.e_stats.p_cru.ru_stime);
+#if defined(__DragonFly__)
+                       buf->start_time = tv2sec (pinfo[0].kp_thread.td_start);
+#else
                        buf->start_time = tv2sec (pinfo[0].kp_eproc.e_stats.p_start);
+#endif
                        buf->flags = _glibtop_sysdeps_proc_time_user;
                        glibtop_suid_leave (server);
 		}
 #else
 
+#if defined(__DragonFly__)
+        if ((pinfo [0].kp_proc.p_flag & P_SWAPPEDOUT) == 0 &&
+#else
 	if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
+#endif
 	    kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
 		       (unsigned long) &u_addr->u_stats,
 		       (char *) &pstats, sizeof (pstats)) == sizeof (pstats))
