History log of /openbsd-current/usr.sbin/pstat/pstat.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.129 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.128 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


# 1.127 15-Nov-2021 millert

No need to declare optind, optarg or opterr; unistd.h does this for us.
From Jan Stary. OK deraadt@


# 1.126 20-Oct-2021 semarie

revert vnode: remove VLOCKSWORK and check locking when vop_islocked != nullop
(both kernel and userland bits)

GENERIC + VFSLCKDEBUG is broken with it.


# 1.125 19-Oct-2021 semarie

vnode: remove VLOCKSWORK usage in pstat and mention in man pages

unbreak the tree. found hard way by tb@

ok tb@ which have the same diff


Revision tags: OPENBSD_7_0_BASE
# 1.124 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.123 28-Sep-2020 tb

Fix segfault in pstat -v

Broken in r1.122 when the vnode list at the mount point was converted to
a TAILQ to make softdeps happy. There was a for loop that looked a lot
like a LIST_FOREACH that was converted to a TAILQ_FOREACH. Unfortunately,
the loop is a bit more intricate. Revert to the original loop logic, but
now with TAILQ.

"looks correct" millert, "looks good" deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.128 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


# 1.127 15-Nov-2021 millert

No need to declare optind, optarg or opterr; unistd.h does this for us.
From Jan Stary. OK deraadt@


# 1.126 20-Oct-2021 semarie

revert vnode: remove VLOCKSWORK and check locking when vop_islocked != nullop
(both kernel and userland bits)

GENERIC + VFSLCKDEBUG is broken with it.


# 1.125 19-Oct-2021 semarie

vnode: remove VLOCKSWORK usage in pstat and mention in man pages

unbreak the tree. found hard way by tb@

ok tb@ which have the same diff


Revision tags: OPENBSD_7_0_BASE
# 1.124 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.123 28-Sep-2020 tb

Fix segfault in pstat -v

Broken in r1.122 when the vnode list at the mount point was converted to
a TAILQ to make softdeps happy. There was a for loop that looked a lot
like a LIST_FOREACH that was converted to a TAILQ_FOREACH. Unfortunately,
the loop is a bit more intricate. Revert to the original loop logic, but
now with TAILQ.

"looks correct" millert, "looks good" deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.127 15-Nov-2021 millert

No need to declare optind, optarg or opterr; unistd.h does this for us.
From Jan Stary. OK deraadt@


# 1.126 20-Oct-2021 semarie

revert vnode: remove VLOCKSWORK and check locking when vop_islocked != nullop
(both kernel and userland bits)

GENERIC + VFSLCKDEBUG is broken with it.


# 1.125 19-Oct-2021 semarie

vnode: remove VLOCKSWORK usage in pstat and mention in man pages

unbreak the tree. found hard way by tb@

ok tb@ which have the same diff


Revision tags: OPENBSD_7_0_BASE
# 1.124 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.123 28-Sep-2020 tb

Fix segfault in pstat -v

Broken in r1.122 when the vnode list at the mount point was converted to
a TAILQ to make softdeps happy. There was a for loop that looked a lot
like a LIST_FOREACH that was converted to a TAILQ_FOREACH. Unfortunately,
the loop is a bit more intricate. Revert to the original loop logic, but
now with TAILQ.

"looks correct" millert, "looks good" deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.126 20-Oct-2021 semarie

revert vnode: remove VLOCKSWORK and check locking when vop_islocked != nullop
(both kernel and userland bits)

GENERIC + VFSLCKDEBUG is broken with it.


# 1.125 19-Oct-2021 semarie

vnode: remove VLOCKSWORK usage in pstat and mention in man pages

unbreak the tree. found hard way by tb@

ok tb@ which have the same diff


Revision tags: OPENBSD_7_0_BASE
# 1.124 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.123 28-Sep-2020 tb

Fix segfault in pstat -v

