summaryrefslogtreecommitdiff
path: root/lib/libkvm
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-11-07 00:26:34 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-11-07 00:26:34 +0000
commitbd87d530432bb59e0e8e9945eb3552c2580af213 (patch)
tree094ceb36ef2db9352c5687de586c5176477f3c21 /lib/libkvm
parent174c1a4b3e7ca128b5540d3419d42f4d056e96af (diff)
Split PID from TID, giving processes a PID unrelated to the TID of their
initial thread ok jsing@ kettenis@
Diffstat (limited to 'lib/libkvm')
-rw-r--r--lib/libkvm/kvm_file2.c17
-rw-r--r--lib/libkvm/kvm_proc.c6
-rw-r--r--lib/libkvm/kvm_proc2.c42
3 files changed, 26 insertions, 39 deletions
diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c
index 2b880426a32..46aee3da694 100644
--- a/lib/libkvm/kvm_file2.c
+++ b/lib/libkvm/kvm_file2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_file2.c,v 1.50 2016/10/02 23:11:55 guenther Exp $ */
+/* $OpenBSD: kvm_file2.c,v 1.51 2016/11/07 00:26:33 guenther Exp $ */
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -329,6 +329,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (process.ps_mainproc == NULL)
continue;
+ /* XXX only needed for p_comm now */
if (KREAD(kd, (u_long)process.ps_mainproc, &proc)) {
_kvm_err(kd, kd->program, "can't read proc at %lx",
(u_long)process.ps_mainproc);
@@ -337,7 +338,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (op == KERN_FILE_BYPID) {
/* check if this is the pid we are looking for */
- if (arg > 0 && proc.p_pid != (pid_t)arg)
+ if (arg > 0 && process.ps_pid != (pid_t)arg)
continue;
matched = 1;
}
@@ -393,7 +394,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (buflen < esize)
goto done;
if (fill_file(kd, &kf, NULL, 0, process.ps_textvp,
- &process, KERN_FILE_TEXT, proc.p_pid) == -1)
+ &process, KERN_FILE_TEXT, process.ps_pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
where += esize;
@@ -404,7 +405,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (buflen < esize)
goto done;
if (fill_file(kd, &kf, NULL, 0, filed.fd_cdir,
- &process, KERN_FILE_CDIR, proc.p_pid) == -1)
+ &process, KERN_FILE_CDIR, process.ps_pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
where += esize;
@@ -415,7 +416,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (buflen < esize)
goto done;
if (fill_file(kd, &kf, NULL, 0, filed.fd_rdir,
- &process, KERN_FILE_RDIR, proc.p_pid) == -1)
+ &process, KERN_FILE_RDIR, process.ps_pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
where += esize;
@@ -426,7 +427,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (buflen < esize)
goto done;
if (fill_file(kd, &kf, NULL, 0, process.ps_tracevp,
- &process, KERN_FILE_TRACE, proc.p_pid) == -1)
+ &process, KERN_FILE_TRACE, process.ps_pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
where += esize;
@@ -439,7 +440,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
filed.fd_freefile > filed.fd_lastfile + 1) {
_kvm_err(kd, kd->program,
"filedesc corrupted at %lx for pid %d",
- (u_long)process.ps_fd, proc.p_pid);
+ (u_long)process.ps_fd, process.ps_pid);
goto cleanup;
}
@@ -453,7 +454,7 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
goto cleanup;
}
if (fill_file(kd, &kf, &file, (u_long)fp, NULL,
- &process, i, proc.p_pid) == -1)
+ &process, i, process.ps_pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
where += esize;
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
index c98b3be2159..12221d565c8 100644
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_proc.c,v 1.57 2016/09/16 04:03:27 dlg Exp $ */
+/* $OpenBSD: kvm_proc.c,v 1.58 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -404,10 +404,10 @@ proc_verify(kvm_t *kd, const struct kinfo_proc *p)
*/
if (KREAD(kd, (u_long)p->p_paddr, &kernproc))
return (0);
- if (p->p_pid != kernproc.p_pid)
- return (0);
if (KREAD(kd, (u_long)kernproc.p_p, &kernprocess))
return (0);
+ if (p->p_pid != kernprocess.ps_pid)
+ return (0);
return ((kernprocess.ps_flags & (PS_EMBRYO | PS_ZOMBIE)) == 0);
}
diff --git a/lib/libkvm/kvm_proc2.c b/lib/libkvm/kvm_proc2.c
index 52b74fe8815..a08fbcdf880 100644
--- a/lib/libkvm/kvm_proc2.c
+++ b/lib/libkvm/kvm_proc2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_proc2.c,v 1.26 2015/09/08 15:40:32 dlg Exp $ */
+/* $OpenBSD: kvm_proc2.c,v 1.27 2016/11/07 00:26:33 guenther Exp $ */
/* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -112,14 +112,14 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
struct kinfo_proc kp;
struct session sess;
struct ucred ucred;
- struct proc proc, proc2, *p;
+ struct proc proc, *p;
struct process process, process2;
struct pgrp pgrp;
struct tty tty;
struct sigacts sa, *sap;
struct vmspace vm, *vmp;
struct plimit limits, *limp;
- pid_t process_pid, parent_pid, leader_pid;
+ pid_t parent_pid, leader_pid;
int cnt = 0;
int dothreads = 0;
@@ -139,12 +139,6 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
continue;
if (process.ps_flags & PS_EMBRYO)
continue;
- if (KREAD(kd, (u_long)process.ps_mainproc, &proc)) {
- _kvm_err(kd, kd->program, "can't read proc at %lx",
- (u_long)process.ps_mainproc);
- return (-1);
- }
- process_pid = proc.p_pid;
if (KREAD(kd, (u_long)process.ps_ucred, &ucred)) {
_kvm_err(kd, kd->program, "can't read ucred at %lx",
(u_long)process.ps_ucred);
@@ -173,13 +167,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
(u_long)process.ps_pptr);
return (-1);
}
- if (KREAD(kd, (u_long)process2.ps_mainproc, &proc2)) {
- _kvm_err(kd, kd->program,
- "can't read proc at %lx",
- (u_long)process2.ps_mainproc);
- return (-1);
- }
- parent_pid = proc2.p_pid;
+ parent_pid = process2.ps_pid;
}
else
parent_pid = 0;
@@ -190,13 +178,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
(u_long)sess.s_leader);
return (-1);
}
- if (KREAD(kd, (u_long)process2.ps_mainproc, &proc2)) {
- _kvm_err(kd, kd->program,
- "can't read proc at %lx",
- (u_long)process2.ps_mainproc);
- return (-1);
- }
- leader_pid = proc2.p_pid;
+ leader_pid = process2.ps_pid;
}
else
leader_pid = 0;
@@ -247,7 +229,7 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
break;
case KERN_PROC_ALL:
- if (proc.p_flag & P_SYSTEM)
+ if (process.ps_flags & PS_SYSTEM)
continue;
break;
@@ -284,11 +266,10 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
#define do_copy_str(_d, _s, _l) kvm_read(kd, (u_long)(_s), (_d), (_l)-1)
FILL_KPROC(&kp, do_copy_str, &proc, &process,
- &ucred, &pgrp, process.ps_mainproc, proc.p_p, &sess,
+ &ucred, &pgrp, process.ps_mainproc, pr, &sess,
vmp, limp, sap, 0, 1);
/* stuff that's too painful to generalize */
- kp.p_pid = process_pid;
kp.p_ppid = parent_pid;
kp.p_sid = leader_pid;
if ((process.ps_flags & PS_CONTROLT) && sess.s_ttyp != NULL) {
@@ -310,6 +291,12 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
/* update %cpu for all threads */
if (dothreads) {
+ if (KREAD(kd, (u_long)process.ps_mainproc, &proc)) {
+ _kvm_err(kd, kd->program,
+ "can't read proc at %lx",
+ (u_long)process.ps_mainproc);
+ return (-1);
+ }
kp.p_pctcpu = proc.p_pctcpu;
kp.p_stat = proc.p_stat;
} else {
@@ -360,11 +347,10 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
return (-1);
}
FILL_KPROC(&kp, do_copy_str, &proc, &process,
- &ucred, &pgrp, p, proc.p_p, &sess, vmp, limp, sap,
+ &ucred, &pgrp, p, pr, &sess, vmp, limp, sap,
1, 1);
/* see above */
- kp.p_pid = process_pid;
kp.p_ppid = parent_pid;
kp.p_sid = leader_pid;
if ((process.ps_flags & PS_CONTROLT) &&