225 lines
6.6 KiB
Plaintext
225 lines
6.6 KiB
Plaintext
$OpenBSD: patch-machine_m_openbsd_c,v 1.3 2012/12/18 21:38:12 sthen Exp $
|
|
--- machine/m_openbsd.c.orig Sat Apr 5 11:09:06 2008
|
|
+++ machine/m_openbsd.c Thu Dec 6 15:30:59 2012
|
|
@@ -38,6 +38,7 @@
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
+#include <sys/proc.h>
|
|
#include <sys/sysctl.h>
|
|
#include <sys/dkstat.h>
|
|
#include <sys/swap.h>
|
|
@@ -51,13 +52,13 @@
|
|
#include "loadavg.h"
|
|
|
|
static long swapmode(long *, long *);
|
|
-static char *state_abbr(struct kinfo_proc2 *);
|
|
-static char *format_comm(struct kinfo_proc2 *);
|
|
+static char *state_abbr(struct kinfo_proc *);
|
|
+static char *format_comm(struct kinfo_proc *);
|
|
|
|
/* get_process_info passes back a handle. This is what it looks like: */
|
|
|
|
struct handle {
|
|
- struct kinfo_proc2 **next_proc; /* points to next valid proc pointer */
|
|
+ struct kinfo_proc **next_proc; /* points to next valid proc pointer */
|
|
int remaining; /* number of pointers remaining */
|
|
};
|
|
|
|
@@ -138,8 +139,8 @@ int (*proc_compares[]) () =
|
|
static int nproc;
|
|
static int onproc = -1;
|
|
static int pref_len;
|
|
-static struct kinfo_proc2 *pbase;
|
|
-static struct kinfo_proc2 **pref;
|
|
+static struct kinfo_proc *pbase;
|
|
+static struct kinfo_proc **pref;
|
|
|
|
/* these are for getting the memory statistics */
|
|
static int pageshift; /* log base 2 of the pagesize */
|
|
@@ -312,7 +313,7 @@ get_process_info(struct system_info *si, struct proces
|
|
{
|
|
int show_idle, show_system, show_threads, show_uid, show_cmd;
|
|
int total_procs, active_procs;
|
|
- struct kinfo_proc2 **prefp, *pp;
|
|
+ struct kinfo_proc **prefp, *pp;
|
|
int mib[6];
|
|
size_t size;
|
|
|
|
@@ -320,11 +321,11 @@ get_process_info(struct system_info *si, struct proces
|
|
PGconn *pgconn;
|
|
PGresult *pgresult = NULL;
|
|
|
|
- size = (size_t) sizeof(struct kinfo_proc2);
|
|
+ size = (size_t) sizeof(struct kinfo_proc);
|
|
mib[0] = CTL_KERN;
|
|
- mib[1] = KERN_PROC2;
|
|
+ mib[1] = KERN_PROC;
|
|
mib[2] = KERN_PROC_PID;
|
|
- mib[4] = sizeof(struct kinfo_proc2);
|
|
+ mib[4] = sizeof(struct kinfo_proc);
|
|
mib[5] = 1;
|
|
|
|
nproc = 0;
|
|
@@ -333,14 +334,14 @@ get_process_info(struct system_info *si, struct proces
|
|
{
|
|
pgresult = PQexec(pgconn, QUERY_PROCESSES);
|
|
nproc = PQntuples(pgresult);
|
|
- pbase = (struct kinfo_proc2 *) realloc(pbase,
|
|
- sizeof(struct kinfo_proc2 *) * nproc);
|
|
+ pbase = (struct kinfo_proc *) realloc(pbase,
|
|
+ sizeof(struct kinfo_proc *) * nproc);
|
|
}
|
|
PQfinish(pgconn);
|
|
|
|
if (nproc > onproc)
|
|
- pref = (struct kinfo_proc2 **)realloc(pref,
|
|
- sizeof(struct kinfo_proc2 *) * (onproc = nproc));
|
|
+ pref = (struct kinfo_proc **)realloc(pref,
|
|
+ sizeof(struct kinfo_proc *) * (onproc = nproc));
|
|
if (pref == NULL) {
|
|
warnx("Out of memory.");
|
|
quit(23);
|
|
@@ -392,9 +393,9 @@ get_process_info(struct system_info *si, struct proces
|
|
}
|
|
|
|
/* if requested, sort the "interesting" processes */
|
|
- if (compare_index != NULL)
|
|
+ if (compare_index != 0)
|
|
qsort((char *) pref, active_procs,
|
|
- sizeof(struct kinfo_proc2 *), proc_compares[compare_index]);
|
|
+ sizeof(struct kinfo_proc *), proc_compares[compare_index]);
|
|
/* remember active and total counts */
|
|
si->p_total = total_procs;
|
|
si->p_active = pref_len = active_procs;
|
|
@@ -408,7 +409,7 @@ get_process_info(struct system_info *si, struct proces
|
|
char fmt[MAX_COLS]; /* static area where result is built */
|
|
|
|
static char *
|
|
-state_abbr(struct kinfo_proc2 *pp)
|
|
+state_abbr(struct kinfo_proc *pp)
|
|
{
|
|
static char buf[10];
|
|
|
|
@@ -422,7 +423,7 @@ state_abbr(struct kinfo_proc2 *pp)
|
|
}
|
|
|
|
static char *
|
|
-format_comm(struct kinfo_proc2 *kp)
|
|
+format_comm(struct kinfo_proc *kp)
|
|
{
|
|
#define ARG_SIZE 60
|
|
static char **s, buf[ARG_SIZE];
|
|
@@ -457,7 +458,7 @@ char *
|
|
format_next_process(caddr_t handle, char *(*get_userid)(uid_t))
|
|
{
|
|
char *p_wait, waddr[sizeof(void *) * 2 + 3]; /* Hexify void pointer */
|
|
- struct kinfo_proc2 *pp;
|
|
+ struct kinfo_proc *pp;
|
|
struct handle *hp;
|
|
int cputime;
|
|
double pct;
|
|
@@ -477,7 +478,7 @@ format_next_process(caddr_t handle, char *(*get_userid
|
|
p_wait = pp->p_wmesg;
|
|
else {
|
|
snprintf(waddr, sizeof(waddr), "%llx",
|
|
- (unsigned long long)(pp->p_wchan & ~KERNBASE));
|
|
+ (unsigned long long)pp->p_wchan);
|
|
p_wait = waddr;
|
|
}
|
|
} else
|
|
@@ -541,13 +542,13 @@ compare_cpu(const void *v1, const void *v2)
|
|
{
|
|
struct proc **pp1 = (struct proc **) v1;
|
|
struct proc **pp2 = (struct proc **) v2;
|
|
- struct kinfo_proc2 *p1, *p2;
|
|
+ struct kinfo_proc *p1, *p2;
|
|
pctcpu lresult;
|
|
int result;
|
|
|
|
/* remove one level of indirection */
|
|
- p1 = *(struct kinfo_proc2 **) pp1;
|
|
- p2 = *(struct kinfo_proc2 **) pp2;
|
|
+ p1 = *(struct kinfo_proc **) pp1;
|
|
+ p2 = *(struct kinfo_proc **) pp2;
|
|
|
|
ORDERKEY_PCTCPU
|
|
ORDERKEY_CPUTIME
|
|
@@ -565,13 +566,13 @@ compare_size(const void *v1, const void *v2)
|
|
{
|
|
struct proc **pp1 = (struct proc **) v1;
|
|
struct proc **pp2 = (struct proc **) v2;
|
|
- struct kinfo_proc2 *p1, *p2;
|
|
+ struct kinfo_proc *p1, *p2;
|
|
pctcpu lresult;
|
|
int result;
|
|
|
|
/* remove one level of indirection */
|
|
- p1 = *(struct kinfo_proc2 **) pp1;
|
|
- p2 = *(struct kinfo_proc2 **) pp2;
|
|
+ p1 = *(struct kinfo_proc **) pp1;
|
|
+ p2 = *(struct kinfo_proc **) pp2;
|
|
|
|
ORDERKEY_MEM
|
|
ORDERKEY_RSSIZE
|
|
@@ -589,13 +590,13 @@ compare_res(const void *v1, const void *v2)
|
|
{
|
|
struct proc **pp1 = (struct proc **) v1;
|
|
struct proc **pp2 = (struct proc **) v2;
|
|
- struct kinfo_proc2 *p1, *p2;
|
|
+ struct kinfo_proc *p1, *p2;
|
|
pctcpu lresult;
|
|
int result;
|
|
|
|
/* remove one level of indirection */
|
|
- p1 = *(struct kinfo_proc2 **) pp1;
|
|
- p2 = *(struct kinfo_proc2 **) pp2;
|
|
+ p1 = *(struct kinfo_proc **) pp1;
|
|
+ p2 = *(struct kinfo_proc **) pp2;
|
|
|
|
ORDERKEY_RSSIZE
|
|
ORDERKEY_MEM
|
|
@@ -613,13 +614,13 @@ compare_time(const void *v1, const void *v2)
|
|
{
|
|
struct proc **pp1 = (struct proc **) v1;
|
|
struct proc **pp2 = (struct proc **) v2;
|
|
- struct kinfo_proc2 *p1, *p2;
|
|
+ struct kinfo_proc *p1, *p2;
|
|
pctcpu lresult;
|
|
int result;
|
|
|
|
/* remove one level of indirection */
|
|
- p1 = *(struct kinfo_proc2 **) pp1;
|
|
- p2 = *(struct kinfo_proc2 **) pp2;
|
|
+ p1 = *(struct kinfo_proc **) pp1;
|
|
+ p2 = *(struct kinfo_proc **) pp2;
|
|
|
|
ORDERKEY_CPUTIME
|
|
ORDERKEY_PCTCPU
|
|
@@ -637,13 +638,13 @@ compare_prio(const void *v1, const void *v2)
|
|
{
|
|
struct proc **pp1 = (struct proc **) v1;
|
|
struct proc **pp2 = (struct proc **) v2;
|
|
- struct kinfo_proc2 *p1, *p2;
|
|
+ struct kinfo_proc *p1, *p2;
|
|
pctcpu lresult;
|
|
int result;
|
|
|
|
/* remove one level of indirection */
|
|
- p1 = *(struct kinfo_proc2 **) pp1;
|
|
- p2 = *(struct kinfo_proc2 **) pp2;
|
|
+ p1 = *(struct kinfo_proc **) pp1;
|
|
+ p2 = *(struct kinfo_proc **) pp2;
|
|
|
|
ORDERKEY_PRIO
|
|
ORDERKEY_PCTCPU
|
|
@@ -667,7 +668,7 @@ compare_prio(const void *v1, const void *v2)
|
|
uid_t
|
|
proc_owner(pid_t pid)
|
|
{
|
|
- struct kinfo_proc2 **prefp, *pp;
|
|
+ struct kinfo_proc **prefp, *pp;
|
|
int cnt;
|
|
|
|
prefp = pref;
|