Broken in r1.122 when the vnode list at the mount point was converted to
a TAILQ to make softdeps happy. There was a for loop that looked a lot
like a LIST_FOREACH that was converted to a TAILQ_FOREACH. Unfortunately,
the loop is a bit more intricate. Revert to the original loop logic, but
now with TAILQ.

"looks correct" millert, "looks good" deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.124 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.123 28-Sep-2020 tb

Fix segfault in pstat -v

Broken in r1.122 when the vnode list at the mount point was converted to
a TAILQ to make softdeps happy. There was a for loop that looked a lot
like a LIST_FOREACH that was converted to a TAILQ_FOREACH. Unfortunately,
the loop is a bit more intricate. Revert to the original loop logic, but
now with TAILQ.

"looks correct" millert, "looks good" deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_8_BASE
# 1.123 28-Sep-2020 tb

Fix segfault in pstat -v

Broken in r1.122 when the vnode list at the mount point was converted to
a TAILQ to make softdeps happy. There was a for loop that looked a lot
like a LIST_FOREACH that was converted to a TAILQ_FOREACH. Unfortunately,
the loop is a bit more intricate. Revert to the original loop logic, but
now with TAILQ.

"looks correct" millert, "looks good" deraadt


Revision tags: OPENBSD_6_7_BASE
# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.122 10-Jan-2020 bluhm

Convert the vnode list at the mount point into a tailq. During
unmount this list is traversed and the dirty vnodes are flushed to
disk. Forced unmount expects that the list is empty after flushing,
otherwise the kernel panics with "dangling vnode". As the write
to disk can sleep, new vnodes may be inserted. If softdep is
enabled, resolving the dependencies creates new dirty vnodes and
inserts them to the list. To fix the panic, let insmntque() insert
new vnodes at the tail of the list. Then vflush() will still catch
them while traversing the list in forward direction.
OK tedu@ millert@ visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.121 05-Feb-2019 deraadt

dev_t is signed to permit passing -1 as an invalid condition, but the
decomposition into major and minor is unsigned, so we should print them
with %u instead of %d.
ok guenther


Revision tags: OPENBSD_6_4_BASE
# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.120 10-Sep-2018 yasuoka

Fix previous commit. It mistakenly included a change for debug.


# 1.119 07-Sep-2018 yasuoka

Fix "_nfiles" reference for crash dump.
Diff from fukaumi at soum.co.jp

ok mpi


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.118 03-Aug-2018 deraadt

unveil _PATH_DEVDB for devname(). All other filenames are opened
before unveil/pledge.


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.117 18-Jun-2018 mpi

Put file descriptors on shared data structures when they are completely
setup, take 3.

LARVAL fd still exist, but they are no longer marked with a flag and no
longer reachable via `fd_ofiles[]' or the global linked list. This allows
us to simplifies a lot code grabbing new references to fds.

All of this is now possible because dup2(2) refuses to clone LARVAL fds.

Note that the `fdplock' could now be release in all open(2)-like syscalls,
just like it is done in accept(2).

With inputs from Mathieu Masson, visa@, guenther@ and art@

Previous version ok bluhm@, ok visa@, sthen@


# 1.116 05-Jun-2018 mpi

Revert introduction of fdinsert(), a sanitify check triggers when
closing a LARVAL file.

Found the hardway by sthen@.


# 1.115 02-Jun-2018 mpi

LARVAL fds are now invisble from userland.

From tb@


Revision tags: OPENBSD_6_3_BASE
# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.114 02-Jan-2018 guenther

Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.

ok millert@ sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.113 09-Feb-2017 jca

Teach pstat -d to also print untyped kernel symbols.

Storage defined in assembly code often doesn't define its type and size,
thus the nlist interface can't present it as N_DATA. Instead of fixing
all the assembly by adding .type pseudo ops, work around the problem in
pstat. Let's hope that allowing N_COMM is sufficient. This makes
''pstat -d u cpuid_level'' useful.

Reported by mikeb@, "looks sane" mikeb@ guenther@


# 1.112 26-Nov-2016 mpi

