summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-09-22 17:28:33 +0000
committerguenther <guenther@openbsd.org>2013-09-22 17:28:33 +0000
commit447f61ceb96730e27d7a7b3aa43a220baab5f6f7 (patch)
treea78278ed5d1759c69bd4a7f35b57aeaf8f19379b
parentDelete a T32 chunk that I missed before and update the comment on (diff)
downloadwireguard-openbsd-447f61ceb96730e27d7a7b3aa43a220baab5f6f7.tar.xz
wireguard-openbsd-447f61ceb96730e27d7a7b3aa43a220baab5f6f7.zip
Stop merging the per-thread and per-process flags when reporting
them via sysctl(KERN_PROC). In struct kinfo_proc the per-process flags move to p_psflags, leaving the per-thread flags in p_flags. Flag descriptions in ps(1) updated to be less obtuse. discussed with matthew@ some time ago; ok jca@, manpage bits ok jmc@
-rw-r--r--bin/ps/keyword.c4
-rw-r--r--bin/ps/print.c8
-rw-r--r--bin/ps/ps.159
-rw-r--r--bin/ps/ps.c4
-rw-r--r--sys/kern/kern_proc.c4
-rw-r--r--sys/sys/proc.h90
-rw-r--r--sys/sys/sysctl.h8
-rw-r--r--usr.bin/pkill/pkill.c4
8 files changed, 78 insertions, 103 deletions
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 21eac632377..fadd0fc79c9 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keyword.c,v 1.37 2012/04/11 17:33:26 guenther Exp $ */
+/* $OpenBSD: keyword.c,v 1.38 2013/09/22 17:28:34 guenther Exp $ */
/* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */
/*-
@@ -84,6 +84,7 @@ int utime(), stime(), ixrss(), idrss(), isrss();
#define CWDLEN 40
/* Bit types must match their respective entries in struct kinfo_proc */
+/* Entries must be sorted in lexical ascending order! */
VAR var[] = {
{"%cpu", "%CPU", NULL, NLIST, pcpu, 4},
{"%mem", "%MEM", NULL, NLIST, pmem, 4},
@@ -144,6 +145,7 @@ VAR var[] = {
{"pmem", "", "%mem"},
PID("ppid", "PPID", pvar, POFF(p_ppid)),
{"pri", "PRI", NULL, 0, pri, 3},
+ {"procflags", "PROCF", NULL, 0, pvar, 7, 0, POFF(p_psflags), INT32, "x"},
{"re", "RE", NULL, INF127, pvar, 3, 0, POFF(p_swtime), UINT32, "u"},
GID("rgid", "RGID", pvar, POFF(p_rgid)),
/* XXX */
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 46d06c66c82..835d345dadb 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.54 2013/03/23 21:12:31 tedu Exp $ */
+/* $OpenBSD: print.c,v 1.55 2013/09/22 17:28:34 guenther Exp $ */
/* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */
/*-
@@ -255,13 +255,13 @@ state(const struct kinfo_proc *kp, VARENT *ve)
*cp++ = '<';
else if (kp->p_nice > NZERO)
*cp++ = 'N';
- if (flag & P_TRACED)
+ if (kp->p_psflags & PS_TRACED)
*cp++ = 'X';
if (flag & P_SYSTRACE)
*cp++ = 'x';
if (flag & P_WEXIT && kp->p_stat != SZOMB)
*cp++ = 'E';
- if (flag & PS_ISPWAIT)
+ if (kp->p_psflags & PS_ISPWAIT)
*cp++ = 'V';
if (flag & P_SYSTEM)
*cp++ = 'K';
@@ -270,7 +270,7 @@ state(const struct kinfo_proc *kp, VARENT *ve)
*cp++ = '>';
if (kp->p_eflag & EPROC_SLEADER)
*cp++ = 's';
- if ((flag & P_CONTROLT) && kp->p__pgid == kp->p_tpgid)
+ if ((kp->p_psflags & PS_CONTROLT) && kp->p__pgid == kp->p_tpgid)
*cp++ = '+';
*cp = '\0';
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 432df90e1f9..b9b855d64ab 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ps.1,v 1.83 2012/08/02 03:18:48 guenther Exp $
+.\" $OpenBSD: ps.1,v 1.84 2013/09/22 17:28:34 guenther Exp $
.\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
@@ -30,7 +30,7 @@
.\"
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: August 2 2012 $
+.Dd $Mdocdate: September 22 2013 $
.Dt PS 1
.Os
.Sh NAME
@@ -218,40 +218,25 @@ Name of system call emulation environment.
.It Cm flags
Alias:
.Cm f .
-The union of the flags (in hexadecimal) associated with the process
-and the thread as in the include file
+The thread flags (in hexadecimal), as defined in the include file
.Aq Pa sys/proc.h :
.Bd -literal
-PS_CONTROLT 0x2 process has a controlling terminal
+P_INKTR 0x1 writing ktrace(2) record
P_SIGSUSPEND 0x8 need to restore before-suspend mask
-PS_PPWAIT 0x10 parent is waiting for child to
- exec/exit
-PS_PROFIL 0x20 process has started profiling
P_SELECT 0x40 selecting; wakeup/waiting danger
P_SINTR 0x80 sleep is interruptible
-PS_SUGID 0x100 process had set ID privileges since
- last exec
P_SYSTEM 0x200 system process: no sigs, stats, or
- swapping
+ swapping
P_TIMEOUT 0x400 timing out during sleep
-P_TRACED 0x800 process is being traced
-P_WAITED 0x1000 debugging process has waited for
- child
P_WEXIT 0x2000 working on exiting
-PS_EXEC 0x4000 process called exec(3)
-P_OWEUPC 0x8000 owe process an addupc() call at next
- ast
-.\" the routine addupc is not documented in the man pages
-PS_ISPWAIT 0x10000 is parent of PPWAIT child
-P_SSTEP 0x20000 process needs single-step fixup
-PS_SUGIDEXEC 0x40000 last exec(3) was set[ug]id
+P_OWEUPC 0x8000 profiling sample needs recording
P_NOZOMBIE 0x100000 pid 1 waits for me instead of dad
-P_INEXEC 0x200000 process is doing an exec right now
-P_SYSTRACE 0x400000 process system call tracing is active
-P_THREAD 0x4000000 only a thread, not a real process
-P_IGNEXITRV 0x8000000 for thread kills
+P_SYSTRACE 0x400000 systrace(4) policy is active
+P_CONTINUED 0x800000 thread has continued after a stop
+P_THREAD 0x4000000 not the original thread
+P_SUSPSIG 0x8000000 stopped because of a signal
P_SOFTDEP 0x10000000 stuck processing softdep worklist
-P_STOPPED 0x20000000 just stopped
+P_STOPPED 0x20000000 just stopped, need to send SIGCHLD
P_CPUPEG 0x40000000 do not move to another cpu
.Ed
.It Cm gid
@@ -326,6 +311,28 @@ Process ID.
Parent process ID.
.It Cm pri
Scheduling priority.
+.It Cm procflags
+The process flags (in hexadecimal), as defined in the include file
+.Aq Pa sys/proc.h :
+.Bd -literal
+PS_CONTROLT 0x1 process has a controlling terminal
+PS_EXEC 0x2 process called exec(3)
+PS_INEXEC 0x4 process is doing an exec right now
+PS_EXITING 0x8 process is exiting
+PS_SUGID 0x10 process had set ID privileges since
+ last exec
+PS_SUGIDEXEC 0x20 last exec(3) was set[ug]id
+PS_PPWAIT 0x40 parent is waiting for process to
+ exec/exit
+PS_ISPWAIT 0x80 process is parent of PPWAIT child
+PS_PROFIL 0x100 process has started profiling
+PS_TRACED 0x200 process is being traced
+PS_WAITED 0x400 debugging process has waited for
+ child
+PS_COREDUMP 0x800 busy coredumping
+PS_SINGLEEXIT 0x1000 other threads must die
+PS_SINGLEUNWIND 0x2000 other threads must unwind
+.Ed
.It Cm re
Core residency time (in seconds; 127 = infinity).
.It Cm rgid
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 95f6f49b309..c321963a4c2 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ps.c,v 1.55 2012/04/21 03:14:50 guenther Exp $ */
+/* $OpenBSD: ps.c,v 1.56 2013/09/22 17:28:34 guenther Exp $ */
/* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */
/*-
@@ -339,7 +339,7 @@ main(int argc, char *argv[])
if (showthreads == 0 && (kinfo[i]->p_flag & P_THREAD) != 0)
continue;
if (xflg == 0 && ((int)kinfo[i]->p_tdev == NODEV ||
- (kinfo[i]->p_flag & P_CONTROLT ) == 0))
+ (kinfo[i]->p_psflags & PS_CONTROLT ) == 0))
continue;
if (showthreads && kinfo[i]->p_tid == -1)
continue;
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 1258b937742..86bb22c4dec 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_proc.c,v 1.52 2013/08/12 20:43:28 bluhm Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.53 2013/09/22 17:28:34 guenther Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
@@ -397,7 +397,7 @@ proc_printit(struct proc *p, const char *modif,
(*pr)("PROC (%s) pid=%d stat=%s\n", p->p_comm, p->p_pid, pst);
(*pr)(" flags process=%b proc=%b\n",
- p->p_p->ps_flags, P_BITS, p->p_flag, P_BITS);
+ p->p_p->ps_flags, PS_BITS, p->p_flag, P_BITS);
(*pr)(" pri=%u, usrpri=%u, nice=%d\n",
p->p_priority, p->p_usrpri, p->p_p->ps_nice);
(*pr)(" forw=%p, list=%p,%p\n",
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 92892f16501..1ea8794a796 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.169 2013/08/12 20:43:28 bluhm Exp $ */
+/* $OpenBSD: proc.h,v 1.170 2013/09/22 17:28:33 guenther Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -222,30 +222,28 @@ struct process {
#endif /* __need_process */
/*
- * These flags are kept in ps_flags, but they used to be in proc's p_flag
- * and were exported to userspace via the KERN_PROC sysctl. We'll retain
- * compat by using non-overlapping bits for PS_* and P_* flags and just
- * OR them together for export.
+ * These flags are kept in ps_flags.
*/
-#define PS_CONTROLT _P_CONTROLT
-#define PS_PPWAIT _P_PPWAIT
-#define PS_PROFIL _P_PROFIL
-#define PS_SUGID _P_SUGID
-#define PS_SYSTEM _P_SYSTEM
-#define PS_TRACED _P_TRACED
-#define PS_WAITED _P_WAITED
-#define PS_EXEC _P_EXEC
-#define PS_ISPWAIT _P_ISPWAIT
-#define PS_SUGIDEXEC _P_SUGIDEXEC
-#define PS_NOZOMBIE _P_NOZOMBIE
-#define PS_INEXEC _P_INEXEC
-#define PS_SYSTRACE _P_SYSTRACE
-#define PS_CONTINUED _P_CONTINUED
-#define PS_STOPPED _P_STOPPED
-#define PS_SINGLEEXIT _P_SINGLEEXIT
-#define PS_SINGLEUNWIND _P_SINGLEUNWIND
-#define PS_EXITING _P_EXITING
-#define PS_COREDUMP _P_COREDUMP
+#define PS_CONTROLT 0x00000001 /* Has a controlling terminal. */
+#define PS_EXEC 0x00000002 /* Process called exec. */
+#define PS_INEXEC 0x00000004 /* Process is doing an exec right now */
+#define PS_EXITING 0x00000008 /* Process is exiting. */
+#define PS_SUGID 0x00000010 /* Had set id privs since last exec. */
+#define PS_SUGIDEXEC 0x00000020 /* last execve() was set[ug]id */
+#define PS_PPWAIT 0x00000040 /* Parent waits for exec/exit. */
+#define PS_ISPWAIT 0x00000080 /* Is parent of PPWAIT child. */
+#define PS_PROFIL 0x00000100 /* Has started profiling. */
+#define PS_TRACED 0x00000200 /* Being ptraced. */
+#define PS_WAITED 0x00000400 /* Stopped proc has waited for. */
+#define PS_COREDUMP 0x00000800 /* Busy coredumping */
+#define PS_SINGLEEXIT 0x00001000 /* Other threads must die. */
+#define PS_SINGLEUNWIND 0x00002000 /* Other threads must unwind. */
+
+#define PS_BITS \
+ ("\20\01CONTROLT\02EXEC\03INEXEC\04EXITING\05SUGID" \
+ "\06SUGIDEXEC\07PPWAIT\010ISPWAIT\011PROFIL\012TRACED" \
+ "\013WAITED\014COREDUMP\015SINGLEEXIT\016SINGLEUNWIND")
+
struct proc {
TAILQ_ENTRY(proc) p_runq;
@@ -361,65 +359,31 @@ struct proc {
#define P_ZOMBIE(p) ((p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
/*
- * These flags are kept in p_flag, except those with a leading underbar,
- * which are in process's ps_flags
+ * These flags are per-thread and kept in p_flag
*/
#define P_INKTR 0x000001 /* In a ktrace op, don't recurse */
-#define _P_CONTROLT 0x000002 /* Has a controlling terminal. */
-#define P_INMEM 0x000004 /* Loaded into memory. UNUSED */
#define P_SIGSUSPEND 0x000008 /* Need to restore before-suspend mask*/
-#define _P_PPWAIT 0x000010 /* Parent waits for exec/exit. */
-#define _P_PROFIL 0x000020 /* Has started profiling. */
#define P_SELECT 0x000040 /* Selecting; wakeup/waiting danger. */
#define P_SINTR 0x000080 /* Sleep is interruptible. */
-#define _P_SUGID 0x000100 /* Had set id privs since last exec. */
#define P_SYSTEM 0x000200 /* No sigs, stats or swapping. */
#define P_TIMEOUT 0x000400 /* Timing out during sleep. */
-#define _P_TRACED 0x000800 /* Debugged process being traced. */
-#define _P_WAITED 0x001000 /* Debugging proc has waited for child. */
#define P_WEXIT 0x002000 /* Working on exiting. */
-#define _P_EXEC 0x004000 /* Process called exec. */
-
-/* Should be moved to machine-dependent areas. */
#define P_OWEUPC 0x008000 /* Owe proc an addupc() at next ast. */
-
-#define _P_ISPWAIT 0x010000 /* Is parent of PPWAIT child. */
-#define _P_COREDUMP 0x020000 /* busy coredumping */
-#define _P_SUGIDEXEC 0x040000 /* last execve() was set[ug]id */
#define P_SUSPSINGLE 0x080000 /* Need to stop for single threading. */
#define P_NOZOMBIE 0x100000 /* Pid 1 waits for me instead of dad */
-#define _P_INEXEC 0x200000 /* Process is doing an exec right now */
#define P_SYSTRACE 0x400000 /* Process system call tracing active*/
#define P_CONTINUED 0x800000 /* Proc has continued from a stopped state. */
-#define _P_SINGLEEXIT 0x1000000 /* Other threads must die. */
-#define _P_SINGLEUNWIND 0x2000000 /* Other threads must unwind. */
#define P_THREAD 0x4000000 /* Only a thread, not a real process */
#define P_SUSPSIG 0x8000000 /* Stopped from signal. */
#define P_SOFTDEP 0x10000000 /* Stuck processing softdep worklist */
#define P_STOPPED 0x20000000 /* Just stopped, need sig to parent. */
#define P_CPUPEG 0x40000000 /* Do not move to another cpu. */
-#define _P_EXITING 0x80000000 /* Process is exiting. */
-
-#ifndef _KERNEL
-#define P_CONTROLT _P_CONTROLT
-#define P_PPWAIT _P_PPWAIT
-#define P_PROFIL _P_PROFIL
-#define P_SUGID _P_SUGID
-#define P_TRACED _P_TRACED
-#define P_EXEC _P_EXEC
-#define P_SUGIDEXEC _P_SUGIDEXEC
-#define P_INEXEC _P_INEXEC
-#endif
#define P_BITS \
- ("\20\01INKTR\02CONTROLT\03INMEM\04SIGSUSPEND" \
- "\05PPWAIT\06PROFIL\07SELECT\010SINTR" \
- "\011SUGID\012SYSTEM\013TIMEOUT\014TRACED" \
- "\015WAITED\016WEXIT\017EXEC\020OWEUPC" \
- "\021ISPWAIT\022COREDUMP\023SUGIDEXEC\024SUSPSINGLE" \
- "\025NOZOMBIE\026INEXEC\027SYSTRACE\030CONTINUED" \
- "\031SINGLEEXIT\032SINGLEUNWIND\033THREAD\034SUSPSIG" \
- "\035SOFTDEP\036STOPPED\037CPUPEG\040EXITING")
+ ("\20\01INKTR\04SIGSUSPEND\07SELECT\010SINTR\012SYSTEM" \
+ "\013TIMEOUT\016WEXIT\020OWEUPC\024SUSPSINGLE" \
+ "\025NOZOMBIE\027SYSTRACE\030CONTINUED\033THREAD" \
+ "\034SUSPSIG\035SOFTDEP\036STOPPED\037CPUPEG")
/* Macro to compute the exit signal to be delivered. */
#define P_EXITSIG(p) \
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 2a3a129f53b..19bfee3c48e 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.137 2013/08/13 05:52:27 guenther Exp $ */
+/* $OpenBSD: sysctl.h,v 1.138 2013/09/22 17:28:33 guenther Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -423,7 +423,8 @@ struct kinfo_proc {
u_int32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */
u_int32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */
- u_int64_t p_realflag; /* INT: P_* flags (not including LWPs). */
+ int32_t p_psflags; /* INT: PS_* flags on the process. */
+ int32_t p_spare; /* INT: unused. */
u_int32_t p_svuid; /* UID_T: saved user id */
u_int32_t p_svgid; /* GID_T: saved group id */
char p_emul[KI_EMULNAMELEN]; /* syscall emulation name */
@@ -478,7 +479,8 @@ do { \
} \
(kp)->p_stats = 0; \
(kp)->p_exitsig = (p)->p_exitsig; \
- (kp)->p_flag = (p)->p_flag | (pr)->ps_flags | P_INMEM; \
+ (kp)->p_flag = (p)->p_flag; \
+ (kp)->p_psflags = (pr)->ps_flags; \
\
(kp)->p__pgid = (pg)->pg_id; \
\
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index cc0d65848b4..931a7235c34 100644
--- a/usr.bin/pkill/pkill.c
+++ b/usr.bin/pkill/pkill.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pkill.c,v 1.32 2013/06/03 04:17:37 tedu Exp $ */
+/* $OpenBSD: pkill.c,v 1.33 2013/09/22 17:28:34 guenther Exp $ */
/* $NetBSD: pkill.c,v 1.5 2002/10/27 11:49:34 kleink Exp $ */
/*-
@@ -362,7 +362,7 @@ main(int argc, char **argv)
SLIST_FOREACH(li, &tdevlist, li_chain) {
if (li->li_number == -1 &&
- (kp->p_flag & P_CONTROLT) == 0)
+ (kp->p_psflags & PS_CONTROLT) == 0)
break;
if (kp->p_tdev == (uid_t)li->li_number)
break;