$OpenBSD: patch-src_processes_c,v 1.2 2014/10/27 09:07:07 landry Exp $
https://github.com/collectd/collectd/pull/778
--- src/processes.c.orig	Sun Jan 26 09:09:14 2014
+++ src/processes.c	Sun Oct 26 21:27:10 2014
@@ -94,13 +94,13 @@
 #  endif
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD )
 #  include <kvm.h>
 #  include <sys/param.h>
 #  include <sys/sysctl.h>
 #  include <sys/user.h>
 #  include <sys/proc.h>
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD ) */
 
 #elif HAVE_PROCINFO_H
 #  include <procinfo.h>
@@ -210,9 +210,9 @@ static mach_msg_type_number_t     pset_list_len;
 static long pagesize_g;
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD )
 static int pagesize;
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD ) */
 
 #elif HAVE_PROCINFO_H
 static  struct procentry64 procentry[MAXPROCENTRY];
@@ -619,9 +619,9 @@ static int ps_init (void)
 			pagesize_g, CONFIG_HZ);
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD )
 	pagesize = getpagesize();
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD ) */
 
 #elif HAVE_PROCINFO_H
 	pagesize = getpagesize();
@@ -1777,14 +1777,14 @@ static int ps_read (void)
 	read_fork_rate();
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD )
 	int running  = 0;
 	int sleeping = 0;
 	int zombies  = 0;
 	int stopped  = 0;
-	int blocked  = 0;
+	int onproc   = 0;
 	int idle     = 0;
-	int wait     = 0;
+	int dead     = 0;
 
 	kvm_t *kd;
 	char errbuf[1024];
@@ -1808,7 +1808,7 @@ static int ps_read (void)
 	}
 
 	/* Get the list of processes. */
-	procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count);
+	procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
 	if (procs == NULL)
 	{
 		ERROR ("processes plugin: Cannot get kvm processes list: %s",
@@ -1822,22 +1822,20 @@ static int ps_read (void)
 	{
 		/* Create only one process list entry per _process_, i.e.
 		 * filter out threads (duplicate PID entries). */
-		if ((proc_ptr == NULL) || (proc_ptr->ki_pid != procs[i].ki_pid))
+		if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid))
 		{
 			char cmdline[ARG_MAX] = "";
 			_Bool have_cmdline = 0;
 
 			proc_ptr = &(procs[i]);
-			/* Don't probe system processes and processes without arguments */
-			if (((procs[i].ki_flag & P_SYSTEM) == 0)
-					&& (procs[i].ki_args != NULL))
+			/* Don't probe zombie processes */
+			if (!P_ZOMBIE(proc_ptr))
 			{
 				char **argv;
 				int argc;
 				int status;
 
-				/* retrieve the arguments */
-				argv = kvm_getargv (kd, proc_ptr, /* nchr = */ 0);
+				argv = kvm_getargv (kd, proc_ptr, 0);
 				argc = 0;
 				if ((argv != NULL) && (argv[0] != NULL))
 				{
@@ -1852,39 +1850,28 @@ static int ps_read (void)
 				}
 			} /* if (process has argument list) */
 
-			pse.id       = procs[i].ki_pid;
+			pse.id       = procs[i].p_pid;
 			pse.age      = 0;
 
 			pse.num_proc = 1;
-			pse.num_lwp  = procs[i].ki_numthreads;
+			pse.num_lwp  = 1; /*procs[i].ki_numthreads; see top -H code*/
 
-			pse.vmem_size = procs[i].ki_size;
-			pse.vmem_rss = procs[i].ki_rssize * pagesize;
-			pse.vmem_data = procs[i].ki_dsize * pagesize;
-			pse.vmem_code = procs[i].ki_tsize * pagesize;
-			pse.stack_size = procs[i].ki_ssize * pagesize;
+			pse.vmem_rss = procs[i].p_vm_rssize * pagesize;
+			pse.vmem_data = procs[i].p_vm_dsize * pagesize;
+			pse.vmem_code = procs[i].p_vm_tsize * pagesize;
+			pse.stack_size = procs[i].p_vm_ssize * pagesize;
+			pse.vmem_size = pse.stack_size + pse.vmem_code + pse.vmem_data;
 			pse.vmem_minflt = 0;
-			pse.vmem_minflt_counter = procs[i].ki_rusage.ru_minflt;
+			pse.vmem_minflt_counter = procs[i].p_uru_minflt;
 			pse.vmem_majflt = 0;
-			pse.vmem_majflt_counter = procs[i].ki_rusage.ru_majflt;
+			pse.vmem_majflt_counter = procs[i].p_uru_majflt;
 
 			pse.cpu_user = 0;
 			pse.cpu_system = 0;
-			pse.cpu_user_counter = 0;
-			pse.cpu_system_counter = 0;
-			/*
-			 * The u-area might be swapped out, and we can't get
-			 * at it because we have a crashdump and no swap.
-			 * If it's here fill in these fields, otherwise, just
-			 * leave them 0.
-			 */
-			if (procs[i].ki_flag & P_INMEM)
-			{
-				pse.cpu_user_counter = procs[i].ki_rusage.ru_utime.tv_usec
-				       	+ (1000000lu * procs[i].ki_rusage.ru_utime.tv_sec);
-				pse.cpu_system_counter = procs[i].ki_rusage.ru_stime.tv_usec
-					+ (1000000lu * procs[i].ki_rusage.ru_stime.tv_sec);
-			}
+			pse.cpu_user_counter = procs[i].p_uutime_usec +
+						(1000000lu * procs[i].p_uutime_sec);
+			pse.cpu_system_counter = procs[i].p_ustime_usec +
+						(1000000lu * procs[i].p_ustime_sec);
 
 			/* no I/O data */
 			pse.io_rchar = -1;
@@ -1892,17 +1879,17 @@ static int ps_read (void)
 			pse.io_syscr = -1;
 			pse.io_syscw = -1;
 
-			ps_list_add (procs[i].ki_comm, have_cmdline ? cmdline : NULL, &pse);
-		} /* if ((proc_ptr == NULL) || (proc_ptr->ki_pid != procs[i].ki_pid)) */
+			ps_list_add (procs[i].p_comm, have_cmdline ? cmdline : NULL, &pse);
+		} /* if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid)) */
 
-		switch (procs[i].ki_stat)
+		switch (procs[i].p_stat)
 		{
 			case SSTOP: 	stopped++;	break;
 			case SSLEEP:	sleeping++;	break;
 			case SRUN:	running++;	break;
 			case SIDL:	idle++;		break;
-			case SWAIT:	wait++;		break;
-			case SLOCK:	blocked++;	break;
+			case SONPROC:	onproc++;	break;
+			case SDEAD:	dead++;		break;
 			case SZOMB:	zombies++;	break;
 		}
 	}
@@ -1913,13 +1900,13 @@ static int ps_read (void)
 	ps_submit_state ("sleeping", sleeping);
 	ps_submit_state ("zombies",  zombies);
 	ps_submit_state ("stopped",  stopped);
-	ps_submit_state ("blocked",  blocked);
+	ps_submit_state ("onproc",   onproc);
 	ps_submit_state ("idle",     idle);
-	ps_submit_state ("wait",     wait);
+	ps_submit_state ("dead",     dead);
 
 	for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
 		ps_submit_proc_list (ps_ptr);
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && ( HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD ) */
 
 #elif HAVE_PROCINFO_H
 	/* AIX */