Remove leftovers of line disciplines that are no more.

ok mikeb@


# 1.111 23-Oct-2016 kettenis

For -d, if there is no modifier, don't go down the "longformat" path.
Fixes cases like "pstat -d x ticks" on armv7.

ok jca@, deraadt@


# 1.110 19-Sep-2016 tb

Add pledge support to pstat

The filemode(), ttymode() and vnodemode() functions can be split into two
pieces. The *_prep() piece must be hoisted to before pledge and the rest
can run under pledge "stdio rpath vminfo". The magic block that decides
which ones of the *_prep() pieces must be run with which combination of
command line switches is quite impressive.

Patch from Rob Pierce, thanks!

ok deraadt


# 1.109 19-Sep-2016 tb

Fix pstat -ft. In presence of the -f flag, a logic error in ttymode()
leads to entering codepaths that try to work with only partially
initialized kvm structures -- with unsurprising outcomes.

Problem found by Rob Pierce, ok deraadt


# 1.108 14-Aug-2016 guenther

Convert %q to %ll and cast opaque system values to long long.
Use uint64_t for the KERN_INTRCNT_CNT sysctl()

ok krw@


Revision tags: OPENBSD_6_0_BASE
# 1.107 18-Jul-2016 guenther

Fix VFLAG formatting

ok bluhm@


# 1.106 03-Jun-2016 deraadt

correct synopsis to make -d usage clearer.
The shed fell over because 15 layers of paint exceeded engineering margins.


# 1.105 27-May-2016 deraadt

W^X violations are no longer permitted by default. A kernel log message
is generated, and mprotect/mmap return ENOTSUP. If the sysctl(8) flag
kern.wxabort is set then a SIGABRT occurs instead, for gdb use or coredump
creation.

W^X violating programs can be permitted on a ffs/nfs filesystem-basis,
using the "wxallowed" mount option. One day far in the future
upstream software developers will understand that W^X violations are a
tremendously risky practice and that style of programming will be
banished outright. Until then, we recommend most users need to use the
wxallowed option on their /usr/local filesystem. At least your other
filesystems don't permit such programs.

ok jca kettenis mlarkin natano


# 1.104 25-May-2016 deraadt

remove code to display MNT_EXKERB bit


# 1.103 25-Apr-2016 tedu

remove systrace


# 1.102 12-Apr-2016 millert

The -T flag consumes the same data as the -f flag so it requires
nlist too. Fixes a crash when the -T flag is specified due to
calling kvm_read() with a NULL kvm_t. From Rob Pierce


Revision tags: OPENBSD_5_9_BASE
# 1.101 11-Dec-2015 tedu

dformat is pointer, don't compare with 0


# 1.100 28-Aug-2015 guenther

Rework the UNIX domain socket garbage collector, including ideas from
{Free,Net}BSD
- when a socket is closed with fds in its input, defer closing them to
a task to avoid recursing. This eliminates the complicated extra
reference taking which had a 37 line(!) comment explanation
- move flags, counts, and links only needed for this from struct file to
struct unpcb
- document the flow of the mark/sweep collector

much help from claudio@ who made me explain the GC to him until we trusted it
ok claudio@ mpi@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.99 11-Mar-2015 deraadt

Remove setgid kmem support. As a result, -d and -v will require you to
run this as root.
ok millert, also discussed with guenther


Revision tags: OPENBSD_5_7_BASE
# 1.98 10-Feb-2015 miod

Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 19-Dec-2014 tedu

don't print vnodes if we didn't read them


# 1.95 19-Dec-2014 tedu

1. -T (totalflag) requires nlist too.
2. If we can't read a vnode, there's no way LIST_NEXT is going to be
meaningful.
3. set numvnodes before looping in case we return early.
getting better, but still not all fixed


# 1.94 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.93 19-Nov-2014 tedu

delete the KERN_VNODE sysctl. it fails to provide any isolation from the
kernel struct vnode defintion, and the only consumer (pstat) still needs
kvm to read much of the required information. no great loss to always use
kvm until there's a better replacement interface.
ok deraadt millert uebayasi


