diff options
author | Paul Irofti <pirofti@cvs.openbsd.org> | 2012-04-17 23:17:54 +0000 |
---|---|---|
committer | Paul Irofti <pirofti@cvs.openbsd.org> | 2012-04-17 23:17:54 +0000 |
commit | 9423fd636fbb829a3beb96e6bf91a8435aca0dac (patch) | |
tree | 662e13cd8db382c4a64c9981a968e8662067d7d4 | |
parent | 0dda1e76ea40698dad18b59045a473096026880e (diff) |
Make it optional for kvm_getprocs() (and related sysctl) to return
thread information.
Add a KERN_PROC_SHOW_THREADS flag that has to be set in order to get the
thread info and make it off by default. This creates backwards compatibility
for applications that relied on a given size/number of items to be returned.
Modify ps(1) and top(1) accordingly.
Okay guenther@.
-rw-r--r-- | bin/ps/ps.c | 4 | ||||
-rw-r--r-- | lib/libkvm/kvm_proc2.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 10 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 3 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 8 |
5 files changed, 29 insertions, 6 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 77a0e48f97f..0577bfa1563 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.53 2012/04/12 14:59:19 pirofti Exp $ */ +/* $OpenBSD: ps.c,v 1.54 2012/04/17 23:17:53 pirofti Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -307,6 +307,8 @@ main(int argc, char *argv[]) what = KERN_PROC_ALL; flag = 0; } + if (showthreads) + what |= KERN_PROC_SHOW_THREADS; /* * select procs diff --git a/lib/libkvm/kvm_proc2.c b/lib/libkvm/kvm_proc2.c index 31b6db78cd1..8c4dd7a148e 100644 --- a/lib/libkvm/kvm_proc2.c +++ b/lib/libkvm/kvm_proc2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc2.c,v 1.12 2012/04/14 12:15:21 guenther Exp $ */ +/* $OpenBSD: kvm_proc2.c,v 1.13 2012/04/17 23:17:53 pirofti Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -119,6 +119,10 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, struct plimit limits, *limp; pid_t process_pid, parent_pid, leader_pid; int cnt = 0; + int dothreads = 0; + + dothreads = op & KERN_PROC_SHOW_THREADS; + op &= ~KERN_PROC_SHOW_THREADS; for (; cnt < maxcnt && p != NULL; p = LIST_NEXT(&proc, p_list)) { if (KREAD(kd, (u_long)p, &proc)) { @@ -313,6 +317,10 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, bp += esize; ++cnt; } + + if (!dothreads) + continue; + FILL_KPROC(&kp, do_copy_str, &proc, &process, &pcred, &ucred, &pgrp, p, proc.p_p, &sess, vmp, limp, sap, 1); diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index c6b9cf784f3..c7b1e5331e3 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.220 2012/04/12 14:59:19 pirofti Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.221 2012/04/17 23:17:53 pirofti Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1373,6 +1373,7 @@ sysctl_doproc(int *name, u_int namelen, char *where, size_t *sizep) char *dp; int arg, buflen, doingzomb, elem_size, elem_count; int error, needed, op; + int dothreads = 0; dp = where; buflen = where != NULL ? *sizep : 0; @@ -1386,6 +1387,9 @@ sysctl_doproc(int *name, u_int namelen, char *where, size_t *sizep) elem_size = name[2]; elem_count = name[3]; + dothreads = op & KERN_PROC_SHOW_THREADS; + op &= ~KERN_PROC_SHOW_THREADS; + if (where != NULL) kproc = malloc(sizeof(*kproc), M_TEMP, M_WAITOK); @@ -1470,6 +1474,10 @@ again: } needed += elem_size; } + /* Skip the second entry if not required by op */ + if (!dothreads) + continue; + if (buflen >= elem_size && elem_count > 0) { fill_kproc(p, kproc, 1); error = copyout(kproc, dp, elem_size); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 0dfa6bb1441..3ad7ddb292f 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.124 2012/04/12 14:59:18 pirofti Exp $ */ +/* $OpenBSD: sysctl.h,v 1.125 2012/04/17 23:17:53 pirofti Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -288,6 +288,7 @@ struct ctlname { #define KERN_PROC_UID 5 /* by effective uid */ #define KERN_PROC_RUID 6 /* by real uid */ #define KERN_PROC_KTHREAD 7 /* also return kernel threads */ +#define KERN_PROC_SHOW_THREADS 0x40000000/* also return normal threads */ /* * KERN_SYSVIPC_INFO subtypes diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 0bedc42da0f..5b5db66f81e 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.70 2012/04/12 14:59:19 pirofti Exp $ */ +/* $OpenBSD: machine.c,v 1.71 2012/04/17 23:17:53 pirofti Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> @@ -332,8 +332,12 @@ get_process_info(struct system_info *si, struct process_select *sel, int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd; int total_procs, active_procs; struct kinfo_proc **prefp, *pp; + int what = KERN_PROC_KTHREAD; - if ((pbase = getprocs(KERN_PROC_KTHREAD, 0, &nproc)) == NULL) { + if (sel->threads) + what |= KERN_PROC_SHOW_THREADS; + + if ((pbase = getprocs(what, 0, &nproc)) == NULL) { /* warnx("%s", kvm_geterr(kd)); */ quit(23); } |