# 1.92 08-Oct-2014 deraadt

use reallocarray(NULL, a, b) instead of malloc(a*b)
ok doug


# 1.91 20-Aug-2014 mikeb

Remove userland bits related to the crypto(4) interface; ok deraadt


Revision tags: OPENBSD_5_6_BASE
# 1.90 19-Mar-2014 guenther

Pull in FreeBSD r37363 and r37887:
--
Sync timestamp changes for inodes of special files to disk as late
as possible (when the inode is reclaimed). Temporarily only do
this if option UFS_LAZYMOD configured and softupdates aren't enabled.
UFS_LAZYMOD is intentionally left out of /sys/conf/options.

This is mainly to avoid almost useless disk i/o on battery powered
machines. It's silly to write to disk (on the next sync or when the
inode becomes inactive) just because someone hit a key or something
wrote to the screen or /dev/null.
--
Made lazy syncing of timestamps for special files non-optional.
--

Also, include support in 'pstat -v' to display the IN_LAZYMOD flag.

ok tedu@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.89 01-Dec-2013 krw

Change 'mountlist' from CIRCLEQ to TAILQ. Be paranoid and
use TAILQ_*_SAFE more than might be needed.

Bulk ports build by sthen@ showed nobody sticking their fingers
so deep into the kernel.

Feedback and suggestions from millert@. ok jsing@


# 1.88 12-Nov-2013 deraadt

ensure there are prototypes


# 1.87 22-Oct-2013 guenther

- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.

ok deraadt@, millert@
ports scan sthen@


# 1.86 22-Aug-2013 guenther

Correct format string mismatches turned up by -Wformat=2

suggestions and ok millert@


Revision tags: OPENBSD_5_4_BASE
# 1.85 05-Jun-2013 guenther

Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passing
O_* flags and eliminating an XXX comment.

ok matthew@ deraadt@


# 1.84 21-Apr-2013 guenther

Tweak #include order to work during the big time_t transition

noted by matthieu@


# 1.83 24-Mar-2013 deraadt

Do not leak kernel pointers, unless operating as root. Some other display
functionality is lost, but one can argue that privacy was being violated
there...
ok various, including bluhm and guenther


Revision tags: OPENBSD_5_3_BASE
# 1.82 18-Dec-2012 millert

We no longer use struct eproc for kinfo_proc in sysctl.h so there
is no direct need for sys/proc.h or sys/resource.h. Some consumers
of kinfo_proc need these for the proc flags and rlimit defines like
RLIM_INF so add the appropriate includes to them.
OK deraadt@ sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.81 11-Jul-2012 guenther

Don't skip pipe, kqueue, crypto, or systrace files in pstat -f output
Also, cast to long to make printf formatting portable

with help from matthew; ok deraadt@


# 1.80 09-Jul-2012 deraadt

According to miod, KERNBASE used as a userland symbol should die
in a fire. Start by removing the definitions, before we clean the
headers later.


# 1.79 17-May-2012 deraadt

show the f_iflags; ok guenther


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.78 28-Jun-2011 guenther

Use kvm_getfile2() instead of sysctl(KERN_FILE) for the -f option
Make -T behave as documented: only report totals
Only open the kvm files when necessary

prompted by a comment from matthew@
ok and corrections millert@, ok tedu@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.77 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_6_BASE
# 1.76 31-May-2009 thib

Don't define NFS before including kernel header files,
besides it being gnarly its useless since no magic is
done if it is define.

pointed out by deraadt@


Revision tags: OPENBSD_4_5_BASE
# 1.75 07-Oct-2008 deraadt

pstat can hide information too; also based on PR 5113


# 1.74 01-Sep-2008 sobrado

sync synopsis and usage; KNF.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.73 20-Feb-2008 thib

set globalnl to vnodenl in filemode() so we access the right
thing in the KGET() macros. Fixes a segfault when pstat is
called with '-vT';

ok miod@,krw@,beck@


# 1.72 28-Dec-2007 chl

printf field widths are always int, so add casts to remove
"warning: field width is not type int"

"looks good" otto@


# 1.71 08-Dec-2007 deraadt

no need to pre-check for % in dformat, it will fail later anyways


# 1.70 28-Nov-2007 tedu

refine format string, support hh and c for real. ok deraadt


# 1.69 28-Nov-2007 deraadt

Be more careful with printf-style formats, and fix a few other niggles
ok tedu


# 1.68 28-Nov-2007 tedu

add a -d argument, which can be used to peek at values in the kernel.
this is easier than using the ddb console. ok deraadt


# 1.67 26-Nov-2007 tedu

cleanup. nl is a poor name for a global (accessed via macro no less).
also, man page says nlist ends with NULL name, not "".
ok art bob deraadt


# 1.66 03-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); ok espie


# 1.65 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.64 04-Jun-2006 deraadt

teach this about NMEADISC too


# 1.63 18-Apr-2006 deraadt

simple variable renaming to please lint


# 1.62 27-Mar-2006 pedro

Check for syncer vnodes before the file system specific routine gets
called, so that we handle NFS and ext2fs as well, okay deraadt@.


# 1.61 26-Mar-2006 uwe

Pretty-print addresses on 64-bit architectures; with input and ok deraadt@


# 1.60 26-Mar-2006 uwe

Back out -r1.59. I did not follow the process.


# 1.59 26-Mar-2006 uwe

Set the width of address columns based on the machine word width.
pedro@ likes the diff.


# 1.58 25-Mar-2006 pedro

Kill double word


# 1.57 25-Mar-2006 pedro

Handle syncer vnodes gracefully, okay deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.56 28-Dec-2005 pedro

Use the DIP macros to uniformly access fields from UFS1 and UFS2 dinodes.
No functional change, okay tedu@.


# 1.55 17-Dec-2005 pedro

Remove the 'on disk' inode (dinode) from the 'in memory' inode in UFS.
Instead of having the dinode inside the inode structure itself, we now
have just a pointer to it, and use a separate pool to allocate dinodes
as needed. Inspiration from FreeBSD, various testing for a while, thanks.


# 1.54 11-Dec-2005 pedro

inode/dinode separation for ext2fs


# 1.53 15-Oct-2005 otto

Use queue macros instead of directly accessing fields. ok miod@ pat@ millert@


Revision tags: OPENBSD_3_8_BASE
# 1.52 26-May-2005 pedro

typo


# 1.51 26-May-2005 pedro

remove reference to MNT_UNION


# 1.50 03-May-2005 djm

setresgid; ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.49 08-Feb-2005 pat

* plug memory leaks in some paths. From Andrey Matveev

ok otto


# 1.48 14-Sep-2004 deraadt

remove unused variables


Revision tags: OPENBSD_3_6_BASE
# 1.47 03-Aug-2004 mjc

make pstat -f show locking

ok art@ tedu@
much help from pedro@


Revision tags: OPENBSD_3_5_BASE
# 1.46 16-Mar-2004 jmc

add -M and -N to options list;
sort options;
sync usage();


Revision tags: OPENBSD_3_4_BASE
# 1.45 08-Sep-2003 deraadt

insufficient size for mib; andrushock@korovino.net


# 1.44 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.43 06-Jan-2003 deraadt

some cleanup; andrushock@korovino.net


# 1.42 06-Jan-2003 deraadt

only do kvm_openfiles for -v, all others use sysctl


# 1.41 06-Jan-2003 deraadt

minor tweaks


# 1.40 12-Dec-2002 deraadt

can now get _ttylist via sysctl; millert ok


# 1.39 09-Dec-2002 deraadt

knf


Revision tags: OPENBSD_3_2_BASE
# 1.38 13-Jul-2002 deraadt

slight cleanup


# 1.37 12-Jul-2002 art

remove printing of soon-to-be-gone flags.


# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

size_t cleanups


# 1.34 16-Jun-2002 miod

When processing the KERN_VNODE sysctl, the kernel builds a packed structure,
while pstat(8) expects a C structure abiding the regular structure packing
rules. This caused pstat -v to break on powerpc.

Unbreak the confusion by defining the structure in a common header file,
and having the kernel use it.

ok millert@ deraadt@


# 1.33 08-Jun-2002 angelos

Take advantage of sysctls for stats --- not in use, as we need the
mountlist and the ttylist. To come.


# 1.32 02-Jun-2002 deraadt

KNF


# 1.31 30-May-2002 deraadt

minor KNF


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 mpech

kill more registers.

millert@ ok


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 19-Jan-2002 millert

We don't have <sys/map.h> any more; Tim Tickel


Revision tags: OPENBSD_3_0_BASE
# 1.27 11-Aug-2001 pvalchev

cleanup; ok millert


# 1.26 24-Jun-2001 csapuntz

Get rid of NQNFS options


Revision tags: OPENBSD_2_9_BASE
# 1.25 25-Feb-2001 csapuntz

Update pstat to reflect vnode changes


Revision tags: OPENBSD_2_8_BASE
# 1.24 16-Jun-2000 assar

update and sort list of vflags, iflags, nfsflags, mntflags. also
update man-page to be compatible with the code.


# 1.23 24-May-2000 deraadt

handle 64 bit arch in -f; janjaap@stack.nl


Revision tags: OPENBSD_2_7_BASE
# 1.22 05-Dec-1999 art

Learn pstat about soft updates.


Revision tags: OPENBSD_2_6_BASE
# 1.21 23-Jun-1999 millert

Use DEV_BSIZE instead of hard-coding 512


# 1.20 03-Jun-1999 deraadt

sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.


# 1.19 22-May-1999 weingart

Update for new vmswap code.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.18 08-Jul-1998 deraadt

whack kmem gid after kvm_openfiles()


# 1.17 25-Jun-1998 deraadt

handle no swap case


Revision tags: OPENBSD_2_3_BASE
# 1.16 09-Nov-1997 millert

#if 0 out references to IN_LOCKED, IN_WANTED, IN_LWAIT.
Need to merge in changes from lite2 pstat.c but this will do for now.


Revision tags: OPENBSD_2_2_BASE
# 1.15 18-Sep-1997 deraadt

make pstat -f columns line up


# 1.14 18-Sep-1997 deraadt

lengthen terminal name, make columns line up


# 1.13 12-Sep-1997 millert

Kill extra newline in err()/warn().


# 1.12 10-Aug-1997 millert

Line up better with -t.


# 1.11 07-Aug-1997 millert

Support -n in conjunction with -s. Problem noted by
Carsten Hammer <chammer@vogon.party.de>. Fixes PR#297.
Also made "pstat -tn" consistent with -n in other modes
(and it now lines up correctly).


# 1.10 31-May-1997 deraadt

various


# 1.9 31-May-1997 downsj

Support for ext2fs vnodes.


# 1.8 30-May-1997 downsj

FFS changes.


Revision tags: OPENBSD_2_1_BASE
# 1.7 22-Dec-1996 deraadt

Deal with _POSIX_SAVED_IDS when relinquishing privileges


# 1.6 24-Nov-1996 millert

Add recognition for remaining mount flags (from <sys/mount.h>)
that make sense to "pstat -v". From NetBSD.


Revision tags: OPENBSD_2_0_BASE
# 1.5 10-Jun-1996 deraadt

update ttystats


# 1.4 05-May-1996 deraadt

from netbsd:
handle the VISTTY vnode flag with the same letter ('I') that BSDI used.
Update the documentation of the vnode flags so that it lists only (and all)
of the flags understood by the program. (The documentation is likely in need
of more cleanup.)


# 1.3 25-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.2 06-Nov-1995 deraadt

complete ufs -> ffs change (From John Kohl; PR #1403)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision