summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committersjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commit65145fa4c81da358fcbc3b650156dab705dfa34e (patch)
tree55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /usr.bin
parent60ff4eb0dff94a04d75d0d52a3957aaaf5f8c693 (diff)
parente6b664c390af88d4a87208bc042ce503da664c3b (diff)
downloadFreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.zip
FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.tar.gz
Merge sync of head
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/Makefile64
-rw-r--r--usr.bin/addr2line/Makefile16
-rw-r--r--usr.bin/apply/Makefile4
-rw-r--r--usr.bin/ar/Makefile3
-rw-r--r--usr.bin/ar/Makefile.depend6
-rw-r--r--usr.bin/ar/read.c13
-rw-r--r--usr.bin/atm/sscop/Makefile3
-rw-r--r--usr.bin/atm/sscop/Makefile.depend1
-rw-r--r--usr.bin/awk/Makefile3
-rw-r--r--usr.bin/awk/Makefile.depend1
-rw-r--r--usr.bin/bc/Makefile3
-rw-r--r--usr.bin/bc/Makefile.depend1
-rw-r--r--usr.bin/bluetooth/bthost/Makefile3
-rw-r--r--usr.bin/bluetooth/bthost/bthost.c1
-rw-r--r--usr.bin/bluetooth/btsockstat/Makefile3
-rw-r--r--usr.bin/bluetooth/btsockstat/btsockstat.c18
-rw-r--r--usr.bin/bluetooth/rfcomm_sppd/Makefile3
-rw-r--r--usr.bin/bluetooth/rfcomm_sppd/rfcomm_sdp.c2
-rw-r--r--usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c1
-rw-r--r--usr.bin/bmake/Makefile10
-rw-r--r--usr.bin/bmake/unit-tests/Makefile111
-rw-r--r--usr.bin/bsdiff/bsdiff/Makefile3
-rw-r--r--usr.bin/bsdiff/bspatch/Makefile3
-rw-r--r--usr.bin/bzip2/Makefile3
-rw-r--r--usr.bin/calendar/Makefile5
-rw-r--r--usr.bin/calendar/calcpp.c232
-rw-r--r--usr.bin/calendar/calendar.h4
-rw-r--r--usr.bin/calendar/calendars/calendar.freebsd1
-rw-r--r--usr.bin/calendar/calendars/calendar.holiday2
-rw-r--r--usr.bin/calendar/io.c266
-rw-r--r--usr.bin/checknr/checknr.16
-rw-r--r--usr.bin/checknr/checknr.c146
-rw-r--r--usr.bin/chkey/Makefile3
-rw-r--r--usr.bin/chpass/Makefile6
-rw-r--r--usr.bin/clang/Makefile3
-rw-r--r--usr.bin/clang/bugpoint/Makefile11
-rw-r--r--usr.bin/clang/bugpoint/bugpoint.111
-rw-r--r--usr.bin/clang/clang/Makefile34
-rw-r--r--usr.bin/clang/clang/Makefile.depend10
-rw-r--r--usr.bin/clang/clang/clang.1731
-rw-r--r--usr.bin/clang/llc/Makefile22
-rw-r--r--usr.bin/clang/llc/llc.112
-rw-r--r--usr.bin/clang/lldb/Makefile89
-rw-r--r--usr.bin/clang/lli/Makefile19
-rw-r--r--usr.bin/clang/lli/lli.111
-rw-r--r--usr.bin/clang/llvm-ar/Makefile56
-rw-r--r--usr.bin/clang/llvm-ar/llvm-ar.14
-rw-r--r--usr.bin/clang/llvm-as/llvm-as.14
-rw-r--r--usr.bin/clang/llvm-bcanalyzer/llvm-bcanalyzer.14
-rw-r--r--usr.bin/clang/llvm-cov/Makefile26
-rw-r--r--usr.bin/clang/llvm-cov/llvm-cov.1165
-rw-r--r--usr.bin/clang/llvm-diff/llvm-diff.14
-rw-r--r--usr.bin/clang/llvm-dis/Makefile1
-rw-r--r--usr.bin/clang/llvm-dis/llvm-dis.14
-rw-r--r--usr.bin/clang/llvm-extract/Makefile7
-rw-r--r--usr.bin/clang/llvm-extract/llvm-extract.14
-rw-r--r--usr.bin/clang/llvm-link/Makefile1
-rw-r--r--usr.bin/clang/llvm-link/llvm-link.14
-rw-r--r--usr.bin/clang/llvm-mc/Makefile22
-rw-r--r--usr.bin/clang/llvm-nm/Makefile56
-rw-r--r--usr.bin/clang/llvm-nm/llvm-nm.14
-rw-r--r--usr.bin/clang/llvm-objdump/Makefile26
-rw-r--r--usr.bin/clang/llvm-profdata/Makefile18
-rw-r--r--usr.bin/clang/llvm-profdata/llvm-profdata.1117
-rw-r--r--usr.bin/clang/llvm-rtdyld/Makefile25
-rw-r--r--usr.bin/clang/llvm-symbolizer/Makefile22
-rw-r--r--usr.bin/clang/llvm-symbolizer/llvm-symbolizer.1144
-rw-r--r--usr.bin/clang/macho-dump/Makefile4
-rw-r--r--usr.bin/clang/opt/Makefile23
-rw-r--r--usr.bin/clang/opt/opt.140
-rw-r--r--usr.bin/clang/tblgen/Makefile2
-rw-r--r--usr.bin/clang/tblgen/tblgen.16
-rw-r--r--usr.bin/col/Makefile6
-rw-r--r--usr.bin/col/col.129
-rw-r--r--usr.bin/col/col.c171
-rw-r--r--usr.bin/col/tests/Makefile11
-rwxr-xr-xusr.bin/col/tests/col.sh33
-rw-r--r--usr.bin/col/tests/rlf.in2
-rw-r--r--usr.bin/col/tests/rlf2.in2
-rw-r--r--usr.bin/colldef/Makefile3
-rw-r--r--usr.bin/column/column.c12
-rw-r--r--usr.bin/compile_et/Makefile5
-rw-r--r--usr.bin/compile_et/Makefile.depend1
-rw-r--r--usr.bin/compress/compress.c11
-rw-r--r--usr.bin/cpio/Makefile10
-rw-r--r--usr.bin/cpio/Makefile.depend1
-rw-r--r--usr.bin/cpio/test/Makefile3
-rw-r--r--usr.bin/cpuset/cpuset.113
-rw-r--r--usr.bin/cpuset/cpuset.c30
-rw-r--r--usr.bin/csup/Makefile.depend1
-rw-r--r--usr.bin/ctlstat/ctlstat.85
-rw-r--r--usr.bin/ctlstat/ctlstat.c7
-rw-r--r--usr.bin/cxxfilt/Makefile17
-rw-r--r--usr.bin/dc/Makefile3
-rw-r--r--usr.bin/dc/stack.c6
-rw-r--r--usr.bin/dpv/Makefile3
-rw-r--r--usr.bin/dpv/dpv.130
-rw-r--r--usr.bin/drill/Makefile4
-rw-r--r--usr.bin/du/Makefile3
-rw-r--r--usr.bin/du/du.c7
-rw-r--r--usr.bin/ee/Makefile3
-rw-r--r--usr.bin/elfcopy/Makefile24
-rw-r--r--usr.bin/elfdump/elfdump.c19
-rw-r--r--usr.bin/enigma/Makefile3
-rw-r--r--usr.bin/enigma/enigma.c5
-rw-r--r--usr.bin/env/envopts.c4
-rw-r--r--usr.bin/fetch/Makefile10
-rw-r--r--usr.bin/fetch/fetch.17
-rw-r--r--usr.bin/fetch/fetch.c25
-rw-r--r--usr.bin/file/Makefile3
-rw-r--r--usr.bin/find/find.12
-rw-r--r--usr.bin/fstat/Makefile3
-rw-r--r--usr.bin/ftp/Makefile3
-rw-r--r--usr.bin/gcore/Makefile3
-rw-r--r--usr.bin/gcore/elf32core.c18
-rw-r--r--usr.bin/gcore/elfcore.c70
-rw-r--r--usr.bin/grep/Makefile29
-rw-r--r--usr.bin/grep/Makefile.depend1
-rw-r--r--usr.bin/grep/file.c61
-rw-r--r--usr.bin/grep/grep.c2
-rw-r--r--usr.bin/gzip/Makefile6
-rw-r--r--usr.bin/gzip/Makefile.depend1
-rw-r--r--usr.bin/gzip/gzip.19
-rw-r--r--usr.bin/gzip/gzip.c38
-rw-r--r--usr.bin/hexdump/display.c2
-rw-r--r--usr.bin/host/Makefile4
-rw-r--r--usr.bin/iconv/iconv.c3
-rw-r--r--usr.bin/id/id.c9
-rw-r--r--usr.bin/ipcrm/Makefile3
-rw-r--r--usr.bin/ipcs/Makefile5
-rw-r--r--usr.bin/ipcs/ipc.c21
-rw-r--r--usr.bin/ipcs/ipc.h5
-rw-r--r--usr.bin/ipcs/ipcs.c55
-rw-r--r--usr.bin/iscsictl/Makefile5
-rw-r--r--usr.bin/iscsictl/iscsi.conf.5162
-rw-r--r--usr.bin/iscsictl/iscsictl.c296
-rw-r--r--usr.bin/iscsictl/iscsictl.h1
-rw-r--r--usr.bin/iscsictl/parse.y71
-rw-r--r--usr.bin/iscsictl/periphs.c38
-rw-r--r--usr.bin/iscsictl/token.l1
-rw-r--r--usr.bin/jot/jot.14
-rw-r--r--usr.bin/kdump/Makefile23
-rw-r--r--usr.bin/kdump/Makefile.depend4
-rw-r--r--usr.bin/kdump/kdump.c38
-rw-r--r--usr.bin/kdump/mkioctls1
-rw-r--r--usr.bin/keylogin/Makefile3
-rw-r--r--usr.bin/killall/Makefile3
-rw-r--r--usr.bin/killall/killall.c8
-rw-r--r--usr.bin/ktrdump/Makefile3
-rw-r--r--usr.bin/ktrdump/ktrdump.812
-rw-r--r--usr.bin/ktrdump/ktrdump.c18
-rw-r--r--usr.bin/lam/lam.14
-rw-r--r--usr.bin/last/last.14
-rw-r--r--usr.bin/ldd/ldd.c11
-rw-r--r--usr.bin/less/Makefile3
-rw-r--r--usr.bin/lex/Makefile2
-rw-r--r--usr.bin/lex/lex.15
-rw-r--r--usr.bin/limits/Makefile3
-rw-r--r--usr.bin/locate/locate/util.c19
-rw-r--r--usr.bin/lock/Makefile4
-rw-r--r--usr.bin/lockf/lockf.11
-rw-r--r--usr.bin/lockf/lockf.c2
-rw-r--r--usr.bin/logger/logger.13
-rw-r--r--usr.bin/login/Makefile6
-rw-r--r--usr.bin/lzmainfo/Makefile3
-rw-r--r--usr.bin/lzmainfo/Makefile.depend1
-rw-r--r--usr.bin/m4/Makefile3
-rw-r--r--usr.bin/m4/Makefile.depend1
-rw-r--r--usr.bin/m4/extern.h1
-rw-r--r--usr.bin/m4/gnum4.c20
-rw-r--r--usr.bin/m4/look.c68
-rw-r--r--usr.bin/m4/m4.16
-rw-r--r--usr.bin/m4/main.c7
-rw-r--r--usr.bin/m4/mdef.h21
-rw-r--r--usr.bin/m4/misc.c25
-rw-r--r--usr.bin/m4/parser.y8
-rw-r--r--usr.bin/make/Makefile2
-rw-r--r--usr.bin/makewhatis/Makefile3
-rw-r--r--usr.bin/man/man.141
-rwxr-xr-xusr.bin/man/man.sh36
-rw-r--r--usr.bin/mandoc/Makefile82
-rw-r--r--usr.bin/mandoc/Makefile.depend4
-rw-r--r--usr.bin/minigzip/Makefile3
-rw-r--r--usr.bin/ministat/Makefile8
-rw-r--r--usr.bin/ministat/ministat.14
-rw-r--r--usr.bin/ministat/ministat.c6
-rw-r--r--usr.bin/mkcsmapper/mkcsmapper.14
-rw-r--r--usr.bin/mkesdb/mkesdb.14
-rw-r--r--usr.bin/mkimg/Makefile5
-rw-r--r--usr.bin/mkimg/mbr.c4
-rw-r--r--usr.bin/mkimg/mkimg.127
-rw-r--r--usr.bin/mkimg/mkimg.c59
-rw-r--r--usr.bin/mkimg/qcow.c9
-rw-r--r--usr.bin/mkimg/scheme.c17
-rw-r--r--usr.bin/mkulzma/Makefile4
-rw-r--r--usr.bin/mkulzma/Makefile.depend1
-rw-r--r--usr.bin/mkuzip/Makefile4
-rw-r--r--usr.bin/msgs/Makefile4
-rw-r--r--usr.bin/mt/Makefile1
-rw-r--r--usr.bin/mt/Makefile.depend3
-rw-r--r--usr.bin/mt/mt.1271
-rw-r--r--usr.bin/mt/mt.c1265
-rw-r--r--usr.bin/nc/Makefile3
-rw-r--r--usr.bin/ncal/Makefile3
-rw-r--r--usr.bin/netstat/Makefile8
-rw-r--r--usr.bin/netstat/Makefile.depend1
-rw-r--r--usr.bin/netstat/bpf.c57
-rw-r--r--usr.bin/netstat/flowtable.c1
-rw-r--r--usr.bin/netstat/if.c326
-rw-r--r--usr.bin/netstat/inet.c1058
-rw-r--r--usr.bin/netstat/inet6.c648
-rw-r--r--usr.bin/netstat/ipsec.c262
-rw-r--r--usr.bin/netstat/main.c100
-rw-r--r--usr.bin/netstat/mbuf.c106
-rw-r--r--usr.bin/netstat/mroute.c207
-rw-r--r--usr.bin/netstat/mroute6.c203
-rw-r--r--usr.bin/netstat/netgraph.c27
-rw-r--r--usr.bin/netstat/netisr.c190
-rw-r--r--usr.bin/netstat/netstat.125
-rw-r--r--usr.bin/netstat/netstat.h4
-rw-r--r--usr.bin/netstat/pfkey.c94
-rw-r--r--usr.bin/netstat/route.c535
-rw-r--r--usr.bin/netstat/sctp.c438
-rw-r--r--usr.bin/netstat/unix.c76
-rw-r--r--usr.bin/newgrp/Makefile4
-rw-r--r--usr.bin/newkey/Makefile3
-rw-r--r--usr.bin/nfsstat/Makefile4
-rw-r--r--usr.bin/nfsstat/nfsstat.112
-rw-r--r--usr.bin/nfsstat/nfsstat.c555
-rw-r--r--usr.bin/nm/Makefile16
-rw-r--r--usr.bin/opieinfo/Makefile3
-rw-r--r--usr.bin/opiekey/Makefile3
-rw-r--r--usr.bin/opiepasswd/Makefile3
-rw-r--r--usr.bin/pamtest/Makefile4
-rw-r--r--usr.bin/passwd/Makefile3
-rw-r--r--usr.bin/patch/common.h1
-rw-r--r--usr.bin/patch/inp.c58
-rw-r--r--usr.bin/patch/patch.c26
-rw-r--r--usr.bin/patch/pch.c215
-rw-r--r--usr.bin/patch/util.c24
-rw-r--r--usr.bin/patch/util.h3
-rw-r--r--usr.bin/perror/perror.12
-rw-r--r--usr.bin/perror/perror.c2
-rw-r--r--usr.bin/printf/printf.c1
-rw-r--r--usr.bin/procstat/Makefile4
-rw-r--r--usr.bin/procstat/procstat.116
-rw-r--r--usr.bin/procstat/procstat.c13
-rw-r--r--usr.bin/procstat/procstat.h1
-rw-r--r--usr.bin/procstat/procstat_cs.c108
-rw-r--r--usr.bin/procstat/procstat_rusage.c2
-rw-r--r--usr.bin/protect/protect.12
-rw-r--r--usr.bin/protect/protect.c2
-rw-r--r--usr.bin/quota/Makefile3
-rw-r--r--usr.bin/rctl/Makefile3
-rw-r--r--usr.bin/rctl/rctl.812
-rw-r--r--usr.bin/rctl/rctl.c47
-rw-r--r--usr.bin/readelf/Makefile14
-rw-r--r--usr.bin/rlogin/Makefile1
-rw-r--r--usr.bin/rlogin/rlogin.c2
-rw-r--r--usr.bin/rpcgen/rpc_sample.c2
-rw-r--r--usr.bin/rs/rs.14
-rw-r--r--usr.bin/rsh/Makefile1
-rw-r--r--usr.bin/rup/Makefile3
-rw-r--r--usr.bin/rup/rup.14
-rw-r--r--usr.bin/rusers/Makefile3
-rw-r--r--usr.bin/rusers/rusers.14
-rw-r--r--usr.bin/rwall/rwall.14
-rw-r--r--usr.bin/script/Makefile4
-rw-r--r--usr.bin/script/script.12
-rw-r--r--usr.bin/sed/compile.c5
-rw-r--r--usr.bin/sed/main.c8
-rw-r--r--usr.bin/sed/process.c10
-rw-r--r--usr.bin/sed/tests/multi_test.sh4
-rw-r--r--usr.bin/sed/tests/regress.multitest.out/2.232
-rw-r--r--usr.bin/seq/Makefile4
-rw-r--r--usr.bin/seq/seq.19
-rw-r--r--usr.bin/seq/seq.c75
-rw-r--r--usr.bin/setchannel/setchannel.12
-rw-r--r--usr.bin/showmount/showmount.84
-rw-r--r--usr.bin/size/Makefile16
-rw-r--r--usr.bin/smbutil/Makefile3
-rw-r--r--usr.bin/sockstat/sockstat.14
-rw-r--r--usr.bin/soelim/Makefile11
-rw-r--r--usr.bin/soelim/soelim.186
-rw-r--r--usr.bin/soelim/soelim.c178
-rw-r--r--usr.bin/soelim/tests/Makefile15
-rw-r--r--usr.bin/soelim/tests/basic1
-rw-r--r--usr.bin/soelim/tests/basic-with-space.in3
-rw-r--r--usr.bin/soelim/tests/basic-with-space.out4
-rw-r--r--usr.bin/soelim/tests/basic.in3
-rw-r--r--usr.bin/soelim/tests/basic.out3
-rw-r--r--usr.bin/soelim/tests/nonexisting.in3
-rwxr-xr-xusr.bin/soelim/tests/soelim.sh103
-rw-r--r--usr.bin/sort/Makefile6
-rw-r--r--usr.bin/sort/bwstring.c27
-rw-r--r--usr.bin/sort/coll.c14
-rw-r--r--usr.bin/sort/file.c38
-rw-r--r--usr.bin/sort/file.h14
-rw-r--r--usr.bin/sort/mem.c1
-rw-r--r--usr.bin/sort/radixsort.c4
-rw-r--r--usr.bin/sort/sort.1.in22
-rw-r--r--usr.bin/sort/sort.c54
-rw-r--r--usr.bin/split/Makefile4
-rwxr-xr-xusr.bin/ssh-copy-id/ssh-copy-id.sh2
-rw-r--r--usr.bin/strings/Makefile15
-rw-r--r--usr.bin/su/Makefile6
-rw-r--r--usr.bin/svn/Makefile.inc3
-rw-r--r--usr.bin/svn/lib/Makefile2
-rw-r--r--usr.bin/svn/lib/libsqlite3/Makefile25
-rw-r--r--usr.bin/svn/svn/Makefile11
-rw-r--r--usr.bin/svn/svnadmin/Makefile8
-rw-r--r--usr.bin/svn/svndumpfilter/Makefile8
-rw-r--r--usr.bin/svn/svnlook/Makefile8
-rw-r--r--usr.bin/svn/svnmucc/Makefile9
-rw-r--r--usr.bin/svn/svnrdump/Makefile9
-rw-r--r--usr.bin/svn/svnserve/Makefile9
-rw-r--r--usr.bin/svn/svnsync/Makefile9
-rw-r--r--usr.bin/svn/svnversion/Makefile9
-rw-r--r--usr.bin/systat/Makefile3
-rw-r--r--usr.bin/systat/netstat.c4
-rw-r--r--usr.bin/tabs/Makefile4
-rw-r--r--usr.bin/talk/Makefile4
-rw-r--r--usr.bin/tar/Makefile11
-rw-r--r--usr.bin/tar/Makefile.depend1
-rw-r--r--usr.bin/telnet/Makefile16
-rw-r--r--usr.bin/tftp/Makefile4
-rw-r--r--usr.bin/time/time.c18
-rw-r--r--usr.bin/timeout/timeout.c63
-rw-r--r--usr.bin/top/Makefile3
-rw-r--r--usr.bin/top/Makefile.depend2
-rw-r--r--usr.bin/top/machine.c4
-rw-r--r--usr.bin/touch/touch.14
-rw-r--r--usr.bin/touch/touch.c106
-rw-r--r--usr.bin/tput/Makefile3
-rw-r--r--usr.bin/truncate/Makefile5
-rw-r--r--usr.bin/tset/Makefile3
-rw-r--r--usr.bin/ul/Makefile3
-rw-r--r--usr.bin/unifdef/unifdef.1129
-rw-r--r--usr.bin/unifdef/unifdef.c560
-rw-r--r--usr.bin/unifdef/unifdef.h4
-rw-r--r--usr.bin/unifdef/unifdefall.sh34
-rw-r--r--usr.bin/units/Makefile3
-rw-r--r--usr.bin/unzip/Makefile3
-rw-r--r--usr.bin/unzip/Makefile.depend1
-rw-r--r--usr.bin/unzip/unzip.c28
-rw-r--r--usr.bin/usbhidaction/Makefile3
-rw-r--r--usr.bin/usbhidctl/Makefile4
-rw-r--r--usr.bin/vacation/Makefile12
-rw-r--r--usr.bin/vgrind/Makefile2
-rw-r--r--usr.bin/vgrind/extern.h8
-rw-r--r--usr.bin/vgrind/regexp.c129
-rw-r--r--usr.bin/vgrind/vfontedpr.c235
-rw-r--r--usr.bin/vgrind/vgrindefs.c46
-rw-r--r--usr.bin/vi/Makefile8
-rw-r--r--usr.bin/vi/catalog/Makefile2
-rw-r--r--usr.bin/vmstat/Makefile3
-rw-r--r--usr.bin/vmstat/vmstat.c153
-rw-r--r--usr.bin/vtfontcvt/vtfontcvt.c36
-rw-r--r--usr.bin/w/Makefile3
-rw-r--r--usr.bin/w/Makefile.depend1
-rw-r--r--usr.bin/w/w.c29
-rw-r--r--usr.bin/wc/Makefile3
-rw-r--r--usr.bin/wc/wc.c15
-rw-r--r--usr.bin/whereis/pathnames.h3
-rw-r--r--usr.bin/whereis/whereis.13
-rw-r--r--usr.bin/whereis/whereis.c5
-rw-r--r--usr.bin/whois/whois.1130
-rw-r--r--usr.bin/whois/whois.c265
-rw-r--r--usr.bin/xinstall/Makefile3
-rw-r--r--usr.bin/xinstall/Makefile.depend.host (renamed from usr.bin/svn/lib/libsqlite3/Makefile.depend)4
-rw-r--r--usr.bin/xlint/Makefile.inc14
-rw-r--r--usr.bin/xlint/arch/aarch64/targparam.h50
-rw-r--r--usr.bin/xlint/arch/sparc64/targparam.h4
-rw-r--r--usr.bin/xlint/common/lint.h6
-rw-r--r--usr.bin/xlint/common/mem.c11
-rw-r--r--usr.bin/xlint/lint1/Makefile3
-rw-r--r--usr.bin/xlint/lint1/Makefile.depend1
-rw-r--r--usr.bin/xlint/lint1/cgram.y176
-rw-r--r--usr.bin/xlint/lint1/decl.c86
-rw-r--r--usr.bin/xlint/lint1/emit1.c10
-rw-r--r--usr.bin/xlint/lint1/err.c62
-rw-r--r--usr.bin/xlint/lint1/externs1.h19
-rw-r--r--usr.bin/xlint/lint1/func.c36
-rw-r--r--usr.bin/xlint/lint1/init.c179
-rw-r--r--usr.bin/xlint/lint1/lint1.h16
-rw-r--r--usr.bin/xlint/lint1/main1.c22
-rw-r--r--usr.bin/xlint/lint1/makeman2
-rw-r--r--usr.bin/xlint/lint1/param.h3
-rw-r--r--usr.bin/xlint/lint1/scan.l179
-rw-r--r--usr.bin/xlint/lint1/tree.c345
-rw-r--r--usr.bin/xlint/lint2/read.c29
-rw-r--r--usr.bin/xlint/xlint/lint.116
-rw-r--r--usr.bin/xlint/xlint/xlint.c26
-rw-r--r--usr.bin/xo/Makefile3
-rw-r--r--usr.bin/xz/Makefile4
-rw-r--r--usr.bin/xz/Makefile.depend1
-rw-r--r--usr.bin/xzdec/Makefile3
-rw-r--r--usr.bin/xzdec/Makefile.depend1
398 files changed, 10341 insertions, 5916 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index 865be93..af9b471 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -9,7 +9,8 @@
# Moved to secure: bdes
#
-SUBDIR= alias \
+SUBDIR= ${_addr2line} \
+ alias \
apply \
asa \
awk \
@@ -35,25 +36,23 @@ SUBDIR= alias \
csplit \
ctlstat \
cut \
+ ${_cxxfilt} \
dirname \
dpv \
du \
- ee \
elf2aout \
+ ${_elfcopy} \
elfdump \
enigma \
env \
expand \
false \
fetch \
- file \
find \
- finger \
fmt \
fold \
fstat \
fsync \
- ftp \
gcore \
gencat \
getconf \
@@ -67,7 +66,6 @@ SUBDIR= alias \
id \
ipcrm \
ipcs \
- iscsictl \
join \
jot \
${_kdump} \
@@ -118,6 +116,7 @@ SUBDIR= alias \
nfsstat \
nice \
nl \
+ ${_nm} \
nohup \
opieinfo \
opiekey \
@@ -134,6 +133,7 @@ SUBDIR= alias \
procstat \
protect \
rctl \
+ ${_readelf} \
renice \
rev \
revoke \
@@ -148,21 +148,22 @@ SUBDIR= alias \
seq \
shar \
showmount \
+ ${_size} \
sockstat \
+ soelim \
sort \
split \
stat \
stdbuf \
+ ${_strings} \
su \
systat \
tabs \
tail \
- talk \
tar \
tcopy \
tee \
${_tests} \
- tftp \
time \
timeout \
tip \
@@ -196,12 +197,9 @@ SUBDIR= alias \
write \
xargs \
xinstall \
- ${_xlint} \
xo \
- ${_xstr} \
xz \
xzdec \
- ${_yacc} \
yes \
${_ypcat} \
${_ypmatch} \
@@ -233,10 +231,36 @@ SUBDIR+= calendar
_clang= clang
.endif
+.if ${MK_EE} != "no"
+SUBDIR+= ee
+.endif
+
+.if ${MK_ELFTOOLCHAIN_TOOLS} != "no"
+_addr2line= addr2line
+_cxxfilt= cxxfilt
+_elfcopy= elfcopy
+_nm= nm
+_readelf= readelf
+_size= size
+_strings= strings
+.endif
+
+.if ${MK_FILE} != "no"
+SUBDIR+= file
+.endif
+
+.if ${MK_FINGER} != "no"
+SUBDIR+= finger
+.endif
+
.if ${MK_FMAKE} != "no"
SUBDIR+= make
.endif
+.if ${MK_FTP} != "no"
+SUBDIR+= ftp
+.endif
+
.if ${MK_GPL_DTC} != "yes"
SUBDIR+= dtc
.endif
@@ -255,10 +279,16 @@ _mkcsmapper= mkcsmapper
_mkesdb= mkesdb
.endif
+.if ${MK_ISCSI} != "no"
+SUBDIR+= iscsictl
+.endif
+
.if ${MK_KDUMP} != "no"
SUBDIR+= kdump
+.if ${MACHINE_ARCH} != "aarch64" # ARM64TODO truss does not build
SUBDIR+= truss
.endif
+.endif
.if ${MK_KERBEROS_SUPPORT} != "no"
SUBDIR+= compile_et
@@ -327,6 +357,10 @@ SUBDIR+= rwho
SUBDIR+= vacation
.endif
+.if ${MK_TALK} != "no"
+SUBDIR+= talk
+.endif
+
.if ${MK_TELNET} != "no"
SUBDIR+= telnet
.endif
@@ -341,19 +375,27 @@ SUBDIR+= colcrt
SUBDIR+= ul
.endif
+.if ${MK_TFTP} != "no"
+SUBDIR+= tftp
+.endif
+
.if ${MK_TOOLCHAIN} != "no"
SUBDIR+= ar
SUBDIR+= c89
SUBDIR+= c99
SUBDIR+= ctags
SUBDIR+= file2c
+.if ${MACHINE_ARCH} != "aarch64" # ARM64TODO gprof does not build
SUBDIR+= gprof
+.endif
SUBDIR+= indent
SUBDIR+= lex
SUBDIR+= mkstr
SUBDIR+= rpcgen
SUBDIR+= unifdef
+.if ${MACHINE_ARCH} != "aarch64" # ARM64TODO xlint does not build
SUBDIR+= xlint
+.endif
SUBDIR+= xstr
SUBDIR+= yacc
.endif
diff --git a/usr.bin/addr2line/Makefile b/usr.bin/addr2line/Makefile
new file mode 100644
index 0000000..918707a
--- /dev/null
+++ b/usr.bin/addr2line/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+ADDR2LINEDIR= ${ELFTCDIR}/addr2line
+
+.PATH: ${ADDR2LINEDIR}
+
+PROG= addr2line
+
+LIBADD= elftc dwarf elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/apply/Makefile b/usr.bin/apply/Makefile
index 3ecf038..2233434 100644
--- a/usr.bin/apply/Makefile
+++ b/usr.bin/apply/Makefile
@@ -4,8 +4,8 @@
.include <src.opts.mk>
PROG= apply
-DPADD= ${LIBSBUF}
-LDADD= -lsbuf
+
+LIBADD= sbuf
.if ${MK_TESTS} != "no"
SUBDIR+= tests
diff --git a/usr.bin/ar/Makefile b/usr.bin/ar/Makefile
index 157d411..7a6601a 100644
--- a/usr.bin/ar/Makefile
+++ b/usr.bin/ar/Makefile
@@ -5,8 +5,7 @@
PROG= ar
SRCS= ar.c acplex.l acpyacc.y read.c util.c write.c y.tab.h
-DPADD= ${LIBARCHIVE} ${LIBELF} ${LIBZ}
-LDADD= -larchive -lelf -lz
+LIBADD= archive elf
NO_WMISSING_VARIABLE_DECLARATIONS=
diff --git a/usr.bin/ar/Makefile.depend b/usr.bin/ar/Makefile.depend
index c8ce9ca..924359f 100644
--- a/usr.bin/ar/Makefile.depend
+++ b/usr.bin/ar/Makefile.depend
@@ -8,10 +8,16 @@ DIRDEPS = \
include/xlocale \
lib/${CSU_DIR} \
lib/libarchive \
+ lib/libbz2 \
lib/libc \
lib/libcompiler_rt \
lib/libelf \
+ lib/libexpat \
+ lib/liblzma \
+ lib/libthr \
lib/libz \
+ secure/lib/libcrypto \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/ar/read.c b/usr.bin/ar/read.c
index e595869..704812c 100644
--- a/usr.bin/ar/read.c
+++ b/usr.bin/ar/read.c
@@ -102,7 +102,8 @@ read_archive(struct bsdar *bsdar, char mode)
continue;
}
- name = archive_entry_pathname(entry);
+ if ((name = archive_entry_pathname(entry)) == NULL)
+ break;
/* Skip pseudo members. */
if (strcmp(name, "/") == 0 || strcmp(name, "//") == 0)
@@ -186,7 +187,15 @@ read_archive(struct bsdar *bsdar, char mode)
if (bsdar->options & AR_V)
(void)fprintf(stdout, "x - %s\n", name);
- flags = 0;
+ /* Disallow absolute paths. */
+ if (name[0] == '/') {
+ bsdar_warnc(bsdar, 0,
+ "Absolute path '%s'", name);
+ continue;
+ }
+ /* Basic path security flags. */
+ flags = ARCHIVE_EXTRACT_SECURE_SYMLINKS |
+ ARCHIVE_EXTRACT_SECURE_NODOTDOT;
if (bsdar->options & AR_O)
flags |= ARCHIVE_EXTRACT_TIME;
diff --git a/usr.bin/atm/sscop/Makefile b/usr.bin/atm/sscop/Makefile
index 36d3dcf..cc688fd 100644
--- a/usr.bin/atm/sscop/Makefile
+++ b/usr.bin/atm/sscop/Makefile
@@ -8,7 +8,6 @@ PROG= sscop
SRCS= common.c sscop_main.c
CFLAGS+= -I${CONTRIB} -DUSE_LIBBEGEMOT
-DPADD= ${LIBBEGEMOT} ${LIBNETGRAPH} ${LIBNGATM}
-LDADD= -lbegemot -lnetgraph -lngatm
+LIBADD= begemot ngatm
.include <bsd.prog.mk>
diff --git a/usr.bin/atm/sscop/Makefile.depend b/usr.bin/atm/sscop/Makefile.depend
index 08035b1..d537961 100644
--- a/usr.bin/atm/sscop/Makefile.depend
+++ b/usr.bin/atm/sscop/Makefile.depend
@@ -11,7 +11,6 @@ DIRDEPS = \
lib/libbegemot \
lib/libc \
lib/libcompiler_rt \
- lib/libnetgraph \
lib/libngatm \
diff --git a/usr.bin/awk/Makefile b/usr.bin/awk/Makefile
index 6538636..a8bcb5c 100644
--- a/usr.bin/awk/Makefile
+++ b/usr.bin/awk/Makefile
@@ -10,8 +10,7 @@ CFLAGS+= -DHAS_ISBLANK -I. -I${AWKSRC} -DFOPEN_MAX=64
WARNS?= 1
-DPADD= ${LIBM}
-LDADD= -lm
+LIBADD= m
LINKS= ${BINDIR}/awk ${BINDIR}/nawk
MLINKS= awk.1 nawk.1
diff --git a/usr.bin/awk/Makefile.depend b/usr.bin/awk/Makefile.depend
index bcdaffe..e16eb95 100644
--- a/usr.bin/awk/Makefile.depend
+++ b/usr.bin/awk/Makefile.depend
@@ -11,6 +11,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/msun \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/bc/Makefile b/usr.bin/bc/Makefile
index d2f26f1..14d5677 100644
--- a/usr.bin/bc/Makefile
+++ b/usr.bin/bc/Makefile
@@ -5,8 +5,7 @@ PROG= bc
SRCS= bc.y scan.l tty.c
CFLAGS+= -I. -I${.CURDIR}
-DPADD+= ${LIBEDIT} ${LIBNCURSESW}
-LDADD+= -ledit -lncursesw
+LIBADD= edit
NO_WMISSING_VARIABLE_DECLARATIONS=
diff --git a/usr.bin/bc/Makefile.depend b/usr.bin/bc/Makefile.depend
index ec6db2c..3a04789 100644
--- a/usr.bin/bc/Makefile.depend
+++ b/usr.bin/bc/Makefile.depend
@@ -12,6 +12,7 @@ DIRDEPS = \
lib/libcompiler_rt \
lib/libedit \
lib/ncurses/ncursesw \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/bluetooth/bthost/Makefile b/usr.bin/bluetooth/bthost/Makefile
index 833d107..13b1d90 100644
--- a/usr.bin/bluetooth/bthost/Makefile
+++ b/usr.bin/bluetooth/bthost/Makefile
@@ -3,7 +3,6 @@
PROG= bthost
-DPADD= ${LIBBLUETOOTH}
-LDADD= -lbluetooth
+LIBADD= bluetooth
.include <bsd.prog.mk>
diff --git a/usr.bin/bluetooth/bthost/bthost.c b/usr.bin/bluetooth/bthost/bthost.c
index 2dd5635..69ce3f5 100644
--- a/usr.bin/bluetooth/bthost/bthost.c
+++ b/usr.bin/bluetooth/bthost/bthost.c
@@ -29,6 +29,7 @@
* $FreeBSD$
*/
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/usr.bin/bluetooth/btsockstat/Makefile b/usr.bin/bluetooth/btsockstat/Makefile
index cdec9f7..36ef850 100644
--- a/usr.bin/bluetooth/btsockstat/Makefile
+++ b/usr.bin/bluetooth/btsockstat/Makefile
@@ -6,7 +6,6 @@ WARNS?= 2
BINGRP= kmem
BINMODE= 2555
-DPADD= ${LIBBLUETOOTH} ${LIBKVM}
-LDADD= -lbluetooth -lkvm
+LIBADD= bluetooth kvm
.include <bsd.prog.mk>
diff --git a/usr.bin/bluetooth/btsockstat/btsockstat.c b/usr.bin/bluetooth/btsockstat/btsockstat.c
index f63ee1f..aa85286 100644
--- a/usr.bin/bluetooth/btsockstat/btsockstat.c
+++ b/usr.bin/bluetooth/btsockstat/btsockstat.c
@@ -38,8 +38,8 @@
#include <sys/socketvar.h>
#include <net/if.h>
-#include <net/if_var.h>
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <err.h>
#include <fcntl.h>
@@ -255,8 +255,8 @@ hcirawpr(kvm_t *kvmd, u_long addr)
(unsigned long) pcb.so,
(unsigned long) this,
pcb.flags,
- so.so_rcv.sb_cc,
- so.so_snd.sb_cc,
+ so.so_rcv.sb_ccc,
+ so.so_snd.sb_ccc,
pcb.addr.hci_node);
}
} /* hcirawpr */
@@ -303,8 +303,8 @@ l2caprawpr(kvm_t *kvmd, u_long addr)
"%-8lx %-8lx %6d %6d %-17.17s\n",
(unsigned long) pcb.so,
(unsigned long) this,
- so.so_rcv.sb_cc,
- so.so_snd.sb_cc,
+ so.so_rcv.sb_ccc,
+ so.so_snd.sb_ccc,
bdaddrpr(&pcb.src, NULL, 0));
}
} /* l2caprawpr */
@@ -361,8 +361,8 @@ l2cappr(kvm_t *kvmd, u_long addr)
fprintf(stdout,
"%-8lx %6d %6d %-17.17s/%-5d %-17.17s %-5d %s\n",
(unsigned long) this,
- so.so_rcv.sb_cc,
- so.so_snd.sb_cc,
+ so.so_rcv.sb_ccc,
+ so.so_snd.sb_ccc,
bdaddrpr(&pcb.src, local, sizeof(local)),
pcb.psm,
bdaddrpr(&pcb.dst, remote, sizeof(remote)),
@@ -467,8 +467,8 @@ rfcommpr(kvm_t *kvmd, u_long addr)
fprintf(stdout,
"%-8lx %6d %6d %-17.17s %-17.17s %-4d %-4d %s\n",
(unsigned long) this,
- so.so_rcv.sb_cc,
- so.so_snd.sb_cc,
+ so.so_rcv.sb_ccc,
+ so.so_snd.sb_ccc,
bdaddrpr(&pcb.src, local, sizeof(local)),
bdaddrpr(&pcb.dst, remote, sizeof(remote)),
pcb.channel,
diff --git a/usr.bin/bluetooth/rfcomm_sppd/Makefile b/usr.bin/bluetooth/rfcomm_sppd/Makefile
index 0da7498..b17c5cf 100644
--- a/usr.bin/bluetooth/rfcomm_sppd/Makefile
+++ b/usr.bin/bluetooth/rfcomm_sppd/Makefile
@@ -5,7 +5,6 @@ PROG= rfcomm_sppd
SRCS= rfcomm_sppd.c rfcomm_sdp.c
WARNS?= 2
-DPADD= ${LIBBLUETOOTH} ${LIBSDP}
-LDADD= -lbluetooth -lsdp -lutil
+LIBADD= bluetooth sdp util
.include <bsd.prog.mk>
diff --git a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sdp.c b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sdp.c
index 5873071..239597d 100644
--- a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sdp.c
+++ b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sdp.c
@@ -28,7 +28,7 @@
* $Id: rfcomm_sdp.c,v 1.1 2003/09/07 18:15:55 max Exp $
* $FreeBSD$
*/
-
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <errno.h>
#include <sdp.h>
diff --git a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
index ab6e1a7..309bab9 100644
--- a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
+++ b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
@@ -33,6 +33,7 @@
#include <sys/stat.h>
#include <sys/types.h>
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <ctype.h>
#include <err.h>
diff --git a/usr.bin/bmake/Makefile b/usr.bin/bmake/Makefile
index 2fc2bee..4abb45fe 100644
--- a/usr.bin/bmake/Makefile
+++ b/usr.bin/bmake/Makefile
@@ -14,10 +14,10 @@ CFLAGS+= -I${.CURDIR}
CLEANDIRS+= FreeBSD
CLEANFILES+= bootstrap
-# $Id: Makefile,v 1.27 2014/06/20 14:51:54 sjg Exp $
+# $Id: Makefile,v 1.38 2015/05/05 21:58:05 sjg Exp $
# Base version on src date
-MAKE_VERSION= 20140620
+MAKE_VERSION= 20150505
PROG?= ${.CURDIR:T}
@@ -148,9 +148,9 @@ COPTS.parse.c += -Wno-format-nonliteral
COPTS.var.c += -Wno-format-nonliteral
# Force these
-SHAREDIR= ${prefix}/share
-BINDIR= ${prefix}/bin
-MANDIR= ${SHAREDIR}/man
+SHAREDIR= ${SHAREDIR.bmake:U${prefix}/share}
+BINDIR= ${BINDIR.bmake:U${prefix}/bin}
+MANDIR= ${MANDIR.bmake:U${SHAREDIR}/man}
.if !exists(.depend)
${OBJS}: config.h
diff --git a/usr.bin/bmake/unit-tests/Makefile b/usr.bin/bmake/unit-tests/Makefile
index be4cd2f..100b467 100644
--- a/usr.bin/bmake/unit-tests/Makefile
+++ b/usr.bin/bmake/unit-tests/Makefile
@@ -5,20 +5,21 @@
SRCTOP?= ${.CURDIR:H:H:H}
-# $Id: Makefile.in,v 1.44 2013/08/28 22:09:29 sjg Exp $
+# $Id: Makefile.in,v 1.47 2015/05/05 21:58:06 sjg Exp $
#
-# $NetBSD: Makefile,v 1.38 2013/08/28 21:56:50 sjg Exp $
+# $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 sjg Exp $
#
# Unit tests for make(1)
# The main targets are:
#
# all: run all the tests
-# test: run 'all', capture output and compare to expected results
+# test: run 'all', and compare to expected results
# accept: move generated output to expected results
#
# Adding a test case.
# Each feature should get its own set of tests in its own suitably
-# named makefile which should be added to SUBFILES to hook it in.
+# named makefile (*.mk), with its own set of expected results (*.exp),
+# and it should be added to the TESTNAMES list.
#
srcdir= ${SRCTOP}/contrib/bmake/unit-tests
@@ -26,12 +27,14 @@ srcdir= ${SRCTOP}/contrib/bmake/unit-tests
.MAIN: all
UNIT_TESTS:= ${srcdir}
+.PATH: ${UNIT_TESTS}
-# Simple sub-makefiles - we run them as a black box
-# keep the list sorted.
-SUBFILES= \
+# Each test is in a sub-makefile.
+# Keep the list sorted.
+TESTNAMES= \
comment \
cond1 \
+ cond2 \
error \
export \
export-all \
@@ -49,7 +52,6 @@ SUBFILES= \
modts \
modword \
order \
- phony-end \
posix \
qequals \
sunshcmd \
@@ -57,23 +59,36 @@ SUBFILES= \
ternary \
unexport \
unexport-env \
- varcmd
-
-all: ${SUBFILES}
+ varcmd \
+ varmisc \
+ varshell
+
+# these tests were broken by referting POSIX chanegs
+STRICT_POSIX_TESTS = \
+ escape \
+ impsrc \
+ phony-end \
+ posix1 \
+ suffixes
+# Override make flags for certain tests
flags.doterror=
flags.order=-j1
-# the tests are actually done with sub-makes.
-.PHONY: ${SUBFILES}
-.PRECIOUS: ${SUBFILES}
-${SUBFILES}:
- -@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
+OUTFILES= ${TESTNAMES:S/$/.out/}
-clean:
- rm -f *.out *.fail *.core
+all: ${OUTFILES}
-.sinclude <bsd.obj.mk>
+CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
+CLEANFILES += obj*.[och] lib*.a # posix1.mk
+CLEANFILES += issue* .[ab]* # suffixes.mk
+CLEANRECURSIVE += dir dummy # posix1.mk
+
+clean:
+ rm -f ${CLEANFILES}
+.if !empty(CLEANRECURSIVE)
+ rm -rf ${CLEANRECURSIVE}
+.endif
TEST_MAKE?= ${.MAKE}
TOOL_SED?= sed
@@ -88,22 +103,56 @@ LANG= C
.export LANG LC_ALL
.endif
-# The driver.
+# some tests need extra post-processing
+SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \
+ -e '/command/s,No such.*,not found,'
+
+# the tests are actually done with sub-makes.
+.SUFFIXES: .mk .rawout .out
+.mk.rawout:
+ @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
+ -@cd ${.OBJDIR} && \
+ { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
+ 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
+ @mv ${.TARGET}.tmp ${.TARGET}
+
# We always pretend .MAKE was called 'make'
# and strip ${.CURDIR}/ from the output
# and replace anything after 'stopped in' with unit-tests
# so the results can be compared.
-test:
- @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
- @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
- ${TOOL_TR} -d '\015' | \
- ${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[^:]*:,make:,' \
- -e '/stopped/s, /.*, unit-tests,' \
- -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
- -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
- tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
- ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
+.rawout.out:
+ @echo postprocess ${.TARGET}
+ @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
+ -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
+ -e '/stopped/s, /.*, unit-tests,' \
+ -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
+ -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \
+ < ${.IMPSRC} > ${.TARGET}.tmp
+ @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
+ @mv ${.TARGET}.tmp ${.TARGET}
+
+# Compare all output files
+test: ${OUTFILES} .PHONY
+ @failed= ; \
+ for test in ${TESTNAMES}; do \
+ ${TOOL_DIFF} -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
+ || failed="$${failed}$${failed:+ }$${test}" ; \
+ done ; \
+ if [ -n "$${failed}" ]; then \
+ echo "Failed tests: $${failed}" ; false ; \
+ else \
+ echo "All tests passed" ; \
+ fi
accept:
- mv test.out ${srcdir}/test.exp
+ @for test in ${TESTNAMES}; do \
+ cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
+ || { echo "Replacing $${test}.exp" ; \
+ cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
+ done
+
+.if exists(${TEST_MAKE})
+${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
+.endif
+.sinclude <bsd.obj.mk>
diff --git a/usr.bin/bsdiff/bsdiff/Makefile b/usr.bin/bsdiff/bsdiff/Makefile
index 0e8498f..7569b4f 100644
--- a/usr.bin/bsdiff/bsdiff/Makefile
+++ b/usr.bin/bsdiff/bsdiff/Makefile
@@ -2,7 +2,6 @@
PROG= bsdiff
-DPADD= ${LIBBZ2}
-LDADD= -lbz2
+LIBADD= bz2
.include <bsd.prog.mk>
diff --git a/usr.bin/bsdiff/bspatch/Makefile b/usr.bin/bsdiff/bspatch/Makefile
index c0ed521..c2d6d4e 100644
--- a/usr.bin/bsdiff/bspatch/Makefile
+++ b/usr.bin/bsdiff/bspatch/Makefile
@@ -2,7 +2,6 @@
PROG= bspatch
-DPADD= ${LIBBZ2}
-LDADD= -lbz2
+LIBADD= bz2
.include <bsd.prog.mk>
diff --git a/usr.bin/bzip2/Makefile b/usr.bin/bzip2/Makefile
index c2490a2..5cb33b3 100644
--- a/usr.bin/bzip2/Makefile
+++ b/usr.bin/bzip2/Makefile
@@ -8,8 +8,7 @@ CFLAGS+= -D_FILE_OFFSET_BITS=64
WARNS?= 3
-DPADD= ${LIBBZ2}
-LDADD= -lbz2
+LIBADD= bz2
LINKS= ${BINDIR}/bzip2 ${BINDIR}/bunzip2
LINKS+= ${BINDIR}/bzip2 ${BINDIR}/bzcat
diff --git a/usr.bin/calendar/Makefile b/usr.bin/calendar/Makefile
index ef1d7f2..5e8ba88 100644
--- a/usr.bin/calendar/Makefile
+++ b/usr.bin/calendar/Makefile
@@ -5,9 +5,8 @@
PROG= calendar
SRCS= calendar.c locale.c events.c dates.c parsedata.c io.c day.c \
- ostern.c paskha.c pom.c sunpos.c calcpp.c
-DPADD= ${LIBM}
-LDADD= -lm
+ ostern.c paskha.c pom.c sunpos.c
+LIBADD= m
INTER= de_AT.ISO_8859-15 de_DE.ISO8859-1 fr_FR.ISO8859-1 \
hr_HR.ISO8859-2 hu_HU.ISO8859-2 pt_BR.ISO8859-1 \
pt_BR.UTF-8 ru_RU.KOI8-R ru_RU.UTF-8 uk_UA.KOI8-U
diff --git a/usr.bin/calendar/calcpp.c b/usr.bin/calendar/calcpp.c
deleted file mode 100644
index 6a15683..0000000
--- a/usr.bin/calendar/calcpp.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*-
- * Copyright (c) 2013 Diane Bruce
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-/* calendar fake cpp does a very limited cpp version */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <assert.h>
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <langinfo.h>
-#include <locale.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "pathnames.h"
-#include "calendar.h"
-
-#define MAXFPSTACK 50
-static FILE *fpstack[MAXFPSTACK];
-static int curfpi;
-static void pushfp(FILE *fp);
-static FILE *popfp(void);
-static int tokenscpp(char *buf, char *string);
-
-#define T_INVALID -1
-#define T_INCLUDE 0
-#define T_DEFINE 1
-#define T_IFNDEF 2
-#define T_ENDIF 3
-
-#define MAXSYMS 100
-static char *symtable[MAXSYMS];
-static void addsym(const char *name);
-static int findsym(const char *name);
-
-FILE *
-fincludegets(char *buf, int size, FILE *fp)
-{
- char name[MAXPATHLEN];
- FILE *nfp=NULL;
- char *p;
- int ch;
-
- if (fp == NULL)
- return(NULL);
-
- if (fgets(buf, size, fp) == NULL) {
- *buf = '\0';
- fclose(fp);
- fp = popfp();
- return (fp);
- }
- if ((p = strchr(buf, '\n')) != NULL)
- *p = '\0';
- else {
- /* Flush this line */
- while ((ch = fgetc(fp)) != '\n' && ch != EOF);
- if (ch == EOF) {
- *buf = '\0';
- fclose(fp);
- fp = popfp();
- return(fp);
- }
- }
- switch (tokenscpp(buf, name)) {
- case T_INCLUDE:
- *buf = '\0';
- if ((nfp = fopen(name, "r")) != NULL) {
- pushfp(fp);
- fp = nfp;
- }
- break;
- case T_DEFINE:
- addsym(name);
- break;
- case T_IFNDEF:
- if (findsym(name)) {
- fclose(fp);
- fp = popfp();
- *buf = '\0';
- }
- break;
- case T_ENDIF:
- *buf = '\0';
- break;
- default:
- break;
- }
- return (fp);
-}
-
-static int
-tokenscpp(char *buf, char *string)
-{
- char *p;
- char *s;
-
- if ((p = strstr(buf, "#define")) != NULL) {
- p += 8;
- while (isspace((unsigned char)*p))
- p++;
- s = p;
- while(!isspace((unsigned char)*p))
- p++;
- strlcpy(string, s, MAXPATHLEN);
- return(T_DEFINE);
- } else if ((p = strstr(buf, "#ifndef")) != NULL) {
- p += 8;
- while (isspace((unsigned char)*p))
- p++;
- s = p;
- while(!isspace((unsigned char)*p))
- p++;
- *p = '\0';
- strncpy(string, s, MAXPATHLEN);
- return(T_IFNDEF);
- } else if ((p = strstr(buf, "#endif")) != NULL) {
- return(T_ENDIF);
- } if ((p = strstr(buf, "#include")) != NULL) {
- p += 8;
- while (isspace((unsigned char)*p))
- p++;
- if (*p == '<') {
- s = p+1;
- if ((p = strchr(s, '>')) != NULL)
- *p = '\0';
- if (*s != '/')
- snprintf (string, MAXPATHLEN, "%s/%s",
- _PATH_INCLUDE, s);
- else
- strncpy(string, s, MAXPATHLEN);
- } else if (*p == '(') {
- s = p+1;
- if ((p = strchr(p, '>')) != NULL)
- *p = '\0';
- snprintf (string, MAXPATHLEN, "%s", s);
- }
- return(T_INCLUDE);
- }
- return(T_INVALID);
-}
-
-static void
-pushfp(FILE *fp)
-{
- curfpi++;
- if (curfpi == MAXFPSTACK)
- errx(1, "Max #include reached");
- fpstack[curfpi] = fp;
-}
-
-static
-FILE *popfp(void)
-{
- FILE *tmp;
-
- assert(curfpi >= 0);
- tmp = fpstack[curfpi];
- curfpi--;
- return(tmp);
-}
-
-void
-initcpp(void)
-{
- int i;
-
- for (i=0; i < MAXSYMS; i++)
- symtable[i] = NULL;
- fpstack[0] = NULL;
- curfpi = 0;
-}
-
-
-static void
-addsym(const char *name)
-{
- int i;
-
- if (!findsym(name))
- for (i=0; i < MAXSYMS; i++) {
- if (symtable[i] == NULL) {
- symtable[i] = strdup(name);
- if (symtable[i] == NULL)
- errx(1, "malloc error in addsym");
- return;
- }
- }
- errx(1, "symbol table full\n");
-}
-
-static int
-findsym(const char *name)
-{
- int i;
-
- for (i=0; i < MAXSYMS; i++)
- if (symtable[i] != NULL && strcmp(symtable[i],name) == 0)
- return (1);
- return (0);
-}
diff --git a/usr.bin/calendar/calendar.h b/usr.bin/calendar/calendar.h
index 0138fd2..1113c4a 100644
--- a/usr.bin/calendar/calendar.h
+++ b/usr.bin/calendar/calendar.h
@@ -168,10 +168,6 @@ void closecal(FILE *);
FILE *opencalin(void);
FILE *opencalout(void);
-/* calcpp.c */
-void initcpp(void);
-FILE *fincludegets(char *buf, int size, FILE *fp);
-
/* ostern.c / paskha.c */
int paskha(int);
int easter(int);
diff --git a/usr.bin/calendar/calendars/calendar.freebsd b/usr.bin/calendar/calendars/calendar.freebsd
index fc6df82..9ea3d81 100644
--- a/usr.bin/calendar/calendars/calendar.freebsd
+++ b/usr.bin/calendar/calendars/calendar.freebsd
@@ -359,6 +359,7 @@
12/01 Alexey Dokuchaev <danfe@FreeBSD.org> born in Magadan, USSR, 1980
12/02 Ermal Luçi <eri@FreeBSD.org> born in Tirane, Albania, 1980
12/03 Diane Bruce <db@FreeBSD.org> born in Ottawa, Ontario, Canada, 1952
+12/04 Mariusz Zaborski <oshogbo@FreeBSD.org> born in Skierniewice, Poland, 1990
12/05 Ivan Voras <ivoras@FreeBSD.org> born in Slavonski Brod, Croatia, 1981
12/06 Stefan Farfeleder <stefanf@FreeBSD.org> born in Wien, Austria, 1980
12/11 Ganael Laplanche <martymac@FreeBSD.org> born in Reims, France, 1980
diff --git a/usr.bin/calendar/calendars/calendar.holiday b/usr.bin/calendar/calendars/calendar.holiday
index 3fdee69..fe9029e 100644
--- a/usr.bin/calendar/calendars/calendar.holiday
+++ b/usr.bin/calendar/calendars/calendar.holiday
@@ -144,8 +144,8 @@
04/26 Confederate Memorial Day in Florida & Georgia
04/26 Union Day in Tanzania
04/27 Independence Day in Togo
+04/27 King's Birthday in the Netherlands, the Netherlands Antilles
04/29 Showa Day in Japan
-04/30 Queen's Birthday in the Netherlands, the Netherlands Antilles
04/30 The Workers Day in Uruguay
04/MonLast Arbor Day in Wyoming (last Monday)
04/MonLast Confederate Memorial Day in Alabama & Mississippi (last Monday)
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index 0f34882..5e5c146 100644
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -51,14 +51,23 @@ __FBSDID("$FreeBSD$");
#include <langinfo.h>
#include <locale.h>
#include <pwd.h>
+#include <stdbool.h>
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stringlist.h>
#include <unistd.h>
#include "pathnames.h"
#include "calendar.h"
+enum {
+ T_OK = 0,
+ T_ERR,
+ T_PROCESS,
+};
+
const char *calendarFile = "calendar"; /* default calendar file */
static const char *calendarHomes[] = {".calendar", _PATH_INCLUDE}; /* HOME */
static const char *calendarNoMail = "nomail";/* don't sent mail if file exist */
@@ -68,6 +77,147 @@ static char path[MAXPATHLEN];
struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon;
struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
+static int cal_parse(FILE *in, FILE *out);
+
+static StringList *definitions = NULL;
+static struct event *events[MAXCOUNT];
+static char *extradata[MAXCOUNT];
+
+static void
+trimlr(char **buf)
+{
+ char *walk = *buf;
+
+ while (isspace(*walk))
+ walk++;
+ while (isspace(walk[strlen(walk) -1]))
+ walk[strlen(walk) -1] = '\0';
+
+ *buf = walk;
+}
+
+static FILE *
+cal_fopen(const char *file)
+{
+ FILE *fp;
+ char *home = getenv("HOME");
+ unsigned int i;
+
+ if (home == NULL || *home == '\0') {
+ warnx("Cannot get home directory");
+ return (NULL);
+ }
+
+ if (chdir(home) != 0) {
+ warnx("Cannot enter home directory");
+ return (NULL);
+ }
+
+ for (i = 0; i < sizeof(calendarHomes)/sizeof(calendarHomes[0]) ; i++) {
+ if (chdir(calendarHomes[i]) != 0)
+ continue;
+
+ if ((fp = fopen(file, "r")) != NULL)
+ return (fp);
+ }
+
+ warnx("can't open calendar file \"%s\"", file);
+
+ return (NULL);
+}
+
+static int
+token(char *line, FILE *out, bool *skip)
+{
+ char *walk, c, a;
+
+ if (strncmp(line, "endif", 5) == 0) {
+ *skip = false;
+ return (T_OK);
+ }
+
+ if (*skip)
+ return (T_OK);
+
+ if (strncmp(line, "include", 7) == 0) {
+ walk = line + 7;
+
+ trimlr(&walk);
+
+ if (*walk == '\0') {
+ warnx("Expecting arguments after #include");
+ return (T_ERR);
+ }
+
+ if (*walk != '<' && *walk != '\"') {
+ warnx("Excecting '<' or '\"' after #include");
+ return (T_ERR);
+ }
+
+ a = *walk;
+ walk++;
+ c = walk[strlen(walk) - 1];
+
+ switch(c) {
+ case '>':
+ if (a != '<') {
+ warnx("Unterminated include expecting '\"'");
+ return (T_ERR);
+ }
+ break;
+ case '\"':
+ if (a != '\"') {
+ warnx("Unterminated include expecting '>'");
+ return (T_ERR);
+ }
+ break;
+ default:
+ warnx("Unterminated include expecting '%c'",
+ a == '<' ? '>' : '\"' );
+ return (T_ERR);
+ }
+ walk[strlen(walk) - 1] = '\0';
+
+ if (cal_parse(cal_fopen(walk), out))
+ return (T_ERR);
+
+ return (T_OK);
+ }
+
+ if (strncmp(line, "define", 6) == 0) {
+ if (definitions == NULL)
+ definitions = sl_init();
+ walk = line + 6;
+ trimlr(&walk);
+
+ if (*walk == '\0') {
+ warnx("Expecting arguments after #define");
+ return (T_ERR);
+ }
+
+ sl_add(definitions, strdup(walk));
+ return (T_OK);
+ }
+
+ if (strncmp(line, "ifndef", 6) == 0) {
+ walk = line + 6;
+ trimlr(&walk);
+
+ if (*walk == '\0') {
+ warnx("Expecting arguments after #ifndef");
+ return (T_ERR);
+ }
+
+ if (definitions != NULL && sl_find(definitions, walk) != NULL)
+ *skip = true;
+
+ return (T_OK);
+ }
+
+ return (T_PROCESS);
+
+}
+
#define REPLACE(string, slen, struct_) \
if (strncasecmp(buf, (string), (slen)) == 0 && buf[(slen)]) { \
if (struct_.name != NULL) \
@@ -77,30 +227,25 @@ struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
struct_.len = strlen(buf + (slen)); \
continue; \
}
-void
-cal(void)
+static int
+cal_parse(FILE *in, FILE *out)
{
- char *pp, p;
- FILE *fpin;
- FILE *fpout;
- int l;
- int count, i;
+ char *line = NULL;
+ char *buf;
+ size_t linecap = 0;
+ ssize_t linelen;
+ ssize_t l;
+ static int d_first = -1;
+ static int count = 0;
+ int i;
int month[MAXCOUNT];
int day[MAXCOUNT];
int year[MAXCOUNT];
- char **extradata; /* strings of 20 length */
- int flags;
- static int d_first = -1;
- char buf[2048 + 1];
- struct event *events[MAXCOUNT];
- struct tm tm;
+ bool skip = false;
char dbuf[80];
-
- initcpp();
- extradata = (char **)calloc(MAXCOUNT, sizeof(char *));
- for (i = 0; i < MAXCOUNT; i++) {
- extradata[i] = (char *)calloc(1, 20);
- }
+ char *pp, p;
+ struct tm tm;
+ int flags;
/* Unused */
tm.tm_sec = 0;
@@ -108,20 +253,29 @@ cal(void)
tm.tm_hour = 0;
tm.tm_wday = 0;
- count = 0;
- if ((fpin = opencalin()) == NULL) {
- free(extradata);
- return;
- }
- if ((fpout = opencalout()) == NULL) {
- fclose(fpin);
- free(extradata);
- return;
- }
- while ((fpin = fincludegets(buf, sizeof(buf), fpin)) != NULL) {
- if (*buf == '\0')
+ if (in == NULL)
+ return (1);
+
+ while ((linelen = getline(&line, &linecap, in)) > 0) {
+ if (*line == '#') {
+ switch (token(line+1, out, &skip)) {
+ case T_ERR:
+ free(line);
+ return (1);
+ case T_OK:
+ continue;
+ case T_PROCESS:
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (skip)
continue;
- for (l = strlen(buf);
+
+ buf = line;
+ for (l = linelen;
l > 0 && isspace((unsigned char)buf[l - 1]);
l--)
;
@@ -208,16 +362,41 @@ cal(void)
}
}
+ free(line);
+ fclose(in);
+
+ return (0);
+}
+
+void
+cal(void)
+{
+ FILE *fpin;
+ FILE *fpout;
+ int i;
+
+ for (i = 0; i < MAXCOUNT; i++)
+ extradata[i] = (char *)calloc(1, 20);
+
+
+ if ((fpin = opencalin()) == NULL)
+ return;
+
+ if ((fpout = opencalout()) == NULL) {
+ fclose(fpin);
+ return;
+ }
+
+ if (cal_parse(fpin, fpout))
+ return;
+
event_print_all(fpout);
closecal(fpout);
- free(extradata);
}
FILE *
opencalin(void)
{
- size_t i;
- int found;
struct stat sbuf;
FILE *fpin;
@@ -231,22 +410,7 @@ opencalin(void)
if ((fpin = fopen(calendarFile, "r")) == NULL)
return (NULL);
} else {
- char *home = getenv("HOME");
- if (home == NULL || *home == '\0')
- errx(1, "cannot get home directory");
- if (chdir(home) != 0)
- errx(1, "cannot enter home directory");
- for (found = i = 0; i < sizeof(calendarHomes) /
- sizeof(calendarHomes[0]); i++)
- if (chdir(calendarHomes[i]) == 0 &&
- (fpin = fopen(calendarFile, "r")) != NULL) {
- found = 1;
- break;
- }
- if (!found)
- errx(1,
- "can't open calendar file \"%s\": %s (%d)",
- calendarFile, strerror(errno), errno);
+ fpin = cal_fopen(calendarFile);
}
}
return (fpin);
diff --git a/usr.bin/checknr/checknr.1 b/usr.bin/checknr/checknr.1
index 8888fdd..a89706e 100644
--- a/usr.bin/checknr/checknr.1
+++ b/usr.bin/checknr/checknr.1
@@ -28,7 +28,7 @@
.\" @(#)checknr.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd January 26, 2005
+.Dd May 5, 2015
.Dt CHECKNR 1
.Os
.Sh NAME
@@ -157,7 +157,3 @@ There is no way to define a 1 character macro name using
.Pp
Does not correctly recognize certain reasonable constructs,
such as conditionals.
-.Pp
-Input lines are limited to
-.Dv LINE_MAX
-(2048) bytes in length.
diff --git a/usr.bin/checknr/checknr.c b/usr.bin/checknr/checknr.c
index d3e5355..06395b0 100644
--- a/usr.bin/checknr/checknr.c
+++ b/usr.bin/checknr/checknr.c
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
* structured typesetting.
*/
#include <err.h>
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -57,7 +58,7 @@ __FBSDID("$FreeBSD$");
#define MAXSTK 100 /* Stack size */
#define MAXBR 100 /* Max number of bracket pairs known */
-#define MAXCMDS 500 /* Max number of commands known */
+#define MAXCMDS 600 /* Max number of commands known */
static void addcmd(char *);
static void addmac(const char *);
@@ -133,6 +134,19 @@ static struct brstr {
{"(q", ")q"},
{"(x", ")x"},
{"(z", ")z"},
+ /* The -mdoc package */
+ {"Ao", "Ac"},
+ {"Bd", "Ed"},
+ {"Bk", "Ek"},
+ {"Bo", "Bc"},
+ {"Do", "Dc"},
+ {"Fo", "Fc"},
+ {"Oo", "Oc"},
+ {"Po", "Pc"},
+ {"Qo", "Qc"},
+ {"Rs", "Re"},
+ {"So", "Sc"},
+ {"Xo", "Xc"},
/* Things needed by preprocessors */
{"EQ", "EN"},
{"TS", "TE"},
@@ -146,37 +160,47 @@ static struct brstr {
* Used so we can complain about unrecognized commands.
*/
static const char *knowncmds[MAXCMDS] = {
-"$c", "$f", "$h", "$p", "$s", "(b", "(c", "(d", "(f", "(l", "(q", "(t",
-"(x", "(z", ")b", ")c", ")d", ")f", ")l", ")q", ")t", ")x", ")z", "++",
-"+c", "1C", "1c", "2C", "2c", "@(", "@)", "@C", "@D", "@F", "@I", "@M",
-"@c", "@e", "@f", "@h", "@m", "@n", "@o", "@p", "@r", "@t", "@z", "AB",
-"AE", "AF", "AI", "AL", "AM", "AS", "AT", "AU", "AX", "B", "B1", "B2",
-"BD", "BE", "BG", "BL", "BS", "BT", "BX", "C1", "C2", "CD", "CM", "CT",
-"D", "DA", "DE", "DF", "DL", "DS", "DT", "EC", "EF", "EG", "EH", "EM",
-"EN", "EQ", "EX", "FA", "FD", "FE", "FG", "FJ", "FK", "FL", "FN", "FO",
-"FQ", "FS", "FV", "FX", "H", "HC", "HD", "HM", "HO", "HU", "I", "ID",
-"IE", "IH", "IM", "IP", "IX", "IZ", "KD", "KE", "KF", "KQ", "KS", "LB",
-"LC", "LD", "LE", "LG", "LI", "LP", "MC", "ME", "MF", "MH", "ML", "MR",
-"MT", "ND", "NE", "NH", "NL", "NP", "NS", "OF", "OH", "OK", "OP", "P",
-"P1", "PF", "PH", "PP", "PT", "PX", "PY", "QE", "QP", "QS", "R", "RA",
-"RC", "RE", "RL", "RP", "RQ", "RS", "RT", "S", "S0", "S2", "S3", "SA",
-"SG", "SH", "SK", "SM", "SP", "SY", "T&", "TA", "TB", "TC", "TD", "TE",
-"TH", "TL", "TM", "TP", "TQ", "TR", "TS", "TX", "UL", "US", "UX", "VL",
-"WC", "WH", "XA", "XD", "XE", "XF", "XK", "XP", "XS", "[", "[-", "[0",
-"[1", "[2", "[3", "[4", "[5", "[<", "[>", "[]", "]", "]-", "]<", "]>",
-"][", "ab", "ac", "ad", "af", "am", "ar", "as", "b", "ba", "bc", "bd",
-"bi", "bl", "bp", "br", "bx", "c.", "c2", "cc", "ce", "cf", "ch", "cs",
-"ct", "cu", "da", "de", "di", "dl", "dn", "ds", "dt", "dw", "dy", "ec",
-"ef", "eh", "el", "em", "eo", "ep", "ev", "ex", "fc", "fi", "fl", "fo",
-"fp", "ft", "fz", "hc", "he", "hl", "hp", "ht", "hw", "hx", "hy", "i",
-"ie", "if", "ig", "in", "ip", "it", "ix", "lc", "lg", "li", "ll", "ln",
-"lo", "lp", "ls", "lt", "m1", "m2", "m3", "m4", "mc", "mk", "mo", "n1",
-"n2", "na", "ne", "nf", "nh", "nl", "nm", "nn", "np", "nr", "ns", "nx",
-"of", "oh", "os", "pa", "pc", "pi", "pl", "pm", "pn", "po", "pp", "ps",
-"q", "r", "rb", "rd", "re", "rm", "rn", "ro", "rr", "rs", "rt", "sb",
-"sc", "sh", "sk", "so", "sp", "ss", "st", "sv", "sz", "ta", "tc", "th",
-"ti", "tl", "tm", "tp", "tr", "u", "uf", "uh", "ul", "vs", "wh", "xp",
-"yr", 0
+"$c", "$f", "$h", "$p", "$s", "%A", "%B", "%C", "%D", "%I", "%J", "%N", "%O",
+"%P", "%Q", "%R", "%T", "%V", "(b", "(c", "(d", "(f", "(l", "(q", "(t", "(x",
+"(z", ")b", ")c", ")d", ")f", ")l", ")q", ")t", ")x", ")z", "++", "+c", "1C",
+"1c", "2C", "2c", "@(", "@)", "@C", "@D", "@F", "@I", "@M", "@c", "@e", "@f",
+"@h", "@m", "@n", "@o", "@p", "@r", "@t", "@z", "AB", "AE", "AF", "AI", "AL",
+"AM", "AS", "AT", "AU", "AX", "Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At",
+"B", "B" , "B1", "B2", "BD", "BE", "BG", "BL", "BS", "BT", "BX", "Bc", "Bd",
+"Bf", "Bk", "Bl", "Bo", "Bq", "Bsx", "Bx", "C1", "C2", "CD", "CM", "CT", "Cd",
+"Cm", "D", "D" , "D1", "DA", "DE", "DF", "DL", "DS", "DT", "Db", "Dc", "Dd",
+"Dl", "Do", "Dq", "Dt", "Dv", "EC", "EF", "EG", "EH", "EM", "EN", "EQ", "EX",
+"Ec", "Ed", "Ef", "Ek", "El", "Em", "Eo", "Er", "Ev", "FA", "FD", "FE", "FG",
+"FJ", "FK", "FL", "FN", "FO", "FQ", "FS", "FV", "FX", "Fa", "Fc", "Fd", "Fl",
+"Fn", "Fo", "Ft", "Fx", "H", "H" , "HC", "HD", "HM", "HO", "HU", "I", "I" ,
+"ID", "IE", "IH", "IM", "IP", "IX", "IZ", "Ic", "In", "It", "KD", "KE", "KF",
+"KQ", "KS", "LB", "LC", "LD", "LE", "LG", "LI", "LP", "Lb", "Li", "MC", "ME",
+"MF", "MH", "ML", "MR", "MT", "ND", "NE", "NH", "NL", "NP", "NS", "Nd", "Nm",
+"No", "Ns", "Nx", "OF", "OH", "OK", "OP", "Oc", "Oo", "Op", "Os", "Ot", "Ox",
+"P", "P" , "P1", "PF", "PH", "PP", "PT", "PX", "PY", "Pa", "Pc", "Pf", "Po",
+"Pp", "Pq", "QE", "QP", "QS", "Qc", "Ql", "Qo", "Qq", "R", "R" , "RA", "RC",
+"RE", "RL", "RP", "RQ", "RS", "RT", "Re", "Rs", "S", "S" , "S0", "S2", "S3",
+"SA", "SG", "SH", "SK", "SM", "SP", "SY", "Sc", "Sh", "Sm", "So", "Sq", "Ss",
+"St", "Sx", "Sy", "T&", "TA", "TB", "TC", "TD", "TE", "TH", "TL", "TM", "TP",
+"TQ", "TR", "TS", "TX", "Tn", "UL", "US", "UX", "Ud", "Ux", "VL", "Va", "Vt",
+"WC", "WH", "XA", "XD", "XE", "XF", "XK", "XP", "XS", "Xc", "Xo", "Xr", "[",
+"[" , "[-", "[0", "[1", "[2", "[3", "[4", "[5", "[<", "[>", "[]", "\\{", "\\}",
+"]", "]" , "]-", "]<", "]>", "][", "ab", "ac", "ad", "af", "am", "ar", "as",
+"b", "b" , "ba", "bc", "bd", "bi", "bl", "bp", "br", "bx", "c.", "c2", "cc",
+"ce", "cf", "ch", "chop", "cs", "ct", "cu", "da", "de", "di", "dl", "dn", "do",
+"ds", "dt", "dw", "dy", "ec", "ef", "eh", "el", "em", "eo", "ep", "ev", "evc",
+"ex", "fallback", "fc", "feature", "fi", "fl", "flig", "fo", "fp", "ft", "ftr",
+"fz", "fzoom", "hc", "he", "hidechar", "hl", "hp", "ht", "hw", "hx", "hy",
+"hylang", "i", "i" , "ie", "if", "ig", "in", "ip", "it", "ix", "kern",
+"kernafter", "kernbefore", "kernpair", "lc", "lc_ctype", "lg", "lhang", "li",
+"ll", "ln", "lo", "lp", "ls", "lt", "m1", "m2", "m3", "m4", "mc", "mk", "mo",
+"n1", "n2", "na", "ne", "nf", "nh", "nl", "nm", "nn", "np", "nr", "ns", "nx",
+"of", "oh", "os", "pa", "papersize", "pc", "pi", "pl", "pm", "pn", "po", "pp",
+"ps", "q", "q" , "r", "r" , "rb", "rd", "re", "recursionlimit", "return",
+"rhang", "rm", "rn", "ro", "rr", "rs", "rt", "sb", "sc", "sh", "shift", "sk",
+"so", "sp", "ss", "st", "sv", "sz", "ta", "tc", "th", "ti", "tl", "tm", "tp",
+"tr", "track", "u", "uf", "uh", "ul", "vs", "wh", "xflag", "xp", "yr",
+0
};
static int lineno; /* current line number in input file */
@@ -210,8 +234,18 @@ main(int argc, char **argv)
for (i=0; br[i].opbr; i++)
;
for (cp=argv[1]+3; cp[-1]; cp += 6) {
- br[i].opbr = strncpy(malloc(3), cp, 2);
- br[i].clbr = strncpy(malloc(3), cp+3, 2);
+ char *tmp;
+
+ if (i >= MAXBR)
+ errx(1, "too many pairs");
+ if ((tmp = malloc(3)) == NULL)
+ err(1, "malloc");
+ strlcpy(tmp, cp, 3);
+ br[i].opbr = tmp;
+ if ((tmp = malloc(3)) == NULL)
+ err(1, "malloc");
+ strlcpy(tmp, cp+3, 3);
+ br[i].clbr = tmp;
addmac(br[i].opbr); /* knows pairs are also known cmds */
addmac(br[i].clbr);
i++;
@@ -250,7 +284,7 @@ main(int argc, char **argv)
nfiles = argc - 1;
if (nfiles > 0) {
- for (i=1; i<argc; i++) {
+ for (i = 1; i < argc; i++) {
cfilename = argv[i];
f = fopen(cfilename, "r");
if (f == NULL)
@@ -279,12 +313,15 @@ static void
process(FILE *f)
{
int i, n;
- char mac[5]; /* The current macro or nroff command */
+ char mac[64]; /* The current macro or nroff command */
+ char *line;
+ size_t linecap;
int pl;
- static char line[256]; /* the current line */
+ line = NULL;
+ linecap = 0;
stktop = -1;
- for (lineno = 1; fgets(line, sizeof line, f); lineno++) {
+ for (lineno = 1; getline(&line, &linecap, f) > 0; lineno++) {
if (line[0] == '.') {
/*
* find and isolate the macro/command name.
@@ -320,9 +357,9 @@ process(FILE *f)
* At this point we process the line looking
* for \s and \f.
*/
- for (i=0; line[i]; i++)
- if (line[i]=='\\' && (i==0 || line[i-1]!='\\')) {
- if (!sflag && line[++i]=='s') {
+ for (i = 0; line[i]; i++)
+ if (line[i] == '\\' && (i == 0 || line[i-1] != '\\')) {
+ if (!sflag && line[++i] == 's') {
pl = line[++i];
if (isdigit(pl)) {
n = pl - '0';
@@ -333,7 +370,8 @@ process(FILE *f)
n = 10 * n + line[i] - '0';
i--;
if (n == 0) {
- if (stk[stktop].opno == SZ) {
+ if (stktop >= 0 &&
+ stk[stktop].opno == SZ) {
stktop--;
} else {
pe(lineno);
@@ -345,10 +383,11 @@ process(FILE *f)
stk[stktop].parm = n;
stk[stktop].lno = lineno;
}
- } else if (!fflag && line[i]=='f') {
+ } else if (!fflag && line[i] == 'f') {
n = line[++i];
if (n == 'P') {
- if (stk[stktop].opno == FT) {
+ if (stktop >= 0 &&
+ stk[stktop].opno == FT) {
stktop--;
} else {
pe(lineno);
@@ -363,11 +402,12 @@ process(FILE *f)
}
}
}
+ free(line);
/*
* We've hit the end and look at all this stuff that hasn't been
* matched yet! Complain, complain.
*/
- for (i=stktop; i>=0; i--) {
+ for (i = stktop; i >= 0; i--) {
complain(i);
}
}
@@ -395,7 +435,8 @@ prop(int i)
break;
default:
printf("Bug: stk[%d].opno = %d = .%s, .%s",
- i, stk[i].opno, br[stk[i].opno].opbr, br[stk[i].opno].clbr);
+ i, stk[i].opno, br[stk[i].opno].opbr,
+ br[stk[i].opno].clbr);
}
}
@@ -557,17 +598,20 @@ addmac(const char *mac)
}
/* binsrch sets slot as a side effect */
#ifdef DEBUG
-printf("binsrch(%s) -> %d\n", mac, slot);
+ printf("binsrch(%s) -> %d\n", mac, slot);
#endif
loc = &knowncmds[slot];
src = &knowncmds[ncmds-1];
dest = src+1;
while (dest > loc)
*dest-- = *src--;
- *loc = strcpy(malloc(3), mac);
+ if ((*loc = strdup(mac)) == NULL)
+ err(1, "strdup");
ncmds++;
#ifdef DEBUG
-printf("after: %s %s %s %s %s, %d cmds\n", knowncmds[slot-2], knowncmds[slot-1], knowncmds[slot], knowncmds[slot+1], knowncmds[slot+2], ncmds);
+ printf("after: %s %s %s %s %s, %d cmds\n",
+ knowncmds[slot-2], knowncmds[slot-1], knowncmds[slot],
+ knowncmds[slot+1], knowncmds[slot+2], ncmds);
#endif
}
@@ -592,12 +636,12 @@ binsrch(const char *mac)
if (d == 0)
d = p[1] - mac[1];
if (d == 0)
- return mid;
+ return (mid);
if (d < 0)
bot = mid + 1;
else
top = mid - 1;
}
slot = bot; /* place it would have gone */
- return -1;
+ return (-1);
}
diff --git a/usr.bin/chkey/Makefile b/usr.bin/chkey/Makefile
index a9e00e8..4f47b9c 100644
--- a/usr.bin/chkey/Makefile
+++ b/usr.bin/chkey/Makefile
@@ -10,7 +10,6 @@ CFLAGS+= -I${.CURDIR}/../newkey
.if ${MK_NIS} != "no"
CFLAGS+= -DYP
.endif
-DPADD= ${LIBRPCSVC} ${LIBMP} ${LIBCRYPTO}
-LDADD= -lrpcsvc -lmp -lcrypto
+LIBADD+= rpcsvc mp
.include <bsd.prog.mk>
diff --git a/usr.bin/chpass/Makefile b/usr.bin/chpass/Makefile
index cf3acc6..9b3e878 100644
--- a/usr.bin/chpass/Makefile
+++ b/usr.bin/chpass/Makefile
@@ -16,11 +16,9 @@ CFLAGS+= -DYP
#CFLAGS+=-DRESTRICT_FULLNAME_CHANGE
CFLAGS+=-I${.CURDIR}/../../usr.sbin/pwd_mkdb -I${.CURDIR}/../../lib/libc/gen -I.
-DPADD= ${LIBCRYPT} ${LIBUTIL}
-LDADD= -lcrypt -lutil
+LIBADD= crypt util
.if ${MK_NIS} != "no"
-DPADD+= ${LIBYPCLNT}
-LDADD+= -lypclnt
+LIBADD+= ypclnt
.endif
LINKS= ${BINDIR}/chpass ${BINDIR}/chfn
diff --git a/usr.bin/clang/Makefile b/usr.bin/clang/Makefile
index 9655b06..4d4d2ec 100644
--- a/usr.bin/clang/Makefile
+++ b/usr.bin/clang/Makefile
@@ -13,13 +13,16 @@ SUBDIR+=bugpoint \
llvm-as \
llvm-bcanalyzer \
llvm-diff \
+ llvm-cov \
llvm-dis \
llvm-extract \
llvm-link \
llvm-mc \
llvm-nm \
llvm-objdump \
+ llvm-profdata \
llvm-rtdyld \
+ llvm-symbolizer \
macho-dump \
opt
.endif
diff --git a/usr.bin/clang/bugpoint/Makefile b/usr.bin/clang/bugpoint/Makefile
index 6599b03..a8b34c3 100644
--- a/usr.bin/clang/bugpoint/Makefile
+++ b/usr.bin/clang/bugpoint/Makefile
@@ -16,14 +16,18 @@ SRCS= BugDriver.cpp \
bugpoint.cpp
TGHDRS= Intrinsics
-LIBDEPS=llvmirreader \
+LIBDEPS=llvmcodegen \
+ llvmobjcarcopts \
+ llvmirreader \
llvmbitwriter \
- llvmbitreader \
llvmlinker \
llvmipo \
- llvmobjcarcopts \
llvmvectorize \
llvmscalaropts \
+ llvmprofiledata \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
llvminstcombine \
llvminstrumentation \
llvmtransformutils \
@@ -31,7 +35,6 @@ LIBDEPS=llvmirreader \
llvmanalysis \
llvmtarget \
llvmmc \
- llvmobject \
llvmasmparser \
llvmcore \
llvmsupport
diff --git a/usr.bin/clang/bugpoint/bugpoint.1 b/usr.bin/clang/bugpoint/bugpoint.1
index 8597c27..9537d9e 100644
--- a/usr.bin/clang/bugpoint/bugpoint.1
+++ b/usr.bin/clang/bugpoint/bugpoint.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "BUGPOINT" "1" "2014-01-01" "3.4" "LLVM"
+.TH "BUGPOINT" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
bugpoint \- automatic test case reduction tool
.
@@ -211,13 +211,6 @@ by compiling the program with the "safe" backend and running it.
.UNINDENT
.UNINDENT
.sp
-\fB\-\-profile\-info\-file\fP \fIfilename\fP
-.INDENT 0.0
-.INDENT 3.5
-Profile file loaded by \fB\-\-profile\-loader\fP\&.
-.UNINDENT
-.UNINDENT
-.sp
\fB\-\-run\-{int,jit,llc,custom}\fP
.INDENT 0.0
.INDENT 3.5
@@ -295,6 +288,6 @@ opt|opt
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/clang/Makefile b/usr.bin/clang/clang/Makefile
index 345efde..201e494 100644
--- a/usr.bin/clang/clang/Makefile
+++ b/usr.bin/clang/clang/Makefile
@@ -28,8 +28,7 @@ MLINKS+= clang.1 cc.1 \
clang.1 cpp.1
.endif
-TGHDRS= CC1AsOptions \
- DiagnosticCommonKinds \
+TGHDRS= DiagnosticCommonKinds \
DiagnosticDriverKinds \
DiagnosticFrontendKinds \
DiagnosticLexKinds \
@@ -43,9 +42,6 @@ _clangstaticanalyzer= \
clangstaticanalyzercore
_clangarcmigrate= \
clangarcmigrate
-_clangrewriter= \
- clangrewritefrontend \
- clangrewritecore
.endif # MK_CLANG_FULL
LIBDEPS=clangfrontendtool \
@@ -55,23 +51,31 @@ LIBDEPS=clangfrontendtool \
clangcodegen \
clangparse \
clangsema \
+ clangrewritefrontend \
+ clangrewrite \
${_clangstaticanalyzer} \
${_clangarcmigrate} \
- ${_clangrewriter} \
clanganalysis \
clangedit \
clangast \
- clangbasic \
clanglex \
+ clangbasic \
llvmoption \
+ llvmobjcarcopts \
llvmlinker \
llvmirreader \
llvmipo \
llvmvectorize \
llvminstrumentation \
llvmbitwriter \
- llvmbitreader \
llvmasmparser \
+ llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
llvmarmdisassembler \
llvmarmcodegen \
llvmarmasmparser \
@@ -84,6 +88,7 @@ LIBDEPS=clangfrontendtool \
llvmmipsdesc \
llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
llvmpowerpccodegen \
llvmpowerpcasmparser \
llvmpowerpcdesc \
@@ -100,22 +105,27 @@ LIBDEPS=clangfrontendtool \
llvmx86codegen \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvmcodegen \
- llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
+ llvmtarget \
llvmx86desc \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
+ llvmmcdisassembler \
llvmx86info \
- llvmtarget \
llvmx86instprinter \
llvmmc \
- llvmobject \
llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/clang/Makefile.depend b/usr.bin/clang/clang/Makefile.depend
index 64aadbc..ba86a94 100644
--- a/usr.bin/clang/clang/Makefile.depend
+++ b/usr.bin/clang/clang/Makefile.depend
@@ -18,6 +18,16 @@ DIRDEPS = \
lib/clang/libclangfrontendtool \
lib/clang/libclanglex \
lib/clang/libclangparse \
+ lib/clang/libclangrewrite \
+ lib/clang/libllvmaarch64disassembler \
+ lib/clang/libllvmaarch64codegen \
+ lib/clang/libllvmaarch64asmparser \
+ lib/clang/libllvmaarch64desc \
+ lib/clang/libllvmaarch64info \
+ lib/clang/libllvmaarch64instprinter \
+ lib/clang/libllvmaarch64utils \
+ lib/clang/libllvmpowerpcdisassembler \
+ lib/clang/libllvmprofiledata \
lib/clang/libclangrewritecore \
lib/clang/libclangrewritefrontend \
lib/clang/libclangsema \
diff --git a/usr.bin/clang/clang/clang.1 b/usr.bin/clang/clang/clang.1
index 0e84db1..2420722 100644
--- a/usr.bin/clang/clang/clang.1
+++ b/usr.bin/clang/clang/clang.1
@@ -1,542 +1,403 @@
.\" $FreeBSD$
-.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" Set up some character translations and predefined strings. \*(-- will
-.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote. \*(C+ will
-.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
-.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
-.\" nothing in troff, for use with C<>.
-.tr \(*W-
-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
-.ie n \{\
-. ds -- \(*W-
-. ds PI pi
-. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-. ds L" ""
-. ds R" ""
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds -- \|\(em\|
-. ds PI \(*p
-. ds L" ``
-. ds R" ''
-. ds C`
-. ds C'
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is turned on, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.\"
-.\" Avoid warning from groff about undefined register 'F'.
-.de IX
-..
-.nr rF 0
-.if \n(.g .if rF .nr rF 1
-.if (\n(rF:(\n(.g==0)) \{
-. if \nF \{
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. if !\nF==2 \{
-. nr % 0
-. nr F 2
-. \}
-. \}
-.\}
-.rr rF
-.\"
-.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
-.\" Fear. Run. Save yourself. No user-serviceable parts.
-. \" fudge factors for nroff and troff
-.if n \{\
-. ds #H 0
-. ds #V .8m
-. ds #F .3m
-. ds #[ \f1
-. ds #] \fP
-.\}
-.if t \{\
-. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
-. ds #V .6m
-. ds #F 0
-. ds #[ \&
-. ds #] \&
-.\}
-. \" simple accents for nroff and troff
-.if n \{\
-. ds ' \&
-. ds ` \&
-. ds ^ \&
-. ds , \&
-. ds ~ ~
-. ds /
-.\}
-.if t \{\
-. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
-. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
-. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
-. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
-. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
-. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
-.\}
-. \" troff and (daisy-wheel) nroff accents
-.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
-.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
-.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
-.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
-.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
-.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
-.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
-.ds ae a\h'-(\w'a'u*4/10)'e
-.ds Ae A\h'-(\w'A'u*4/10)'E
-. \" corrections for vroff
-.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
-.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
-. \" for low resolution devices (crt and lpr)
-.if \n(.H>23 .if \n(.V>19 \
-\{\
-. ds : e
-. ds 8 ss
-. ds o a
-. ds d- d\h'-1'\(ga
-. ds D- D\h'-1'\(hy
-. ds th \o'bp'
-. ds Th \o'LP'
-. ds ae ae
-. ds Ae AE
-.\}
-.rm #[ #] #H #V #F C
-.\" ========================================================================
-.\"
-.IX Title "CLANG 1"
-.TH CLANG 1 "2014-01-01" "clang 3.4" "Clang Tools Documentation"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH "NAME"
-clang \- the Clang C, C++, and Objective\-C compiler
-.SH "SYNOPSIS"
-.IX Header "SYNOPSIS"
-\&\fBclang\fR [\fB\-c\fR|\fB\-S\fR|\fB\-E\fR] \fB\-std=\fR\fIstandard\fR \fB\-g\fR
- [\fB\-O0\fR|\fB\-O1\fR|\fB\-O2\fR|\fB\-O3\fR|\fB\-Ofast\fR|\fB\-Os\fR|\fB\-Oz\fR|\fB\-O\fR|\fB\-O4\fR]
- \fB\-W\fR\fIwarnings...\fR \fB\-pedantic\fR
- \fB\-I\fR\fIdir...\fR \fB\-L\fR\fIdir...\fR
- \fB\-D\fR\fImacro[=defn]\fR
- \fB\-f\fR\fIfeature-option...\fR
- \fB\-m\fR\fImachine-option...\fR
- \fB\-o\fR \fIoutput-file\fR
- \fB\-stdlib=\fR\fIlibrary\fR
- \fIinput-filenames\fR
-.SH "DESCRIPTION"
-.IX Header "DESCRIPTION"
-\&\fBclang\fR is a C, \*(C+, and Objective-C compiler which encompasses preprocessing,
+.Dd February 25, 2015
+.Dt CLANG 1
+.Os
+.Sh NAME
+.Nm clang
+.Nd the Clang C, C++, and Objective-C compiler
+.Sh SYNOPSIS
+.Nm clang
+.Oo
+.Fl c Ns | Ns Fl S Ns | Ns Fl E Ns
+.Oc
+.Ar std= Ns Em standard
+.Fl g
+.br
+.Oo
+.Fl O0 Ns | Ns Fl O1 Ns | Ns Fl O2 Ns | Ns Fl O3 Ns | Ns Fl Ofast Ns | Ns Fl Os Ns | Ns Fl Oz Ns | Ns Fl O Ns | Ns Fl O4 Ns
+.Oc
+.br
+.Fl W Ns Em warnings...
+.Fl pedantic
+.br
+.Fl I Ns Em dir...
+.Fl L Ns Em dir...
+.br
+.Fl D Ns Em macro[=defn]
+.br
+.Fl f Ns Em feature-option...
+.br
+.Fl m Ns Em machine-option...
+.br
+.Fl o
+.Em output-file
+.br
+.Ar stdlib= Ns Em library
+.br
+.Em input-filenames
+.Sh DESCRIPTION
+.Sy clang
+is a C, C++, and Objective-C compiler which encompasses preprocessing,
parsing, optimization, code generation, assembly, and linking. Depending on
which high-level mode setting is passed, Clang will stop before doing a full
link. While Clang is highly integrated, it is important to understand the
stages of compilation, to understand how to invoke it. These stages are:
-.IP "\fBDriver\fR" 4
-.IX Item "Driver"
-The \fBclang\fR executable is actually a small driver which controls the overall
+.Bl -tag -width Ds
+.It Sy Driver
+The
+.Sy clang
+executable is actually a small driver which controls the overall
execution of other tools such as the compiler, assembler and linker. Typically
you do not need to interact with the driver, but you transparently use it to run
the other tools.
-.IP "\fBPreprocessing\fR" 4
-.IX Item "Preprocessing"
+.It Sy Preprocessing
This stage handles tokenization of the input source file, macro expansion,
#include expansion and handling of other preprocessor directives. The output of
-this stage is typically called a \*(L".i\*(R" (for C), \*(L".ii\*(R" (for \*(C+), \*(L".mi\*(R" (for
-Objective-C) , or \*(L".mii\*(R" (for Objective\-\*(C+) file.
-.IP "\fBParsing and Semantic Analysis\fR" 4
-.IX Item "Parsing and Semantic Analysis"
+this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for
+Objective-C) , or ".mii" (for Objective-C++) file.
+.It Sy Parsing and Semantic Analysis
This stage parses the input file, translating preprocessor tokens into a parse
tree. Once in the form of a parser tree, it applies semantic analysis to compute
types for expressions as well and determine whether the code is well formed. This
stage is responsible for generating most of the compiler warnings as well as
-parse errors. The output of this stage is an \*(L"Abstract Syntax Tree\*(R" (\s-1AST\s0).
-.IP "\fBCode Generation and Optimization\fR" 4
-.IX Item "Code Generation and Optimization"
-This stage translates an \s-1AST\s0 into low-level intermediate code (known as \*(L"\s-1LLVM
-IR\*(R"\s0) and ultimately to machine code. This phase is responsible for optimizing
+parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
+.It Sy Code Generation and Optimization
+This stage translates an AST into low-level intermediate code (known as "LLVM
+IR") and ultimately to machine code. This phase is responsible for optimizing
the generated code and handling target-specific code generation. The output of
-this stage is typically called a \*(L".s\*(R" file or \*(L"assembly\*(R" file.
-.Sp
+this stage is typically called a ".s" file or "assembly" file.
+.Pp
Clang also supports the use of an integrated assembler, in which the code
generator produces object files directly. This avoids the overhead of generating
-the \*(L".s\*(R" file and of calling the target assembler.
-.IP "\fBAssembler\fR" 4
-.IX Item "Assembler"
+the ".s" file and of calling the target assembler.
+.It Sy Assembler
This stage runs the target assembler to translate the output of the compiler
-into a target object file. The output of this stage is typically called a \*(L".o\*(R"
-file or \*(L"object\*(R" file.
-.IP "\fBLinker\fR" 4
-.IX Item "Linker"
+into a target object file. The output of this stage is typically called a ".o"
+file or "object" file.
+.It Sy Linker
This stage runs the target linker to merge multiple object files into an
executable or dynamic library. The output of this stage is typically called an
-\&\*(L"a.out\*(R", \*(L".dylib\*(R" or \*(L".so\*(R" file.
-.PP
+"a.out", ".dylib" or ".so" file.
+.El
+.Pp
The Clang compiler supports a large number of options to control each of these
stages. In addition to compilation of code, Clang also supports other tools:
-.PP
-\&\fBClang Static Analyzer\fR
-.PP
+.Pp
+.Sy Clang Static Analyzer
+.Pp
The Clang Static Analyzer is a tool that scans source code to try to find bugs
through code analysis. This tool uses many parts of Clang and is built into the
-same driver. Please see <http://clang\-analyzer.llvm.org> for more details
+same driver. Please see
+.Lk http://clang-analyzer.llvm.org
+for more details
on how to use the static analyzer.
-.SH "OPTIONS"
-.IX Header "OPTIONS"
-.SS "Stage Selection Options"
-.IX Subsection "Stage Selection Options"
-.IP "\fB\-E\fR" 4
-.IX Item "-E"
+.Sh OPTIONS
+.Ss Stage Selection Options
+.Bl -tag -width Ds
+.It Sy -E
Run the preprocessor stage.
-.IP "\fB\-fsyntax\-only\fR" 4
-.IX Item "-fsyntax-only"
+.It Sy -fsyntax-only
Run the preprocessor, parser and type checking stages.
-.IP "\fB\-S\fR" 4
-.IX Item "-S"
-Run the previous stages as well as \s-1LLVM\s0 generation and optimization stages and
+.It Sy -S
+Run the previous stages as well as LLVM generation and optimization stages and
target-specific code generation, producing an assembly file.
-.IP "\fB\-c\fR" 4
-.IX Item "-c"
-Run all of the above, plus the assembler, generating a target \*(L".o\*(R" object file.
-.IP "\fBno stage selection option\fR" 4
-.IX Item "no stage selection option"
+.It Sy -c
+Run all of the above, plus the assembler, generating a target ".o" object file.
+.It Sy no stage selection option
If no stage selection option is specified, all stages above are run, and the
linker is run to combine the results into an executable or shared library.
-.SS "Language Selection and Mode Options"
-.IX Subsection "Language Selection and Mode Options"
-.IP "\fB\-x\fR \fIlanguage\fR" 4
-.IX Item "-x language"
-Treat subsequent input files as having type \fIlanguage\fR.
-.IP "\fB\-std\fR=\fIlanguage\fR" 4
-.IX Item "-std=language"
+.El
+.Ss Language Selection and Mode Options
+.Bl -tag -width Ds
+.It Sy -x Em language
+Treat subsequent input files as having type
+.Em language .
+.It Sy -std Ns = Ns Em language
Specify the language standard to compile for.
-.IP "\fB\-stdlib\fR=\fIlibrary\fR" 4
-.IX Item "-stdlib=library"
-Specify the \*(C+ standard library to use; supported options are libstdc++ and
+.It Sy -stdlib Ns = Ns Em library
+Specify the C++ standard library to use; supported options are libstdc++ and
libc++.
-.IP "\fB\-ansi\fR" 4
-.IX Item "-ansi"
-Same as \fB\-std=c89\fR.
-.IP "\fB\-ObjC++\fR" 4
-.IX Item "-ObjC++"
-Treat source input files as Objective\-\*(C+ inputs.
-.IP "\fB\-ObjC\fR" 4
-.IX Item "-ObjC"
+.It Sy -ansi
+Same as
+.Sy -std=c89 .
+.It Sy -ObjC++
+Treat source input files as Objective-C++ inputs.
+.It Sy -ObjC
Treat source input files as Objective-C inputs.
-.IP "\fB\-trigraphs\fR" 4
-.IX Item "-trigraphs"
+.It Sy -trigraphs
Enable trigraphs.
-.IP "\fB\-ffreestanding\fR" 4
-.IX Item "-ffreestanding"
+.It Sy -ffreestanding
Indicate that the file should be compiled for a freestanding, not a hosted,
environment.
-.IP "\fB\-fno\-builtin\fR" 4
-.IX Item "-fno-builtin"
+.It Sy -fno-builtin
Disable special handling and optimizations of builtin functions like strlen and
malloc.
-.IP "\fB\-fmath\-errno\fR" 4
-.IX Item "-fmath-errno"
+.It Sy -fmath-errno
Indicate that math functions should be treated as updating errno.
-.IP "\fB\-fpascal\-strings\fR" 4
-.IX Item "-fpascal-strings"
-Enable support for Pascal-style strings with \*(L"\epfoo\*(R".
-.IP "\fB\-fms\-extensions\fR" 4
-.IX Item "-fms-extensions"
+.It Sy -fpascal-strings
+Enable support for Pascal-style strings with "\epfoo".
+.It Sy -fms-extensions
Enable support for Microsoft extensions.
-.IP "\fB\-fmsc\-version=\fR" 4
-.IX Item "-fmsc-version="
+.It Sy -fmsc-version=
Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
-.IP "\fB\-fborland\-extensions\fR" 4
-.IX Item "-fborland-extensions"
+.It Sy -fborland-extensions
Enable support for Borland extensions.
-.IP "\fB\-fwritable\-strings\fR" 4
-.IX Item "-fwritable-strings"
+.It Sy -fwritable-strings
Make all string literals default to writable. This disables uniquing of
strings and other optimizations.
-.IP "\fB\-flax\-vector\-conversions\fR" 4
-.IX Item "-flax-vector-conversions"
+.It Sy -flax-vector-conversions
Allow loose type checking rules for implicit vector conversions.
-.IP "\fB\-fblocks\fR" 4
-.IX Item "-fblocks"
-Enable the \*(L"Blocks\*(R" language feature.
-.IP "\fB\-fobjc\-gc\-only\fR" 4
-.IX Item "-fobjc-gc-only"
+.It Sy -fblocks
+Enable the "Blocks" language feature.
+.It Sy -fobjc-gc-only
Indicate that Objective-C code should be compiled in GC-only mode, which only
works when Objective-C Garbage Collection is enabled.
-.IP "\fB\-fobjc\-gc\fR" 4
-.IX Item "-fobjc-gc"
+.It Sy -fobjc-gc
Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
-with both \s-1GC\s0 and non-GC mode.
-.IP "\fB\-fobjc\-abi\-version\fR=\fIversion\fR" 4
-.IX Item "-fobjc-abi-version=version"
-Select the Objective-C \s-1ABI\s0 version to use. Available versions are 1 (legacy
-\&\*(L"fragile\*(R" \s-1ABI\s0), 2 (non-fragile \s-1ABI 1\s0), and 3 (non-fragile \s-1ABI 2\s0).
-.IP "\fB\-fobjc\-nonfragile\-abi\-version\fR=\fIversion\fR" 4
-.IX Item "-fobjc-nonfragile-abi-version=version"
-Select the Objective-C non-fragile \s-1ABI\s0 version to use by default. This will only
-be used as the Objective-C \s-1ABI\s0 when the non-fragile \s-1ABI\s0 is enabled (either via
-\&\-fobjc\-nonfragile\-abi, or because it is the platform default).
-.IP "\fB\-fobjc\-nonfragile\-abi\fR" 4
-.IX Item "-fobjc-nonfragile-abi"
-Enable use of the Objective-C non-fragile \s-1ABI.\s0 On platforms for which this is
-the default \s-1ABI,\s0 it can be disabled with \fB\-fno\-objc\-nonfragile\-abi\fR.
-.SS "Target Selection Options"
-.IX Subsection "Target Selection Options"
+with both GC and non-GC mode.
+.It Sy -fobjc-abi-version Ns = Ns Em version
+Select the Objective-C ABI version to use. Available versions are 1 (legacy
+"fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
+.It Sy -fobjc-nonfragile-abi-version Ns = Ns Em version
+Select the Objective-C non-fragile ABI version to use by default. This will only
+be used as the Objective-C ABI when the non-fragile ABI is enabled (either via
+-fobjc-nonfragile-abi, or because it is the platform default).
+.It Sy -fobjc-nonfragile-abi
+Enable use of the Objective-C non-fragile ABI. On platforms for which this is
+the default ABI, it can be disabled with
+.Sy -fno-objc-nonfragile-abi .
+.El
+.Ss Target Selection Options
Clang fully supports cross compilation as an inherent part of its design.
Depending on how your version of Clang is configured, it may have support for
a number of cross compilers, or may only support a native target.
-.IP "\fB\-arch\fR \fIarchitecture\fR" 4
-.IX Item "-arch architecture"
+.Bl -tag -width Ds
+.It Sy -arch Em architecture
Specify the architecture to build for.
-.IP "\fB\-mmacosx\-version\-min\fR=\fIversion\fR" 4
-.IX Item "-mmacosx-version-min=version"
-When building for Mac \s-1OS/X,\s0 specify the minimum version supported by your
+.It Sy -mmacosx-version-min Ns = Ns Em version
+When building for Mac OS X, specify the minimum version supported by your
application.
-.IP "\fB\-miphoneos\-version\-min\fR" 4
-.IX Item "-miphoneos-version-min"
-When building for iPhone \s-1OS,\s0 specify the minimum version supported by your
+.It Sy -miphoneos-version-min
+When building for iPhone OS, specify the minimum version supported by your
application.
-.IP "\fB\-march\fR=\fIcpu\fR" 4
-.IX Item "-march=cpu"
+.It Sy -march Ns = Ns Em cpu
Specify that Clang should generate code for a specific processor family member
-and later. For example, if you specify \-march=i486, the compiler is allowed to
+and later. For example, if you specify -march=i486, the compiler is allowed to
generate instructions that are valid on i486 and later processors, but which
may not exist on earlier ones.
-.SS "Code Generation Options"
-.IX Subsection "Code Generation Options"
-.IP "\fB\-O0\fR \fB\-O1\fR \fB\-O2\fR \fB\-O3\fR \fB\-Ofast\fR \fB\-Os\fR \fB\-Oz\fR \fB\-O\fR \fB\-O4\fR" 4
-.IX Item "-O0 -O1 -O2 -O3 -Ofast -Os -Oz -O -O4"
+.El
+.Ss Code Generation Options
+.Bl -tag -width Ds
+.It Sy -O0 Sy -O1 Sy -O2 Sy -O3 Sy -Ofast Sy -\&Os Sy -\&Oz Sy -O Sy -O4
Specify which optimization level to use:
-.RS 4
-.IP "\fB\-O0\fR" 4
-.IX Item "-O0"
-Means \*(L"no optimization\*(R": this level compiles the fastest and
+.Bl -tag -width Ds
+.It Sy -O0
+Means "no optimization": this level compiles the fastest and
generates the most debuggable code.
-.IP "\fB\-O1\fR" 4
-.IX Item "-O1"
-Somewhere between \fB\-O0\fR and \fB\-O2\fR.
-.IP "\fB\-O2\fR" 4
-.IX Item "-O2"
+.It Sy -O1
+Somewhere between
+.Sy -O0
+and
+.Sy -O2 .
+.It Sy -O2
Moderate level of optimization which enables most optimizations.
-.IP "\fB\-O3\fR" 4
-.IX Item "-O3"
-Like \fB\-O2\fR, except that it enables optimizations that take longer to perform
+.It Sy -O3
+Like
+.Sy -O2 ,
+except that it enables optimizations that take longer to perform
or that may generate larger code (in an attempt to make the program run faster).
-.IP "\fB\-Ofast\fR" 4
-.IX Item "-Ofast"
-Enables all the optimizations from \fB\-O3\fR along with other aggressive
+.It Sy -Ofast
+Enables all the optimizations from
+.Sy -O3
+along with other aggressive
optimizations that may violate strict compliance with language standards.
-.IP "\fB\-Os\fR" 4
-.IX Item "-Os"
-Like \fB\-O2\fR with extra optimizations to reduce code size.
-.IP "\fB\-Oz\fR" 4
-.IX Item "-Oz"
-Like \fB\-Os\fR (and thus \fB\-O2\fR), but reduces code size further.
-.IP "\fB\-O\fR" 4
-.IX Item "-O"
-Equivalent to \fB\-O2\fR.
-.IP "\fB\-O4\fR and higher" 4
-.IX Item "-O4 and higher"
-Currently equivalent to \fB\-O3\fR
-.RE
-.RS 4
-.RE
-.IP "\fB\-g\fR" 4
-.IX Item "-g"
+.It Sy -\&Os
+Like
+.Sy -O2
+with extra optimizations to reduce code size.
+.It Sy -\&Oz
+Like
+.Sy -\&Os
+(and thus
+.Sy -O2 Ns ), but reduces code size further.
+.It Sy -O
+Equivalent to
+.Sy -O2 .
+.It Sy -O4 No and higher
+Currently equivalent to
+.Sy -O3
+.El
+.It Sy -g
Generate debug information. Note that Clang debug information works best at
-\&\fB\-O0\fR. At higher optimization levels, only line number information is
-currently available.
-.IP "\fB\-fexceptions\fR" 4
-.IX Item "-fexceptions"
+.Sy -O0 .
+.It Sy -fstandalone-debug Sy -fno-standalone-debug
+Clang supports a number of optimizations to reduce the size of debug
+information in the binary. They work based on the assumption that the
+debug type information can be spread out over multiple compilation
+units. For instance, Clang will not emit type definitions for types
+that are not needed by a module and could be replaced with a forward
+declaration. Further, Clang will only emit type info for a dynamic
+C++ class in the module that contains the vtable for the class.
+.Pp
+The
+.Sy -fstandalone-debug
+option turns off these optimizations. This
+is useful when working with 3rd-party libraries that don't come with
+debug information. This is the default on Darwin. Note that Clang
+will never emit type information for types that are not referenced at
+all by the program.
+.It Sy -fexceptions
Enable generation of unwind information, this allows exceptions to be thrown
-through Clang compiled stack frames. This is on by default in x86\-64.
-.IP "\fB\-ftrapv\fR" 4
-.IX Item "-ftrapv"
+through Clang compiled stack frames. This is on by default in x86-64.
+.It Sy -ftrapv
Generate code to catch integer overflow errors. Signed integer overflow is
undefined in C, with this flag, extra code is generated to detect this and abort
when it happens.
-.IP "\fB\-fvisibility\fR" 4
-.IX Item "-fvisibility"
+.It Sy -fvisibility
This flag sets the default visibility level.
-.IP "\fB\-fcommon\fR" 4
-.IX Item "-fcommon"
+.It Sy -fcommon
This flag specifies that variables without initializers get common linkage. It
-can be disabled with \fB\-fno\-common\fR.
-.IP "\fB\-ftls\-model\fR" 4
-.IX Item "-ftls-model"
-Set the default thread-local storage (\s-1TLS\s0) model to use for thread-local
-variables. Valid values are: \*(L"global-dynamic\*(R", \*(L"local-dynamic\*(R", \*(L"initial-exec\*(R"
-and \*(L"local-exec\*(R". The default is \*(L"global-dynamic\*(R". The default model can be
+can be disabled with
+.Sy -fno-common .
+.It Sy -ftls-model
+Set the default thread-local storage (TLS) model to use for thread-local
+variables. Valid values are: "global-dynamic", "local-dynamic", "initial-exec"
+and "local-exec". The default is "global-dynamic". The default model can be
overridden with the tls_model attribute. The compiler will try to choose a more
efficient model if possible.
-.IP "\fB\-flto\fR \fB\-emit\-llvm\fR" 4
-.IX Item "-flto -emit-llvm"
-Generate output files in \s-1LLVM\s0 formats, suitable for link time optimization. When
-used with \fB\-S\fR this generates \s-1LLVM\s0 intermediate language assembly files,
-otherwise this generates \s-1LLVM\s0 bitcode format object files (which may be passed
+.It Sy -flto Sy -emit-llvm
+Generate output files in LLVM formats, suitable for link time optimization. When
+used with
+.Sy -S
+this generates LLVM intermediate language assembly files,
+otherwise this generates LLVM bitcode format object files (which may be passed
to the linker depending on the stage selection options).
-.SS "Driver Options"
-.IX Subsection "Driver Options"
-.IP "\fB\-###\fR" 4
-.IX Item "-###"
-Print the commands to run for this compilation.
-.IP "\fB\-\-help\fR" 4
-.IX Item "--help"
+.El
+.Ss Driver Options
+.Bl -tag -width Ds
+.It Sy -###
+Print (but do not run) the commands to run for this compilation.
+.It Sy --help
Display available options.
-.IP "\fB\-Qunused\-arguments\fR" 4
-.IX Item "-Qunused-arguments"
+.It Sy -Qunused-arguments
Don't emit warning for unused driver arguments.
-.IP "\fB\-Wa,\fR\fIargs\fR" 4
-.IX Item "-Wa,args"
-Pass the comma separated arguments in \fIargs\fR to the assembler.
-.IP "\fB\-Wl,\fR\fIargs\fR" 4
-.IX Item "-Wl,args"
-Pass the comma separated arguments in \fIargs\fR to the linker.
-.IP "\fB\-Wp,\fR\fIargs\fR" 4
-.IX Item "-Wp,args"
-Pass the comma separated arguments in \fIargs\fR to the preprocessor.
-.IP "\fB\-Xanalyzer\fR \fIarg\fR" 4
-.IX Item "-Xanalyzer arg"
-Pass \fIarg\fR to the static analyzer.
-.IP "\fB\-Xassembler\fR \fIarg\fR" 4
-.IX Item "-Xassembler arg"
-Pass \fIarg\fR to the assembler.
-.IP "\fB\-Xlinker\fR \fIarg\fR" 4
-.IX Item "-Xlinker arg"
-Pass \fIarg\fR to the linker.
-.IP "\fB\-Xpreprocessor\fR \fIarg\fR" 4
-.IX Item "-Xpreprocessor arg"
-Pass \fIarg\fR to the preprocessor.
-.IP "\fB\-o\fR \fIfile\fR" 4
-.IX Item "-o file"
-Write output to \fIfile\fR.
-.IP "\fB\-print\-file\-name\fR=\fIfile\fR" 4
-.IX Item "-print-file-name=file"
-Print the full library path of \fIfile\fR.
-.IP "\fB\-print\-libgcc\-file\-name\fR" 4
-.IX Item "-print-libgcc-file-name"
-Print the library path for \*(L"libgcc.a\*(R".
-.IP "\fB\-print\-prog\-name\fR=\fIname\fR" 4
-.IX Item "-print-prog-name=name"
-Print the full program path of \fIname\fR.
-.IP "\fB\-print\-search\-dirs\fR" 4
-.IX Item "-print-search-dirs"
+.It Sy -Wa, Ns Em args
+Pass the comma separated arguments in
+.Em args
+to the assembler.
+.It Sy -Wl, Ns Em args
+Pass the comma separated arguments in
+.Em args
+to the linker.
+.It Sy -Wp, Ns Em args
+Pass the comma separated arguments in
+.Em args
+to the preprocessor.
+.It Sy -Xanalyzer Em arg
+Pass
+.Em arg
+to the static analyzer.
+.It Sy -Xassembler Em arg
+Pass
+.Em arg
+to the assembler.
+.It Sy -Xlinker Em arg
+Pass
+.Em arg
+to the linker.
+.It Sy -Xpreprocessor Em arg
+Pass
+.Em arg
+to the preprocessor.
+.It Sy -o Em file
+Write output to
+.Em file .
+.It Sy -print-file-name Ns = Ns Em file
+Print the full library path of
+.Em file .
+.It Sy -print-libgcc-file-name
+Print the library path for "libgcc.a".
+.It Sy -print-prog-name Ns = Ns Em name
+Print the full program path of
+.Em name .
+.It Sy -print-search-dirs
Print the paths used for finding libraries and programs.
-.IP "\fB\-save\-temps\fR" 4
-.IX Item "-save-temps"
+.It Sy -save-temps
Save intermediate compilation results.
-.IP "\fB\-integrated\-as\fR \fB\-no\-integrated\-as\fR" 4
-.IX Item "-integrated-as -no-integrated-as"
+.It Sy -integrated-as Sy -no-integrated-as
Used to enable and disable, respectively, the use of the integrated
assembler. Whether the integrated assembler is on by default is target
dependent.
-.IP "\fB\-time\fR" 4
-.IX Item "-time"
+.It Sy -time
Time individual commands.
-.IP "\fB\-ftime\-report\fR" 4
-.IX Item "-ftime-report"
+.It Sy -ftime-report
Print timing summary of each stage of compilation.
-.IP "\fB\-v\fR" 4
-.IX Item "-v"
+.It Sy -v
Show commands to run and use verbose output.
-.SS "Diagnostics Options"
-.IX Subsection "Diagnostics Options"
-.IP "\fB\-fshow\-column\fR \fB\-fshow\-source\-location\fR \fB\-fcaret\-diagnostics\fR \fB\-fdiagnostics\-fixit\-info\fR \fB\-fdiagnostics\-parseable\-fixits\fR \fB\-fdiagnostics\-print\-source\-range\-info\fR \fB\-fprint\-source\-range\-info\fR \fB\-fdiagnostics\-show\-option\fR \fB\-fmessage\-length\fR" 4
-.IX Item "-fshow-column -fshow-source-location -fcaret-diagnostics -fdiagnostics-fixit-info -fdiagnostics-parseable-fixits -fdiagnostics-print-source-range-info -fprint-source-range-info -fdiagnostics-show-option -fmessage-length"
+.El
+.Ss Diagnostics Options
+.Bl -tag -width Ds
+.It Sy -fshow-column Sy -fshow-source-location Sy -fcaret-diagnostics Sy -fdiagnostics-fixit-info Sy -fdiagnostics-parseable-fixits Sy -fdiagnostics-print-source-range-info Sy -fprint-source-range-info Sy -fdiagnostics-show-option Sy -fmessage-length
These options control how Clang prints out information about diagnostics (errors
and warnings). Please see the Clang User's Manual for more information.
-.SS "Preprocessor Options"
-.IX Subsection "Preprocessor Options"
-.IP "\fB\-D\fR\fImacroname=value\fR" 4
-.IX Item "-Dmacroname=value"
+.El
+.Ss Preprocessor Options
+.Bl -tag -width Ds
+.It Sy -D Ns Em macroname=value
Adds an implicit #define into the predefines buffer which is read before the
source file is preprocessed.
-.IP "\fB\-U\fR\fImacroname\fR" 4
-.IX Item "-Umacroname"
+.It Sy -U Ns Em macroname
Adds an implicit #undef into the predefines buffer which is read before the
source file is preprocessed.
-.IP "\fB\-include\fR \fIfilename\fR" 4
-.IX Item "-include filename"
+.It Sy -include Em filename
Adds an implicit #include into the predefines buffer which is read before the
source file is preprocessed.
-.IP "\fB\-I\fR\fIdirectory\fR" 4
-.IX Item "-Idirectory"
+.It Sy -I Ns Em directory
Add the specified directory to the search path for include files.
-.IP "\fB\-F\fR\fIdirectory\fR" 4
-.IX Item "-Fdirectory"
+.It Sy -F Ns Em directory
Add the specified directory to the search path for framework include files.
-.IP "\fB\-nostdinc\fR" 4
-.IX Item "-nostdinc"
+.It Sy -nostdinc
Do not search the standard system directories or compiler builtin directories
for include files.
-.IP "\fB\-nostdlibinc\fR" 4
-.IX Item "-nostdlibinc"
+.It Sy -nostdlibinc
Do not search the standard system directories for include files, but do search
compiler builtin include directories.
-.IP "\fB\-nobuiltininc\fR" 4
-.IX Item "-nobuiltininc"
+.It Sy -nobuiltininc
Do not search clang's builtin directory for include files.
-.SH "ENVIRONMENT"
-.IX Header "ENVIRONMENT"
-.IP "\fB\s-1TMPDIR\s0\fR, \fB\s-1TEMP\s0\fR, \fB\s-1TMP\s0\fR" 4
-.IX Item "TMPDIR, TEMP, TMP"
+.El
+.Sh ENVIRONMENT
+.Bl -tag -width Ds
+.It Sy TMPDIR Ns , Sy TEMP Ns , Sy TMP
These environment variables are checked, in order, for the location to
write temporary files used during the compilation process.
-.IP "\fB\s-1CPATH\s0\fR" 4
-.IX Item "CPATH"
+.It Sy CPATH
If this environment variable is present, it is treated as a delimited
list of paths to be added to the default system include path list. The
-delimiter is the platform dependent delimiter, as used in the \fI\s-1PATH\s0\fR
+delimiter is the platform dependent delimitor, as used in the
+.Em PATH
environment variable.
-.Sp
+.Pp
Empty components in the environment variable are ignored.
-.IP "\fBC_INCLUDE_PATH\fR, \fB\s-1OBJC_INCLUDE_PATH\s0\fR, \fB\s-1CPLUS_INCLUDE_PATH\s0\fR, \fB\s-1OBJCPLUS_INCLUDE_PATH\s0\fR" 4
-.IX Item "C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH"
-These environment variables specify additional paths, as for \s-1CPATH,\s0
+.It Sy C_INCLUDE_PATH Ns , Sy OBJC_INCLUDE_PATH Ns , Sy CPLUS_INCLUDE_PATH Ns , Sy OBJCPLUS_INCLUDE_PATH
+These environment variables specify additional paths, as for CPATH,
which are only used when processing the appropriate language.
-.IP "\fB\s-1MACOSX_DEPLOYMENT_TARGET\s0\fR" 4
-.IX Item "MACOSX_DEPLOYMENT_TARGET"
-If \-mmacosx\-version\-min is unspecified, the default deployment target
+.It Sy MACOSX_DEPLOYMENT_TARGET
+If -mmacosx-version-min is unspecified, the default deployment target
is read from this environment variable. This option only affects darwin
targets.
-.SH "BUGS"
-.IX Header "BUGS"
-To report bugs, please visit <http://llvm.org/bugs/>. Most bug reports should
-include preprocessed source files (use the \fB\-E\fR option) and the full output of
+.El
+.Sh BUGS
+To report bugs, please visit
+.Lk http://llvm.org/bugs/ .
+Most bug reports should
+include preprocessed source files (use the
+.Sy -E
+option) and the full output of
the compiler, along with information to reproduce.
-.SH "SEE ALSO"
-.IX Header "SEE ALSO"
-.Vb 1
-\& as(1), ld(1)
-.Ve
-.SH "AUTHOR"
-.IX Header "AUTHOR"
-Maintained by the Clang / \s-1LLVM\s0 Team (<http://clang.llvm.org>).
+.Sh SEE ALSO
+.Bd -literal
+ as(1), ld(1)
+.Ed
+.Sh AUTHOR
+Maintained by the Clang / LLVM Team
+.Pf ( Lk http://clang.llvm.org Ns ).
diff --git a/usr.bin/clang/llc/Makefile b/usr.bin/clang/llc/Makefile
index 43eaf9b..eef537e 100644
--- a/usr.bin/clang/llc/Makefile
+++ b/usr.bin/clang/llc/Makefile
@@ -9,7 +9,13 @@ SRCS= llc.cpp
LIBDEPS=llvmirreader \
llvmasmparser \
- llvmbitreader \
+ llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
llvmarmdisassembler \
llvmarmcodegen \
llvmarmasmparser \
@@ -22,6 +28,7 @@ LIBDEPS=llvmirreader \
llvmmipsdesc \
llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
llvmpowerpccodegen \
llvmpowerpcasmparser \
llvmpowerpcdesc \
@@ -38,22 +45,27 @@ LIBDEPS=llvmirreader \
llvmx86codegen \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvmcodegen \
- llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
+ llvmtarget \
llvmx86desc \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
+ llvmmcdisassembler \
llvmx86info \
- llvmtarget \
llvmx86instprinter \
llvmmc \
- llvmobject \
llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llc/llc.1 b/usr.bin/clang/llc/llc.1
index 81fd80a..02c2f9e 100644
--- a/usr.bin/clang/llc/llc.1
+++ b/usr.bin/clang/llc/llc.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLC" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLC" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llc \- LLVM static compiler
.
@@ -69,7 +69,7 @@ Print a summary of command line options.
.B \-O=uint
Generate code at different optimization levels. These correspond to the
\fB\-O0\fP, \fB\-O1\fP, \fB\-O2\fP, and \fB\-O3\fP optimization levels used by
-\fBllvm\-gcc\fP and \fBclang\fP\&.
+\fBclang\fP\&.
.UNINDENT
.INDENT 0.0
.TP
@@ -160,12 +160,6 @@ would otherwise not be usable (such as \fBfsin\fP on X86).
.UNINDENT
.INDENT 0.0
.TP
-.B \-\-enable\-correct\-eh\-support
-Instruct the \fBlowerinvoke\fP pass to insert code for correct exception
-handling support. This is expensive and is by default omitted for efficiency.
-.UNINDENT
-.INDENT 0.0
-.TP
.B \-\-stats
Print statistics recorded by code\-generation passes.
.UNINDENT
@@ -260,6 +254,6 @@ lli
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/lldb/Makefile b/usr.bin/clang/lldb/Makefile
index 92e2640..5102835 100644
--- a/usr.bin/clang/lldb/Makefile
+++ b/usr.bin/clang/lldb/Makefile
@@ -16,8 +16,8 @@ SRCS= Driver.cpp \
lldb.1:
ln -fs ${LLDB_SRCS}/docs/lldb.1 ${.TARGET}
-DPADD= ${LIBEDIT} ${LIBNCURSESW} ${LIBEXECINFO} ${LIBPANEL}
-LDADD= -ledit -lncursesw -lexecinfo -lpanel
+DPADD= ${LIBEDIT} ${LIBNCURSESW} ${LIBEXECINFO} ${LIBPANEL} ${LIBZ}
+LDADD= -ledit -lncursesw -lexecinfo -lpanel -lz
LLDB_LIBS=\
lldb \
@@ -30,21 +30,29 @@ LLDB_LIBS=\
lldbExpression \
lldbHostFreeBSD \
lldbHostCommon \
+ lldbHostPOSIX \
lldbInterpreter \
lldbSymbol \
lldbTarget \
lldbUtility \
\
+ lldbPluginABISysV_ppc \
+ lldbPluginABISysV_ppc64 \
lldbPluginABISysV_x86_64 \
lldbPluginCXXItaniumABI \
lldbPluginDisassemblerLLVM \
lldbPluginInstructionARM \
+ lldbPluginInstructionARM64 \
+ lldbPluginInstrumentationRuntimeAddressSanitizer \
+ lldbPluginJITLoaderGDB \
lldbPluginSymbolFileDWARF \
lldbPluginSymbolFileSymtab \
lldbPluginDynamicLoaderStatic \
lldbPluginDynamicLoaderPosixDYLD \
+ lldbPluginMemoryHistoryASan \
lldbPluginObjectContainerBSDArchive \
lldbPluginObjectFileELF \
+ lldbPluginObjectFileJIT \
lldbPluginSymbolVendorELF \
lldbPluginPlatformFreeBSD \
lldbPluginPlatformGDB \
@@ -78,65 +86,72 @@ LIBDEPS=\
clangbasic \
clanglex \
\
+ llvmmcdisassembler \
+ llvmobjcarcopts \
+ llvmprofiledata \
llvmoption \
- llvmarmasmparser \
- llvmarmcodegen \
- llvminstrumentation \
- llvmirreader \
llvmlinker \
- llvmmipsasmparser \
- llvmmipscodegen \
- llvmmipsdisassembler \
- llvmobjcarcopts \
- llvmpowerpccodegen \
- llvmx86asmparser \
- llvmx86codegen \
- llvmx86disassembler \
llvmmcjit \
- llvmmcdisassembler \
- llvmarmdisassembler \
- llvmselectiondag \
+ llvmruntimedyld \
+ llvmexecutionengine \
+ llvmirreader \
llvmipo \
+ llvmvectorize \
+ llvminstrumentation \
llvmbitwriter \
- llvmbitreader \
llvmasmparser \
- llvminterpreter \
- llvmjit \
+ llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
+ llvmarmdisassembler \
+ llvmarmcodegen \
+ llvmarmasmparser \
llvmarmdesc \
- llvmasmprinter \
+ llvmarminfo \
+ llvmarminstprinter \
+ llvmmipsdisassembler \
+ llvmmipscodegen \
+ llvmmipsasmparser \
llvmmipsdesc \
+ llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
+ llvmpowerpccodegen \
+ llvmpowerpcasmparser \
llvmpowerpcdesc \
+ llvmpowerpcinfo \
llvmpowerpcinstprinter \
- llvmpowerpcasmparser \
- llvmruntimedyld \
- llvmvectorize \
- llvmx86desc \
- llvmx86instprinter \
- llvmexecutionengine \
- llvmcodegen \
- llvmscalaropts \
llvmsparcdisassembler \
llvmsparccodegen \
llvmsparcasmparser \
llvmsparcdesc \
llvmsparcinfo \
llvmsparcinstprinter \
- llvmarminfo \
- llvmarminstprinter \
- llvmmcparser \
- llvmmipsinfo \
- llvmpowerpcinfo \
- llvmx86info \
- llvmx86utils \
- llvmobject \
+ llvmx86disassembler \
+ llvmx86asmparser \
+ llvmx86codegen \
+ llvmselectiondag \
+ llvmasmprinter \
+ llvmcodegen \
+ llvmscalaropts \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
llvmtarget \
+ llvmx86desc \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
llvmcore \
+ llvmx86info \
+ llvmx86instprinter \
llvmmc \
+ llvmx86utils \
llvmsupport
.include "../clang.prog.mk"
diff --git a/usr.bin/clang/lli/Makefile b/usr.bin/clang/lli/Makefile
index ecce2c5..b672acf 100644
--- a/usr.bin/clang/lli/Makefile
+++ b/usr.bin/clang/lli/Makefile
@@ -14,32 +14,35 @@ LIBDEPS=llvmx86disassembler \
llvmx86asmparser \
llvmirreader \
llvmasmparser \
- llvmbitreader \
llvmx86codegen \
llvmx86desc \
llvmx86info \
+ llvmmcdisassembler \
llvmx86instprinter \
llvmx86utils \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvminterpreter \
- llvminstrumentation \
- llvmmcjit \
- llvmjit \
llvmcodegen \
- llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
llvminstcombine \
+ llvminstrumentation \
llvmtransformutils \
llvmipa \
llvmanalysis \
+ llvmmcjit \
+ llvmtarget \
llvmruntimedyld \
llvmexecutionengine \
- llvmtarget \
- llvmmc \
llvmobject \
+ llvmmcparser \
+ llvmbitreader \
+ llvmmc \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/lli/lli.1 b/usr.bin/clang/lli/lli.1
index e1ea14c..de9e30c 100644
--- a/usr.bin/clang/lli/lli.1
+++ b/usr.bin/clang/lli/lli.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLI" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLI" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
lli \- directly execute programs from LLVM bitcode
.
@@ -216,13 +216,6 @@ Disable fusing of spill code into instructions.
.UNINDENT
.UNINDENT
.sp
-\fB\-enable\-correct\-eh\-support\fP
-.INDENT 0.0
-.INDENT 3.5
-Make the \-lowerinvoke pass insert expensive, but correct, EH code.
-.UNINDENT
-.UNINDENT
-.sp
\fB\-jit\-enable\-eh\fP
.INDENT 0.0
.INDENT 3.5
@@ -345,6 +338,6 @@ llc|llc
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-ar/Makefile b/usr.bin/clang/llvm-ar/Makefile
index fc41038..44586dc 100644
--- a/usr.bin/clang/llvm-ar/Makefile
+++ b/usr.bin/clang/llvm-ar/Makefile
@@ -7,9 +7,63 @@ PROG_CXX=llvm-ar
SRCDIR= tools/llvm-ar
SRCS= llvm-ar.cpp
-LIBDEPS=llvmobject \
+LIBDEPS=llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
+ llvmarmdisassembler \
+ llvmarmcodegen \
+ llvmarmasmparser \
+ llvmarmdesc \
+ llvmarminfo \
+ llvmarminstprinter \
+ llvmmipsdisassembler \
+ llvmmipscodegen \
+ llvmmipsasmparser \
+ llvmmipsdesc \
+ llvmmipsinfo \
+ llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
+ llvmpowerpccodegen \
+ llvmpowerpcasmparser \
+ llvmpowerpcdesc \
+ llvmpowerpcinfo \
+ llvmpowerpcinstprinter \
+ llvmsparcdisassembler \
+ llvmsparccodegen \
+ llvmsparcasmparser \
+ llvmsparcdesc \
+ llvmsparcinfo \
+ llvmsparcinstprinter \
+ llvmx86disassembler \
+ llvmx86asmparser \
+ llvmx86codegen \
+ llvmselectiondag \
+ llvmasmprinter \
+ llvmcodegen \
+ llvmscalaropts \
+ llvmprofiledata \
+ llvminstcombine \
+ llvmtransformutils \
+ llvmipa \
+ llvmanalysis \
+ llvmtarget \
+ llvmx86desc \
+ llvmobject \
+ llvmmcparser \
llvmbitreader \
+ llvmmcdisassembler \
+ llvmx86info \
+ llvmx86instprinter \
+ llvmmc \
+ llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llvm-ar/llvm-ar.1 b/usr.bin/clang/llvm-ar/llvm-ar.1
index 11fc856..729e2d4 100644
--- a/usr.bin/clang/llvm-ar/llvm-ar.1
+++ b/usr.bin/clang/llvm-ar/llvm-ar.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-AR" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-AR" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-ar \- LLVM archiver
.
@@ -385,6 +385,6 @@ ar(1)
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-as/llvm-as.1 b/usr.bin/clang/llvm-as/llvm-as.1
index bca402b..bda01da 100644
--- a/usr.bin/clang/llvm-as/llvm-as.1
+++ b/usr.bin/clang/llvm-as/llvm-as.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-AS" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-AS" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-as \- LLVM assembler
.
@@ -82,6 +82,6 @@ llvm\-dis|llvm\-dis, gccas|gccas
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-bcanalyzer/llvm-bcanalyzer.1 b/usr.bin/clang/llvm-bcanalyzer/llvm-bcanalyzer.1
index 1745278..fef510d 100644
--- a/usr.bin/clang/llvm-bcanalyzer/llvm-bcanalyzer.1
+++ b/usr.bin/clang/llvm-bcanalyzer/llvm-bcanalyzer.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-BCANALYZER" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-BCANALYZER" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-bcanalyzer \- LLVM bitcode analyzer
.
@@ -471,6 +471,6 @@ Rate encoding scheme. The percentage is relative to # of VBR Expanded Bytes.
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-cov/Makefile b/usr.bin/clang/llvm-cov/Makefile
new file mode 100644
index 0000000..16834cf
--- /dev/null
+++ b/usr.bin/clang/llvm-cov/Makefile
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+PROG_CXX=llvm-cov
+
+SRCDIR= tools/llvm-cov
+SRCS= CodeCoverage.cpp \
+ CoverageFilters.cpp \
+ CoverageReport.cpp \
+ CoverageSummary.cpp \
+ CoverageSummaryInfo.cpp \
+ SourceCoverageView.cpp \
+ TestingSupport.cpp \
+ gcov.cpp \
+ llvm-cov.cpp
+
+LIBDEPS=llvmprofiledata \
+ llvmobject \
+ llvmmcparser \
+ llvmmc \
+ llvmbitreader \
+ llvmcore \
+ llvmsupport
+
+.include "../clang.prog.mk"
diff --git a/usr.bin/clang/llvm-cov/llvm-cov.1 b/usr.bin/clang/llvm-cov/llvm-cov.1
new file mode 100644
index 0000000..c76b7ab
--- /dev/null
+++ b/usr.bin/clang/llvm-cov/llvm-cov.1
@@ -0,0 +1,165 @@
+.\" $FreeBSD$
+.\" Man page generated from reStructuredText.
+.
+.TH "LLVM-COV" "1" "2015-04-01" "3.6" "LLVM"
+.SH NAME
+llvm-cov \- emit coverage information
+.
+.nr rst2man-indent-level 0
+.
+.de1 rstReportMargin
+\\$1 \\n[an-margin]
+level \\n[rst2man-indent-level]
+level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
+-
+\\n[rst2man-indent0]
+\\n[rst2man-indent1]
+\\n[rst2man-indent2]
+..
+.de1 INDENT
+.\" .rstReportMargin pre:
+. RS \\$1
+. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
+. nr rst2man-indent-level +1
+.\" .rstReportMargin post:
+..
+.de UNINDENT
+. RE
+.\" indent \\n[an-margin]
+.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.nr rst2man-indent-level -1
+.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
+..
+.SH SYNOPSIS
+.sp
+\fBllvm\-cov\fP [options] SOURCEFILE
+.SH DESCRIPTION
+.sp
+The \fBllvm\-cov\fP tool reads code coverage data files and displays the
+coverage information for a specified source file. It is compatible with the
+\fBgcov\fP tool from version 4.2 of \fBGCC\fP and may also be compatible with
+some later versions of \fBgcov\fP\&.
+.sp
+To use llvm\-cov, you must first build an instrumented version of your
+application that collects coverage data as it runs. Compile with the
+\fB\-fprofile\-arcs\fP and \fB\-ftest\-coverage\fP options to add the
+instrumentation. (Alternatively, you can use the \fB\-\-coverage\fP option, which
+includes both of those other options.) You should compile with debugging
+information (\fB\-g\fP) and without optimization (\fB\-O0\fP); otherwise, the
+coverage data cannot be accurately mapped back to the source code.
+.sp
+At the time you compile the instrumented code, a \fB\&.gcno\fP data file will be
+generated for each object file. These \fB\&.gcno\fP files contain half of the
+coverage data. The other half of the data comes from \fB\&.gcda\fP files that are
+generated when you run the instrumented program, with a separate \fB\&.gcda\fP
+file for each object file. Each time you run the program, the execution counts
+are summed into any existing \fB\&.gcda\fP files, so be sure to remove any old
+files if you do not want their contents to be included.
+.sp
+By default, the \fB\&.gcda\fP files are written into the same directory as the
+object files, but you can override that by setting the \fBGCOV_PREFIX\fP and
+\fBGCOV_PREFIX_STRIP\fP environment variables. The \fBGCOV_PREFIX_STRIP\fP
+variable specifies a number of directory components to be removed from the
+start of the absolute path to the object file directory. After stripping those
+directories, the prefix from the \fBGCOV_PREFIX\fP variable is added. These
+environment variables allow you to run the instrumented program on a machine
+where the original object file directories are not accessible, but you will
+then need to copy the \fB\&.gcda\fP files back to the object file directories
+where llvm\-cov expects to find them.
+.sp
+Once you have generated the coverage data files, run llvm\-cov for each main
+source file where you want to examine the coverage results. This should be run
+from the same directory where you previously ran the compiler. The results for
+the specified source file are written to a file named by appending a \fB\&.gcov\fP
+suffix. A separate output file is also created for each file included by the
+main source file, also with a \fB\&.gcov\fP suffix added.
+.sp
+The basic content of an llvm\-cov output file is a copy of the source file with
+an execution count and line number prepended to every line. The execution
+count is shown as \fB\-\fP if a line does not contain any executable code. If
+a line contains code but that code was never executed, the count is displayed
+as \fB#####\fP\&.
+.SH OPTIONS
+.INDENT 0.0
+.TP
+.B \-a, \-\-all\-blocks
+Display all basic blocks. If there are multiple blocks for a single line of
+source code, this option causes llvm\-cov to show the count for each block
+instead of just one count for the entire line.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-b, \-\-branch\-probabilities
+Display conditional branch probabilities and a summary of branch information.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-c, \-\-branch\-counts
+Display branch counts instead of probabilities (requires \-b).
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-f, \-\-function\-summaries
+Show a summary of coverage for each function instead of just one summary for
+an entire source file.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-\-help
+Display available options (\-\-help\-hidden for more).
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-l, \-\-long\-file\-names
+For coverage output of files included from the main source file, add the
+main file name followed by \fB##\fP as a prefix to the output file names. This
+can be combined with the \-\-preserve\-paths option to use complete paths for
+both the main file and the included file.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-n, \-\-no\-output
+Do not output any \fB\&.gcov\fP files. Summary information is still
+displayed.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-o=<DIR|FILE>, \-\-object\-directory=<DIR>, \-\-object\-file=<FILE>
+Find objects in DIR or based on FILE\(aqs path. If you specify a particular
+object file, the coverage data files are expected to have the same base name
+with \fB\&.gcno\fP and \fB\&.gcda\fP extensions. If you specify a directory, the
+files are expected in that directory with the same base name as the source
+file.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-p, \-\-preserve\-paths
+Preserve path components when naming the coverage output files. In addition
+to the source file name, include the directories from the path to that
+file. The directories are separate by \fB#\fP characters, with \fB\&.\fP directories
+removed and \fB\&..\fP directories replaced by \fB^\fP characters. When used with
+the \-\-long\-file\-names option, this applies to both the main file name and the
+included file name.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-u, \-\-unconditional\-branches
+Include unconditional branches in the output for the \-\-branch\-probabilities
+option.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-version
+Display the version of llvm\-cov.
+.UNINDENT
+.SH EXIT STATUS
+.sp
+\fBllvm\-cov\fP returns 1 if it cannot read input files. Otherwise, it
+exits with zero.
+.SH AUTHOR
+Maintained by The LLVM Team (http://llvm.org/).
+.SH COPYRIGHT
+2003-2014, LLVM Project
+.\" Generated by docutils manpage writer.
+.
diff --git a/usr.bin/clang/llvm-diff/llvm-diff.1 b/usr.bin/clang/llvm-diff/llvm-diff.1
index 7445bc7..0fa5a01 100644
--- a/usr.bin/clang/llvm-diff/llvm-diff.1
+++ b/usr.bin/clang/llvm-diff/llvm-diff.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-DIFF" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-DIFF" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-diff \- LLVM structural 'diff'
.
@@ -72,6 +72,6 @@ massive detected differences in blocks.
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-dis/Makefile b/usr.bin/clang/llvm-dis/Makefile
index 3fe3f78..18be77a 100644
--- a/usr.bin/clang/llvm-dis/Makefile
+++ b/usr.bin/clang/llvm-dis/Makefile
@@ -11,7 +11,6 @@ TGHDRS= Intrinsics
LIBDEPS=llvmanalysis \
llvmtarget \
llvmmc \
- llvmobject \
llvmbitreader \
llvmcore \
llvmsupport
diff --git a/usr.bin/clang/llvm-dis/llvm-dis.1 b/usr.bin/clang/llvm-dis/llvm-dis.1
index d3096a6..bdf0bdb 100644
--- a/usr.bin/clang/llvm-dis/llvm-dis.1
+++ b/usr.bin/clang/llvm-dis/llvm-dis.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-DIS" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-DIS" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-dis \- LLVM disassembler
.
@@ -83,6 +83,6 @@ llvm\-as|llvm\-as
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-extract/Makefile b/usr.bin/clang/llvm-extract/Makefile
index 007c9c7..8456a0f 100644
--- a/usr.bin/clang/llvm-extract/Makefile
+++ b/usr.bin/clang/llvm-extract/Makefile
@@ -10,18 +10,19 @@ SRCS= llvm-extract.cpp
LIBDEPS=llvmirreader \
llvmasmparser \
llvmbitwriter \
- llvmbitreader \
llvmipo \
- llvmobjcarcopts \
llvmvectorize \
llvmscalaropts \
+ llvmprofiledata \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
llvmtarget \
llvmmc \
- llvmobject \
llvmcore \
llvmsupport
diff --git a/usr.bin/clang/llvm-extract/llvm-extract.1 b/usr.bin/clang/llvm-extract/llvm-extract.1
index 579b0f6..6de6452 100644
--- a/usr.bin/clang/llvm-extract/llvm-extract.1
+++ b/usr.bin/clang/llvm-extract/llvm-extract.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-EXTRACT" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-EXTRACT" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-extract \- extract a function from an LLVM module
.
@@ -124,6 +124,6 @@ bugpoint
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-link/Makefile b/usr.bin/clang/llvm-link/Makefile
index 12591ae..b7e1fed 100644
--- a/usr.bin/clang/llvm-link/Makefile
+++ b/usr.bin/clang/llvm-link/Makefile
@@ -17,7 +17,6 @@ LIBDEPS=llvmirreader \
llvmanalysis \
llvmtarget \
llvmmc \
- llvmobject \
llvmcore \
llvmsupport
diff --git a/usr.bin/clang/llvm-link/llvm-link.1 b/usr.bin/clang/llvm-link/llvm-link.1
index 0ac2d28..136344a 100644
--- a/usr.bin/clang/llvm-link/llvm-link.1
+++ b/usr.bin/clang/llvm-link/llvm-link.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-LINK" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-LINK" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-link \- LLVM bitcode linker
.
@@ -84,6 +84,6 @@ occurs, it will exit with a non\-zero value.
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-mc/Makefile b/usr.bin/clang/llvm-mc/Makefile
index 9159088..6e85993 100644
--- a/usr.bin/clang/llvm-mc/Makefile
+++ b/usr.bin/clang/llvm-mc/Makefile
@@ -9,7 +9,13 @@ SRCDIR= tools/llvm-mc
SRCS= llvm-mc.cpp \
Disassembler.cpp
-LIBDEPS=llvmmcdisassembler \
+LIBDEPS=llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
llvmarmdisassembler \
llvmarmcodegen \
llvmarmasmparser \
@@ -22,6 +28,7 @@ LIBDEPS=llvmmcdisassembler \
llvmmipsdesc \
llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
llvmpowerpccodegen \
llvmpowerpcasmparser \
llvmpowerpcdesc \
@@ -38,22 +45,27 @@ LIBDEPS=llvmmcdisassembler \
llvmx86codegen \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvmcodegen \
- llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
+ llvmtarget \
llvmx86desc \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
+ llvmmcdisassembler \
llvmx86info \
- llvmtarget \
llvmx86instprinter \
llvmmc \
- llvmobject \
llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llvm-nm/Makefile b/usr.bin/clang/llvm-nm/Makefile
index 762cda3..79afa5a 100644
--- a/usr.bin/clang/llvm-nm/Makefile
+++ b/usr.bin/clang/llvm-nm/Makefile
@@ -7,9 +7,63 @@ PROG_CXX=llvm-nm
SRCDIR= tools/llvm-nm
SRCS= llvm-nm.cpp
-LIBDEPS=llvmobject \
+LIBDEPS=llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
+ llvmarmdisassembler \
+ llvmarmcodegen \
+ llvmarmasmparser \
+ llvmarmdesc \
+ llvmarminfo \
+ llvmarminstprinter \
+ llvmmipsdisassembler \
+ llvmmipscodegen \
+ llvmmipsasmparser \
+ llvmmipsdesc \
+ llvmmipsinfo \
+ llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
+ llvmpowerpccodegen \
+ llvmpowerpcasmparser \
+ llvmpowerpcdesc \
+ llvmpowerpcinfo \
+ llvmpowerpcinstprinter \
+ llvmsparcdisassembler \
+ llvmsparccodegen \
+ llvmsparcasmparser \
+ llvmsparcdesc \
+ llvmsparcinfo \
+ llvmsparcinstprinter \
+ llvmx86disassembler \
+ llvmx86asmparser \
+ llvmx86codegen \
+ llvmselectiondag \
+ llvmasmprinter \
+ llvmcodegen \
+ llvmscalaropts \
+ llvmprofiledata \
+ llvminstcombine \
+ llvmtransformutils \
+ llvmipa \
+ llvmanalysis \
+ llvmtarget \
+ llvmx86desc \
+ llvmobject \
+ llvmmcparser \
llvmbitreader \
+ llvmmcdisassembler \
+ llvmx86info \
+ llvmx86instprinter \
+ llvmmc \
+ llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llvm-nm/llvm-nm.1 b/usr.bin/clang/llvm-nm/llvm-nm.1
index 1683289..c20e701 100644
--- a/usr.bin/clang/llvm-nm/llvm-nm.1
+++ b/usr.bin/clang/llvm-nm/llvm-nm.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "LLVM-NM" "1" "2014-01-01" "3.4" "LLVM"
+.TH "LLVM-NM" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
llvm-nm \- list LLVM bitcode and object file's symbol table
.
@@ -208,6 +208,6 @@ llvm\-dis, ar(1), nm(1)
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/llvm-objdump/Makefile b/usr.bin/clang/llvm-objdump/Makefile
index a12cfd1..ccb7ed9 100644
--- a/usr.bin/clang/llvm-objdump/Makefile
+++ b/usr.bin/clang/llvm-objdump/Makefile
@@ -4,8 +4,6 @@ MAN=
.include <bsd.own.mk>
PROG_CXX=llvm-objdump
-DPADD= ${LIBZ}
-LDADD= -lz
SRCDIR= tools/llvm-objdump
SRCS= llvm-objdump.cpp \
@@ -13,8 +11,14 @@ SRCS= llvm-objdump.cpp \
ELFDump.cpp \
MachODump.cpp
-LIBDEPS=llvmmcdisassembler \
- llvmdebuginfo \
+LIBDEPS=llvmdebuginfo \
+ llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
llvmarmdisassembler \
llvmarmcodegen \
llvmarmasmparser \
@@ -27,6 +31,7 @@ LIBDEPS=llvmmcdisassembler \
llvmmipsdesc \
llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
llvmpowerpccodegen \
llvmpowerpcasmparser \
llvmpowerpcdesc \
@@ -43,22 +48,27 @@ LIBDEPS=llvmmcdisassembler \
llvmx86codegen \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvmcodegen \
- llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
+ llvmtarget \
llvmx86desc \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
+ llvmmcdisassembler \
llvmx86info \
- llvmtarget \
llvmx86instprinter \
llvmmc \
- llvmobject \
llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llvm-profdata/Makefile b/usr.bin/clang/llvm-profdata/Makefile
new file mode 100644
index 0000000..5078521
--- /dev/null
+++ b/usr.bin/clang/llvm-profdata/Makefile
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+PROG_CXX=llvm-profdata
+
+SRCDIR= tools/llvm-profdata
+SRCS= llvm-profdata.cpp
+
+LIBDEPS=llvmprofiledata \
+ llvmobject \
+ llvmmcparser \
+ llvmmc \
+ llvmbitreader \
+ llvmcore \
+ llvmsupport
+
+.include "../clang.prog.mk"
diff --git a/usr.bin/clang/llvm-profdata/llvm-profdata.1 b/usr.bin/clang/llvm-profdata/llvm-profdata.1
new file mode 100644
index 0000000..4f66e63
--- /dev/null
+++ b/usr.bin/clang/llvm-profdata/llvm-profdata.1
@@ -0,0 +1,117 @@
+.\" $FreeBSD$
+.\" Man page generated from reStructuredText.
+.
+.TH "LLVM-PROFDATA" "1" "2015-04-01" "3.6" "LLVM"
+.SH NAME
+llvm-profdata \- Profile data tool
+.
+.nr rst2man-indent-level 0
+.
+.de1 rstReportMargin
+\\$1 \\n[an-margin]
+level \\n[rst2man-indent-level]
+level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
+-
+\\n[rst2man-indent0]
+\\n[rst2man-indent1]
+\\n[rst2man-indent2]
+..
+.de1 INDENT
+.\" .rstReportMargin pre:
+. RS \\$1
+. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
+. nr rst2man-indent-level +1
+.\" .rstReportMargin post:
+..
+.de UNINDENT
+. RE
+.\" indent \\n[an-margin]
+.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.nr rst2man-indent-level -1
+.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
+..
+.SH SYNOPSIS
+.sp
+\fBllvm\-profdata\fP \fIcommand\fP [\fIargs...\fP]
+.SH DESCRIPTION
+.sp
+The \fBllvm\-profdata\fP tool is a small utility for working with profile
+data files.
+.SH COMMANDS
+.INDENT 0.0
+.IP \(bu 2
+\fI\%merge\fP
+.IP \(bu 2
+\fI\%show\fP
+.UNINDENT
+.SH MERGE
+.SS SYNOPSIS
+.sp
+\fBllvm\-profdata merge\fP [\fIoptions\fP] [\fIfilenames...\fP]
+.SS DESCRIPTION
+.sp
+\fBllvm\-profdata merge\fP takes several profile data files
+generated by PGO instrumentation and merges them together into a single
+indexed profile data file.
+.SS OPTIONS
+.INDENT 0.0
+.TP
+.B \-help
+Print a summary of command line options.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-output=output, \-o=output
+Specify the output file name. \fIOutput\fP cannot be \fB\-\fP as the resulting
+indexed profile data can\(aqt be written to standard output.
+.UNINDENT
+.SH SHOW
+.SS SYNOPSIS
+.sp
+\fBllvm\-profdata show\fP [\fIoptions\fP] [\fIfilename\fP]
+.SS DESCRIPTION
+.sp
+\fBllvm\-profdata show\fP takes a profile data file and displays the
+information about the profile counters for this file and
+for any of the specified function(s).
+.sp
+If \fIfilename\fP is omitted or is \fB\-\fP, then \fBllvm\-profdata show\fP reads its
+input from standard input.
+.SS OPTIONS
+.INDENT 0.0
+.TP
+.B \-all\-functions
+Print details for every function.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-counts
+Print the counter values for the displayed functions.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-function=string
+Print details for a function if the function\(aqs name contains the given string.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-help
+Print a summary of command line options.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-output=output, \-o=output
+Specify the output file name. If \fIoutput\fP is \fB\-\fP or it isn\(aqt specified,
+then the output is sent to standard output.
+.UNINDENT
+.SH EXIT STATUS
+.sp
+\fBllvm\-profdata\fP returns 1 if the command is omitted or is invalid,
+if it cannot read input files, or if there is a mismatch between their data.
+.SH AUTHOR
+Maintained by The LLVM Team (http://llvm.org/).
+.SH COPYRIGHT
+2003-2014, LLVM Project
+.\" Generated by docutils manpage writer.
+.
diff --git a/usr.bin/clang/llvm-rtdyld/Makefile b/usr.bin/clang/llvm-rtdyld/Makefile
index 0279026..df74a5b 100644
--- a/usr.bin/clang/llvm-rtdyld/Makefile
+++ b/usr.bin/clang/llvm-rtdyld/Makefile
@@ -4,16 +4,21 @@ MAN=
.include <bsd.own.mk>
PROG_CXX=llvm-rtdyld
-DPADD= ${LIBZ}
-LDADD= -lz
SRCDIR= tools/llvm-rtdyld
SRCS= llvm-rtdyld.cpp
LIBDEPS=llvmdebuginfo \
- llvmjit \
+ llvmmcjit \
llvmexecutionengine \
llvmruntimedyld \
+ llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
llvmarmdisassembler \
llvmarmcodegen \
llvmarmasmparser \
@@ -26,6 +31,7 @@ LIBDEPS=llvmdebuginfo \
llvmmipsdesc \
llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
llvmpowerpccodegen \
llvmpowerpcasmparser \
llvmpowerpcdesc \
@@ -42,22 +48,27 @@ LIBDEPS=llvmdebuginfo \
llvmx86codegen \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvmcodegen \
- llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
llvminstcombine \
llvmtransformutils \
llvmipa \
llvmanalysis \
+ llvmtarget \
llvmx86desc \
+ llvmobject \
+ llvmmcparser \
+ llvmbitreader \
+ llvmmcdisassembler \
llvmx86info \
- llvmtarget \
llvmx86instprinter \
llvmmc \
- llvmobject \
llvmx86utils \
llvmcore \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llvm-symbolizer/Makefile b/usr.bin/clang/llvm-symbolizer/Makefile
new file mode 100644
index 0000000..9e3b584
--- /dev/null
+++ b/usr.bin/clang/llvm-symbolizer/Makefile
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+PROG_CXX=llvm-symbolizer
+
+SRCDIR= tools/llvm-symbolizer
+SRCS= llvm-symbolizer.cpp \
+ LLVMSymbolize.cpp
+
+LIBDEPS=llvmdebuginfo \
+ llvmobject \
+ llvmmcparser \
+ llvmmc \
+ llvmbitreader \
+ llvmcore \
+ llvmsupport
+
+.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/llvm-symbolizer/llvm-symbolizer.1 b/usr.bin/clang/llvm-symbolizer/llvm-symbolizer.1
new file mode 100644
index 0000000..6372aed
--- /dev/null
+++ b/usr.bin/clang/llvm-symbolizer/llvm-symbolizer.1
@@ -0,0 +1,144 @@
+.\" $FreeBSD$
+.\" Man page generated from reStructuredText.
+.
+.TH "LLVM-SYMBOLIZER" "1" "2015-03-14" "3.6" "LLVM"
+.SH NAME
+llvm-symbolizer \- convert addresses into source code locations
+.
+.nr rst2man-indent-level 0
+.
+.de1 rstReportMargin
+\\$1 \\n[an-margin]
+level \\n[rst2man-indent-level]
+level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
+-
+\\n[rst2man-indent0]
+\\n[rst2man-indent1]
+\\n[rst2man-indent2]
+..
+.de1 INDENT
+.\" .rstReportMargin pre:
+. RS \\$1
+. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
+. nr rst2man-indent-level +1
+.\" .rstReportMargin post:
+..
+.de UNINDENT
+. RE
+.\" indent \\n[an-margin]
+.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.nr rst2man-indent-level -1
+.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
+..
+.SH SYNOPSIS
+.sp
+\fBllvm\-symbolizer\fP [options]
+.SH DESCRIPTION
+.sp
+\fBllvm\-symbolizer\fP reads object file names and addresses from standard
+input and prints corresponding source code locations to standard output.
+If object file is specified in command line, \fBllvm\-symbolizer\fP reads
+only addresses from standard input. This
+program uses debug info sections and symbol table in the object files.
+.SH EXAMPLE
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+$ cat addr.txt
+a.out 0x4004f4
+/tmp/b.out 0x400528
+/tmp/c.so 0x710
+/tmp/mach_universal_binary:i386 0x1f84
+/tmp/mach_universal_binary:x86_64 0x100000f24
+$ llvm\-symbolizer < addr.txt
+main
+/tmp/a.cc:4
+
+f(int, int)
+/tmp/b.cc:11
+
+h_inlined_into_g
+/tmp/header.h:2
+g_inlined_into_f
+/tmp/header.h:7
+f_inlined_into_main
+/tmp/source.cc:3
+main
+/tmp/source.cc:8
+
+_main
+/tmp/source_i386.cc:8
+
+_main
+/tmp/source_x86_64.cc:8
+$ cat addr2.txt
+0x4004f4
+0x401000
+$ llvm\-symbolizer \-obj=a.out < addr2.txt
+main
+/tmp/a.cc:4
+
+foo(int)
+/tmp/a.cc:12
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.SH OPTIONS
+.INDENT 0.0
+.TP
+.B \-obj
+Path to object file to be symbolized.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-functions=[none|short|linkage]
+Specify the way function names are printed (omit function name,
+print short function name, or print full linkage name, respectively).
+Defaults to \fBlinkage\fP\&.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-use\-symbol\-table
+Prefer function names stored in symbol table to function names
+in debug info sections. Defaults to true.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-demangle
+Print demangled function names. Defaults to true.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-inlining
+If a source code location is in an inlined function, prints all the
+inlnied frames. Defaults to true.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-default\-arch
+If a binary contains object files for multiple architectures (e.g. it is a
+Mach\-O universal binary), symbolize the object file for a given architecture.
+You can also specify architecture by writing \fBbinary_name:arch_name\fP in the
+input (see example above). If architecture is not specified in either way,
+address will not be symbolized. Defaults to empty string.
+.UNINDENT
+.INDENT 0.0
+.TP
+.B \-dsym\-hint=<path/to/file.dSYM>
+(Darwin\-only flag). If the debug info for a binary isn\(aqt present in the default
+location, look for the debug info at the .dSYM path provided via the
+\fB\-dsym\-hint\fP flag. This flag can be used multiple times.
+.UNINDENT
+.SH EXIT STATUS
+.sp
+\fBllvm\-symbolizer\fP returns 0. Other exit codes imply internal program error.
+.SH AUTHOR
+Maintained by The LLVM Team (http://llvm.org/).
+.SH COPYRIGHT
+2003-2014, LLVM Project
+.\" Generated by docutils manpage writer.
+.
diff --git a/usr.bin/clang/macho-dump/Makefile b/usr.bin/clang/macho-dump/Makefile
index 0452583..d74326c 100644
--- a/usr.bin/clang/macho-dump/Makefile
+++ b/usr.bin/clang/macho-dump/Makefile
@@ -9,6 +9,10 @@ SRCDIR= tools/macho-dump
SRCS= macho-dump.cpp
LIBDEPS=llvmobject \
+ llvmmcparser \
+ llvmmc \
+ llvmbitreader \
+ llvmcore \
llvmsupport
.include "../clang.prog.mk"
diff --git a/usr.bin/clang/opt/Makefile b/usr.bin/clang/opt/Makefile
index eee7949..075a7bd 100644
--- a/usr.bin/clang/opt/Makefile
+++ b/usr.bin/clang/opt/Makefile
@@ -6,12 +6,23 @@ PROG_CXX=opt
SRCDIR= tools/opt
SRCS= AnalysisWrappers.cpp \
+ BreakpointPrinter.cpp \
GraphPrinters.cpp \
+ NewPMDriver.cpp \
+ PassPrinters.cpp \
+ Passes.cpp \
PrintSCC.cpp \
opt.cpp
TGHDRS= Intrinsics
-LIBDEPS=llvmarmdisassembler \
+LIBDEPS=llvmaarch64disassembler \
+ llvmaarch64codegen \
+ llvmaarch64asmparser \
+ llvmaarch64desc \
+ llvmaarch64info \
+ llvmaarch64instprinter \
+ llvmaarch64utils \
+ llvmarmdisassembler \
llvmarmcodegen \
llvmarmasmparser \
llvmarmdesc \
@@ -23,6 +34,7 @@ LIBDEPS=llvmarmdisassembler \
llvmmipsdesc \
llvmmipsinfo \
llvmmipsinstprinter \
+ llvmpowerpcdisassembler \
llvmpowerpccodegen \
llvmpowerpcasmparser \
llvmpowerpcdesc \
@@ -39,9 +51,9 @@ LIBDEPS=llvmarmdisassembler \
llvmx86codegen \
llvmselectiondag \
llvmasmprinter \
- llvmmcparser \
llvmcodegen \
llvmx86desc \
+ llvmmcdisassembler \
llvmx86info \
llvmx86instprinter \
llvmx86utils \
@@ -49,6 +61,9 @@ LIBDEPS=llvmarmdisassembler \
llvmvectorize \
llvmobjcarcopts \
llvmscalaropts \
+ llvmprofiledata \
+ llvmobject \
+ llvmmcparser \
llvminstcombine \
llvminstrumentation \
llvmtransformutils \
@@ -56,7 +71,6 @@ LIBDEPS=llvmarmdisassembler \
llvmanalysis \
llvmtarget \
llvmmc \
- llvmobject \
llvmirreader \
llvmasmparser \
llvmbitwriter \
@@ -65,3 +79,6 @@ LIBDEPS=llvmarmdisassembler \
llvmsupport
.include "../clang.prog.mk"
+
+DPADD+= ${LIBZ}
+LDADD+= -lz
diff --git a/usr.bin/clang/opt/opt.1 b/usr.bin/clang/opt/opt.1
index 8e1960a..bf357d9 100644
--- a/usr.bin/clang/opt/opt.1
+++ b/usr.bin/clang/opt/opt.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "OPT" "1" "2014-01-01" "3.4" "LLVM"
+.TH "OPT" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
opt \- LLVM optimizer
.
@@ -93,35 +93,14 @@ order in which they are executed (within pass constraints).
.UNINDENT
.INDENT 0.0
.TP
-.B \-std\-compile\-opts
-This is short hand for a standard list of \fIcompile time optimization\fP passes.
-This is typically used to optimize the output from the llvm\-gcc front end. It
-might be useful for other front end compilers as well. To discover the full
-set of options available, use the following command:
-.INDENT 7.0
-.INDENT 3.5
-.sp
-.nf
-.ft C
-llvm\-as < /dev/null | opt \-std\-compile\-opts \-disable\-output \-debug\-pass=Arguments
-.ft P
-.fi
-.UNINDENT
-.UNINDENT
-.UNINDENT
-.INDENT 0.0
-.TP
.B \-disable\-inlining
-This option is only meaningful when \fI\%\-std\-compile\-opts\fP is given. It
-simply removes the inlining pass from the standard list.
+This option simply removes the inlining pass from the standard list.
.UNINDENT
.INDENT 0.0
.TP
.B \-disable\-opt
-This option is only meaningful when \fI\%\-std\-compile\-opts\fP is given. It
-disables most, but not all, of the \fI\%\-std\-compile\-opts\fP\&. The ones that
-remain are \fI\-verify\fP, \fI\-lower\-setjmp\fP, and
-\fI\-funcresolve\fP\&.
+This option is only meaningful when \fI\-std\-link\-opts\fP is given. It
+disables most passes.
.UNINDENT
.INDENT 0.0
.TP
@@ -136,14 +115,7 @@ but it ensures that stripping of debug information is done first.
This option causes opt to add a verify pass after every pass otherwise
specified on the command line (including \fI\-verify\fP). This is useful
for cases where it is suspected that a pass is creating an invalid module but
-it is not clear which pass is doing it. The combination of
-\fI\%\-std\-compile\-opts\fP and \fI\%\-verify\-each\fP can quickly track down
-this kind of problem.
-.UNINDENT
-.INDENT 0.0
-.TP
-.B \-profile\-info\-file <filename>
-Specify the name of the file loaded by the \fB\-profile\-loader\fP option.
+it is not clear which pass is doing it.
.UNINDENT
.INDENT 0.0
.TP
@@ -193,6 +165,6 @@ occurs, it will exit with a non\-zero value.
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/clang/tblgen/Makefile b/usr.bin/clang/tblgen/Makefile
index f06150e..75a45de 100644
--- a/usr.bin/clang/tblgen/Makefile
+++ b/usr.bin/clang/tblgen/Makefile
@@ -31,9 +31,7 @@ SRCS= AsmMatcherEmitter.cpp \
OptParserEmitter.cpp \
PseudoLoweringEmitter.cpp \
RegisterInfoEmitter.cpp \
- SetTheory.cpp \
SubtargetEmitter.cpp \
- TGValueTypes.cpp \
TableGen.cpp \
X86DisassemblerTables.cpp \
X86ModRMFilters.cpp \
diff --git a/usr.bin/clang/tblgen/tblgen.1 b/usr.bin/clang/tblgen/tblgen.1
index 95036eb..1f8dec0 100644
--- a/usr.bin/clang/tblgen/tblgen.1
+++ b/usr.bin/clang/tblgen/tblgen.1
@@ -1,7 +1,7 @@
.\" $FreeBSD$
.\" Man page generated from reStructuredText.
.
-.TH "TBLGEN" "1" "2014-01-01" "3.4" "LLVM"
+.TH "TBLGEN" "1" "2015-03-14" "3.6" "LLVM"
.SH NAME
tblgen \- Target Description To C++ Code Generator
.
@@ -42,7 +42,7 @@ users of LLVM will not need to use this program. It is only for assisting with
writing an LLVM target backend.
.sp
The input and output of \fBtblgen\fP is beyond the scope of this short
-introduction. Please see \fB\&../TableGenFundamentals\fP\&.
+introduction; please see the \fBintroduction to TableGen\fP\&.
.sp
The \fIfilename\fP argument specifies the name of a Target Description (\fB\&.td\fP)
file to read as input.
@@ -177,6 +177,6 @@ occurs, it will exit with a non\-zero value.
.SH AUTHOR
Maintained by The LLVM Team (http://llvm.org/).
.SH COPYRIGHT
-2003-2013, LLVM Project
+2003-2014, LLVM Project
.\" Generated by docutils manpage writer.
.
diff --git a/usr.bin/col/Makefile b/usr.bin/col/Makefile
index 8e3a959..a162866 100644
--- a/usr.bin/col/Makefile
+++ b/usr.bin/col/Makefile
@@ -1,6 +1,12 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $FreeBSD$
+.include <src.opts.mk>
+
PROG= col
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
diff --git a/usr.bin/col/col.1 b/usr.bin/col/col.1
index 9419fe3..fc02ca4 100644
--- a/usr.bin/col/col.1
+++ b/usr.bin/col/col.1
@@ -31,7 +31,7 @@
.\" @(#)col.1 8.1 (Berkeley) 6/29/93
.\" $FreeBSD$
.\"
-.Dd August 4, 2004
+.Dd May 10, 2015
.Dt COL 1
.Os
.Sh NAME
@@ -82,18 +82,33 @@ recognized and interpreted by itself, which are listed below.
Output multiple spaces instead of tabs.
.El
.Pp
-The control sequences for carriage motion that
+In the input stream,
.Nm
-understands and their decimal values are listed in the following
-table:
+understands both the escape sequences of the form escape-digit
+mandated by
+.St -susv2
+and the traditional
+.Bx
+format escape-control-character.
+The control sequences for carriage motion and their ASCII values
+are as follows:
.Pp
.Bl -tag -width "carriage return" -compact
+.It ESC\-BELL
+reverse line feed (escape then bell).
.It ESC\-7
-reverse line feed (escape then 7)
+reverse line feed (escape then 7).
+.It ESC\-BACKSPACE
+half reverse line feed (escape then backspace).
.It ESC\-8
-half reverse line feed (escape then 8)
+half reverse line feed (escape then 8).
+.It ESC\-TAB
+half forward line feed (escape than tab).
.It ESC\-9
-half forward line feed (escape then 9)
+half forward line feed (escape then 9).
+In
+.Fl f
+mode, this sequence may also occur in the output stream.
.It backspace
moves back one column (8); ignored in the first column
.It carriage return
diff --git a/usr.bin/col/col.c b/usr.bin/col/col.c
index 52214857..13df126 100644
--- a/usr.bin/col/col.c
+++ b/usr.bin/col/col.c
@@ -45,11 +45,15 @@ static char sccsid[] = "@(#)col.c 8.5 (Berkeley) 5/4/95";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/capsicum.h>
+
#include <err.h>
+#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>
@@ -63,9 +67,9 @@ __FBSDID("$FreeBSD$");
#define SI '\017' /* shift in to normal character set */
#define SO '\016' /* shift out to alternate character set */
#define VT '\013' /* vertical tab (aka reverse line feed) */
-#define RLF '\007' /* ESC-07 reverse line feed */
-#define RHLF '\010' /* ESC-010 reverse half-line feed */
-#define FHLF '\011' /* ESC-011 forward half-line feed */
+#define RLF '7' /* ESC-7 reverse line feed */
+#define RHLF '8' /* ESC-8 reverse half-line feed */
+#define FHLF '9' /* ESC-9 forward half-line feed */
/* build up at least this many lines before flushing them out */
#define BUFFER_MARGIN 32
@@ -92,6 +96,7 @@ struct line_str {
int l_max_col; /* max column in the line */
};
+static void addto_lineno(int *, int);
static LINE *alloc_line(void);
static void dowarn(int);
static void flush_line(LINE *);
@@ -104,7 +109,7 @@ static CSET last_set; /* char_set of last char printed */
static LINE *lines;
static int compress_spaces; /* if doing space -> tab conversion */
static int fine; /* if `fine' resolution (half lines) */
-static int max_bufd_lines; /* max # lines to keep in memory */
+static int max_bufd_lines; /* max # of half lines to keep in memory */
static int nblank_lines; /* # blanks after last flushed line */
static int no_backspaces; /* if not to output any backspaces */
static int pass_unknown_seqs; /* pass unknown control sequences */
@@ -129,10 +134,26 @@ main(int argc, char **argv)
int this_line; /* line l points to */
int nflushd_lines; /* number of lines that were flushed */
int adjust, opt, warned, width;
+ const char *errstr;
+ cap_rights_t rights;
+ unsigned long cmd;
(void)setlocale(LC_CTYPE, "");
- max_bufd_lines = 128;
+ cap_rights_init(&rights, CAP_FSTAT, CAP_READ);
+ if (cap_rights_limit(STDIN_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stdin");
+ cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE, CAP_IOCTL);
+ if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stdout");
+ cmd = TIOCGETA; /* required by isatty(3) in printf(3) */
+ if (cap_ioctls_limit(STDOUT_FILENO, &cmd, 1) < 0 && errno != ENOSYS)
+ err(1, "unable to limit ioctls for stdout");
+
+ if (cap_enter() < 0 && errno != ENOSYS)
+ err(1, "unable to enter capability mode");
+
+ max_bufd_lines = 256;
compress_spaces = 1; /* compress spaces into tabs */
while ((opt = getopt(argc, argv, "bfhl:px")) != -1)
switch (opt) {
@@ -146,8 +167,11 @@ main(int argc, char **argv)
compress_spaces = 1;
break;
case 'l': /* buffered line count */
- if ((max_bufd_lines = atoi(optarg)) <= 0)
- errx(1, "bad -l argument %s", optarg);
+ max_bufd_lines = strtonum(optarg, 1,
+ (INT_MAX - BUFFER_MARGIN) / 2, &errstr) * 2;
+ if (errstr != NULL)
+ errx(1, "bad -l argument, %s: %s", errstr,
+ optarg);
break;
case 'p': /* pass unknown control sequences */
pass_unknown_seqs = 1;
@@ -163,9 +187,6 @@ main(int argc, char **argv)
if (optind != argc)
usage();
- /* this value is in half lines */
- max_bufd_lines *= 2;
-
adjust = cur_col = extra_lines = warned = 0;
cur_line = max_line = nflushd_lines = this_line = 0;
cur_set = last_set = CS_NORMAL;
@@ -184,20 +205,31 @@ main(int argc, char **argv)
continue;
case ESC: /* just ignore EOF */
switch(getwchar()) {
+ /*
+ * In the input stream, accept both the
+ * XPG5 sequences ESC-digit and the
+ * traditional BSD sequences ESC-ctrl.
+ */
+ case '\007':
+ /* FALLTHROUGH */
case RLF:
- cur_line -= 2;
+ addto_lineno(&cur_line, -2);
break;
+ case '\010':
+ /* FALLTHROUGH */
case RHLF:
- cur_line--;
+ addto_lineno(&cur_line, -1);
break;
+ case '\011':
+ /* FALLTHROUGH */
case FHLF:
- cur_line++;
+ addto_lineno(&cur_line, 1);
if (cur_line > max_line)
max_line = cur_line;
}
continue;
case NL:
- cur_line += 2;
+ addto_lineno(&cur_line, 2);
if (cur_line > max_line)
max_line = cur_line;
cur_col = 0;
@@ -216,7 +248,7 @@ main(int argc, char **argv)
++cur_col;
continue;
case VT:
- cur_line -= 2;
+ addto_lineno(&cur_line, -2);
continue;
}
if (iswspace(ch)) {
@@ -229,58 +261,61 @@ main(int argc, char **argv)
}
/* Must stuff ch in a line - are we at the right one? */
- if (cur_line != this_line - adjust) {
+ if (cur_line + adjust != this_line) {
LINE *lnew;
- int nmove;
-
- adjust = 0;
- nmove = cur_line - this_line;
- if (!fine) {
- /* round up to next line */
- if (cur_line & 1) {
- adjust = 1;
- nmove++;
- }
- }
- if (nmove < 0) {
- for (; nmove < 0 && l->l_prev; nmove++)
+
+ /* round up to next line */
+ adjust = !fine && (cur_line & 1);
+
+ if (cur_line + adjust < this_line) {
+ while (cur_line + adjust < this_line &&
+ l->l_prev != NULL) {
l = l->l_prev;
- if (nmove) {
+ this_line--;
+ }
+ if (cur_line + adjust < this_line) {
if (nflushd_lines == 0) {
/*
* Allow backup past first
* line if nothing has been
* flushed yet.
*/
- for (; nmove < 0; nmove++) {
+ while (cur_line + adjust
+ < this_line) {
lnew = alloc_line();
l->l_prev = lnew;
lnew->l_next = l;
l = lines = lnew;
extra_lines++;
+ this_line--;
}
} else {
if (!warned++)
dowarn(cur_line);
- cur_line -= nmove;
+ cur_line = this_line - adjust;
}
}
} else {
/* may need to allocate here */
- for (; nmove > 0 && l->l_next; nmove--)
+ while (cur_line + adjust > this_line) {
+ if (l->l_next == NULL) {
+ l->l_next = alloc_line();
+ l->l_next->l_prev = l;
+ }
l = l->l_next;
- for (; nmove > 0; nmove--) {
- lnew = alloc_line();
- lnew->l_prev = l;
- l->l_next = lnew;
- l = lnew;
+ this_line++;
}
}
- this_line = cur_line + adjust;
- nmove = this_line - nflushd_lines;
- if (nmove >= max_bufd_lines + BUFFER_MARGIN) {
- nflushd_lines += nmove - max_bufd_lines;
- flush_lines(nmove - max_bufd_lines);
+ if (this_line > nflushd_lines &&
+ this_line - nflushd_lines >=
+ max_bufd_lines + BUFFER_MARGIN) {
+ if (extra_lines) {
+ flush_lines(extra_lines);
+ extra_lines = 0;
+ }
+ flush_lines(this_line - nflushd_lines -
+ max_bufd_lines);
+ nflushd_lines = this_line - max_bufd_lines;
}
}
/* grow line's buffer? */
@@ -290,7 +325,7 @@ main(int argc, char **argv)
need = l->l_lsize ? l->l_lsize * 2 : 90;
if ((l->l_line = realloc(l->l_line,
(unsigned)need * sizeof(CHAR))) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
l->l_lsize = need;
}
c = &l->l_line[l->l_line_len++];
@@ -311,25 +346,23 @@ main(int argc, char **argv)
}
if (ferror(stdin))
err(1, NULL);
- if (max_line == 0)
- exit(0); /* no lines, so just exit */
+ if (extra_lines)
+ flush_lines(extra_lines);
/* goto the last line that had a character on it */
for (; l->l_next; l = l->l_next)
this_line++;
- flush_lines(this_line - nflushd_lines + extra_lines + 1);
+ flush_lines(this_line - nflushd_lines + 1);
/* make sure we leave things in a sane state */
if (last_set != CS_NORMAL)
- PUTC('\017');
+ PUTC(SI);
/* flush out the last few blank lines */
- nblank_lines = max_line - this_line;
+ if (max_line > this_line)
+ nblank_lines = max_line - this_line;
if (max_line & 1)
nblank_lines++;
- else if (!nblank_lines)
- /* missing a \n on the last line? */
- nblank_lines = 2;
flush_blanks();
exit(0);
}
@@ -346,7 +379,8 @@ flush_lines(int nflush)
flush_blanks();
flush_line(l);
}
- nblank_lines++;
+ if (l->l_line || l->l_next)
+ nblank_lines++;
if (l->l_line)
(void)free(l->l_line);
free_line(l);
@@ -377,8 +411,8 @@ flush_blanks(void)
for (i = nb; --i >= 0;)
PUTC('\n');
if (half) {
- PUTC('\033');
- PUTC('\011');
+ PUTC(ESC);
+ PUTC(FHLF);
if (!nb)
PUTC('\r');
}
@@ -410,13 +444,13 @@ flush_line(LINE *l)
sorted_size = l->l_lsize;
if ((sorted = realloc(sorted,
(unsigned)sizeof(CHAR) * sorted_size)) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
}
if (l->l_max_col >= count_size) {
count_size = l->l_max_col + 1;
if ((count = realloc(count,
(unsigned)sizeof(int) * count_size)) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
}
memset(count, 0, sizeof(int) * l->l_max_col + 1);
for (i = nchars, c = l->l_line; --i >= 0; c++)
@@ -480,10 +514,10 @@ flush_line(LINE *l)
if (c->c_set != last_set) {
switch (c->c_set) {
case CS_NORMAL:
- PUTC('\017');
+ PUTC(SI);
break;
case CS_ALTERNATE:
- PUTC('\016');
+ PUTC(SO);
}
last_set = c->c_set;
}
@@ -498,6 +532,23 @@ flush_line(LINE *l)
}
}
+/*
+ * Increment or decrement a line number, checking for overflow.
+ * Stop one below INT_MAX such that the adjust variable is safe.
+ */
+void
+addto_lineno(int *lno, int offset)
+{
+ if (offset > 0) {
+ if (*lno >= INT_MAX - offset)
+ errx(1, "too many lines");
+ } else {
+ if (*lno < INT_MIN - offset)
+ errx(1, "too many reverse line feeds");
+ }
+ *lno += offset;
+}
+
#define NALLOC 64
static LINE *line_freelist;
@@ -510,7 +561,7 @@ alloc_line(void)
if (!line_freelist) {
if ((l = realloc(NULL, sizeof(LINE) * NALLOC)) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
line_freelist = l;
for (i = 1; i < NALLOC; i++, l++)
l->l_next = l + 1;
diff --git a/usr.bin/col/tests/Makefile b/usr.bin/col/tests/Makefile
new file mode 100644
index 0000000..43838e9
--- /dev/null
+++ b/usr.bin/col/tests/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/usr.bin/col
+
+ATF_TESTS_SH= col
+
+FILES= rlf.in \
+ rlf2.in
+FILESDIR= ${TESTSDIR}
+
+.include <bsd.test.mk>
diff --git a/usr.bin/col/tests/col.sh b/usr.bin/col/tests/col.sh
new file mode 100755
index 0000000..c072aab
--- /dev/null
+++ b/usr.bin/col/tests/col.sh
@@ -0,0 +1,33 @@
+# $FreeBSD$
+
+atf_test_case rlf
+
+rlf_head()
+{
+ atf_set "descr" "testing reverse line feed"
+}
+rlf_body()
+{
+ atf_check \
+ -o inline:"a b\n" \
+ -e empty \
+ -s exit:0 \
+ col < $(atf_get_srcdir)/rlf.in
+
+ atf_check \
+ -o inline:"a b\n" \
+ -e empty \
+ -s exit:0 \
+ col < $(atf_get_srcdir)/rlf2.in
+
+ atf_check \
+ -o inline:"a b\n" \
+ -e empty \
+ -s exit:0 \
+ col -x < $(atf_get_srcdir)/rlf2.in
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case rlf
+}
diff --git a/usr.bin/col/tests/rlf.in b/usr.bin/col/tests/rlf.in
new file mode 100644
index 0000000..57a14e5
--- /dev/null
+++ b/usr.bin/col/tests/rlf.in
@@ -0,0 +1,2 @@
+a
+ 7b
diff --git a/usr.bin/col/tests/rlf2.in b/usr.bin/col/tests/rlf2.in
new file mode 100644
index 0000000..dd46851
--- /dev/null
+++ b/usr.bin/col/tests/rlf2.in
@@ -0,0 +1,2 @@
+a
+ 7b
diff --git a/usr.bin/colldef/Makefile b/usr.bin/colldef/Makefile
index c028e4a..fd59a6c 100644
--- a/usr.bin/colldef/Makefile
+++ b/usr.bin/colldef/Makefile
@@ -5,8 +5,7 @@ SRCS= parse.y scan.l y.tab.h
LFLAGS= -8 -i
CFLAGS+=-I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc/locale
CFLAGS+=-DCOLLATE_DEBUG -DYY_NO_UNPUT -DYY_NO_INPUT
-LDADD= -ll
-DPADD= ${LIBL}
+LIBADD= l
WARNS?= 2
diff --git a/usr.bin/column/column.c b/usr.bin/column/column.c
index bc7aa32..b092deb 100644
--- a/usr.bin/column/column.c
+++ b/usr.bin/column/column.c
@@ -233,11 +233,11 @@ maketbl(void)
wchar_t *last;
if ((t = tbl = calloc(entries, sizeof(TBL))) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
if ((cols = calloc((maxcols = DEFCOLS), sizeof(*cols))) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
if ((lens = calloc(maxcols, sizeof(int))) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
for (coloff = 0, p = *lp;
(cols[coloff] = wcstok(p, separator, &last));
@@ -253,9 +253,9 @@ maketbl(void)
maxcols += DEFCOLS;
}
if ((t->list = calloc(coloff, sizeof(*t->list))) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
if ((t->len = calloc(coloff, sizeof(int))) == NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
for (t->cols = coloff; --coloff >= 0;) {
t->list[coloff] = cols[coloff];
t->len[coloff] = width(cols[coloff]);
@@ -284,7 +284,7 @@ input(FILE *fp)
if (!list)
if ((list = calloc((maxentry = DEFNUM), sizeof(*list))) ==
NULL)
- err(1, (char *)NULL);
+ err(1, NULL);
while (fgetws(buf, MAXLINELEN, fp)) {
for (p = buf; *p && iswspace(*p); ++p);
if (!*p)
diff --git a/usr.bin/compile_et/Makefile b/usr.bin/compile_et/Makefile
index d7177b2..8af87ae 100644
--- a/usr.bin/compile_et/Makefile
+++ b/usr.bin/compile_et/Makefile
@@ -2,12 +2,9 @@
.PATH: ${.CURDIR}/../../contrib/com_err
-LIBVERS= ${.OBJDIR}/../../kerberos5/lib/libvers/libvers.a
-
PROG= compile_et
SRCS= compile_et.c parse.y lex.l
-LDADD= -lroken ${LIBVERS}
-DPADD= ${LIBROKEN} ${LIBVERS}
+LIBADD= roken vers
CFLAGS+=-I. -I${.CURDIR}/../../contrib/com_err
WARNS?= 0
diff --git a/usr.bin/compile_et/Makefile.depend b/usr.bin/compile_et/Makefile.depend
index f90d17c..debff2e 100644
--- a/usr.bin/compile_et/Makefile.depend
+++ b/usr.bin/compile_et/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libcrypt \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/compress/compress.c b/usr.bin/compress/compress.c
index 1f458e5..2d2efb3 100644
--- a/usr.bin/compress/compress.c
+++ b/usr.bin/compress/compress.c
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -360,14 +361,14 @@ err: if (ofp) {
static void
setfile(const char *name, struct stat *fs)
{
- static struct timeval tv[2];
+ static struct timespec tspec[2];
fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
- TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
- TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
- if (utimes(name, tv))
- cwarn("utimes: %s", name);
+ tspec[0] = fs->st_atim;
+ tspec[1] = fs->st_mtim;
+ if (utimensat(AT_FDCWD, name, tspec, 0))
+ cwarn("utimensat: %s", name);
/*
* Changing the ownership probably won't succeed, unless we're root
diff --git a/usr.bin/cpio/Makefile b/usr.bin/cpio/Makefile
index 16446c4..72a0e2b 100644
--- a/usr.bin/cpio/Makefile
+++ b/usr.bin/cpio/Makefile
@@ -23,15 +23,7 @@ CFLAGS+= -I${LIBARCHIVEDIR}/cpio -I${LIBARCHIVEDIR}/libarchive_fe
# statically linked, cannot use -lcrypto, and are size sensitive.
CFLAGS+= -DSMALLER
.endif
-DPADD= ${LIBARCHIVE} ${LIBZ} ${LIBBZ2} ${LIBLZMA} ${LIBBSDXML}
-LDADD= -larchive -lz -lbz2 -llzma -lbsdxml
-.if ${MK_OPENSSL} != "no"
-DPADD+= ${LIBCRYPTO}
-LDADD+= -lcrypto
-.else
-DPADD+= ${LIBMD}
-LDADD+= -lmd
-.endif
+LIBADD= archive
.if ${MK_ICONV} != "no"
CFLAGS+= -DHAVE_ICONV=1 -DHAVE_ICONV_H=1 -DICONV_CONST=const
diff --git a/usr.bin/cpio/Makefile.depend b/usr.bin/cpio/Makefile.depend
index 7f1d531..52fc11f 100644
--- a/usr.bin/cpio/Makefile.depend
+++ b/usr.bin/cpio/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/libcompiler_rt \
lib/libexpat \
lib/liblzma \
+ lib/libthr \
lib/libz \
secure/lib/libcrypto \
diff --git a/usr.bin/cpio/test/Makefile b/usr.bin/cpio/test/Makefile
index 13293b0..77c73d7 100644
--- a/usr.bin/cpio/test/Makefile
+++ b/usr.bin/cpio/test/Makefile
@@ -67,10 +67,9 @@ CLEANFILES+= list.h bsdcpio_test
MAN=
PROG=bsdcpio_test
-DPADD=${LIBARCHIVE} ${LIBBZ2} ${LIBZ} ${LIBLZMA}
CFLAGS+= -DPLATFORM_CONFIG_H=\"${.CURDIR}/../../../lib/libarchive/config_freebsd.h\"
CFLAGS+= -I${.CURDIR}/../../../lib/libarchive -I${.OBJDIR}
-LDADD= -larchive -lz -lbz2 -llzma
+LIBADD= archive
#CFLAGS+= -static -g -O2 -Wall
CFLAGS+= -g -O2 -Wall
CFLAGS+= -I${.OBJDIR}
diff --git a/usr.bin/cpuset/cpuset.1 b/usr.bin/cpuset/cpuset.1
index 8ea2702..174eeb6 100644
--- a/usr.bin/cpuset/cpuset.1
+++ b/usr.bin/cpuset/cpuset.1
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 14, 2011
+.Dd January 8, 2015
.Dt CPUSET 1
.Os
.Sh NAME
@@ -46,12 +46,13 @@
.Fl C
.Fl p Ar pid
.Nm
-.Op Fl cr
+.Op Fl c
.Op Fl l Ar cpu-list
.Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq
.Nm
-.Op Fl cgir
-.Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq
+.Fl g
+.Op Fl cir
+.Op Fl d Ar domain | j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq
.Sh DESCRIPTION
The
.Nm
@@ -62,7 +63,7 @@ about processor binding, sets, and available processors in the system.
.Nm
requires a target to modify or query.
The target may be specified as a command, process id, thread id, a
-cpuset id, an irq or a jail id.
+cpuset id, an irq, a jail id, or a NUMA domain.
Using
.Fl g
the target's set id or mask may be queried.
@@ -108,6 +109,8 @@ Create a new cpuset and assign the target process to that set.
.It Fl c
The requested operation should reference the cpuset available via the
target specifier.
+.It Fl d Ar domain
+Specifies a NUMA domain id as the target of the operation.
.It Fl g
Causes
.Nm
diff --git a/usr.bin/cpuset/cpuset.c b/usr.bin/cpuset/cpuset.c
index 898c3e5..c619259 100644
--- a/usr.bin/cpuset/cpuset.c
+++ b/usr.bin/cpuset/cpuset.c
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
static int Cflag;
static int cflag;
+static int dflag;
static int gflag;
static int iflag;
static int jflag;
@@ -161,7 +162,8 @@ printset(cpuset_t *mask)
printf("\n");
}
-static const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq", "jail" };
+static const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq", "jail",
+ "domain" };
static const char *levelnames[] = { NULL, " root", " cpuset", "" };
static void
@@ -206,17 +208,20 @@ main(int argc, char *argv[])
level = CPU_LEVEL_WHICH;
which = CPU_WHICH_PID;
id = pid = tid = setid = -1;
- while ((ch = getopt(argc, argv, "Ccgij:l:p:rs:t:x:")) != -1) {
+ while ((ch = getopt(argc, argv, "Ccd:gij:l:p:rs:t:x:")) != -1) {
switch (ch) {
case 'C':
Cflag = 1;
break;
case 'c':
- if (rflag)
- usage();
cflag = 1;
level = CPU_LEVEL_CPUSET;
break;
+ case 'd':
+ dflag = 1;
+ which = CPU_WHICH_DOMAIN;
+ id = atoi(optarg);
+ break;
case 'g':
gflag = 1;
break;
@@ -238,8 +243,6 @@ main(int argc, char *argv[])
id = pid = atoi(optarg);
break;
case 'r':
- if (cflag)
- usage();
level = CPU_LEVEL_ROOT;
rflag = 1;
break;
@@ -268,7 +271,7 @@ main(int argc, char *argv[])
if (argc || Cflag || lflag)
usage();
/* Only one identity specifier. */
- if (jflag + xflag + sflag + pflag + tflag > 1)
+ if (dflag + jflag + xflag + sflag + pflag + tflag > 1)
usage();
if (iflag)
printsetid();
@@ -276,13 +279,13 @@ main(int argc, char *argv[])
printaffinity();
exit(EXIT_SUCCESS);
}
- if (iflag)
+ if (dflag || iflag || rflag)
usage();
/*
* The user wants to run a command with a set and possibly cpumask.
*/
if (argc) {
- if (Cflag | pflag | rflag | tflag | xflag | jflag)
+ if (Cflag || pflag || tflag || xflag || jflag)
usage();
if (sflag) {
if (cpuset_setid(CPU_WHICH_PID, -1, setid))
@@ -303,9 +306,9 @@ main(int argc, char *argv[])
/*
* We're modifying something that presently exists.
*/
- if (Cflag && (sflag || rflag || !pflag || tflag || xflag || jflag))
+ if (Cflag && (jflag || !pflag || sflag || tflag || xflag))
usage();
- if (!lflag && (cflag || rflag))
+ if (!lflag && cflag)
usage();
if (!lflag && !(Cflag || sflag))
usage();
@@ -354,8 +357,9 @@ usage(void)
fprintf(stderr,
" cpuset [-c] [-l cpu-list] -C -p pid\n");
fprintf(stderr,
- " cpuset [-cr] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
+ " cpuset [-c] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
fprintf(stderr,
- " cpuset [-cgir] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
+ " cpuset -g [-cir] [-d domain | -j jailid | -p pid | -t tid | -s setid |\n"
+ " -x irq]\n");
exit(1);
}
diff --git a/usr.bin/csup/Makefile.depend b/usr.bin/csup/Makefile.depend
index 061f7d0..33da45f 100644
--- a/usr.bin/csup/Makefile.depend
+++ b/usr.bin/csup/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/libmd \
lib/libthr \
lib/libz \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/ctlstat/ctlstat.8 b/usr.bin/ctlstat/ctlstat.8
index 22da2bf..500ffb0 100644
--- a/usr.bin/ctlstat/ctlstat.8
+++ b/usr.bin/ctlstat/ctlstat.8
@@ -34,7 +34,7 @@
.\" $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.8#2 $
.\" $FreeBSD$
.\"
-.Dd March 6, 2013
+.Dd May 22, 2015
.Dt CTLSTAT 8
.Os
.Sh NAME
@@ -69,7 +69,7 @@ and a combined total column that also includes non I/O operations.
.It Fl c Ar count
Display statistics this many times.
.It Fl C
-Disable display of CPU statistics.
+Disable CPU statistics display.
.It Fl d
Display DMA operation time (latency) instead of overall I/O time (latency).
.It Fl D
@@ -117,6 +117,7 @@ every 10 seconds.
.Xr xpt 4 ,
.Xr camcontrol 8 ,
.Xr ctladm 8 ,
+.Xr ctld 8 ,
.Xr iostat 8
.Sh AUTHORS
.An Ken Merry Aq Mt ken@FreeBSD.org
diff --git a/usr.bin/ctlstat/ctlstat.c b/usr.bin/ctlstat/ctlstat.c
index e04aa54..3bfb248 100644
--- a/usr.bin/ctlstat/ctlstat.c
+++ b/usr.bin/ctlstat/ctlstat.c
@@ -449,7 +449,7 @@ ctlstat_standard(struct ctlstat_context *ctx) {
(F_LUNVAL(ctx) != 0) ? " " : "",
(F_LUNVAL(ctx) != 0) ? " " : "",
(F_LUNVAL(ctx) != 0) ? " " : "",
- (F_CPU(ctx) == 0) ? " CPU" : "");
+ (F_CPU(ctx)) ? " CPU" : "");
hdr_devs = 3;
} else {
if (F_CPU(ctx))
@@ -468,8 +468,9 @@ ctlstat_standard(struct ctlstat_context *ctx) {
if (bit_test(ctx->lun_mask, lun) == 0)
continue;
- fprintf(stdout, "%15.6s%d ",
- "lun", lun);
+ fprintf(stdout, "%15.6s%d %s",
+ "lun", lun,
+ (F_LUNVAL(ctx) != 0) ? " " : "");
hdr_devs++;
}
fprintf(stdout, "\n");
diff --git a/usr.bin/cxxfilt/Makefile b/usr.bin/cxxfilt/Makefile
new file mode 100644
index 0000000..496b240
--- /dev/null
+++ b/usr.bin/cxxfilt/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+SRCDIR= ${ELFTCDIR}/cxxfilt
+
+.PATH: ${SRCDIR}
+
+PROG= c++filt
+SRCS= cxxfilt.c
+
+LIBADD= elftc
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/dc/Makefile b/usr.bin/dc/Makefile
index 67af146..832b197 100644
--- a/usr.bin/dc/Makefile
+++ b/usr.bin/dc/Makefile
@@ -3,7 +3,6 @@
PROG= dc
SRCS= dc.c bcode.c inout.c mem.c stack.c
-DPADD= ${LIBCRYPTO}
-LDADD= -lcrypto
+LIBADD= crypto
.include <bsd.prog.mk>
diff --git a/usr.bin/dc/stack.c b/usr.bin/dc/stack.c
index 950b4e5..3364ae2 100644
--- a/usr.bin/dc/stack.c
+++ b/usr.bin/dc/stack.c
@@ -137,14 +137,12 @@ stack_swap(struct stack *stack)
static void
stack_grow(struct stack *stack)
{
- size_t i, new_size;
+ size_t new_size;
if (++stack->sp == stack->size) {
new_size = stack->size * 2 + 1;
stack->stack = brealloc(stack->stack,
new_size * sizeof(*stack->stack));
- for (i = stack->size; i < new_size; i++)
- stack->stack[i].array = NULL;
stack->size = new_size;
}
}
@@ -156,6 +154,7 @@ stack_pushnumber(struct stack *stack, struct number *b)
stack_grow(stack);
stack->stack[stack->sp].type = BCODE_NUMBER;
stack->stack[stack->sp].u.num = b;
+ stack->stack[stack->sp].array = NULL;
}
void
@@ -165,6 +164,7 @@ stack_pushstring(struct stack *stack, char *string)
stack_grow(stack);
stack->stack[stack->sp].type = BCODE_STRING;
stack->stack[stack->sp].u.string = string;
+ stack->stack[stack->sp].array = NULL;
}
void
diff --git a/usr.bin/dpv/Makefile b/usr.bin/dpv/Makefile
index 3cc18ca..93a6cd1 100644
--- a/usr.bin/dpv/Makefile
+++ b/usr.bin/dpv/Makefile
@@ -4,8 +4,7 @@ PROG= dpv
CFLAGS+= -I${.CURDIR}
-DPADD= ${LIBDPV} ${LIBDIALOG} ${LIBFIGPAR} ${LIBNCURSESW} ${LIBUTIL}
-LDADD= -ldpv -ldialog -lfigpar -lncursesw -lutil
+LIBADD= dpv dialog
WARNS?= 6
diff --git a/usr.bin/dpv/dpv.1 b/usr.bin/dpv/dpv.1
index c8d321b..d277446 100644
--- a/usr.bin/dpv/dpv.1
+++ b/usr.bin/dpv/dpv.1
@@ -104,7 +104,7 @@ Do not use the default interface of
.Xr dialog 3 ,
but instead spawn an instance of
.Xr dialog 1 .
-The path to
+The path to
.Xr dialog 1
is taken from the
.Ev DIALOG
@@ -308,7 +308,6 @@ is required.
.It Pa $HOME/.dialogrc
.El
.Sh EXAMPLES
-.Pp
Simple example to show how fast
.Xr yes 1
produces lines
@@ -358,7 +357,18 @@ Zeroing a disk:
.Bd -literal -offset indent
dpv -o /dev/md42 < /dev/zero
.Ed
-.Pp
+.Sh SEE ALSO
+.Xr dialog 1 ,
+.Xr sh 1 ,
+.Xr Xdialog 1 ,
+.Xr dialog 3
+.Sh HISTORY
+A
+.Nm
+utility first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+.An Devin Teske Aq dteske@FreeBSD.org
.Sh BUGS
.Xr Xdialog 1 ,
when given both
@@ -410,21 +420,9 @@ This does not effect
.Xr Xdialog 1 ,
which renders the color escape sequences as plain text.
See
-.Do Li
+.Do
embedded "\\Z" sequences
.Dc
in
.Xr dialog 1
for additional information.
-.Sh SEE ALSO
-.Xr dialog 1 ,
-.Xr dialog 3 ,
-.Xr sh 1 ,
-.Xr Xdialog 1
-.Sh HISTORY
-A
-.Nm
-utility first appeared in
-.Fx 11.0 .
-.Sh AUTHORS
-.An Devin Teske Aq dteske@FreeBSD.org
diff --git a/usr.bin/drill/Makefile b/usr.bin/drill/Makefile
index 0db0604..0de0ae5 100644
--- a/usr.bin/drill/Makefile
+++ b/usr.bin/drill/Makefile
@@ -12,8 +12,6 @@ CFLAGS+= -I${LDNSDIR}
NO_WERROR= true
MAN= drill.1
-DPADD+= ${LIBLDNS} ${LIBCRYPTO}
-LDADD+= ${LDLDNS} -lcrypto
-USEPRIVATELIB= ldns
+LIBADD= ldns crypto
.include <bsd.prog.mk>
diff --git a/usr.bin/du/Makefile b/usr.bin/du/Makefile
index f614866..9f96ec6 100644
--- a/usr.bin/du/Makefile
+++ b/usr.bin/du/Makefile
@@ -2,7 +2,6 @@
# $FreeBSD$
PROG= du
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD= util
.include <bsd.prog.mk>
diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c
index 6194a12..506c3f5 100644
--- a/usr.bin/du/du.c
+++ b/usr.bin/du/du.c
@@ -376,7 +376,7 @@ linkchk(FTSENT *p)
/* If the hash table is getting too full, enlarge it. */
if (number_entries > number_buckets * 10 && !stop_allocating) {
new_size = number_buckets * 2;
- new_buckets = malloc(new_size * sizeof(struct links_entry *));
+ new_buckets = calloc(new_size, sizeof(struct links_entry *));
/* Try releasing the free list to see if that helps. */
if (new_buckets == NULL && free_list != NULL) {
@@ -385,16 +385,13 @@ linkchk(FTSENT *p)
free_list = le->next;
free(le);
}
- new_buckets = malloc(new_size *
- sizeof(new_buckets[0]));
+ new_buckets = calloc(new_size, sizeof(new_buckets[0]));
}
if (new_buckets == NULL) {
stop_allocating = 1;
warnx("No more memory for tracking hard links");
} else {
- memset(new_buckets, 0,
- new_size * sizeof(struct links_entry *));
for (i = 0; i < number_buckets; i++) {
while (buckets[i] != NULL) {
/* Remove entry from old bucket. */
diff --git a/usr.bin/ee/Makefile b/usr.bin/ee/Makefile
index 8dcf2f5..7423fa7 100644
--- a/usr.bin/ee/Makefile
+++ b/usr.bin/ee/Makefile
@@ -8,8 +8,7 @@ CFLAGS+= -DHAS_NCURSES -DHAS_UNISTD -DHAS_STDARG -DHAS_STDLIB \
PROG= ee
LINKS= ${BINDIR}/ee ${BINDIR}/ree ${BINDIR}/ee ${BINDIR}/edit
MLINKS= ee.1 ree.1 ee.1 edit.1
-DPADD= ${LIBNCURSESW}
-LDADD= -lncursesw
+LIBADD= ncursesw
WARNS?= 2
diff --git a/usr.bin/elfcopy/Makefile b/usr.bin/elfcopy/Makefile
new file mode 100644
index 0000000..8e7f31d
--- /dev/null
+++ b/usr.bin/elfcopy/Makefile
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+ELFCOPYDIR= ${ELFTCDIR}/elfcopy
+
+.PATH: ${ELFCOPYDIR}
+
+PROG= elfcopy
+
+SRCS= archive.c ascii.c binary.c main.c sections.c segments.c symbols.c
+
+WARNS?= 5
+
+LIBADD= archive elftc elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+MAN= elfcopy.1 strip.1
+
+LINKS= ${BINDIR}/elfcopy ${BINDIR}/strip
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/elfdump/elfdump.c b/usr.bin/elfdump/elfdump.c
index bf9b718..cd10ce3 100644
--- a/usr.bin/elfdump/elfdump.c
+++ b/usr.bin/elfdump/elfdump.c
@@ -29,12 +29,15 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+
+#include <sys/capsicum.h>
#include <sys/elf32.h>
#include <sys/elf64.h>
#include <sys/endian.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stddef.h>
@@ -258,6 +261,7 @@ e_machines(u_int mach)
case EM_386: return "EM_386";
case EM_68K: return "EM_68K";
case EM_88K: return "EM_88K";
+ case EM_IAMCU: return "EM_IAMCU";
case EM_860: return "EM_860";
case EM_MIPS: return "EM_MIPS";
case EM_PPC: return "EM_PPC";
@@ -467,6 +471,7 @@ elf_get_shstrndx(Elf32_Ehdr *e, void *sh)
int
main(int ac, char **av)
{
+ cap_rights_t rights;
u_int64_t phoff;
u_int64_t shoff;
u_int64_t phentsize;
@@ -527,6 +532,9 @@ main(int ac, char **av)
case 'w':
if ((out = fopen(optarg, "w")) == NULL)
err(1, "%s", optarg);
+ cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE);
+ if (cap_rights_limit(fileno(out), &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for %s", optarg);
break;
case '?':
default:
@@ -539,6 +547,17 @@ main(int ac, char **av)
if ((fd = open(*av, O_RDONLY)) < 0 ||
fstat(fd, &sb) < 0)
err(1, "%s", *av);
+ cap_rights_init(&rights, CAP_MMAP_R);
+ if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for %s", *av);
+ close(STDIN_FILENO);
+ cap_rights_init(&rights, CAP_WRITE);
+ if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stdout");
+ if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stderr");
+ if (cap_enter() < 0 && errno != ENOSYS)
+ err(1, "unable to enter capability mode");
e = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (e == MAP_FAILED)
err(1, NULL);
diff --git a/usr.bin/enigma/Makefile b/usr.bin/enigma/Makefile
index 32a670b..55fcc46 100644
--- a/usr.bin/enigma/Makefile
+++ b/usr.bin/enigma/Makefile
@@ -5,7 +5,6 @@ PROG= enigma
LINKS= ${BINDIR}/enigma ${BINDIR}/crypt
MLINKS= enigma.1 crypt.1
-DPADD= ${LIBCRYPT}
-LDADD= -lcrypt
+LIBADD= crypt
.include <bsd.prog.mk>
diff --git a/usr.bin/enigma/enigma.c b/usr.bin/enigma/enigma.c
index 893766e..e476e65 100644
--- a/usr.bin/enigma/enigma.c
+++ b/usr.bin/enigma/enigma.c
@@ -43,6 +43,11 @@ setup(char *pw)
int32_t seed;
char *cryptpw;
+ if (crypt_set_format("des") == 0) {
+ fprintf(stderr, "crypt_set_format(\"des\") failed.\n");
+ exit(1);
+ }
+
strlcpy(salt, pw, sizeof(salt));
cryptpw = crypt(pw, salt);
if (cryptpw == NULL) {
diff --git a/usr.bin/env/envopts.c b/usr.bin/env/envopts.c
index f821430..5740062 100644
--- a/usr.bin/env/envopts.c
+++ b/usr.bin/env/envopts.c
@@ -372,9 +372,9 @@ str_done:
*nextarg = NULL;
/* Update optind/argc/argv in the calling routine */
- *origind = 1;
- *origc += addcount;
+ *origc += addcount - *origind + 1;
*origv = newargv;
+ *origind = 1;
}
/**
diff --git a/usr.bin/fetch/Makefile b/usr.bin/fetch/Makefile
index ed56f2f..93c43a7 100644
--- a/usr.bin/fetch/Makefile
+++ b/usr.bin/fetch/Makefile
@@ -1,15 +1,7 @@
# $FreeBSD$
-.include <src.opts.mk>
-
PROG= fetch
CSTD?= c99
-.if ${MK_OPENSSL} != "no"
-DPADD= ${LIBFETCH} ${LIBSSL} ${LIBCRYPTO}
-LDADD= -lfetch -lssl -lcrypto
-.else
-DPADD= ${LIBFETCH} ${LIBMD}
-LDADD= -lfetch -lmd
-.endif
+LIBADD= fetch
.include <bsd.prog.mk>
diff --git a/usr.bin/fetch/fetch.1 b/usr.bin/fetch/fetch.1
index 10df421..58b59ad 100644
--- a/usr.bin/fetch/fetch.1
+++ b/usr.bin/fetch/fetch.1
@@ -30,7 +30,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 28, 2014
+.Dd March 25, 2015
.Dt FETCH 1
.Os
.Sh NAME
@@ -39,7 +39,6 @@
.Sh SYNOPSIS
.Nm
.Op Fl 146AadFlMmnPpqRrsUv
-.Op Fl -allow-sslv2
.Op Fl B Ar bytes
.Op Fl -bind-address= Ns Ar host
.Op Fl -ca-cert= Ns Ar file
@@ -113,9 +112,6 @@ Some broken Web sites will return a redirect instead of a not-found
error when the requested object does not exist.
.It Fl a , -retry
Automatically retry the transfer upon soft failures.
-.It Fl -allow-sslv2
-[SSL]
-Allow SSL version 2 when negotiating the connection.
.It Fl B Ar bytes , Fl -buffer-size= Ns Ar bytes
Specify the read buffer size in bytes.
The default is 16,384 bytes.
@@ -350,7 +346,6 @@ for a description of additional environment variables, including
.Ev NETRC ,
.Ev NO_PROXY ,
.Ev no_proxy ,
-.Ev SSL_ALLOW_SSL2 ,
.Ev SSL_CA_CERT_FILE ,
.Ev SSL_CA_CERT_PATH ,
.Ev SSL_CLIENT_CERT_FILE ,
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c
index 3f64151..3fbf343 100644
--- a/usr.bin/fetch/fetch.c
+++ b/usr.bin/fetch/fetch.c
@@ -102,7 +102,6 @@ enum options
OPTION_HTTP_REFERER,
OPTION_HTTP_USER_AGENT,
OPTION_NO_PROXY,
- OPTION_SSL_ALLOW_SSL2,
OPTION_SSL_CA_CERT_FILE,
OPTION_SSL_CA_CERT_PATH,
OPTION_SSL_CLIENT_CERT_FILE,
@@ -154,7 +153,6 @@ static struct option longopts[] =
{ "referer", required_argument, NULL, OPTION_HTTP_REFERER },
{ "user-agent", required_argument, NULL, OPTION_HTTP_USER_AGENT },
{ "no-proxy", required_argument, NULL, OPTION_NO_PROXY },
- { "allow-sslv2", no_argument, NULL, OPTION_SSL_ALLOW_SSL2 },
{ "ca-cert", required_argument, NULL, OPTION_SSL_CA_CERT_FILE },
{ "ca-path", required_argument, NULL, OPTION_SSL_CA_CERT_PATH },
{ "cert", required_argument, NULL, OPTION_SSL_CLIENT_CERT_FILE },
@@ -845,17 +843,17 @@ static void
usage(void)
{
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
-"usage: fetch [-146AadFlMmnPpqRrsUv] [--allow-sslv2] [-B bytes]",
-" [--bind-address=host] [--ca-cert=file] [--ca-path=dir] [--cert=file]",
-" [--crl=file] [-i file] [--key=file] [-N file] [--no-passive]",
-" [--no-proxy=list] [--no-sslv3] [--no-tlsv1] [--no-verify-hostname]",
-" [--no-verify-peer] [-o file] [--referer=URL] [-S bytes] [-T seconds]",
+"usage: fetch [-146AadFlMmnPpqRrsUv] [-B bytes] [--bind-address=host]",
+" [--ca-cert=file] [--ca-path=dir] [--cert=file] [--crl=file]",
+" [-i file] [--key=file] [-N file] [--no-passive] [--no-proxy=list]",
+" [--no-sslv3] [--no-tlsv1] [--no-verify-hostname] [--no-verify-peer]",
+" [-o file] [--referer=URL] [-S bytes] [-T seconds]",
" [--user-agent=agent-string] [-w seconds] URL ...",
-" fetch [-146AadFlMmnPpqRrsUv] [--allow-sslv2] [-B bytes]",
-" [--bind-address=host] [--ca-cert=file] [--ca-path=dir] [--cert=file]",
-" [--crl=file] [-i file] [--key=file] [-N file] [--no-passive]",
-" [--no-proxy=list] [--no-sslv3] [--no-tlsv1] [--no-verify-hostname]",
-" [--no-verify-peer] [-o file] [--referer=URL] [-S bytes] [-T seconds]",
+" fetch [-146AadFlMmnPpqRrsUv] [-B bytes] [--bind-address=host]",
+" [--ca-cert=file] [--ca-path=dir] [--cert=file] [--crl=file]",
+" [-i file] [--key=file] [-N file] [--no-passive] [--no-proxy=list]",
+" [--no-sslv3] [--no-tlsv1] [--no-verify-hostname] [--no-verify-peer]",
+" [-o file] [--referer=URL] [-S bytes] [-T seconds]",
" [--user-agent=agent-string] [-w seconds] -h host -f file [-c dir]");
}
@@ -1004,9 +1002,6 @@ main(int argc, char *argv[])
case OPTION_NO_PROXY:
setenv("NO_PROXY", optarg, 1);
break;
- case OPTION_SSL_ALLOW_SSL2:
- setenv("SSL_ALLOW_SSL2", "", 1);
- break;
case OPTION_SSL_CA_CERT_FILE:
setenv("SSL_CA_CERT_FILE", optarg, 1);
break;
diff --git a/usr.bin/file/Makefile b/usr.bin/file/Makefile
index 4054365..70c211b 100644
--- a/usr.bin/file/Makefile
+++ b/usr.bin/file/Makefile
@@ -31,8 +31,7 @@ MAGICPATH?= /usr/share/misc
CFLAGS+= -DMAGIC='"${MAGICPATH}/magic"' -DHAVE_CONFIG_H
CFLAGS+= -I${.CURDIR}/../../lib/libmagic
-DPADD= ${LIBMAGIC} ${LIBZ}
-LDADD= -lmagic -lz
+LIBADD= magic
FILEVER!= awk '$$1 == "\#define" && $$2 == "VERSION" { print $$3; exit }' \
${.CURDIR}/../../lib/libmagic/config.h
diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1
index 0eb3bf5..a6e4d66 100644
--- a/usr.bin/find/find.1
+++ b/usr.bin/find/find.1
@@ -1015,7 +1015,7 @@ and
as well as
.Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
.Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
-.Ic -path , -print0 , -regex, -sparse
+.Ic -path , -print0 , -regex , -sparse
and all of the
.Ic -B*
birthtime related primaries are extensions to
diff --git a/usr.bin/fstat/Makefile b/usr.bin/fstat/Makefile
index 8ea8da3..830b23c 100644
--- a/usr.bin/fstat/Makefile
+++ b/usr.bin/fstat/Makefile
@@ -4,8 +4,7 @@
PROG= fstat
SRCS= fstat.c fuser.c main.c
LINKS= ${BINDIR}/fstat ${BINDIR}/fuser
-DPADD= ${LIBKVM} ${LIBUTIL} ${LIBPROCSTAT}
-LDADD= -lkvm -lutil -lprocstat
+LIBADD= procstat
MAN1= fuser.1 fstat.1
diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile
index 3d236d8..18068a6 100644
--- a/usr.bin/ftp/Makefile
+++ b/usr.bin/ftp/Makefile
@@ -20,8 +20,7 @@ CFLAGS+= -DINET6
.endif
CFLAGS+= -I${.CURDIR} -I${TNFTP}
-LDADD= -ledit -ltermcapw
-DPADD= ${LIBEDIT} ${LIBTERMCAPW}
+LIBADD= edit
WARNS?= 2
diff --git a/usr.bin/gcore/Makefile b/usr.bin/gcore/Makefile
index 7fff540..ad4b540 100644
--- a/usr.bin/gcore/Makefile
+++ b/usr.bin/gcore/Makefile
@@ -3,8 +3,7 @@
PROG= gcore
SRCS= elfcore.c gcore.c
-DPADD= ${LIBSBUF} ${LIBUTIL}
-LDADD= -lsbuf -lutil
+LIBADD= sbuf util
.if ${MACHINE_ARCH} == "amd64"
SRCS+= elf32core.c
diff --git a/usr.bin/gcore/elf32core.c b/usr.bin/gcore/elf32core.c
index de48500..d13a4ef 100644
--- a/usr.bin/gcore/elf32core.c
+++ b/usr.bin/gcore/elf32core.c
@@ -8,24 +8,6 @@
#include <sys/procfs.h>
-struct prpsinfo32 {
- int pr_version;
- u_int pr_psinfosz;
- char pr_fname[PRFNAMESZ+1];
- char pr_psargs[PRARGSZ+1];
-};
-
-struct prstatus32 {
- int pr_version;
- u_int pr_statussz;
- u_int pr_gregsetsz;
- u_int pr_fpregsetsz;
- int pr_osreldate;
- int pr_cursig;
- pid_t pr_pid;
- struct reg32 pr_reg;
-};
-
#define ELFCORE_COMPAT_32 1
#include "elfcore.c"
diff --git a/usr.bin/gcore/elfcore.c b/usr.bin/gcore/elfcore.c
index 037854c..2d1acb8 100644
--- a/usr.bin/gcore/elfcore.c
+++ b/usr.bin/gcore/elfcore.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -101,6 +102,12 @@ static void *elf_note_fpregset(void *, size_t *);
static void *elf_note_prpsinfo(void *, size_t *);
static void *elf_note_prstatus(void *, size_t *);
static void *elf_note_thrmisc(void *, size_t *);
+#if defined(__i386__) || defined(__amd64__)
+static void *elf_note_x86_xstate(void *, size_t *);
+#endif
+#if defined(__powerpc__)
+static void *elf_note_powerpc_vmx(void *, size_t *);
+#endif
static void *elf_note_procstat_auxv(void *, size_t *);
static void *elf_note_procstat_files(void *, size_t *);
static void *elf_note_procstat_groups(void *, size_t *);
@@ -341,6 +348,12 @@ elf_putnotes(pid_t pid, struct sbuf *sb, size_t *sizep)
elf_putnote(NT_PRSTATUS, elf_note_prstatus, tids + i, sb);
elf_putnote(NT_FPREGSET, elf_note_fpregset, tids + i, sb);
elf_putnote(NT_THRMISC, elf_note_thrmisc, tids + i, sb);
+#if defined(__i386__) || defined(__amd64__)
+ elf_putnote(NT_X86_XSTATE, elf_note_x86_xstate, tids + i, sb);
+#endif
+#if defined(__powerpc__)
+ elf_putnote(NT_PPC_VMX, elf_note_powerpc_vmx, tids + i, sb);
+#endif
}
#ifndef ELFCORE_COMPAT_32
@@ -498,7 +511,8 @@ readmap(pid_t pid)
((pflags & PFLAGS_FULL) == 0 &&
kve->kve_type != KVME_TYPE_DEFAULT &&
kve->kve_type != KVME_TYPE_VNODE &&
- kve->kve_type != KVME_TYPE_SWAP))
+ kve->kve_type != KVME_TYPE_SWAP &&
+ kve->kve_type != KVME_TYPE_PHYS))
continue;
ent = calloc(1, sizeof(*ent));
@@ -615,6 +629,60 @@ elf_note_thrmisc(void *arg, size_t *sizep)
return (thrmisc);
}
+#if defined(__i386__) || defined(__amd64__)
+static void *
+elf_note_x86_xstate(void *arg, size_t *sizep)
+{
+ lwpid_t tid;
+ char *xstate;
+ static bool xsave_checked = false;
+ static struct ptrace_xstate_info info;
+
+ tid = *(lwpid_t *)arg;
+ if (!xsave_checked) {
+ if (ptrace(PT_GETXSTATE_INFO, tid, (void *)&info,
+ sizeof(info)) != 0)
+ info.xsave_len = 0;
+ xsave_checked = true;
+ }
+ if (info.xsave_len == 0) {
+ *sizep = 0;
+ return (NULL);
+ }
+ xstate = calloc(1, info.xsave_len);
+ ptrace(PT_GETXSTATE, tid, xstate, 0);
+ *(uint64_t *)(xstate + X86_XSTATE_XCR0_OFFSET) = info.xsave_mask;
+ *sizep = info.xsave_len;
+ return (xstate);
+}
+#endif
+
+#if defined(__powerpc__)
+static void *
+elf_note_powerpc_vmx(void *arg, size_t *sizep)
+{
+ lwpid_t tid;
+ struct vmxreg *vmx;
+ static bool has_vmx = true;
+ struct vmxreg info;
+
+ tid = *(lwpid_t *)arg;
+ if (has_vmx) {
+ if (ptrace(PT_GETVRREGS, tid, (void *)&info,
+ sizeof(info)) != 0)
+ has_vmx = false;
+ }
+ if (!has_vmx) {
+ *sizep = 0;
+ return (NULL);
+ }
+ vmx = calloc(1, sizeof(*vmx));
+ memcpy(vmx, &info, sizeof(*vmx));
+ *sizep = sizeof(*vmx);
+ return (vmx);
+}
+#endif
+
static void *
procstat_sysctl(void *arg, int what, size_t structsz, size_t *sizep)
{
diff --git a/usr.bin/grep/Makefile b/usr.bin/grep/Makefile
index 32941fd..38df85a 100644
--- a/usr.bin/grep/Makefile
+++ b/usr.bin/grep/Makefile
@@ -11,7 +11,7 @@ PROG= bsdgrep
CLEANFILES+= bsdgrep.1
bsdgrep.1: grep.1
- cp -f ${.ALLSRC} ${.TARGET}
+ ${CP} ${.ALLSRC} ${.TARGET}
.endif
SRCS= file.c grep.c queue.c util.c
@@ -31,21 +31,13 @@ MLINKS= grep.1 egrep.1 \
grep.1 fgrep.1 \
grep.1 zgrep.1 \
grep.1 zegrep.1 \
- grep.1 zfgrep.1 \
- grep.1 xzgrep.1 \
- grep.1 xzegrep.1 \
- grep.1 xzfgrep.1 \
- grep.1 lzgrep.1 \
- grep.1 lzegrep.1 \
- grep.1 lzfgrep.1
+ grep.1 zfgrep.1
.endif
-LDADD= -lz
-DPADD= ${LIBZ}
+LIBADD= z
.if ${MK_LZMA_SUPPORT} != "no"
-LDADD+= -llzma
-DPADD+= ${LIBLZMA}
+LIBADD+= lzma
LINKS+= ${BINDIR}/${PROG} ${BINDIR}/xzgrep \
${BINDIR}/${PROG} ${BINDIR}/xzegrep \
@@ -53,13 +45,19 @@ LINKS+= ${BINDIR}/${PROG} ${BINDIR}/xzgrep \
${BINDIR}/${PROG} ${BINDIR}/lzgrep \
${BINDIR}/${PROG} ${BINDIR}/lzegrep \
${BINDIR}/${PROG} ${BINDIR}/lzfgrep
+
+MLINKS+= grep.1 xzgrep.1 \
+ grep.1 xzegrep.1 \
+ grep.1 xzfgrep.1 \
+ grep.1 lzgrep.1 \
+ grep.1 lzegrep.1 \
+ grep.1 lzfgrep.1
.else
CFLAGS+= -DWITHOUT_LZMA
.endif
.if ${MK_BZIP2_SUPPORT} != "no"
-LDADD+= -lbz2
-DPADD+= ${LIBBZ2}
+LIBADD+= bz2
.if ${MK_BSD_GREP} == "yes"
LINKS+= ${BINDIR}/grep ${BINDIR}/bzgrep \
@@ -75,8 +73,7 @@ CFLAGS+= -DWITHOUT_BZIP2
.if ${MK_GNU_GREP_COMPAT} != "no"
CFLAGS+= -I${DESTDIR}/usr/include/gnu
-LDADD+= -lgnuregex
-DPADD+= ${LIBGNUREGEX}
+LIBADD+= gnuregex
.endif
.if ${MK_NLS} != "no"
diff --git a/usr.bin/grep/Makefile.depend b/usr.bin/grep/Makefile.depend
index 6dc4e1d..e170be2 100644
--- a/usr.bin/grep/Makefile.depend
+++ b/usr.bin/grep/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/liblzma \
+ lib/libthr \
lib/libz \
diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c
index 6bcaa52..81f227d 100644
--- a/usr.bin/grep/file.c
+++ b/usr.bin/grep/file.c
@@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$");
static gzFile gzbufdesc;
#ifndef WITHOUT_LZMA
static lzma_stream lstrm = LZMA_STREAM_INIT;
+static lzma_action laction;
+static uint8_t lin_buf[MAXBUFSIZ];
#endif
#ifndef WITHOUT_BZIP2
static BZFILE* bzbufdesc;
@@ -123,34 +125,34 @@ grep_refill(struct file *f)
#endif
#ifndef WITHOUT_LZMA
} else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) {
- lzma_action action = LZMA_RUN;
- uint8_t in_buf[MAXBUFSIZ];
lzma_ret ret;
+ lstrm.next_out = buffer;
- ret = (filebehave == FILE_XZ) ?
- lzma_stream_decoder(&lstrm, UINT64_MAX,
- LZMA_CONCATENATED) :
- lzma_alone_decoder(&lstrm, UINT64_MAX);
+ do {
+ if (lstrm.avail_in == 0) {
+ lstrm.next_in = lin_buf;
+ nr = read(f->fd, lin_buf, MAXBUFSIZ);
- if (ret != LZMA_OK)
- return (-1);
+ if (nr < 0)
+ return (-1);
+ else if (nr == 0)
+ laction = LZMA_FINISH;
- lstrm.next_out = buffer;
- lstrm.avail_out = MAXBUFSIZ;
- lstrm.next_in = in_buf;
- nr = read(f->fd, in_buf, MAXBUFSIZ);
+ lstrm.avail_in = nr;
+ }
- if (nr < 0)
- return (-1);
- else if (nr == 0)
- action = LZMA_FINISH;
+ ret = lzma_code(&lstrm, laction);
- lstrm.avail_in = nr;
- ret = lzma_code(&lstrm, action);
+ if (ret != LZMA_OK && ret != LZMA_STREAM_END)
+ return (-1);
+
+ if (lstrm.avail_out == 0 || ret == LZMA_STREAM_END) {
+ bufrem = MAXBUFSIZ - lstrm.avail_out;
+ lstrm.next_out = buffer;
+ lstrm.avail_out = MAXBUFSIZ;
+ }
+ } while (bufrem == 0 && ret != LZMA_STREAM_END);
- if (ret != LZMA_OK && ret != LZMA_STREAM_END)
- return (-1);
- bufrem = MAXBUFSIZ - lstrm.avail_out;
return (0);
#endif /* WIHTOUT_LZMA */
} else
@@ -291,6 +293,23 @@ grep_open(const char *path)
(bzbufdesc = BZ2_bzdopen(f->fd, "r")) == NULL)
goto error2;
#endif
+#ifndef WITHOUT_LZMA
+ else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) {
+ lzma_ret ret;
+
+ ret = (filebehave == FILE_XZ) ?
+ lzma_stream_decoder(&lstrm, UINT64_MAX,
+ LZMA_CONCATENATED) :
+ lzma_alone_decoder(&lstrm, UINT64_MAX);
+
+ if (ret != LZMA_OK)
+ goto error2;
+
+ lstrm.avail_in = 0;
+ lstrm.avail_out = MAXBUFSIZ;
+ laction = LZMA_RUN;
+ }
+#endif
/* Fill read buffer, also catches errors early */
if (bufrem == 0 && grep_refill(f) != 0)
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 5631877..2dc5a1d 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -316,7 +316,7 @@ read_patterns(const char *fn)
len = 0;
line = NULL;
while ((rlen = getline(&line, &len, f)) != -1)
- add_pattern(line, line[0] == '\n' ? 0 : len);
+ add_pattern(line, line[0] == '\n' ? 0 : (size_t)rlen);
free(line);
if (ferror(f))
err(2, "%s", fn);
diff --git a/usr.bin/gzip/Makefile b/usr.bin/gzip/Makefile
index 24e2506..1266277 100644
--- a/usr.bin/gzip/Makefile
+++ b/usr.bin/gzip/Makefile
@@ -6,12 +6,10 @@
PROG= gzip
MAN= gzip.1 gzexe.1 zdiff.1 zforce.1 zmore.1 znew.1
-DPADD= ${LIBZ} ${LIBLZMA}
-LDADD= -lz -llzma
+LIBADD= z lzma
.if ${MK_BZIP2_SUPPORT} != "no"
-DPADD+= ${LIBBZ2}
-LDADD+= -lbz2
+LIBADD+= bz2
.else
CFLAGS+= -DNO_BZIP2_SUPPORT
.endif
diff --git a/usr.bin/gzip/Makefile.depend b/usr.bin/gzip/Makefile.depend
index 4e4edde..f4f6fd6 100644
--- a/usr.bin/gzip/Makefile.depend
+++ b/usr.bin/gzip/Makefile.depend
@@ -12,6 +12,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/liblzma \
+ lib/libthr \
lib/libz \
diff --git a/usr.bin/gzip/gzip.1 b/usr.bin/gzip/gzip.1
index 5abf1ae..43d0e72 100644
--- a/usr.bin/gzip/gzip.1
+++ b/usr.bin/gzip/gzip.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: gzip.1,v 1.23 2014/03/18 18:20:45 riastradh Exp $
+.\" $NetBSD: gzip.1,v 1.25 2015/04/06 21:41:17 wiz Exp $
.\"
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
.\" All rights reserved.
@@ -25,7 +25,7 @@
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
-.Dd October 9, 2011
+.Dd April 6, 2015
.Dt GZIP 1
.Os
.Sh NAME
@@ -105,9 +105,10 @@ options are enabled.
This version of
.Nm
is also capable of decompressing files compressed using
-.Xr compress 1
+.Xr compress 1 ,
+.Xr bzip2 1 ,
or
-.Xr bzip2 1 .
+.Xr xz 1 .
.Sh OPTIONS
The following options are available:
.Bl -tag -width XXrXXXrecursiveX
diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c
index 9f92b6a..8469c05 100644
--- a/usr.bin/gzip/gzip.c
+++ b/usr.bin/gzip/gzip.c
@@ -1,4 +1,4 @@
-/* $NetBSD: gzip.c,v 1.106 2014/10/18 08:33:30 snj Exp $ */
+/* $NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $ */
/*-
* Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
@@ -158,7 +158,7 @@ static suffixes_t suffixes[] = {
#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
#define SUFFIX_MAXLEN 30
-static const char gzip_version[] = "FreeBSD gzip 20141022";
+static const char gzip_version[] = "FreeBSD gzip 20150413";
#ifndef SMALL
static const char gzip_copyright[] = \
@@ -1070,7 +1070,7 @@ out2:
static void
copymodes(int fd, const struct stat *sbp, const char *file)
{
- struct timeval times[2];
+ struct timespec times[2];
struct stat sb;
/*
@@ -1098,10 +1098,10 @@ copymodes(int fd, const struct stat *sbp, const char *file)
if (fchmod(fd, sb.st_mode) < 0)
maybe_warn("couldn't fchmod: %s", file);
- TIMESPEC_TO_TIMEVAL(&times[0], &sb.st_atim);
- TIMESPEC_TO_TIMEVAL(&times[1], &sb.st_mtim);
- if (futimes(fd, times) < 0)
- maybe_warn("couldn't utimes: %s", file);
+ times[0] = sb.st_atim;
+ times[1] = sb.st_mtim;
+ if (futimens(fd, times) < 0)
+ maybe_warn("couldn't futimens: %s", file);
/* only try flags if they exist already */
if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
@@ -1354,7 +1354,7 @@ file_uncompress(char *file, char *outfile, size_t outsize)
#ifndef SMALL
ssize_t rv;
time_t timestamp = 0;
- unsigned char name[PATH_MAX + 1];
+ char name[PATH_MAX + 1];
#endif
/* gather the old name info */
@@ -1409,21 +1409,33 @@ file_uncompress(char *file, char *outfile, size_t outsize)
timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
if (header1[3] & ORIG_NAME) {
- rbytes = pread(fd, name, sizeof name, GZIP_ORIGNAME);
+ rbytes = pread(fd, name, sizeof(name) - 1, GZIP_ORIGNAME);
if (rbytes < 0) {
maybe_warn("can't read %s", file);
goto lose;
}
- if (name[0] != 0) {
+ if (name[0] != '\0') {
+ char *dp, *nf;
+
+ /* Make sure that name is NUL-terminated */
+ name[rbytes] = '\0';
+
+ /* strip saved directory name */
+ nf = strrchr(name, '/');
+ if (nf == NULL)
+ nf = name;
+ else
+ nf++;
+
/* preserve original directory name */
- char *dp = strrchr(file, '/');
+ dp = strrchr(file, '/');
if (dp == NULL)
dp = file;
else
dp++;
snprintf(outfile, outsize, "%.*s%.*s",
(int) (dp - file),
- file, (int) rbytes, name);
+ file, (int) rbytes, nf);
}
}
}
@@ -2110,7 +2122,7 @@ static void
display_license(void)
{
- fprintf(stderr, "%s (based on NetBSD gzip 20141018)\n", gzip_version);
+ fprintf(stderr, "%s (based on NetBSD gzip 20150113)\n", gzip_version);
fprintf(stderr, "%s\n", gzip_copyright);
exit(0);
}
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c
index a5f2a47..4ff3308 100644
--- a/usr.bin/hexdump/display.c
+++ b/usr.bin/hexdump/display.c
@@ -380,7 +380,7 @@ doskip(const char *fname, int statok)
return;
}
}
- if (S_ISREG(sb.st_mode)) {
+ if (statok && S_ISREG(sb.st_mode)) {
if (fseeko(stdin, skip, SEEK_SET))
err(1, "%s", fname);
address += skip;
diff --git a/usr.bin/host/Makefile b/usr.bin/host/Makefile
index cc1111f..5c2ce52 100644
--- a/usr.bin/host/Makefile
+++ b/usr.bin/host/Makefile
@@ -15,8 +15,6 @@ host.1: ldns-host.1
(rm -rf ${.TARGET} ; false)
CFLAGS+= -I${LDNSDIR}
-DPADD+= ${LIBLDNS} ${LIBCRYPTO}
-LDADD+= ${LDLDNS} -lcrypto
-USEPRIVATELIB= ldns
+LIBADD= ldns
.include <bsd.prog.mk>
diff --git a/usr.bin/iconv/iconv.c b/usr.bin/iconv/iconv.c
index dc2aec0..494aaf7 100644
--- a/usr.bin/iconv/iconv.c
+++ b/usr.bin/iconv/iconv.c
@@ -71,9 +71,8 @@ do_conv(FILE *fp, const char *from, const char *to, bool silent,
bool hide_invalid)
{
iconv_t cd;
- char inbuf[INBUFSIZE], outbuf[OUTBUFSIZE], *out;
+ char inbuf[INBUFSIZE], outbuf[OUTBUFSIZE], *in, *out;
unsigned long long invalids;
- const char *in;
size_t inbytes, outbytes, ret;
if ((cd = iconv_open(to, from)) == (iconv_t)-1)
diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c
index a49fd75..345e2a6 100644
--- a/usr.bin/id/id.c
+++ b/usr.bin/id/id.c
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <grp.h>
#include <pwd.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -346,14 +347,14 @@ auditid(void)
"mask.success=0x%08x\n"
"mask.failure=0x%08x\n"
"asid=%d\n"
- "termid_addr.port=0x%08x\n"
+ "termid_addr.port=0x%08jx\n"
"termid_addr.addr[0]=0x%08x\n"
"termid_addr.addr[1]=0x%08x\n"
"termid_addr.addr[2]=0x%08x\n"
"termid_addr.addr[3]=0x%08x\n",
ainfo_addr.ai_auid, ainfo_addr.ai_mask.am_success,
ainfo_addr.ai_mask.am_failure, ainfo_addr.ai_asid,
- ainfo_addr.ai_termid.at_port,
+ (uintmax_t)ainfo_addr.ai_termid.at_port,
ainfo_addr.ai_termid.at_addr[0],
ainfo_addr.ai_termid.at_addr[1],
ainfo_addr.ai_termid.at_addr[2],
@@ -363,11 +364,11 @@ auditid(void)
"mask.success=0x%08x\n"
"mask.failure=0x%08x\n"
"asid=%d\n"
- "termid.port=0x%08x\n"
+ "termid.port=0x%08jx\n"
"termid.machine=0x%08x\n",
auditinfo.ai_auid, auditinfo.ai_mask.am_success,
auditinfo.ai_mask.am_failure,
- auditinfo.ai_asid, auditinfo.ai_termid.port,
+ auditinfo.ai_asid, (uintmax_t)auditinfo.ai_termid.port,
auditinfo.ai_termid.machine);
}
}
diff --git a/usr.bin/ipcrm/Makefile b/usr.bin/ipcrm/Makefile
index f55311c..990b9f9 100644
--- a/usr.bin/ipcrm/Makefile
+++ b/usr.bin/ipcrm/Makefile
@@ -2,8 +2,7 @@
PROG= ipcrm
SRCS= ipcrm.c ipc.c
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+LIBADD= kvm
CFLAGS+=-I${.CURDIR}/../ipcs
.PATH: ${.CURDIR}/../ipcs
diff --git a/usr.bin/ipcs/Makefile b/usr.bin/ipcs/Makefile
index 0d422e1..d14723f 100644
--- a/usr.bin/ipcs/Makefile
+++ b/usr.bin/ipcs/Makefile
@@ -2,9 +2,6 @@
PROG= ipcs
SRCS= ipcs.c ipc.c
-DPADD= ${LIBKVM}
-LDADD= -lkvm
-
-WARNS?= 1
+LIBADD= kvm
.include <bsd.prog.mk>
diff --git a/usr.bin/ipcs/ipc.c b/usr.bin/ipcs/ipc.c
index 4c62743..306d659 100644
--- a/usr.bin/ipcs/ipc.c
+++ b/usr.bin/ipcs/ipc.c
@@ -55,16 +55,15 @@ struct msginfo msginfo;
struct msqid_kernel *msqids;
struct shminfo shminfo;
struct shmid_kernel *shmsegs;
-void kget(int idx, void *addr, size_t size);
struct nlist symbols[] = {
- {"sema"},
- {"seminfo"},
- {"msginfo"},
- {"msqids"},
- {"shminfo"},
- {"shmsegs"},
- {NULL}
+ { .n_name = "sema" },
+ { .n_name = "seminfo" },
+ { .n_name = "msginfo" },
+ { .n_name = "msqids" },
+ { .n_name = "shminfo" },
+ { .n_name = "shmsegs" },
+ { .n_name = NULL }
};
#define SHMINFO_XVEC X(shmmax, sizeof(u_long)) \
@@ -92,13 +91,13 @@ struct nlist symbols[] = {
#define X(a, b) { "kern.ipc." #a, offsetof(TYPEC, a), (b) },
#define TYPEC struct shminfo
-struct scgs_vector shminfo_scgsv[] = { SHMINFO_XVEC { NULL } };
+static struct scgs_vector shminfo_scgsv[] = { SHMINFO_XVEC { .sysctl=NULL } };
#undef TYPEC
#define TYPEC struct seminfo
-struct scgs_vector seminfo_scgsv[] = { SEMINFO_XVEC { NULL } };
+static struct scgs_vector seminfo_scgsv[] = { SEMINFO_XVEC { .sysctl=NULL } };
#undef TYPEC
#define TYPEC struct msginfo
-struct scgs_vector msginfo_scgsv[] = { MSGINFO_XVEC { NULL } };
+static struct scgs_vector msginfo_scgsv[] = { MSGINFO_XVEC { .sysctl=NULL } };
#undef TYPEC
#undef X
diff --git a/usr.bin/ipcs/ipc.h b/usr.bin/ipcs/ipc.h
index 640c3fd..0b6188a 100644
--- a/usr.bin/ipcs/ipc.h
+++ b/usr.bin/ipcs/ipc.h
@@ -52,7 +52,7 @@
/* SysCtlGatherStruct structure. */
struct scgs_vector {
const char *sysctl;
- off_t offset;
+ size_t offset;
size_t size;
};
@@ -64,8 +64,5 @@ extern struct nlist symbols[];
extern kvm_t *kd;
extern struct semid_kernel *sema;
-extern struct seminfo seminfo;
-extern struct msginfo msginfo;
extern struct msqid_kernel *msqids;
-extern struct shminfo shminfo;
extern struct shmid_kernel *shmsegs;
diff --git a/usr.bin/ipcs/ipcs.c b/usr.bin/ipcs/ipcs.c
index 1d8e354..be6ca56 100644
--- a/usr.bin/ipcs/ipcs.c
+++ b/usr.bin/ipcs/ipcs.c
@@ -112,6 +112,7 @@ main(int argc, char *argv[])
char *core = NULL, *user = NULL, *namelist = NULL;
char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */
int i;
+ u_long shmidx;
uid_t uid = 0;
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTu:y")) != -1)
@@ -247,13 +248,13 @@ main(int argc, char *argv[])
print_kshmheader(option);
- for (i = 0; i < shminfo.shmmni; i += 1) {
- if (kxshmids[i].u.shm_perm.mode & 0x0800) {
+ for (shmidx = 0; shmidx < shminfo.shmmni; shmidx += 1) {
+ if (kxshmids[shmidx].u.shm_perm.mode & 0x0800) {
if (user &&
- uid != kxshmids[i].u.shm_perm.uid)
+ uid != kxshmids[shmidx].u.shm_perm.uid)
continue;
- print_kshmptr(i, option, &kxshmids[i]);
+ print_kshmptr(shmidx, option, &kxshmids[shmidx]);
}
}
printf("\n");
@@ -309,22 +310,22 @@ main(int argc, char *argv[])
}
void
-print_kmsqtotal(struct msginfo msginfo)
+print_kmsqtotal(struct msginfo local_msginfo)
{
printf("msginfo:\n");
printf("\tmsgmax: %12d\t(max characters in a message)\n",
- msginfo.msgmax);
+ local_msginfo.msgmax);
printf("\tmsgmni: %12d\t(# of message queues)\n",
- msginfo.msgmni);
+ local_msginfo.msgmni);
printf("\tmsgmnb: %12d\t(max characters in a message queue)\n",
- msginfo.msgmnb);
+ local_msginfo.msgmnb);
printf("\tmsgtql: %12d\t(max # of messages in system)\n",
- msginfo.msgtql);
+ local_msginfo.msgtql);
printf("\tmsgssz: %12d\t(size of a message segment)\n",
- msginfo.msgssz);
+ local_msginfo.msgssz);
printf("\tmsgseg: %12d\t(# of message segments in system)\n\n",
- msginfo.msgseg);
+ local_msginfo.msgseg);
}
void print_kmsqheader(int option)
@@ -390,20 +391,20 @@ print_kmsqptr(int i, int option, struct msqid_kernel *kmsqptr)
}
void
-print_kshmtotal(struct shminfo shminfo)
+print_kshmtotal(struct shminfo local_shminfo)
{
printf("shminfo:\n");
printf("\tshmmax: %12lu\t(max shared memory segment size)\n",
- shminfo.shmmax);
+ local_shminfo.shmmax);
printf("\tshmmin: %12lu\t(min shared memory segment size)\n",
- shminfo.shmmin);
+ local_shminfo.shmmin);
printf("\tshmmni: %12lu\t(max number of shared memory identifiers)\n",
- shminfo.shmmni);
+ local_shminfo.shmmni);
printf("\tshmseg: %12lu\t(max shared memory segments per process)\n",
- shminfo.shmseg);
+ local_shminfo.shmseg);
printf("\tshmall: %12lu\t(max amount of shared memory in pages)\n\n",
- shminfo.shmall);
+ local_shminfo.shmall);
}
void
@@ -470,28 +471,28 @@ print_kshmptr(int i, int option, struct shmid_kernel *kshmptr)
}
void
-print_ksemtotal(struct seminfo seminfo)
+print_ksemtotal(struct seminfo local_seminfo)
{
printf("seminfo:\n");
printf("\tsemmni: %12d\t(# of semaphore identifiers)\n",
- seminfo.semmni);
+ local_seminfo.semmni);
printf("\tsemmns: %12d\t(# of semaphores in system)\n",
- seminfo.semmns);
+ local_seminfo.semmns);
printf("\tsemmnu: %12d\t(# of undo structures in system)\n",
- seminfo.semmnu);
+ local_seminfo.semmnu);
printf("\tsemmsl: %12d\t(max # of semaphores per id)\n",
- seminfo.semmsl);
+ local_seminfo.semmsl);
printf("\tsemopm: %12d\t(max # of operations per semop call)\n",
- seminfo.semopm);
+ local_seminfo.semopm);
printf("\tsemume: %12d\t(max # of undo entries per process)\n",
- seminfo.semume);
+ local_seminfo.semume);
printf("\tsemusz: %12d\t(size in bytes of undo structure)\n",
- seminfo.semusz);
+ local_seminfo.semusz);
printf("\tsemvmx: %12d\t(semaphore maximum value)\n",
- seminfo.semvmx);
+ local_seminfo.semvmx);
printf("\tsemaem: %12d\t(adjust on exit max value)\n\n",
- seminfo.semaem);
+ local_seminfo.semaem);
}
void
diff --git a/usr.bin/iscsictl/Makefile b/usr.bin/iscsictl/Makefile
index 9351ed7..4437e2d 100644
--- a/usr.bin/iscsictl/Makefile
+++ b/usr.bin/iscsictl/Makefile
@@ -4,10 +4,9 @@ PROG= iscsictl
SRCS= iscsictl.c periphs.c parse.y token.l y.tab.h
CFLAGS+= -I${.CURDIR}
CFLAGS+= -I${.CURDIR}/../../sys/dev/iscsi
-MAN= iscsictl.8
+MAN= iscsi.conf.5 iscsictl.8
-DPADD= ${LIBCAM} ${LIBUTIL}
-LDADD= -lcam -lutil
+LIBADD= xo
YFLAGS+= -v
LFLAGS+= -i
diff --git a/usr.bin/iscsictl/iscsi.conf.5 b/usr.bin/iscsictl/iscsi.conf.5
new file mode 100644
index 0000000..8740fe5
--- /dev/null
+++ b/usr.bin/iscsictl/iscsi.conf.5
@@ -0,0 +1,162 @@
+.\" Copyright (c) 2007-2010 Daniel Braniss <danny@cs.huji.ac.il>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 2, 2015
+.Dt ISCSI.CONF 5
+.Os
+.Sh NAME
+.Nm iscsi.conf
+.Nd iSCSI initiator configuration file
+.Sh DESCRIPTION
+The
+.Nm
+configuration file is used by the
+.Xr iscsictl 8
+and
+.Xr iscontrol 8
+utilities.
+The general syntax is:
+.Bf Li
+.Bd -literal
+ # this is a comment
+ nickname_1 {
+ variable = value;
+ ...
+ }
+ nickname_2 {
+ variable = value;
+ ...
+ }
+ ...
+.Ed
+.Ef
+.Bl -tag -width MaxConnections
+.It Cm AuthMethod
+Sets the authentication type.
+Type can be either
+.Qq Ar None ,
+or
+.Qq Ar CHAP .
+Default is
+.Qq Ar None .
+When set to
+.Cm CHAP ,
+both
+.Cm chapIName
+and
+.Cm chapSecret
+must be defined.
+.It Cm chapIName
+Login for CHAP authentication.
+.It Cm chapSecret
+Secret for CHAP authentication.
+.It Cm tgtChapName
+Target login for Mutual CHAP authentication.
+.It Cm tgtChapSecret
+Target secret for Mutual CHAP authentication.
+.It Cm HeaderDigest
+Sets the header digest; a checksum calculated over the header of iSCSI
+PDUs, and verified on receive.
+Digest can be either
+.Qq Ar None ,
+or
+.Qq Ar CRC32C .
+Default is
+.Qq Ar None .
+.It Cm DataDigest
+Sets the data digest; a checksum calculated over the Data Section of iSCSI
+PDUs, and verified on receive.
+Digest can be either
+.Qq Ar None ,
+or
+.Qq Ar CRC32C .
+Default is
+.Qq Ar None .
+.It Cm InitiatorName
+Sets the initiator name.
+By default, the name is concatenation of
+.Qq Ar iqn.1994-09.org.freebsd:
+with the hostname.
+.It Cm TargetName
+Sets the target name.
+Not required for discovery sessions.
+.It Cm TargetAddress
+Sets the target address and port, in
+.Sy address[:port]
+format.
+The
+.Sy address
+can be either an IP address, or hostname.
+The optional port defaults to 3260.
+.It Cm SessionType
+Sets the session type.
+Type can be either
+.Qq Ar Discovery ,
+or
+.Qq Ar Normal .
+Default is
+.Qq Ar Normal .
+For normal sessions, the
+.Sy TargetName
+must be defined.
+Discovery sessions result in the initiator connecting to all the targets
+returned by SendTargets iSCSI discovery with the defined
+.Sy TargetAddress .
+.It Cm Offload
+Name of selected iSCSI hardware offload driver.
+Default is
+.Qq Ar None .
+.El
+.Sh FILES
+.Bl -tag -width indent
+.It Pa /etc/iscsi.conf
+.El
+.Sh EXAMPLES
+.Bd -literal
+myiscsi { # nickname
+ targetaddress = iscsi1
+ targetname = iqn.1900.com.com:sn.123456
+}
+
+myiscsi6 { # nickname
+ targetaddress = [2001:db8::de:ef]:3260
+ targetname = iqn.1900.com.com:sn.123456
+}
+
+chaptest {
+ targetaddress = 10.0.0.1;
+ targetname = iqn.1900.com.com:sn.123456;
+ initiatorname = iqn.2005-01.il.ac.huji.cs:nobody;
+ authmethod = CHAP;
+ chapiname = iqn.2005-01.il.ac.huji.cs:nobody;
+ chapsecret = "secretsecret";
+}
+.Ed
+.Sh SEE ALSO
+.Xr iscontrol 8 ,
+.Xr iscsictl 8
+.\"Sh HISTORY
+.\"Sh AUTHORS
diff --git a/usr.bin/iscsictl/iscsictl.c b/usr.bin/iscsictl/iscsictl.c
index a27e32b..ac83b49 100644
--- a/usr.bin/iscsictl/iscsictl.c
+++ b/usr.bin/iscsictl/iscsictl.c
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <assert.h>
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -44,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include <iscsi_ioctl.h>
#include "iscsictl.h"
@@ -55,7 +55,7 @@ conf_new(void)
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
- err(1, "calloc");
+ xo_err(1, "calloc");
TAILQ_INIT(&conf->conf_targets);
@@ -83,7 +83,7 @@ target_new(struct conf *conf)
targ = calloc(1, sizeof(*targ));
if (targ == NULL)
- err(1, "calloc");
+ xo_err(1, "calloc");
targ->t_conf = conf;
TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
@@ -110,12 +110,12 @@ default_initiator_name(void)
name = calloc(1, namelen + 1);
if (name == NULL)
- err(1, "calloc");
+ xo_err(1, "calloc");
strcpy(name, DEFAULT_IQN);
error = gethostname(name + strlen(DEFAULT_IQN),
namelen - strlen(DEFAULT_IQN));
if (error != 0)
- err(1, "gethostname");
+ xo_err(1, "gethostname");
return (name);
}
@@ -158,7 +158,7 @@ valid_iscsi_name(const char *name)
int i;
if (strlen(name) >= MAX_NAME_LEN) {
- warnx("overlong name for \"%s\"; max length allowed "
+ xo_warnx("overlong name for \"%s\"; max length allowed "
"by iSCSI specification is %d characters",
name, MAX_NAME_LEN);
return (false);
@@ -178,7 +178,7 @@ valid_iscsi_name(const char *name)
continue;
if (name[i] == '-' || name[i] == '.' || name[i] == ':')
continue;
- warnx("invalid character \"%c\" in iSCSI name "
+ xo_warnx("invalid character \"%c\" in iSCSI name "
"\"%s\"; allowed characters are letters, digits, "
"'-', '.', and ':'", name[i], name);
break;
@@ -188,12 +188,12 @@ valid_iscsi_name(const char *name)
*/
} else if (strncasecmp(name, "eui.", strlen("eui.")) == 0) {
if (strlen(name) != strlen("eui.") + 16)
- warnx("invalid iSCSI name \"%s\"; the \"eui.\" "
+ xo_warnx("invalid iSCSI name \"%s\"; the \"eui.\" "
"should be followed by exactly 16 hexadecimal "
"digits", name);
for (i = strlen("eui."); name[i] != '\0'; i++) {
if (!valid_hex(name[i])) {
- warnx("invalid character \"%c\" in iSCSI "
+ xo_warnx("invalid character \"%c\" in iSCSI "
"name \"%s\"; allowed characters are 1-9 "
"and A-F", name[i], name);
break;
@@ -201,19 +201,19 @@ valid_iscsi_name(const char *name)
}
} else if (strncasecmp(name, "naa.", strlen("naa.")) == 0) {
if (strlen(name) > strlen("naa.") + 32)
- warnx("invalid iSCSI name \"%s\"; the \"naa.\" "
+ xo_warnx("invalid iSCSI name \"%s\"; the \"naa.\" "
"should be followed by at most 32 hexadecimal "
"digits", name);
for (i = strlen("naa."); name[i] != '\0'; i++) {
if (!valid_hex(name[i])) {
- warnx("invalid character \"%c\" in ISCSI "
+ xo_warnx("invalid character \"%c\" in ISCSI "
"name \"%s\"; allowed characters are 1-9 "
"and A-F", name[i], name);
break;
}
}
} else {
- warnx("invalid iSCSI name \"%s\"; should start with "
+ xo_warnx("invalid iSCSI name \"%s\"; should start with "
"either \".iqn\", \"eui.\", or \"naa.\"",
name);
}
@@ -231,26 +231,26 @@ conf_verify(struct conf *conf)
targ->t_session_type = SESSION_TYPE_NORMAL;
if (targ->t_session_type == SESSION_TYPE_NORMAL &&
targ->t_name == NULL)
- errx(1, "missing TargetName for target \"%s\"",
+ xo_errx(1, "missing TargetName for target \"%s\"",
targ->t_nickname);
if (targ->t_session_type == SESSION_TYPE_DISCOVERY &&
targ->t_name != NULL)
- errx(1, "cannot specify TargetName for discovery "
+ xo_errx(1, "cannot specify TargetName for discovery "
"sessions for target \"%s\"", targ->t_nickname);
if (targ->t_name != NULL) {
if (valid_iscsi_name(targ->t_name) == false)
- errx(1, "invalid target name \"%s\"",
+ xo_errx(1, "invalid target name \"%s\"",
targ->t_name);
}
if (targ->t_protocol == PROTOCOL_UNSPECIFIED)
targ->t_protocol = PROTOCOL_ISCSI;
if (targ->t_address == NULL)
- errx(1, "missing TargetAddress for target \"%s\"",
+ xo_errx(1, "missing TargetAddress for target \"%s\"",
targ->t_nickname);
if (targ->t_initiator_name == NULL)
targ->t_initiator_name = default_initiator_name();
if (valid_iscsi_name(targ->t_initiator_name) == false)
- errx(1, "invalid initiator name \"%s\"",
+ xo_errx(1, "invalid initiator name \"%s\"",
targ->t_initiator_name);
if (targ->t_header_digest == DIGEST_UNSPECIFIED)
targ->t_header_digest = DIGEST_NONE;
@@ -268,19 +268,19 @@ conf_verify(struct conf *conf)
}
if (targ->t_auth_method == AUTH_METHOD_CHAP) {
if (targ->t_user == NULL) {
- errx(1, "missing chapIName for target \"%s\"",
+ xo_errx(1, "missing chapIName for target \"%s\"",
targ->t_nickname);
}
if (targ->t_secret == NULL)
- errx(1, "missing chapSecret for target \"%s\"",
+ xo_errx(1, "missing chapSecret for target \"%s\"",
targ->t_nickname);
if (targ->t_mutual_user != NULL ||
targ->t_mutual_secret != NULL) {
if (targ->t_mutual_user == NULL)
- errx(1, "missing tgtChapName for "
+ xo_errx(1, "missing tgtChapName for "
"target \"%s\"", targ->t_nickname);
if (targ->t_mutual_secret == NULL)
- errx(1, "missing tgtChapSecret for "
+ xo_errx(1, "missing tgtChapSecret for "
"target \"%s\"", targ->t_nickname);
}
}
@@ -327,6 +327,9 @@ conf_from_target(struct iscsi_session_conf *conf,
conf->isc_discovery = 1;
if (targ->t_protocol == PROTOCOL_ISER)
conf->isc_iser = 1;
+ if (targ->t_offload != NULL)
+ strlcpy(conf->isc_offload, targ->t_offload,
+ sizeof(conf->isc_offload));
if (targ->t_header_digest == DIGEST_CRC32C)
conf->isc_header_digest = ISCSI_DIGEST_CRC32C;
else
@@ -347,7 +350,7 @@ kernel_add(int iscsi_fd, const struct target *targ)
conf_from_target(&isa.isa_conf, targ);
error = ioctl(iscsi_fd, ISCSISADD, &isa);
if (error != 0)
- warn("ISCSISADD");
+ xo_warn("ISCSISADD");
return (error);
}
@@ -362,7 +365,7 @@ kernel_modify(int iscsi_fd, unsigned int session_id, const struct target *targ)
conf_from_target(&ism.ism_conf, targ);
error = ioctl(iscsi_fd, ISCSISMODIFY, &ism);
if (error != 0)
- warn("ISCSISMODIFY");
+ xo_warn("ISCSISMODIFY");
return (error);
}
@@ -382,7 +385,7 @@ kernel_modify_some(int iscsi_fd, unsigned int session_id, const char *target,
states = realloc(states,
nentries * sizeof(struct iscsi_session_state));
if (states == NULL)
- err(1, "realloc");
+ xo_err(1, "realloc");
memset(&isl, 0, sizeof(isl));
isl.isl_nentries = nentries;
@@ -396,7 +399,7 @@ kernel_modify_some(int iscsi_fd, unsigned int session_id, const char *target,
break;
}
if (error != 0)
- errx(1, "ISCSISLIST");
+ xo_errx(1, "ISCSISLIST");
for (i = 0; i < isl.isl_nentries; i++) {
state = &states[i];
@@ -405,7 +408,7 @@ kernel_modify_some(int iscsi_fd, unsigned int session_id, const char *target,
break;
}
if (i == isl.isl_nentries)
- errx(1, "session-id %u not found", session_id);
+ xo_errx(1, "session-id %u not found", session_id);
conf = &state->iss_conf;
@@ -424,7 +427,7 @@ kernel_modify_some(int iscsi_fd, unsigned int session_id, const char *target,
memcpy(&ism.ism_conf, conf, sizeof(ism.ism_conf));
error = ioctl(iscsi_fd, ISCSISMODIFY, &ism);
if (error != 0)
- warn("ISCSISMODIFY");
+ xo_warn("ISCSISMODIFY");
}
static int
@@ -437,7 +440,7 @@ kernel_remove(int iscsi_fd, const struct target *targ)
conf_from_target(&isr.isr_conf, targ);
error = ioctl(iscsi_fd, ISCSISREMOVE, &isr);
if (error != 0)
- warn("ISCSISREMOVE");
+ xo_warn("ISCSISREMOVE");
return (error);
}
@@ -459,7 +462,7 @@ kernel_list(int iscsi_fd, const struct target *targ __unused,
states = realloc(states,
nentries * sizeof(struct iscsi_session_state));
if (states == NULL)
- err(1, "realloc");
+ xo_err(1, "realloc");
memset(&isl, 0, sizeof(isl));
isl.isl_nentries = nentries;
@@ -473,78 +476,117 @@ kernel_list(int iscsi_fd, const struct target *targ __unused,
break;
}
if (error != 0) {
- warn("ISCSISLIST");
+ xo_warn("ISCSISLIST");
return (error);
}
if (verbose != 0) {
+ xo_open_list("session");
for (i = 0; i < isl.isl_nentries; i++) {
state = &states[i];
conf = &state->iss_conf;
- printf("Session ID: %u\n", state->iss_id);
- printf("Initiator name: %s\n", conf->isc_initiator);
- printf("Initiator portal: %s\n",
- conf->isc_initiator_addr);
- printf("Initiator alias: %s\n",
- conf->isc_initiator_alias);
- printf("Target name: %s\n", conf->isc_target);
- printf("Target portal: %s\n",
- conf->isc_target_addr);
- printf("Target alias: %s\n",
- state->iss_target_alias);
- printf("User: %s\n", conf->isc_user);
- printf("Secret: %s\n", conf->isc_secret);
- printf("Mutual user: %s\n",
- conf->isc_mutual_user);
- printf("Mutual secret: %s\n",
- conf->isc_mutual_secret);
- printf("Session type: %s\n",
+ xo_open_instance("session");
+
+ /*
+ * Display-only modifier as this information
+ * is also present within the 'session' container
+ */
+ xo_emit("{L:/%-18s}{V:sessionId/%u}\n",
+ "Session ID:", state->iss_id);
+
+ xo_open_container("initiator");
+ xo_emit("{L:/%-18s}{V:name/%s}\n",
+ "Initiator name:", conf->isc_initiator);
+ xo_emit("{L:/%-18s}{V:portal/%s}\n",
+ "Initiator portal:", conf->isc_initiator_addr);
+ xo_emit("{L:/%-18s}{V:alias/%s}\n",
+ "Initiator alias:", conf->isc_initiator_alias);
+ xo_close_container("initiator");
+
+ xo_open_container("target");
+ xo_emit("{L:/%-18s}{V:name/%s}\n",
+ "Target name:", conf->isc_target);
+ xo_emit("{L:/%-18s}{V:portal/%s}\n",
+ "Target portal:", conf->isc_target_addr);
+ xo_emit("{L:/%-18s}{V:alias/%s}\n",
+ "Target alias:", state->iss_target_alias);
+ xo_close_container("target");
+
+ xo_open_container("auth");
+ xo_emit("{L:/%-18s}{V:user/%s}\n",
+ "User:", conf->isc_user);
+ xo_emit("{L:/%-18s}{V:secret/%s}\n",
+ "Secret:", conf->isc_secret);
+ xo_emit("{L:/%-18s}{V:mutualUser/%s}\n",
+ "Mutual user:", conf->isc_mutual_user);
+ xo_emit("{L:/%-18s}{V:mutualSecret/%s}\n",
+ "Mutual secret:", conf->isc_mutual_secret);
+ xo_close_container("auth");
+
+ xo_emit("{L:/%-18s}{V:type/%s}\n",
+ "Session type:",
conf->isc_discovery ? "Discovery" : "Normal");
- printf("Session state: %s\n",
- state->iss_connected ?
- "Connected" : "Disconnected");
- printf("Failure reason: %s\n", state->iss_reason);
- printf("Header digest: %s\n",
+ xo_emit("{L:/%-18s}{V:state/%s}\n",
+ "Session state:",
+ state->iss_connected ? "Connected" : "Disconnected");
+ xo_emit("{L:/%-18s}{V:failureReason/%s}\n",
+ "Failure reason:", state->iss_reason);
+ xo_emit("{L:/%-18s}{V:headerDigest/%s}\n",
+ "Header digest:",
state->iss_header_digest == ISCSI_DIGEST_CRC32C ?
"CRC32C" : "None");
- printf("Data digest: %s\n",
+ xo_emit("{L:/%-18s}{V:dataDigest/%s}\n",
+ "Data digest:",
state->iss_data_digest == ISCSI_DIGEST_CRC32C ?
"CRC32C" : "None");
- printf("DataSegmentLen: %d\n",
- state->iss_max_data_segment_length);
- printf("ImmediateData: %s\n",
- state->iss_immediate_data ? "Yes" : "No");
- printf("iSER (RDMA): %s\n",
- conf->isc_iser ? "Yes" : "No");
- printf("Device nodes: ");
+ xo_emit("{L:/%-18s}{V:dataSegmentLen/%d}\n",
+ "DataSegmentLen:", state->iss_max_data_segment_length);
+ xo_emit("{L:/%-18s}{V:immediateData/%s}\n",
+ "ImmediateData:", state->iss_immediate_data ? "Yes" : "No");
+ xo_emit("{L:/%-18s}{V:iSER/%s}\n",
+ "iSER (RDMA):", conf->isc_iser ? "Yes" : "No");
+ xo_emit("{L:/%-18s}{V:offloadDriver/%s}\n",
+ "Offload driver:", state->iss_offload);
+ xo_emit("{L:/%-18s}",
+ "Device nodes:");
print_periphs(state->iss_id);
- printf("\n\n");
+ xo_emit("\n\n");
+ xo_close_instance("session");
}
+ xo_close_list("session");
} else {
- printf("%-36s %-16s %s\n",
+ xo_emit("{T:/%-36s} {T:/%-16s} {T:/%s}\n",
"Target name", "Target portal", "State");
+
+ if (isl.isl_nentries != 0)
+ xo_open_list("session");
for (i = 0; i < isl.isl_nentries; i++) {
+
state = &states[i];
conf = &state->iss_conf;
- printf("%-36s %-16s ",
+ xo_open_instance("session");
+ xo_emit("{V:name/%-36s/%s} {V:portal/%-16s/%s} ",
conf->isc_target, conf->isc_target_addr);
if (state->iss_reason[0] != '\0') {
- printf("%s\n", state->iss_reason);
+ xo_emit("{V:state/%s}\n", state->iss_reason);
} else {
if (conf->isc_discovery) {
- printf("Discovery\n");
+ xo_emit("{V:state}\n", "Discovery");
} else if (state->iss_connected) {
- printf("Connected: ");
+ xo_emit("{V:state}: ", "Connected");
print_periphs(state->iss_id);
- printf("\n");
+ xo_emit("\n");
} else {
- printf("Disconnected\n");
+ xo_emit("{V:state}\n", "Disconnected");
}
}
+ xo_close_instance("session");
}
+ if (isl.isl_nentries != 0)
+ xo_close_list("session");
}
return (0);
@@ -578,7 +620,7 @@ checked_strdup(const char *s)
c = strdup(s);
if (c == NULL)
- err(1, "strdup");
+ xo_err(1, "strdup");
return (c);
}
@@ -596,6 +638,9 @@ main(int argc, char **argv)
struct conf *conf;
struct target *targ;
+ argc = xo_parse_args(argc, argv);
+ xo_open_container("iscsictl");
+
while ((ch = getopt(argc, argv, "AMRLac:d:i:n:p:t:u:s:v")) != -1) {
switch (ch) {
case 'A':
@@ -622,11 +667,11 @@ main(int argc, char **argv)
case 'i':
session_id = strtol(optarg, &end, 10);
if ((size_t)(end - optarg) != strlen(optarg))
- errx(1, "trailing characters after session-id");
+ xo_errx(1, "trailing characters after session-id");
if (session_id < 0)
- errx(1, "session-id cannot be negative");
+ xo_errx(1, "session-id cannot be negative");
if (session_id > UINT_MAX)
- errx(1, "session-id cannot be greater than %u",
+ xo_errx(1, "session-id cannot be greater than %u",
UINT_MAX);
break;
case 'n':
@@ -659,7 +704,7 @@ main(int argc, char **argv)
if (Aflag + Mflag + Rflag + Lflag == 0)
Lflag = 1;
if (Aflag + Mflag + Rflag + Lflag > 1)
- errx(1, "at most one of -A, -M, -R, or -L may be specified");
+ xo_errx(1, "at most one of -A, -M, -R, or -L may be specified");
/*
* Note that we ignore unneccessary/inapplicable "-c" flag; so that
@@ -669,122 +714,122 @@ main(int argc, char **argv)
if (Aflag != 0) {
if (aflag != 0) {
if (portal != NULL)
- errx(1, "-a and -p and mutually exclusive");
+ xo_errx(1, "-a and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-a and -t and mutually exclusive");
+ xo_errx(1, "-a and -t and mutually exclusive");
if (user != NULL)
- errx(1, "-a and -u and mutually exclusive");
+ xo_errx(1, "-a and -u and mutually exclusive");
if (secret != NULL)
- errx(1, "-a and -s and mutually exclusive");
+ xo_errx(1, "-a and -s and mutually exclusive");
if (nickname != NULL)
- errx(1, "-a and -n and mutually exclusive");
+ xo_errx(1, "-a and -n and mutually exclusive");
if (discovery_host != NULL)
- errx(1, "-a and -d and mutually exclusive");
+ xo_errx(1, "-a and -d and mutually exclusive");
} else if (nickname != NULL) {
if (portal != NULL)
- errx(1, "-n and -p and mutually exclusive");
+ xo_errx(1, "-n and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-n and -t and mutually exclusive");
+ xo_errx(1, "-n and -t and mutually exclusive");
if (user != NULL)
- errx(1, "-n and -u and mutually exclusive");
+ xo_errx(1, "-n and -u and mutually exclusive");
if (secret != NULL)
- errx(1, "-n and -s and mutually exclusive");
+ xo_errx(1, "-n and -s and mutually exclusive");
if (discovery_host != NULL)
- errx(1, "-n and -d and mutually exclusive");
+ xo_errx(1, "-n and -d and mutually exclusive");
} else if (discovery_host != NULL) {
if (portal != NULL)
- errx(1, "-d and -p and mutually exclusive");
+ xo_errx(1, "-d and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-d and -t and mutually exclusive");
+ xo_errx(1, "-d and -t and mutually exclusive");
} else {
if (target == NULL && portal == NULL)
- errx(1, "must specify -a, -n or -t/-p");
+ xo_errx(1, "must specify -a, -n or -t/-p");
if (target != NULL && portal == NULL)
- errx(1, "-t must always be used with -p");
+ xo_errx(1, "-t must always be used with -p");
if (portal != NULL && target == NULL)
- errx(1, "-p must always be used with -t");
+ xo_errx(1, "-p must always be used with -t");
}
if (user != NULL && secret == NULL)
- errx(1, "-u must always be used with -s");
+ xo_errx(1, "-u must always be used with -s");
if (secret != NULL && user == NULL)
- errx(1, "-s must always be used with -u");
+ xo_errx(1, "-s must always be used with -u");
if (session_id != -1)
- errx(1, "-i cannot be used with -A");
+ xo_errx(1, "-i cannot be used with -A");
if (vflag != 0)
- errx(1, "-v cannot be used with -A");
+ xo_errx(1, "-v cannot be used with -A");
} else if (Mflag != 0) {
if (session_id == -1)
- errx(1, "-M requires -i");
+ xo_errx(1, "-M requires -i");
if (discovery_host != NULL)
- errx(1, "-M and -d are mutually exclusive");
+ xo_errx(1, "-M and -d are mutually exclusive");
if (aflag != 0)
- errx(1, "-M and -a are mutually exclusive");
+ xo_errx(1, "-M and -a are mutually exclusive");
if (nickname != NULL) {
if (portal != NULL)
- errx(1, "-n and -p and mutually exclusive");
+ xo_errx(1, "-n and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-n and -t and mutually exclusive");
+ xo_errx(1, "-n and -t and mutually exclusive");
if (user != NULL)
- errx(1, "-n and -u and mutually exclusive");
+ xo_errx(1, "-n and -u and mutually exclusive");
if (secret != NULL)
- errx(1, "-n and -s and mutually exclusive");
+ xo_errx(1, "-n and -s and mutually exclusive");
}
if (vflag != 0)
- errx(1, "-v cannot be used with -M");
+ xo_errx(1, "-v cannot be used with -M");
} else if (Rflag != 0) {
if (user != NULL)
- errx(1, "-R and -u are mutually exclusive");
+ xo_errx(1, "-R and -u are mutually exclusive");
if (secret != NULL)
- errx(1, "-R and -s are mutually exclusive");
+ xo_errx(1, "-R and -s are mutually exclusive");
if (discovery_host != NULL)
- errx(1, "-R and -d are mutually exclusive");
+ xo_errx(1, "-R and -d are mutually exclusive");
if (aflag != 0) {
if (portal != NULL)
- errx(1, "-a and -p and mutually exclusive");
+ xo_errx(1, "-a and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-a and -t and mutually exclusive");
+ xo_errx(1, "-a and -t and mutually exclusive");
if (nickname != NULL)
- errx(1, "-a and -n and mutually exclusive");
+ xo_errx(1, "-a and -n and mutually exclusive");
} else if (nickname != NULL) {
if (portal != NULL)
- errx(1, "-n and -p and mutually exclusive");
+ xo_errx(1, "-n and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-n and -t and mutually exclusive");
+ xo_errx(1, "-n and -t and mutually exclusive");
} else if (target == NULL && portal == NULL) {
- errx(1, "must specify either -a, -n, -t, or -p");
+ xo_errx(1, "must specify either -a, -n, -t, or -p");
}
if (session_id != -1)
- errx(1, "-i cannot be used with -R");
+ xo_errx(1, "-i cannot be used with -R");
if (vflag != 0)
- errx(1, "-v cannot be used with -R");
+ xo_errx(1, "-v cannot be used with -R");
} else {
assert(Lflag != 0);
if (portal != NULL)
- errx(1, "-L and -p and mutually exclusive");
+ xo_errx(1, "-L and -p and mutually exclusive");
if (target != NULL)
- errx(1, "-L and -t and mutually exclusive");
+ xo_errx(1, "-L and -t and mutually exclusive");
if (user != NULL)
- errx(1, "-L and -u and mutually exclusive");
+ xo_errx(1, "-L and -u and mutually exclusive");
if (secret != NULL)
- errx(1, "-L and -s and mutually exclusive");
+ xo_errx(1, "-L and -s and mutually exclusive");
if (nickname != NULL)
- errx(1, "-L and -n and mutually exclusive");
+ xo_errx(1, "-L and -n and mutually exclusive");
if (discovery_host != NULL)
- errx(1, "-L and -d and mutually exclusive");
+ xo_errx(1, "-L and -d and mutually exclusive");
if (session_id != -1)
- errx(1, "-i cannot be used with -L");
+ xo_errx(1, "-i cannot be used with -L");
}
iscsi_fd = open(ISCSI_PATH, O_RDWR);
@@ -797,7 +842,7 @@ main(int argc, char **argv)
errno = saved_errno;
}
if (iscsi_fd < 0)
- err(1, "failed to open %s", ISCSI_PATH);
+ xo_err(1, "failed to open %s", ISCSI_PATH);
if (Aflag != 0 && aflag != 0) {
conf = conf_new_from_file(conf_path);
@@ -808,7 +853,7 @@ main(int argc, char **argv)
conf = conf_new_from_file(conf_path);
targ = target_find(conf, nickname);
if (targ == NULL)
- errx(1, "target %s not found in %s",
+ xo_errx(1, "target %s not found in %s",
nickname, conf_path);
if (Aflag != 0)
@@ -825,7 +870,7 @@ main(int argc, char **argv)
} else {
if (Aflag != 0 && target != NULL) {
if (valid_iscsi_name(target) == false)
- errx(1, "invalid target name \"%s\"", target);
+ xo_errx(1, "invalid target name \"%s\"", target);
}
conf = conf_new();
targ = target_new(conf);
@@ -853,9 +898,12 @@ main(int argc, char **argv)
error = close(iscsi_fd);
if (error != 0)
- err(1, "close");
+ xo_err(1, "close");
if (failed > 0)
return (1);
+
+ xo_close_container("iscsictl");
+ xo_finish();
return (0);
}
diff --git a/usr.bin/iscsictl/iscsictl.h b/usr.bin/iscsictl/iscsictl.h
index e8d4768..727e8ae 100644
--- a/usr.bin/iscsictl/iscsictl.h
+++ b/usr.bin/iscsictl/iscsictl.h
@@ -72,6 +72,7 @@ struct target {
int t_auth_method;
int t_session_type;
int t_protocol;
+ char *t_offload;
char *t_user;
char *t_secret;
char *t_mutual_user;
diff --git a/usr.bin/iscsictl/parse.y b/usr.bin/iscsictl/parse.y
index e6343f8..9941904 100644
--- a/usr.bin/iscsictl/parse.y
+++ b/usr.bin/iscsictl/parse.y
@@ -34,12 +34,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
-#include <err.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <libxo/xo.h>
+
#include "iscsictl.h"
extern FILE *yyin;
@@ -57,8 +58,8 @@ extern void yyrestart(FILE *);
%token AUTH_METHOD HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS
%token INITIATOR_NAME INITIATOR_ADDRESS INITIATOR_ALIAS USER SECRET
-%token MUTUAL_USER MUTUAL_SECRET SEMICOLON SESSION_TYPE PROTOCOL IGNORED
-%token EQUALS OPENING_BRACKET CLOSING_BRACKET
+%token MUTUAL_USER MUTUAL_SECRET SEMICOLON SESSION_TYPE PROTOCOL OFFLOAD
+%token IGNORED EQUALS OPENING_BRACKET CLOSING_BRACKET
%union
{
@@ -77,7 +78,7 @@ targets:
target: STR OPENING_BRACKET target_entries CLOSING_BRACKET
{
if (target_find(conf, $1) != NULL)
- errx(1, "duplicated target %s", $1);
+ xo_errx(1, "duplicated target %s", $1);
target->t_nickname = $1;
target = target_new(conf);
}
@@ -117,6 +118,8 @@ target_entry:
|
session_type
|
+ offload
+ |
protocol
|
ignored
@@ -125,7 +128,7 @@ target_entry:
target_name: TARGET_NAME EQUALS STR
{
if (target->t_name != NULL)
- errx(1, "duplicated TargetName at line %d", lineno);
+ xo_errx(1, "duplicated TargetName at line %d", lineno);
target->t_name = $3;
}
;
@@ -133,7 +136,7 @@ target_name: TARGET_NAME EQUALS STR
target_address: TARGET_ADDRESS EQUALS STR
{
if (target->t_address != NULL)
- errx(1, "duplicated TargetAddress at line %d", lineno);
+ xo_errx(1, "duplicated TargetAddress at line %d", lineno);
target->t_address = $3;
}
;
@@ -141,7 +144,7 @@ target_address: TARGET_ADDRESS EQUALS STR
initiator_name: INITIATOR_NAME EQUALS STR
{
if (target->t_initiator_name != NULL)
- errx(1, "duplicated InitiatorName at line %d", lineno);
+ xo_errx(1, "duplicated InitiatorName at line %d", lineno);
target->t_initiator_name = $3;
}
;
@@ -149,7 +152,7 @@ initiator_name: INITIATOR_NAME EQUALS STR
initiator_address: INITIATOR_ADDRESS EQUALS STR
{
if (target->t_initiator_address != NULL)
- errx(1, "duplicated InitiatorAddress at line %d", lineno);
+ xo_errx(1, "duplicated InitiatorAddress at line %d", lineno);
target->t_initiator_address = $3;
}
;
@@ -157,7 +160,7 @@ initiator_address: INITIATOR_ADDRESS EQUALS STR
initiator_alias: INITIATOR_ALIAS EQUALS STR
{
if (target->t_initiator_alias != NULL)
- errx(1, "duplicated InitiatorAlias at line %d", lineno);
+ xo_errx(1, "duplicated InitiatorAlias at line %d", lineno);
target->t_initiator_alias = $3;
}
;
@@ -165,7 +168,7 @@ initiator_alias: INITIATOR_ALIAS EQUALS STR
user: USER EQUALS STR
{
if (target->t_user != NULL)
- errx(1, "duplicated chapIName at line %d", lineno);
+ xo_errx(1, "duplicated chapIName at line %d", lineno);
target->t_user = $3;
}
;
@@ -173,7 +176,7 @@ user: USER EQUALS STR
secret: SECRET EQUALS STR
{
if (target->t_secret != NULL)
- errx(1, "duplicated chapSecret at line %d", lineno);
+ xo_errx(1, "duplicated chapSecret at line %d", lineno);
target->t_secret = $3;
}
;
@@ -181,7 +184,7 @@ secret: SECRET EQUALS STR
mutual_user: MUTUAL_USER EQUALS STR
{
if (target->t_mutual_user != NULL)
- errx(1, "duplicated tgtChapName at line %d", lineno);
+ xo_errx(1, "duplicated tgtChapName at line %d", lineno);
target->t_mutual_user = $3;
}
;
@@ -189,7 +192,7 @@ mutual_user: MUTUAL_USER EQUALS STR
mutual_secret: MUTUAL_SECRET EQUALS STR
{
if (target->t_mutual_secret != NULL)
- errx(1, "duplicated tgtChapSecret at line %d", lineno);
+ xo_errx(1, "duplicated tgtChapSecret at line %d", lineno);
target->t_mutual_secret = $3;
}
;
@@ -197,13 +200,13 @@ mutual_secret: MUTUAL_SECRET EQUALS STR
auth_method: AUTH_METHOD EQUALS STR
{
if (target->t_auth_method != AUTH_METHOD_UNSPECIFIED)
- errx(1, "duplicated AuthMethod at line %d", lineno);
+ xo_errx(1, "duplicated AuthMethod at line %d", lineno);
if (strcasecmp($3, "none") == 0)
target->t_auth_method = AUTH_METHOD_NONE;
else if (strcasecmp($3, "chap") == 0)
target->t_auth_method = AUTH_METHOD_CHAP;
else
- errx(1, "invalid AuthMethod at line %d; "
+ xo_errx(1, "invalid AuthMethod at line %d; "
"must be either \"none\" or \"CHAP\"", lineno);
}
;
@@ -211,13 +214,13 @@ auth_method: AUTH_METHOD EQUALS STR
header_digest: HEADER_DIGEST EQUALS STR
{
if (target->t_header_digest != DIGEST_UNSPECIFIED)
- errx(1, "duplicated HeaderDigest at line %d", lineno);
+ xo_errx(1, "duplicated HeaderDigest at line %d", lineno);
if (strcasecmp($3, "none") == 0)
target->t_header_digest = DIGEST_NONE;
else if (strcasecmp($3, "CRC32C") == 0)
target->t_header_digest = DIGEST_CRC32C;
else
- errx(1, "invalid HeaderDigest at line %d; "
+ xo_errx(1, "invalid HeaderDigest at line %d; "
"must be either \"none\" or \"CRC32C\"", lineno);
}
;
@@ -225,13 +228,13 @@ header_digest: HEADER_DIGEST EQUALS STR
data_digest: DATA_DIGEST EQUALS STR
{
if (target->t_data_digest != DIGEST_UNSPECIFIED)
- errx(1, "duplicated DataDigest at line %d", lineno);
+ xo_errx(1, "duplicated DataDigest at line %d", lineno);
if (strcasecmp($3, "none") == 0)
target->t_data_digest = DIGEST_NONE;
else if (strcasecmp($3, "CRC32C") == 0)
target->t_data_digest = DIGEST_CRC32C;
else
- errx(1, "invalid DataDigest at line %d; "
+ xo_errx(1, "invalid DataDigest at line %d; "
"must be either \"none\" or \"CRC32C\"", lineno);
}
;
@@ -239,34 +242,42 @@ data_digest: DATA_DIGEST EQUALS STR
session_type: SESSION_TYPE EQUALS STR
{
if (target->t_session_type != SESSION_TYPE_UNSPECIFIED)
- errx(1, "duplicated SessionType at line %d", lineno);
+ xo_errx(1, "duplicated SessionType at line %d", lineno);
if (strcasecmp($3, "normal") == 0)
target->t_session_type = SESSION_TYPE_NORMAL;
else if (strcasecmp($3, "discovery") == 0)
target->t_session_type = SESSION_TYPE_DISCOVERY;
else
- errx(1, "invalid SessionType at line %d; "
+ xo_errx(1, "invalid SessionType at line %d; "
"must be either \"normal\" or \"discovery\"", lineno);
}
;
+offload: OFFLOAD EQUALS STR
+ {
+ if (target->t_offload != NULL)
+ xo_errx(1, "duplicated offload at line %d", lineno);
+ target->t_offload = $3;
+ }
+ ;
+
protocol: PROTOCOL EQUALS STR
{
if (target->t_protocol != PROTOCOL_UNSPECIFIED)
- errx(1, "duplicated protocol at line %d", lineno);
+ xo_errx(1, "duplicated protocol at line %d", lineno);
if (strcasecmp($3, "iscsi") == 0)
target->t_protocol = PROTOCOL_ISCSI;
else if (strcasecmp($3, "iser") == 0)
target->t_protocol = PROTOCOL_ISER;
else
- errx(1, "invalid protocol at line %d; "
+ xo_errx(1, "invalid protocol at line %d; "
"must be either \"iscsi\" or \"iser\"", lineno);
}
;
ignored: IGNORED EQUALS STR
{
- warnx("obsolete statement ignored at line %d", lineno);
+ xo_warnx("obsolete statement ignored at line %d", lineno);
}
;
@@ -276,7 +287,7 @@ void
yyerror(const char *str)
{
- errx(1, "error in configuration file at line %d near '%s': %s",
+ xo_errx(1, "error in configuration file at line %d near '%s': %s",
lineno, yytext, str);
}
@@ -288,19 +299,19 @@ check_perms(const char *path)
error = stat(path, &sb);
if (error != 0) {
- warn("stat");
+ xo_warn("stat");
return;
}
if (sb.st_mode & S_IWOTH) {
- warnx("%s is world-writable", path);
+ xo_warnx("%s is world-writable", path);
} else if (sb.st_mode & S_IROTH) {
- warnx("%s is world-readable", path);
+ xo_warnx("%s is world-readable", path);
} else if (sb.st_mode & S_IXOTH) {
/*
* Ok, this one doesn't matter, but still do it,
* just for consistency.
*/
- warnx("%s is world-executable", path);
+ xo_warnx("%s is world-executable", path);
}
/*
@@ -318,7 +329,7 @@ conf_new_from_file(const char *path)
yyin = fopen(path, "r");
if (yyin == NULL)
- err(1, "unable to open configuration file %s", path);
+ xo_err(1, "unable to open configuration file %s", path);
check_perms(path);
lineno = 1;
yyrestart(yyin);
diff --git a/usr.bin/iscsictl/periphs.c b/usr.bin/iscsictl/periphs.c
index fb4a686..0697860 100644
--- a/usr.bin/iscsictl/periphs.c
+++ b/usr.bin/iscsictl/periphs.c
@@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$");
#include <inttypes.h>
#include <limits.h>
#include <fcntl.h>
-#include <err.h>
#include <cam/cam.h>
#include <cam/cam_debug.h>
@@ -58,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <cam/scsi/smp_all.h>
#include <cam/ata/ata_all.h>
#include <camlib.h>
+#include <libxo/xo.h>
#include "iscsictl.h"
@@ -67,10 +67,11 @@ print_periphs(int session_id)
union ccb ccb;
int bufsize, fd;
unsigned int i;
- int skip_bus, skip_device;
+ int have_path_id, skip_bus, skip_device;
+ path_id_t path_id;
if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
- warn("couldn't open %s", XPT_DEVICE);
+ xo_warn("couldn't open %s", XPT_DEVICE);
return;
}
@@ -89,7 +90,7 @@ print_periphs(int session_id)
ccb.cdm.match_buf_len = bufsize;
ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
if (ccb.cdm.matches == NULL) {
- warnx("can't malloc memory for matches");
+ xo_warnx("can't malloc memory for matches");
close(fd);
return;
}
@@ -102,23 +103,27 @@ print_periphs(int session_id)
ccb.cdm.num_patterns = 0;
ccb.cdm.pattern_buf_len = 0;
+ path_id = -1; /* Make GCC happy. */
+ have_path_id = 0;
skip_bus = 1;
skip_device = 1;
+ xo_open_container("devices");
+ xo_open_list("lun");
/*
* We do the ioctl multiple times if necessary, in case there are
* more than 100 nodes in the EDT.
*/
do {
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
- warn("error sending CAMIOCOMMAND ioctl");
+ xo_warn("error sending CAMIOCOMMAND ioctl");
break;
}
if ((ccb.ccb_h.status != CAM_REQ_CMP)
|| ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
&& (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
- warnx("got CAM error %#x, CDM error %d\n",
+ xo_warnx("got CAM error %#x, CDM error %d\n",
ccb.ccb_h.status, ccb.cdm.status);
break;
}
@@ -141,7 +146,6 @@ print_periphs(int session_id)
//printf("wrong unit, %d != %d\n", bus_result->unit_number, session_id);
continue;
}
-
skip_bus = 0;
}
case DEV_MATCH_DEVICE: {
@@ -151,7 +155,6 @@ print_periphs(int session_id)
continue;
skip_device = 0;
-
break;
}
case DEV_MATCH_PERIPH: {
@@ -166,9 +169,17 @@ print_periphs(int session_id)
if (strcmp(periph_result->periph_name, "pass") == 0)
continue;
- fprintf(stdout, "%s%d ",
- periph_result->periph_name,
- periph_result->unit_number);
+ xo_open_instance("lun");
+ xo_emit("{e:lun/%d}", periph_result->target_lun);
+ xo_emit("{Vq:device/%s%d} ",
+ periph_result->periph_name,
+ periph_result->unit_number);
+ xo_close_instance("lun");
+
+ if (have_path_id == 0) {
+ path_id = periph_result->path_id;
+ have_path_id = 1;
+ }
break;
}
@@ -180,6 +191,11 @@ print_periphs(int session_id)
} while ((ccb.ccb_h.status == CAM_REQ_CMP)
&& (ccb.cdm.status == CAM_DEV_MATCH_MORE));
+ xo_close_list("lun");
+
+ xo_emit("{e:scbus/%d}{e:bus/%d}{e:target/%d}",
+ have_path_id ? (int)path_id : -1, 0, have_path_id ? 0 : -1);
+ xo_close_container("devices");
close(fd);
}
diff --git a/usr.bin/iscsictl/token.l b/usr.bin/iscsictl/token.l
index 06af167..8cf2fec 100644
--- a/usr.bin/iscsictl/token.l
+++ b/usr.bin/iscsictl/token.l
@@ -63,6 +63,7 @@ tgtChapSecret { return MUTUAL_SECRET; }
AuthMethod { return AUTH_METHOD; }
SessionType { return SESSION_TYPE; }
protocol { return PROTOCOL; }
+offload { return OFFLOAD; }
port { return IGNORED; }
MaxConnections { return IGNORED; }
TargetAlias { return IGNORED; }
diff --git a/usr.bin/jot/jot.1 b/usr.bin/jot/jot.1
index b6d1d14..8b93837 100644
--- a/usr.bin/jot/jot.1
+++ b/usr.bin/jot/jot.1
@@ -28,7 +28,7 @@
.\" @(#)jot.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd June 2, 2010
+.Dd April 7, 2015
.Dt JOT 1
.Os
.Sh NAME
@@ -324,3 +324,5 @@ The
.Nm
utility first appeared in
.Bx 4.2 .
+.Sh AUTHORS
+.An John A. Kunze
diff --git a/usr.bin/kdump/Makefile b/usr.bin/kdump/Makefile
index e91a8ea..601192b 100644
--- a/usr.bin/kdump/Makefile
+++ b/usr.bin/kdump/Makefile
@@ -11,12 +11,11 @@ SFX= 32
PROG= kdump
SRCS= kdump_subr.c kdump.c ioctl.c subr.c
-DPSRCS= kdump_subr.h
+DPSRCS= kdump_subr.h
CFLAGS+= -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
.if ${MK_CASPER} != "no"
-DPADD+= ${LIBCAPSICUM} ${LIBNV}
-LDADD+= -lcapsicum -lnv
+LIBADD= capsicum
CFLAGS+=-DHAVE_LIBCAPSICUM
.endif
@@ -24,13 +23,13 @@ CFLAGS+=-DHAVE_LIBCAPSICUM
CFLAGS+=-DPF
.endif
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
-SRCS+= linux_syscalls.c
-.endif
-
NO_WERROR?= YES
-CLEANFILES= ioctl.c kdump_subr.c kdump_subr.h linux_syscalls.c
+CLEANFILES= ioctl.c kdump_subr.c kdump_subr.h
+
+.if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386")
+CLEANFILES+= linux_syscalls.c
+.endif
ioctl.c: mkioctls
env MACHINE=${MACHINE} CPP="${CPP}" \
@@ -42,11 +41,9 @@ kdump_subr.h: mksubr
kdump_subr.c: mksubr kdump_subr.h
sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} >${.TARGET}
-
-linux_syscalls.c:
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh \
+.if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386")
+ sh ${.CURDIR}/../../sys/kern/makesyscalls.sh \
${.CURDIR}/../../sys/${MACHINE_ARCH}/linux${SFX}/syscalls.master ${.CURDIR}/linux_syscalls.conf
- echo "int nlinux_syscalls = sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);" \
- >> linux_syscalls.c
+.endif
.include <bsd.prog.mk>
diff --git a/usr.bin/kdump/Makefile.depend b/usr.bin/kdump/Makefile.depend
index 07c251c..dcb7174 100644
--- a/usr.bin/kdump/Makefile.depend
+++ b/usr.bin/kdump/Makefile.depend
@@ -24,11 +24,11 @@ DIRDEPS = \
ioctl.o: ioctl.c
ioctl.po: ioctl.c
kdump.o: kdump_subr.h
+kdump.o: linux_syscalls.c
kdump.po: kdump_subr.h
+kdump.po: linux_syscalls.c
kdump_subr.o: kdump_subr.c
kdump_subr.o: kdump_subr.h
kdump_subr.po: kdump_subr.c
kdump_subr.po: kdump_subr.h
-linux_syscalls.o: linux_syscalls.c
-linux_syscalls.po: linux_syscalls.c
.endif
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index e0a6079..a46fe65 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -148,8 +148,11 @@ static struct ktr_header ktr_header;
void linux_ktrsyscall(struct ktr_syscall *);
void linux_ktrsysret(struct ktr_sysret *);
-extern char *linux_syscallnames[];
-extern int nlinux_syscalls;
+extern const char *linux_syscallnames[];
+
+#include <linux_syscalls.c>
+static int nlinux_syscalls = sizeof(linux_syscallnames) / \
+ sizeof(linux_syscallnames[0]);
/*
* from linux.h
@@ -349,8 +352,6 @@ main(int argc, char *argv[])
limitfd(STDIN_FILENO);
limitfd(STDOUT_FILENO);
limitfd(STDERR_FILENO);
- if (cap_sandboxed())
- fprintf(stderr, "capability mode sandbox enabled\n");
TAILQ_INIT(&trace_procs);
drop_logged = 0;
@@ -583,6 +584,7 @@ dumpheader(struct ktr_header *kth)
static char unknown[64];
static struct timeval prevtime, prevtime_e, temp;
const char *type;
+ const char *sign;
switch (kth->ktr_type) {
case KTR_SYSCALL:
@@ -659,10 +661,20 @@ dumpheader(struct ktr_header *kth)
timevaladd(&kth->ktr_time, &prevtime_e);
}
if (timestamp & TIMESTAMP_RELATIVE) {
+ if (prevtime.tv_sec == 0)
+ prevtime = kth->ktr_time;
temp = kth->ktr_time;
timevalsub(&kth->ktr_time, &prevtime);
- prevtime = temp;
- printf("%jd.%06ld ", (intmax_t)kth->ktr_time.tv_sec,
+ if ((intmax_t)kth->ktr_time.tv_sec < 0) {
+ kth->ktr_time = prevtime;
+ prevtime = temp;
+ timevalsub(&kth->ktr_time, &prevtime);
+ sign = "-";
+ } else {
+ prevtime = temp;
+ sign = "";
+ }
+ printf("%s%jd.%06ld ", sign, (intmax_t)kth->ktr_time.tv_sec,
kth->ktr_time.tv_usec);
}
}
@@ -711,6 +723,7 @@ ktrsyscall(struct ktr_syscall *ktr, u_int flags)
case SYS_readlinkat:
case SYS_renameat:
case SYS_unlinkat:
+ case SYS_utimensat:
putchar('(');
atfdname(*ip, decimal);
c = ',';
@@ -1151,7 +1164,7 @@ ktrsyscall(struct ktr_syscall *ktr, u_int flags)
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- sendfileflagsname(*ip);
+ sendfileflagsname(*(int *)ip);
ip++;
narg--;
break;
@@ -1527,6 +1540,8 @@ ktrcsw(struct ktr_csw *cs)
#define UTRACE_PRELOAD_FINISHED 8
#define UTRACE_INIT_CALL 9
#define UTRACE_FINI_CALL 10
+#define UTRACE_DLSYM_START 11
+#define UTRACE_DLSYM_STOP 12
struct utrace_rtld {
char sig[4]; /* 'RTLD' */
@@ -1606,6 +1621,13 @@ ktruser_rtld(int len, void *p)
printf("RTLD: fini %p for %p (%s)\n", ut->mapbase, ut->handle,
ut->name);
break;
+ case UTRACE_DLSYM_START:
+ printf("RTLD: dlsym(%p, %s)\n", ut->handle, ut->name);
+ break;
+ case UTRACE_DLSYM_STOP:
+ printf("RTLD: %p = dlsym(%p, %s)\n", ut->mapbase, ut->handle,
+ ut->name);
+ break;
default:
cp = p;
cp += 4;
@@ -1934,7 +1956,7 @@ void
ktrfault(struct ktr_fault *ktr)
{
- printf("0x%jx ", ktr->vaddr);
+ printf("0x%jx ", (uintmax_t)ktr->vaddr);
vmprotname(ktr->type);
printf("\n");
}
diff --git a/usr.bin/kdump/mkioctls b/usr.bin/kdump/mkioctls
index f9dff50..6880ee6 100644
--- a/usr.bin/kdump/mkioctls
+++ b/usr.bin/kdump/mkioctls
@@ -54,7 +54,6 @@ BEGIN {
print "#include <bsm/audit.h>"
print "#include <net/ethernet.h>"
print "#include <net/if.h>"
- print "#include <net/if_var.h>"
print "#ifdef PF"
print "#include <net/pfvar.h>"
print "#include <net/if_pfsync.h>"
diff --git a/usr.bin/keylogin/Makefile b/usr.bin/keylogin/Makefile
index 4c03051..2dab249 100644
--- a/usr.bin/keylogin/Makefile
+++ b/usr.bin/keylogin/Makefile
@@ -2,8 +2,7 @@
PROG= keylogin
-DPADD= ${LIBRPCSVC}
-LDADD= -lrpcsvc
+LIBADD= rpcsvc
WARNS?= 0
diff --git a/usr.bin/killall/Makefile b/usr.bin/killall/Makefile
index de58c78..890d7a1 100644
--- a/usr.bin/killall/Makefile
+++ b/usr.bin/killall/Makefile
@@ -1,7 +1,6 @@
# $FreeBSD$
PROG= killall
-DPADD= ${LIBJAIL}
-LDADD= -ljail
+LIBADD= jail
.include <bsd.prog.mk>
diff --git a/usr.bin/killall/killall.c b/usr.bin/killall/killall.c
index b171630..cdb62da 100644
--- a/usr.bin/killall/killall.c
+++ b/usr.bin/killall/killall.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <fcntl.h>
#include <dirent.h>
#include <jail.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -262,7 +263,7 @@ main(int ac, char **av)
errx(1, "%s: not a character device", buf);
tdev = sb.st_rdev;
if (dflag)
- printf("ttydev:0x%x\n", tdev);
+ printf("ttydev:0x%jx\n", (uintmax_t)tdev);
}
if (user) {
uid = strtol(user, &ep, 10);
@@ -410,8 +411,9 @@ main(int ac, char **av)
if (matched == 0)
continue;
if (dflag)
- printf("sig:%d, cmd:%s, pid:%d, dev:0x%x uid:%d\n", sig,
- thiscmd, thispid, thistdev, thisuid);
+ printf("sig:%d, cmd:%s, pid:%d, dev:0x%jx uid:%d\n",
+ sig, thiscmd, thispid, (uintmax_t)thistdev,
+ thisuid);
if (vflag || sflag)
printf("kill -%s %d\n", sys_signame[sig], thispid);
diff --git a/usr.bin/ktrdump/Makefile b/usr.bin/ktrdump/Makefile
index c30dc3d..63cd2cf 100644
--- a/usr.bin/ktrdump/Makefile
+++ b/usr.bin/ktrdump/Makefile
@@ -1,8 +1,7 @@
# $FreeBSD$
PROG= ktrdump
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+LIBADD= kvm
MAN= ktrdump.8
WARNS?= 2
diff --git a/usr.bin/ktrdump/ktrdump.8 b/usr.bin/ktrdump/ktrdump.8
index 697e418..8dade55 100644
--- a/usr.bin/ktrdump/ktrdump.8
+++ b/usr.bin/ktrdump/ktrdump.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 8, 2005
+.Dd February 6, 2015
.Dt KTRDUMP 8
.Os
.Sh NAME
@@ -34,9 +34,9 @@
.Sh SYNOPSIS
.Nm
.Op Fl cfqrtH
-.Op Fl e Ar execfile
.Op Fl i Ar ktrfile
-.Op Fl m Ar corefile
+.Op Fl M Ar core
+.Op Fl N Ar system
.Op Fl o Ar outfile
.Sh DESCRIPTION
The
@@ -44,7 +44,7 @@ The
utility is used to dump the contents of the kernel ktr trace buffer.
.Pp
The following options are available:
-.Bl -tag -width ".Fl e Ar execfile"
+.Bl -tag -width ".Fl i Ar ktrfile"
.It Fl c
Print the CPU number that each entry was logged from.
.It Fl f
@@ -61,11 +61,11 @@ Print the thread ID for each entry.
File containing saved ktr trace events; for more information see the
.Xr ktr 4
manual page.
-.It Fl e Ar execfile
+.It Fl N Ar system
The kernel image to resolve symbols from.
The default is the value returned via
.Xr getbootfile 3 .
-.It Fl m Ar corefile
+.It Fl M Ar core
The core file or memory image to read from.
The default is
.Pa /dev/mem .
diff --git a/usr.bin/ktrdump/ktrdump.c b/usr.bin/ktrdump/ktrdump.c
index 11e78e9..84ab3a8 100644
--- a/usr.bin/ktrdump/ktrdump.c
+++ b/usr.bin/ktrdump/ktrdump.c
@@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$");
#define SBUFLEN 128
#define USAGE \
- "usage: ktrdump [-cfqrtH] [-e execfile] [-i ktrfile] [-m corefile] [-o outfile]\n"
+ "usage: ktrdump [-cfqrtH] [-i ktrfile] [-M core] [-N system] [-o outfile]\n"
static void usage(void);
@@ -59,9 +59,9 @@ static struct nlist nl[] = {
};
static int cflag;
-static int eflag;
static int fflag;
-static int mflag;
+static int Mflag;
+static int Nflag;
static int qflag;
static int rflag;
static int tflag;
@@ -103,16 +103,17 @@ main(int ac, char **av)
* Parse commandline arguments.
*/
out = stdout;
- while ((c = getopt(ac, av, "cfqrtHe:i:m:o:")) != -1)
+ while ((c = getopt(ac, av, "cfqrtHe:i:m:M:N:o:")) != -1)
switch (c) {
case 'c':
cflag = 1;
break;
+ case 'N':
case 'e':
if (strlcpy(execfile, optarg, sizeof(execfile))
>= sizeof(execfile))
errx(1, "%s: File name too long", optarg);
- eflag = 1;
+ Nflag = 1;
break;
case 'f':
fflag = 1;
@@ -122,11 +123,12 @@ main(int ac, char **av)
if ((in = open(optarg, O_RDONLY)) == -1)
err(1, "%s", optarg);
break;
+ case 'M':
case 'm':
if (strlcpy(corefile, optarg, sizeof(corefile))
>= sizeof(corefile))
errx(1, "%s: File name too long", optarg);
- mflag = 1;
+ Mflag = 1;
break;
case 'o':
if ((out = fopen(optarg, "w")) == NULL)
@@ -157,8 +159,8 @@ main(int ac, char **av)
* Open our execfile and corefile, resolve needed symbols and read in
* the trace buffer.
*/
- if ((kd = kvm_openfiles(eflag ? execfile : NULL,
- mflag ? corefile : NULL, NULL, O_RDONLY, errbuf)) == NULL)
+ if ((kd = kvm_openfiles(Nflag ? execfile : NULL,
+ Mflag ? corefile : NULL, NULL, O_RDONLY, errbuf)) == NULL)
errx(1, "%s", errbuf);
if (kvm_nlist(kd, nl) != 0 ||
kvm_read(kd, nl[0].n_value, &version, sizeof(version)) == -1)
diff --git a/usr.bin/lam/lam.1 b/usr.bin/lam/lam.1
index 5c95a3f..896cea2 100644
--- a/usr.bin/lam/lam.1
+++ b/usr.bin/lam/lam.1
@@ -28,7 +28,7 @@
.\" @(#)lam.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd August 12, 2004
+.Dd April 7, 2015
.Dt LAM 1
.Os
.Sh NAME
@@ -136,6 +136,8 @@ The
.Nm
utility first appeared in
.Bx 4.2 .
+.Sh AUTHORS
+.An John A. Kunze
.Sh BUGS
The
.Nm
diff --git a/usr.bin/last/last.1 b/usr.bin/last/last.1
index 6cb2e68..e552dd6 100644
--- a/usr.bin/last/last.1
+++ b/usr.bin/last/last.1
@@ -198,9 +198,9 @@ login data base
.El
.Sh SEE ALSO
.Xr lastcomm 1 ,
-.Xr lastlogin 8 ,
.Xr getutxent 3 ,
-.Xr ac 8
+.Xr ac 8 ,
+.Xr lastlogin 8
.Sh HISTORY
A
.Nm
diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c
index bc4dbb6..2f48e04 100644
--- a/usr.bin/ldd/ldd.c
+++ b/usr.bin/ldd/ldd.c
@@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$");
#include <arpa/inet.h>
-#include <a.out.h>
#include <dlfcn.h>
#include <err.h>
#include <errno.h>
@@ -49,6 +48,12 @@ __FBSDID("$FreeBSD$");
#include "extern.h"
+/* We don't support a.out executables on arm64 */
+#ifndef __aarch64__
+#include <a.out.h>
+#define AOUT_SUPPORTED
+#endif
+
/*
* 32-bit ELF data structures can only be used if the system header[s] declare
* them. There is no official macro for determining whether they are declared,
@@ -274,7 +279,9 @@ static int
is_executable(const char *fname, int fd, int *is_shlib, int *type)
{
union {
+#ifdef AOUT_SUPPORTED
struct exec aout;
+#endif
#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
Elf32_Ehdr elf32;
#endif
@@ -290,6 +297,7 @@ is_executable(const char *fname, int fd, int *is_shlib, int *type)
return (0);
}
+#ifdef AOUT_SUPPORTED
if ((size_t)n >= sizeof(hdr.aout) && !N_BADMAG(hdr.aout)) {
/* a.out file */
if ((N_GETFLAG(hdr.aout) & EX_DPMASK) != EX_DYNAMIC
@@ -303,6 +311,7 @@ is_executable(const char *fname, int fd, int *is_shlib, int *type)
*type = TYPE_AOUT;
return (1);
}
+#endif
#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
if ((size_t)n >= sizeof(hdr.elf32) && IS_ELF(hdr.elf32) &&
diff --git a/usr.bin/less/Makefile b/usr.bin/less/Makefile
index 22147cd..b6adf2c 100644
--- a/usr.bin/less/Makefile
+++ b/usr.bin/less/Makefile
@@ -8,8 +8,7 @@ SRCS= main.c screen.c brac.c ch.c charset.c cmdbuf.c command.c cvt.c \
signal.c tags.c ttyin.c version.c
SCRIPTS=lesspipe.sh zless.sh
SCRIPTSNAME_lesspipe.sh=lesspipe.sh
-DPADD= ${LIBTERMCAPW}
-LDADD= -ltermcapw
+LIBADD= ncursesw
LINKS= ${BINDIR}/less ${BINDIR}/more \
${BINDIR}/zless ${BINDIR}/bzless \
${BINDIR}/zless ${BINDIR}/xzless \
diff --git a/usr.bin/lex/Makefile b/usr.bin/lex/Makefile
index f896092..faa503a 100644
--- a/usr.bin/lex/Makefile
+++ b/usr.bin/lex/Makefile
@@ -51,7 +51,7 @@ bootstrap: ${GENFILES:S/^/init/g}
@diff -I '^#line ' -I '\$$FreeBS[D]: .*\$$' -q \
${.CURDIR}/init${_f} ${_f} 2> /dev/null || { \
echo "Bootstrapping ${_f}" ; \
- cp -f ${.CURDIR}/init${_f} ${_f} ; \
+ ${CP} ${.CURDIR}/init${_f} ${_f} ; \
}
.endfor
diff --git a/usr.bin/lex/lex.1 b/usr.bin/lex/lex.1
index fdb1881..83d3a0c 100644
--- a/usr.bin/lex/lex.1
+++ b/usr.bin/lex/lex.1
@@ -2001,7 +2001,7 @@ can be used to control whether the current buffer's scanning
context for the next token match is done as though at the
beginning of a line.
A non-zero macro argument makes rules anchored with
-'^' active, while a zero argument makes '^' rules inactive.
+ '^' active, while a zero argument makes '^' rules inactive.
.PP
The macro
.B YY_AT_BOL()
@@ -2356,8 +2356,7 @@ automatically anyway.
.TP
.B \-F, \-\-fast
specifies that the
-.ul
-fast
+.I fast
scanner table representation should be used (and stdio
bypassed).
This representation is about as fast as the full table representation
diff --git a/usr.bin/limits/Makefile b/usr.bin/limits/Makefile
index 0133178..13ea597 100644
--- a/usr.bin/limits/Makefile
+++ b/usr.bin/limits/Makefile
@@ -1,7 +1,6 @@
# $FreeBSD$
PROG= limits
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD= util
.include <bsd.prog.mk>
diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c
index a28690a..3ac69b5 100644
--- a/usr.bin/locate/locate/util.c
+++ b/usr.bin/locate/locate/util.c
@@ -235,7 +235,7 @@ getwm(p)
char buf[INTSIZE];
int i;
} u;
- register int i;
+ register int i, hi;
for (i = 0; i < (int)INTSIZE; i++)
u.buf[i] = *p++;
@@ -243,10 +243,11 @@ getwm(p)
i = u.i;
if (i > MAXPATHLEN || i < -(MAXPATHLEN)) {
- i = ntohl(i);
- if (i > MAXPATHLEN || i < -(MAXPATHLEN))
+ hi = ntohl(i);
+ if (hi > MAXPATHLEN || hi < -(MAXPATHLEN))
errx(1, "integer out of +-MAXPATHLEN (%d): %u",
- MAXPATHLEN, abs(i) < abs(htonl(i)) ? i : htonl(i));
+ MAXPATHLEN, abs(i) < abs(hi) ? i : hi);
+ return(hi);
}
return(i);
}
@@ -263,16 +264,16 @@ int
getwf(fp)
FILE *fp;
{
- register int word;
+ register int word, hword;
word = getw(fp);
if (word > MAXPATHLEN || word < -(MAXPATHLEN)) {
- word = ntohl(word);
- if (word > MAXPATHLEN || word < -(MAXPATHLEN))
+ hword = ntohl(word);
+ if (hword > MAXPATHLEN || hword < -(MAXPATHLEN))
errx(1, "integer out of +-MAXPATHLEN (%d): %u",
- MAXPATHLEN, abs(word) < abs(htonl(word)) ? word :
- htonl(word));
+ MAXPATHLEN, abs(word) < abs(hword) ? word : hword);
+ return(hword);
}
return(word);
}
diff --git a/usr.bin/lock/Makefile b/usr.bin/lock/Makefile
index dc09a87..cc5d689 100644
--- a/usr.bin/lock/Makefile
+++ b/usr.bin/lock/Makefile
@@ -4,7 +4,7 @@
PROG= lock
BINOWN= root
BINMODE=4555
-DPADD= ${LIBCRYPT}
-LDADD= -lcrypt
+
+LIBADD= crypt
.include <bsd.prog.mk>
diff --git a/usr.bin/lockf/lockf.1 b/usr.bin/lockf/lockf.1
index 57119e5..e6204a1 100644
--- a/usr.bin/lockf/lockf.1
+++ b/usr.bin/lockf/lockf.1
@@ -162,6 +162,7 @@ but may have been signaled or stopped.
.El
.Sh SEE ALSO
.Xr flock 2 ,
+.Xr lockf 3 ,
.Xr sysexits 3
.Sh HISTORY
A
diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c
index 9a6141f..5555c48 100644
--- a/usr.bin/lockf/lockf.c
+++ b/usr.bin/lockf/lockf.c
@@ -169,7 +169,7 @@ acquire_lock(const char *name, int flags)
{
int fd;
- if ((fd = open(name, flags|O_RDONLY|O_EXLOCK|flags, 0666)) == -1) {
+ if ((fd = open(name, O_RDONLY|O_EXLOCK|flags, 0666)) == -1) {
if (errno == EAGAIN || errno == EINTR)
return (-1);
err(EX_CANTCREAT, "cannot open %s", name);
diff --git a/usr.bin/logger/logger.1 b/usr.bin/logger/logger.1
index 46a2d0f..f82bc44 100644
--- a/usr.bin/logger/logger.1
+++ b/usr.bin/logger/logger.1
@@ -28,7 +28,7 @@
.\" @(#)logger.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd March 4, 2014
+.Dd March 21, 2015
.Dt LOGGER 1
.Os
.Sh NAME
@@ -75,6 +75,7 @@ with each line.
Log the message to standard error, as well as the system log.
.It Fl f Ar file
Read the contents of the specified file into syslog.
+This option is ignored when a message is also specified.
.It Fl h Ar host
Send the message to the remote system
.Ar host
diff --git a/usr.bin/login/Makefile b/usr.bin/login/Makefile
index 1ebc760..0763c84 100644
--- a/usr.bin/login/Makefile
+++ b/usr.bin/login/Makefile
@@ -6,16 +6,14 @@
PROG= login
SRCS= login.c login_fbtab.c
CFLAGS+=-DLOGALL
-DPADD= ${LIBUTIL} ${LIBPAM}
-LDADD= -lutil ${MINUSLPAM}
+LIBADD= util pam
WARNS?= 5
.if ${MK_AUDIT} != "no"
SRCS+= login_audit.c
CFLAGS+= -DUSE_BSM_AUDIT
-DPADD+= ${LIBBSM}
-LDADD+= -lbsm
+LIBADD+= bsm
.endif
.if ${MK_SETUID_LOGIN} != "no"
diff --git a/usr.bin/lzmainfo/Makefile b/usr.bin/lzmainfo/Makefile
index b92b46c..158a209 100644
--- a/usr.bin/lzmainfo/Makefile
+++ b/usr.bin/lzmainfo/Makefile
@@ -16,7 +16,6 @@ CFLAGS+= -DHAVE_CONFIG_H \
-I${LZMALIBDIR} \
-I${XZDIR}/common
-DPADD= ${LIBLZMA}
-LDADD= -llzma
+LIBADD= lzma
.include <bsd.prog.mk>
diff --git a/usr.bin/lzmainfo/Makefile.depend b/usr.bin/lzmainfo/Makefile.depend
index b7653d1..4915738 100644
--- a/usr.bin/lzmainfo/Makefile.depend
+++ b/usr.bin/lzmainfo/Makefile.depend
@@ -11,6 +11,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/liblzma \
+ lib/libthr \
.include <dirdeps.mk>
diff --git a/usr.bin/m4/Makefile b/usr.bin/m4/Makefile
index 9153e71..d955075 100644
--- a/usr.bin/m4/Makefile
+++ b/usr.bin/m4/Makefile
@@ -8,8 +8,7 @@
PROG= m4
CFLAGS+=-DEXTENDED -I${.CURDIR} -I${.CURDIR}/../../lib/libohash
-DPADD= ${LIBY} ${LIBL} ${LIBM} ${LIBOHASH}
-LDADD= -ly -ll -lm ${LDOHASH}
+LIBADD= y l m ohash
NO_WMISSING_VARIABLE_DECLARATIONS=
diff --git a/usr.bin/m4/Makefile.depend b/usr.bin/m4/Makefile.depend
index 5ef57d9..7c87b49 100644
--- a/usr.bin/m4/Makefile.depend
+++ b/usr.bin/m4/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/liby \
lib/msun \
usr.bin/lex/lib \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index fd2d3ae..d10f9ae 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -43,7 +43,6 @@ extern unsigned long expansion_id;
/* expr.c */
extern int expr(const char *);
-extern int32_t end_result;
/* gnum4.c */
extern void addtoincludepath(const char *);
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c
index cac01ec..dcccf3b 100644
--- a/usr.bin/m4/gnum4.c
+++ b/usr.bin/m4/gnum4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gnum4.c,v 1.46 2014/07/10 14:12:31 espie Exp $ */
+/* $OpenBSD: gnum4.c,v 1.50 2015/04/29 00:13:26 millert Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$");
* functions needed to support gnu-m4 extensions, including a fake freezing
*/
-#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <ctype.h>
@@ -40,10 +39,12 @@ __FBSDID("$FreeBSD$");
#include <regex.h>
#include <stddef.h>
#include <stdlib.h>
+#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
+#include <limits.h>
#include "mdef.h"
#include "stdd.h"
#include "extern.h"
@@ -76,9 +77,7 @@ new_path_entry(const char *dirname)
n = malloc(sizeof(struct path_entry));
if (!n)
errx(1, "out of memory");
- n->name = strdup(dirname);
- if (!n->name)
- errx(1, "out of memory");
+ n->name = xstrdup(dirname);
n->next = 0;
return n;
}
@@ -113,9 +112,7 @@ ensure_m4path(void)
if (!envpath)
return;
/* for portability: getenv result is read-only */
- envpath = strdup(envpath);
- if (!envpath)
- errx(1, "out of memory");
+ envpath = xstrdup(envpath);
for (sweep = envpath;
(path = strsep(&sweep, ":")) != NULL;)
addtoincludepath(path);
@@ -126,7 +123,7 @@ static
struct input_file *
dopath(struct input_file *i, const char *filename)
{
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
struct path_entry *pe;
FILE *f;
@@ -214,8 +211,11 @@ addchars(const char *c, size_t n)
while (current + n > bufsize) {
if (bufsize == 0)
bufsize = 1024;
- else
+ else if (bufsize <= SIZE_MAX/2) {
bufsize *= 2;
+ } else {
+ errx(1, "size overflow");
+ }
buffer = xrealloc(buffer, bufsize, NULL);
}
memcpy(buffer+current, c, n);
diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c
index 70497e0..383fbc6 100644
--- a/usr.bin/m4/look.c
+++ b/usr.bin/m4/look.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: look.c,v 1.23 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: look.c,v 1.24 2014/12/21 09:33:12 espie Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -56,6 +56,9 @@ static void hash_free(void *, void *);
static void *element_alloc(size_t, void *);
static void setup_definition(struct macro_definition *, const char *,
const char *);
+static void free_definition(char *);
+static void keep(char *);
+static int string_in_use(const char *);
static struct ohash_info macro_info = {
offsetof(struct ndblock, name),
@@ -155,7 +158,7 @@ macro_define(const char *name, const char *defn)
ndptr n = create_entry(name);
if (n->d != NULL) {
if (n->d->defn != null)
- free(n->d->defn);
+ free_definition(n->d->defn);
} else {
n->d = xalloc(sizeof(struct macro_definition), NULL);
n->d->next = NULL;
@@ -273,3 +276,64 @@ macro_getbuiltin(const char *name)
else
return p;
}
+
+/* XXX things are slightly more complicated than they seem.
+ * a macro may actually be "live" (in the middle of an expansion
+ * on the stack.
+ * So we actually may need to place it in an array for later...
+ */
+
+static int kept_capacity = 0;
+static int kept_size = 0;
+static char **kept = NULL;
+
+static void
+keep(char *ptr)
+{
+ if (kept_capacity <= kept_size) {
+ if (kept_capacity)
+ kept_capacity *= 2;
+ else
+ kept_capacity = 50;
+ kept = xreallocarray(kept, kept_capacity,
+ sizeof(char *), "Out of memory while saving %d strings\n",
+ kept_capacity);
+ }
+ kept[kept_size++] = ptr;
+}
+
+static int
+string_in_use(const char *ptr)
+{
+ int i;
+ for (i = 0; i <= sp; i++) {
+ if (sstack[i] == STORAGE_MACRO && mstack[i].sstr == ptr)
+ return 1;
+ }
+ return 0;
+}
+
+
+static void
+free_definition(char *ptr)
+{
+ int i;
+
+ /* first try to free old strings */
+ for (i = 0; i < kept_size; i++) {
+ if (!string_in_use(kept[i])) {
+ kept_size--;
+ free(kept[i]);
+ if (i != kept_size)
+ kept[i] = kept[kept_size];
+ i--;
+ }
+ }
+
+ /* then deal with us */
+ if (string_in_use(ptr))
+ keep(ptr);
+ else
+ free(ptr);
+}
+
diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1
index 0e1d83a..b7dc131 100644
--- a/usr.bin/m4/m4.1
+++ b/usr.bin/m4/m4.1
@@ -33,7 +33,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 12, 2014
+.Dd $Mdocdate: April 14 2014 $
.Dt M4 1
.Os
.Sh NAME
@@ -98,7 +98,9 @@ recognized as special when not followed by an open parenthesis.
.Pp
The options are as follows:
.Bl -tag -width Ds
-.It Fl D Ns Ar name Ns Op Pf = Ns Ar value
+.It Fl D Ns Ar name Ns Oo
+.Pf = Ns Ar value
+.Oc
Define the symbol
.Ar name
to have some value (or
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index ced881b..84ba03a 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.83 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: main.c,v 1.84 2014/12/21 09:33:12 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -144,6 +144,9 @@ static struct keyblk keywrds[] = { /* m4 keywords to be installed */
#define MAXKEYS (sizeof(keywrds)/sizeof(struct keyblk))
+extern int optind;
+extern char *optarg;
+
#define MAXRECORD 50
static struct position {
char *name;
@@ -396,7 +399,7 @@ macro(void)
/*
* now push the string arguments:
*/
- pushs1(macro_getdef(p)->defn); /* defn string */
+ pushdef(p); /* defn string */
pushs1((char *)macro_name(p)); /* macro name */
pushs(ep); /* start next..*/
diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h
index 0db78ef..49b3f50 100644
--- a/usr.bin/m4/mdef.h
+++ b/usr.bin/m4/mdef.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdef.h,v 1.31 2011/09/27 07:24:02 espie Exp $ */
+/* $OpenBSD: mdef.h,v 1.32 2014/12/21 09:33:12 espie Exp $ */
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
/*
@@ -164,6 +164,10 @@ struct input_file {
int c;
};
+#define STORAGE_STRSPACE 0
+#define STORAGE_MACRO 1
+#define STORAGE_OTHER 2
+
#define CURRENT_NAME (infile[ilevel].name)
#define CURRENT_LINE (infile[ilevel].lineno)
/*
@@ -179,7 +183,7 @@ struct input_file {
if (++sp == (int)STACKMAX) \
enlarge_stack();\
mstack[sp].sfra = (x); \
- sstack[sp] = 0; \
+ sstack[sp] = STORAGE_OTHER; \
} while (0)
#define pushs(x) \
@@ -187,7 +191,7 @@ struct input_file {
if (++sp == (int)STACKMAX) \
enlarge_stack();\
mstack[sp].sstr = (x); \
- sstack[sp] = 1; \
+ sstack[sp] = STORAGE_STRSPACE; \
} while (0)
#define pushs1(x) \
@@ -195,8 +199,17 @@ struct input_file {
if (++sp == (int)STACKMAX) \
enlarge_stack();\
mstack[sp].sstr = (x); \
- sstack[sp] = 0; \
+ sstack[sp] = STORAGE_OTHER; \
+ } while (0)
+
+#define pushdef(p) \
+ do { \
+ if (++sp == (int)STACKMAX) \
+ enlarge_stack();\
+ mstack[sp].sstr = macro_getdef(p)->defn;\
+ sstack[sp] = STORAGE_MACRO; \
} while (0)
+
/*
* . .
diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c
index 1959448..eeca68e 100644
--- a/usr.bin/m4/misc.c
+++ b/usr.bin/m4/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.44 2014/05/12 19:11:19 espie Exp $ */
+/* $OpenBSD: misc.c,v 1.45 2014/12/21 09:33:12 espie Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
/*
@@ -187,7 +187,7 @@ enlarge_strspace(void)
errx(1, "string space overflow");
memcpy(newstrspace, strspace, strsize/2);
for (i = 0; i <= sp; i++)
- if (sstack[i])
+ if (sstack[i] == STORAGE_STRSPACE)
mstack[i].sstr = (mstack[i].sstr - strspace)
+ newstrspace;
ep = (ep-strspace) + newstrspace;
@@ -265,7 +265,7 @@ killdiv(void)
extern char *__progname;
void
-m4errx(int exitstatus, const char *fmt, ...)
+m4errx(int eval, const char *fmt, ...)
{
fprintf(stderr, "%s: ", __progname);
fprintf(stderr, "%s at line %lu: ", CURRENT_NAME, CURRENT_LINE);
@@ -277,7 +277,7 @@ m4errx(int exitstatus, const char *fmt, ...)
va_end(ap);
}
fprintf(stderr, "\n");
- exit(exitstatus);
+ exit(eval);
}
/*
@@ -352,23 +352,6 @@ xrealloc(void *old, size_t n, const char *fmt, ...)
return p;
}
-/*
- * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
- * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
- */
-#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4))
-
-static void *
-reallocarray(void *optr, size_t nmemb, size_t size)
-{
- if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- nmemb > 0 && SIZE_MAX / nmemb < size) {
- errno = ENOMEM;
- return NULL;
- }
- return realloc(optr, size * nmemb);
-}
-
void *
xreallocarray(void *old, size_t s1, size_t s2, const char *fmt, ...)
{
diff --git a/usr.bin/m4/parser.y b/usr.bin/m4/parser.y
index 8e8ad8c..3e4c8051 100644
--- a/usr.bin/m4/parser.y
+++ b/usr.bin/m4/parser.y
@@ -19,15 +19,9 @@
*/
#include <math.h>
-#include <stddef.h>
-#include <stdio.h>
#include <stdint.h>
-
-#include "mdef.h"
-#include "extern.h"
-
#define YYSTYPE int32_t
-
+extern int32_t end_result;
extern int yylex(void);
extern int yyerror(const char *);
%}
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile
index bfdeca0..1d366a5 100644
--- a/usr.bin/make/Makefile
+++ b/usr.bin/make/Makefile
@@ -115,6 +115,6 @@ CFLAGS+= -DDEFSHELLNAME=\"${MAKE_SHELL}\"
PROG= fmake
CLEANFILES+= fmake.1
fmake.1: make.1
- cp ${.ALLSRC} ${.TARGET}
+ ${CP} ${.ALLSRC} ${.TARGET}
.include <bsd.prog.mk>
diff --git a/usr.bin/makewhatis/Makefile b/usr.bin/makewhatis/Makefile
index 4da90ef..ba0e1ee 100644
--- a/usr.bin/makewhatis/Makefile
+++ b/usr.bin/makewhatis/Makefile
@@ -1,8 +1,7 @@
# $FreeBSD$
PROG= makewhatis
-DPADD= ${LIBZ}
-LDADD= -lz
+LIBADD= z
SCRIPTS= makewhatis.local.sh
MAN= makewhatis.1 makewhatis.local.8
SCRIPTSDIR= /usr/libexec
diff --git a/usr.bin/man/man.1 b/usr.bin/man/man.1
index 7517a64..5647b6c 100644
--- a/usr.bin/man/man.1
+++ b/usr.bin/man/man.1
@@ -61,23 +61,32 @@ restricts the search to the specific section of the manual.
The sections of the manual are:
.Bl -enum -offset indent -compact
.It
-.Fx General Commands Manual
+.Fx
+General Commands Manual
.It
-.Fx System Calls Manual
+.Fx
+System Calls Manual
.It
-.Fx Library Functions Manual
+.Fx
+Library Functions Manual
.It
-.Fx Kernel Interfaces Manual
+.Fx
+Kernel Interfaces Manual
.It
-.Fx File Formats Manual
+.Fx
+File Formats Manual
.It
-.Fx Games Manual
+.Fx
+Games Manual
.It
-.Fx Miscellaneous Information Manual
+.Fx
+Miscellaneous Information Manual
.It
-.Fx System Manager's Manual
+.Fx
+System Manager's Manual
.It
-.Fx Kernel Developer's Manual
+.Fx
+Kernel Developer's Manual
.El
.Pp
Options that
@@ -340,17 +349,17 @@ Local configuration files.
.Sh SEE ALSO
.Xr apropos 1 ,
.Xr intro 1 ,
+.Xr locale 1 ,
+.Xr manpath 1 ,
+.Xr nroff 1 ,
+.Xr troff 1 ,
+.Xr whatis 1 ,
.Xr intro 2 ,
.Xr intro 3 ,
.Xr intro 4 ,
.Xr intro 5 ,
+.Xr man.conf 5 ,
.Xr intro 6 ,
.Xr intro 7 ,
.Xr intro 8 ,
-.Xr intro 9 ,
-.Xr locale 1 ,
-.Xr manpath 1 ,
-.Xr nroff 1 ,
-.Xr troff 1 ,
-.Xr whatis 1 ,
-.Xr man.conf 5
+.Xr intro 9
diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
index 0f6249a..5e4d767 100755
--- a/usr.bin/man/man.sh
+++ b/usr.bin/man/man.sh
@@ -279,8 +279,7 @@ man_check_for_so() {
# Usage: man_display_page
# Display either the manpage or catpage depending on the use_cat variable
man_display_page() {
- local EQN NROFF PIC TBL TROFF REFER VGRIND
- local IFS l nroff_dev pipeline preproc_arg tool
+ local IFS pipeline testline
# We are called with IFS set to colon. This causes really weird
# things to happen for the variables that have spaces in them.
@@ -312,6 +311,39 @@ man_display_page() {
return
fi
+ if [ -n "$use_width" ]; then
+ mandoc_args="-O width=${use_width}"
+ fi
+ testline="mandoc -Tlint -Wunsupp 2>/dev/null"
+ pipeline="mandoc $mandoc_args | $MANPAGER"
+
+ if ! eval "$cattool $manpage | $testline" ;then
+ if which -s groff; then
+ man_display_page_groff
+ else
+ echo "This manpage needs groff(1) to be rendered" >&2
+ echo "First install groff(1): " >&2
+ echo "pkg install groff " >&2
+ ret=1
+ fi
+ return
+ fi
+
+ if [ $debug -gt 0 ]; then
+ decho "Command: $cattool $manpage | $pipeline"
+ ret=0
+ else
+ eval "$cattool $manpage | $pipeline"
+ ret=$?
+ fi
+}
+
+# Usage: man_display_page_groff
+# Display the manpage using groff
+man_display_page_groff() {
+ local EQN NROFF PIC TBL TROFF REFER VGRIND
+ local IFS l nroff_dev pipeline preproc_arg tool
+
# So, we really do need to parse the manpage. First, figure out the
# device flag (-T) we have to pass to eqn(1) and groff(1). Then,
# setup the pipeline of commands based on the user's request.
diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile
index ed88f4e..cdb512b 100644
--- a/usr.bin/mandoc/Makefile
+++ b/usr.bin/mandoc/Makefile
@@ -1,22 +1,80 @@
# $FreeBSD$
MDOCMLDIR= ${.CURDIR}/../../contrib/mdocml
-LIBMANDOC= ${.OBJDIR}/../../lib/libmandoc/libmandoc.a
.PATH: ${MDOCMLDIR}
PROG= mandoc
-FILES= example.style.css external.png style.css
+FILES= example.style.css style.css
FILESDIR= ${SHAREDIR}/mdocml
-LINKS= mdocml
-MAN= mandoc.1 eqn.7 mandoc_char.7 tbl.7 # man.7 mdoc.7 roff.7
+MAN= mandoc.1 eqn.7 mandoc_char.7 tbl.7 man.7 mdoc.7 # roff.7
MLINKS= mandoc.1 mdocml.1
-SRCS= eqn_html.c eqn_term.c html.c main.c man_html.c man_term.c mdoc_html.c \
- mdoc_man.c mdoc_term.c out.c tbl_html.c tbl_term.c term.c \
- term_ascii.c term_ps.c tree.c
-
-WARNS?= 3
-CFLAGS+= -DHAVE_CONFIG_H
-DPADD= ${LIBMANDOC}
-LDADD= ${LIBMANDOC}
+
+LIBMAN_SRCS= man.c \
+ man_hash.c \
+ man_macro.c \
+ man_validate.c
+
+LIBMDOC_SRCS= att.c \
+ lib.c \
+ mdoc.c \
+ mdoc_argv.c \
+ mdoc_hash.c \
+ mdoc_macro.c \
+ mdoc_validate.c \
+ st.c \
+
+LIBROFF_SRCS= eqn.c \
+ roff.c \
+ tbl.c \
+ tbl_data.c \
+ tbl_layout.c \
+ tbl_opts.c \
+
+LIB_SRCS= ${LIBMAN_SRCS} \
+ ${LIBMDOC_SRCS} \
+ ${LIBROFF_SRCS} \
+ chars.c \
+ mandoc.c \
+ mandoc_aux.c \
+ msec.c \
+ preconv.c \
+ read.c
+
+HTML_SRCS= eqn_html.c \
+ html.c \
+ man_html.c \
+ mdoc_html.c \
+ tbl_html.c
+
+MAN_SRCS= mdoc_man.c
+
+TERM_SRCS= eqn_term.c \
+ man_term.c \
+ mdoc_term.c \
+ term.c \
+ term_ascii.c \
+ term_ps.c \
+ tbl_term.c
+
+DB_SRCS= mandocdb.c \
+ mansearch.c \
+ mansearch_const.c \
+ manpath.c
+
+SRCS= ${LIB_SRCS} \
+ ${HTML_SRCS} \
+ ${MAN_SRCS} \
+ ${TERM_SRCS} \
+ main.c \
+ out.c \
+ tree.c
+
+SRCS+= ${DB_SRCS}
+
+WARNS?= 2
+CFLAGS+= -DHAVE_CONFIG_H \
+ -I${.CURDIR}/../../lib/libohash/ \
+ -I${.CURDIR}/../../contrib/sqlite3
+LIBADD= ohash sqlite3
.include <bsd.prog.mk>
diff --git a/usr.bin/mandoc/Makefile.depend b/usr.bin/mandoc/Makefile.depend
index 456ca6f..1a4115b 100644
--- a/usr.bin/mandoc/Makefile.depend
+++ b/usr.bin/mandoc/Makefile.depend
@@ -10,7 +10,9 @@ DIRDEPS = \
lib/${CSU_DIR} \
lib/libc \
lib/libcompiler_rt \
- lib/libmandoc \
+ lib/libohash \
+ lib/libsqlite3 \
+ lib/libthr \
.include <dirdeps.mk>
diff --git a/usr.bin/minigzip/Makefile b/usr.bin/minigzip/Makefile
index b2cfc46..da15aa9 100644
--- a/usr.bin/minigzip/Makefile
+++ b/usr.bin/minigzip/Makefile
@@ -7,7 +7,6 @@ PROG= minigzip
WARNS?= 5
CFLAGS+=-DUSE_MMAP
-DPADD= ${LIBZ}
-LDADD= -lz
+LIBADD= z
.include <bsd.prog.mk>
diff --git a/usr.bin/ministat/Makefile b/usr.bin/ministat/Makefile
index e4c2f07..2a63797 100644
--- a/usr.bin/ministat/Makefile
+++ b/usr.bin/ministat/Makefile
@@ -1,13 +1,13 @@
# $FreeBSD$
PROG= ministat
-DPADD= ${LIBM}
-LDADD= -lm
+
+LIBADD= m
.include <bsd.prog.mk>
test: ${PROG}
- ./${PROG} < ${.CURDIR}/chameleon
- ./${PROG} ${.CURDIR}/chameleon
+ ./${PROG} < ${.CURDIR}/chameleon
+ ./${PROG} ${.CURDIR}/chameleon
./${PROG} ${.CURDIR}/iguana ${.CURDIR}/chameleon
./${PROG} -c 80 ${.CURDIR}/iguana ${.CURDIR}/chameleon
./${PROG} -s -c 80 ${.CURDIR}/chameleon ${.CURDIR}/iguana
diff --git a/usr.bin/ministat/ministat.1 b/usr.bin/ministat/ministat.1
index ea31c23..f713bae 100644
--- a/usr.bin/ministat/ministat.1
+++ b/usr.bin/ministat/ministat.1
@@ -68,7 +68,9 @@ See
.Xr strtok 3
for details.
.It Fl w Ar width
-Width of ASCII-art plot in characters, default is 74.
+Width of ASCII-art plot in characters.
+The default is the terminal width, or 74 if standard output is not a
+terminal.
.El
.Pp
A sample output could look like this:
diff --git a/usr.bin/ministat/ministat.c b/usr.bin/ministat/ministat.c
index c8d8e12..4c0ddd0 100644
--- a/usr.bin/ministat/ministat.c
+++ b/usr.bin/ministat/ministat.c
@@ -329,10 +329,8 @@ PlotSet(struct dataset *ds, int val)
else
bar = 0;
- if (pl->bar == NULL) {
- pl->bar = malloc(sizeof(char *) * pl->num_datasets);
- memset(pl->bar, 0, sizeof(char*) * pl->num_datasets);
- }
+ if (pl->bar == NULL)
+ pl->bar = calloc(sizeof(char *), pl->num_datasets);
if (pl->bar[bar] == NULL) {
pl->bar[bar] = malloc(pl->width);
memset(pl->bar[bar], 0, pl->width);
diff --git a/usr.bin/mkcsmapper/mkcsmapper.1 b/usr.bin/mkcsmapper/mkcsmapper.1
index cf1fde2..8faf5e6 100644
--- a/usr.bin/mkcsmapper/mkcsmapper.1
+++ b/usr.bin/mkcsmapper/mkcsmapper.1
@@ -77,8 +77,8 @@ Generate pivot data from
.Ex -std mkcsmapper
.Sh SEE ALSO
.Xr iconv 1 ,
-.Xr iconv 3 ,
-.Xr mkesdb 1
+.Xr mkesdb 1 ,
+.Xr iconv 3
.Sh HISTORY
.Nm
first appeared in
diff --git a/usr.bin/mkesdb/mkesdb.1 b/usr.bin/mkesdb/mkesdb.1
index c5d2edf..a0743b6 100644
--- a/usr.bin/mkesdb/mkesdb.1
+++ b/usr.bin/mkesdb/mkesdb.1
@@ -72,8 +72,8 @@ Put generated binary data to
.Ex -std mkesdb
.Sh SEE ALSO
.Xr iconv 1 ,
-.Xr iconv 3 ,
-.Xr mkcsmapper 1
+.Xr mkcsmapper 1 ,
+.Xr iconv 3
.Sh HISTORY
.Nm
first appeared in
diff --git a/usr.bin/mkimg/Makefile b/usr.bin/mkimg/Makefile
index 28aac7d..d635924 100644
--- a/usr.bin/mkimg/Makefile
+++ b/usr.bin/mkimg/Makefile
@@ -6,7 +6,7 @@ PROG= mkimg
SRCS= format.c image.c mkimg.c scheme.c
MAN= mkimg.1
-MKIMG_VERSION=20141003
+MKIMG_VERSION=20150222
mkimg.o: Makefile
CFLAGS+=-DMKIMG_VERSION=${MKIMG_VERSION}
@@ -31,8 +31,7 @@ SRCS+= \
BINDIR?=/usr/bin
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD= util
WARNS?= 6
diff --git a/usr.bin/mkimg/mbr.c b/usr.bin/mkimg/mbr.c
index c1b7822..9d737a5 100644
--- a/usr.bin/mkimg/mbr.c
+++ b/usr.bin/mkimg/mbr.c
@@ -42,9 +42,13 @@ __FBSDID("$FreeBSD$");
#ifndef DOSPTYP_FAT32
#define DOSPTYP_FAT32 0x0b
#endif
+#ifndef DOSPTYP_EFI
+#define DOSPTYP_EFI 0xef
+#endif
static struct mkimg_alias mbr_aliases[] = {
{ ALIAS_EBR, ALIAS_INT2TYPE(DOSPTYP_EXT) },
+ { ALIAS_EFI, ALIAS_INT2TYPE(DOSPTYP_EFI) },
{ ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) },
{ ALIAS_FREEBSD, ALIAS_INT2TYPE(DOSPTYP_386BSD) },
{ ALIAS_NONE, 0 } /* Keep last! */
diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1
index 56cd605..3b1d63e 100644
--- a/usr.bin/mkimg/mkimg.1
+++ b/usr.bin/mkimg/mkimg.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 27, 2014
+.Dd February 22, 2015
.Dt MKIMG 1
.Os
.Sh NAME
@@ -37,13 +37,12 @@
.Op Fl S Ar secsz
.Op Fl T Ar tracksz
.Op Fl b Ar bootcode
+.Op Fl c Ar capacity
.Op Fl f Ar format
.Op Fl o Ar outfile
.Op Fl v
.Op Fl y
-.Fl s Ar scheme
-.Fl p Ar partition
-.Op Fl p Ar partition ...
+.Op Fl s Ar scheme Op Fl p Ar partition ...
.Nm
.Ar --formats | --schemes | --version
.Sh DESCRIPTION
@@ -109,13 +108,29 @@ utility will use the (physical) block size to determine the start of
partitions and to round the size of the disk image.
.Pp
The
-.Op Fl v
+.Fl c
+option can be used to specify a minimal capacity for the disk image.
+Use this option without the
+.Fl s
+and
+.Fl p
+options to create an empty disk image with the given (virtual) size.
+An empty partition table can be written to the disk when specifying a
+partitioning scheme with the
+.Fl s
+option, but without specifying any partitions.
+When the size required to for all the partitions is larger than the
+given capacity, then the disk image will be larger than the capacity
+given.
+.Pp
+The
+.Fl v
option increases the level of output that the
.Nm
utility prints.
.Pp
The
-.Op Fl y
+.Fl y
option is used for testing purposes only and is not to be used in production.
When present, the
.Nm
diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c
index b55ee7e..5a4b9f9 100644
--- a/usr.bin/mkimg/mkimg.c
+++ b/usr.bin/mkimg/mkimg.c
@@ -60,6 +60,8 @@ static struct option longopts[] = {
{ NULL, 0, NULL, 0 }
};
+static uint64_t capacity;
+
struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist);
u_int nparts = 0;
@@ -147,6 +149,7 @@ usage(const char *why)
fprintf(stderr, "\t--version\t- show version information\n");
fputc('\n', stderr);
fprintf(stderr, "\t-b <file>\t- file containing boot code\n");
+ fprintf(stderr, "\t-c <num>\t- capacity (in bytes) of the disk\n");
fprintf(stderr, "\t-f <format>\n");
fprintf(stderr, "\t-o <file>\t- file to write image into\n");
fprintf(stderr, "\t-p <partition>\n");
@@ -179,7 +182,7 @@ usage(const char *why)
}
static int
-parse_number(u_int *valp, u_int min, u_int max, const char *arg)
+parse_uint32(uint32_t *valp, uint32_t min, uint32_t max, const char *arg)
{
uint64_t val;
@@ -187,7 +190,20 @@ parse_number(u_int *valp, u_int min, u_int max, const char *arg)
return (errno);
if (val > UINT_MAX || val < (uint64_t)min || val > (uint64_t)max)
return (EINVAL);
- *valp = (u_int)val;
+ *valp = (uint32_t)val;
+ return (0);
+}
+
+static int
+parse_uint64(uint64_t *valp, uint64_t min, uint64_t max, const char *arg)
+{
+ uint64_t val;
+
+ if (expand_number(arg, &val) == -1)
+ return (errno);
+ if (val < min || val > max)
+ return (EINVAL);
+ *valp = val;
return (0);
}
@@ -376,6 +392,17 @@ mkimg_uuid(struct uuid *uuid)
memcpy(uuid, gen, sizeof(uuid_t));
}
+static int
+capacity_resize(lba_t end)
+{
+ lba_t capsz;
+
+ capsz = (capacity + secsz - 1) / secsz;
+ if (end >= capsz)
+ return (0);
+ return (image_set_size(capsz));
+}
+
static void
mkimg(void)
{
@@ -437,12 +464,14 @@ mkimg(void)
block = scheme_metadata(SCHEME_META_IMG_END, block);
error = image_set_size(block);
if (!error)
+ error = capacity_resize(block);
+ if (!error)
error = format_resize(block);
if (error)
errc(EX_IOERR, error, "image sizing");
block = image_get_size();
ncyls = block / (nsecs * nheads);
- error = (scheme_write(block));
+ error = scheme_write(block);
if (error)
errc(EX_IOERR, error, "writing metadata");
}
@@ -455,7 +484,7 @@ main(int argc, char *argv[])
bcfd = -1;
outfd = 1; /* Write to stdout by default */
- while ((c = getopt_long(argc, argv, "b:f:o:p:s:vyH:P:S:T:",
+ while ((c = getopt_long(argc, argv, "b:c:f:o:p:s:vyH:P:S:T:",
longopts, NULL)) != -1) {
switch (c) {
case 'b': /* BOOT CODE */
@@ -465,6 +494,11 @@ main(int argc, char *argv[])
if (bcfd == -1)
err(EX_UNAVAILABLE, "%s", optarg);
break;
+ case 'c': /* CAPACITY */
+ error = parse_uint64(&capacity, 1, OFF_MAX, optarg);
+ if (error)
+ errc(EX_DATAERR, error, "capacity in bytes");
+ break;
case 'f': /* OUTPUT FORMAT */
if (format_selected() != NULL)
usage("multiple formats given");
@@ -499,26 +533,26 @@ main(int argc, char *argv[])
verbose++;
break;
case 'H': /* GEOMETRY: HEADS */
- error = parse_number(&nheads, 1, 255, optarg);
+ error = parse_uint32(&nheads, 1, 255, optarg);
if (error)
errc(EX_DATAERR, error, "number of heads");
break;
case 'P': /* GEOMETRY: PHYSICAL SECTOR SIZE */
- error = parse_number(&blksz, 512, INT_MAX+1U, optarg);
+ error = parse_uint32(&blksz, 512, INT_MAX+1U, optarg);
if (error == 0 && !pwr_of_two(blksz))
error = EINVAL;
if (error)
errc(EX_DATAERR, error, "physical sector size");
break;
case 'S': /* GEOMETRY: LOGICAL SECTOR SIZE */
- error = parse_number(&secsz, 512, INT_MAX+1U, optarg);
+ error = parse_uint32(&secsz, 512, INT_MAX+1U, optarg);
if (error == 0 && !pwr_of_two(secsz))
error = EINVAL;
if (error)
errc(EX_DATAERR, error, "logical sector size");
break;
case 'T': /* GEOMETRY: TRACK SIZE */
- error = parse_number(&nsecs, 1, 63, optarg);
+ error = parse_uint32(&nsecs, 1, 63, optarg);
if (error)
errc(EX_DATAERR, error, "track size");
break;
@@ -541,9 +575,9 @@ main(int argc, char *argv[])
if (argc > optind)
usage("trailing arguments");
- if (scheme_selected() == NULL)
+ if (scheme_selected() == NULL && nparts > 0)
usage("no scheme");
- if (nparts == 0)
+ if (nparts == 0 && capacity == 0)
usage("no partitions");
if (secsz > blksz) {
@@ -577,8 +611,9 @@ main(int argc, char *argv[])
fprintf(stderr, "Sectors per track: %u\n", nsecs);
fprintf(stderr, "Number of heads: %u\n", nheads);
fputc('\n', stderr);
- fprintf(stderr, "Partitioning scheme: %s\n",
- scheme_selected()->name);
+ if (scheme_selected())
+ fprintf(stderr, "Partitioning scheme: %s\n",
+ scheme_selected()->name);
fprintf(stderr, "Output file format: %s\n",
format_selected()->name);
fputc('\n', stderr);
diff --git a/usr.bin/mkimg/qcow.c b/usr.bin/mkimg/qcow.c
index 5033286..a89761b 100644
--- a/usr.bin/mkimg/qcow.c
+++ b/usr.bin/mkimg/qcow.c
@@ -71,7 +71,7 @@ struct qcow_header {
uint32_t l1_entries;
uint64_t l1_offset;
uint64_t refcnt_offset;
- uint32_t refcnt_entries;
+ uint32_t refcnt_clstrs;
uint32_t snapshot_count;
uint64_t snapshot_offset;
} v2;
@@ -139,7 +139,7 @@ qcow_write(int fd, u_int version)
uint64_t n, imagesz, nclstrs, ofs, ofsflags;
lba_t blk, blkofs, blk_imgsz;
u_int l1clno, l2clno, rcclno;
- u_int blk_clstrsz;
+ u_int blk_clstrsz, refcnt_clstrs;
u_int clstrsz, l1idx, l2idx;
int error;
@@ -199,14 +199,15 @@ qcow_write(int fd, u_int version)
be32enc(&hdr->u.v2.l1_entries, clstr_l2tbls);
be64enc(&hdr->u.v2.l1_offset, clstrsz * l1clno);
be64enc(&hdr->u.v2.refcnt_offset, clstrsz * rcclno);
- be32enc(&hdr->u.v2.refcnt_entries, clstr_rcblks);
+ refcnt_clstrs = round_clstr(clstr_rcblks * 8) >> clstr_log2sz;
+ be32enc(&hdr->u.v2.refcnt_clstrs, refcnt_clstrs);
break;
default:
return (EDOOFUS);
}
if (sparse_write(fd, hdr, clstrsz) < 0) {
- error = errno;
+ error = errno;
goto out;
}
diff --git a/usr.bin/mkimg/scheme.c b/usr.bin/mkimg/scheme.c
index ff5e201..336f953 100644
--- a/usr.bin/mkimg/scheme.c
+++ b/usr.bin/mkimg/scheme.c
@@ -31,8 +31,10 @@ __FBSDID("$FreeBSD$");
#include <sys/linker_set.h>
#include <sys/queue.h>
#include <sys/stat.h>
+#include <assert.h>
#include <err.h>
#include <errno.h>
+#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -104,7 +106,7 @@ scheme_bootcode(int fd)
{
struct stat sb;
- if (scheme->bootcode == 0)
+ if (scheme == NULL || scheme->bootcode == 0)
return (ENXIO);
if (fstat(fd, &sb) == -1)
@@ -130,6 +132,8 @@ scheme_check_part(struct part *p)
struct mkimg_alias *iter;
enum alias alias;
+ assert(scheme != NULL);
+
/* Check the partition type alias */
alias = scheme_parse_alias(p->alias);
if (alias == ALIAS_NONE)
@@ -158,29 +162,26 @@ u_int
scheme_max_parts(void)
{
- return (scheme->nparts);
+ return ((scheme == NULL) ? 0 : scheme->nparts);
}
u_int
scheme_max_secsz(void)
{
- return (scheme->maxsecsz);
+ return ((scheme == NULL) ? INT_MAX+1U : scheme->maxsecsz);
}
lba_t
scheme_metadata(u_int where, lba_t start)
{
- return (scheme->metadata(where, start));
+ return ((scheme == NULL) ? start : scheme->metadata(where, start));
}
int
scheme_write(lba_t end)
{
- int error;
- end = image_get_size();
- error = scheme->write(end, bootcode);
- return (error);
+ return ((scheme == NULL) ? 0 : scheme->write(end, bootcode));
}
diff --git a/usr.bin/mkulzma/Makefile b/usr.bin/mkulzma/Makefile
index 8147ebf..15596bf 100644
--- a/usr.bin/mkulzma/Makefile
+++ b/usr.bin/mkulzma/Makefile
@@ -2,7 +2,7 @@
PROG= mkulzma
MAN= mkulzma.8
-DPADD= ${LIBLZMA}
-LDADD= -llzma
+
+LIBADD= lzma
.include <bsd.prog.mk>
diff --git a/usr.bin/mkulzma/Makefile.depend b/usr.bin/mkulzma/Makefile.depend
index b7653d1..4915738 100644
--- a/usr.bin/mkulzma/Makefile.depend
+++ b/usr.bin/mkulzma/Makefile.depend
@@ -11,6 +11,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/liblzma \
+ lib/libthr \
.include <dirdeps.mk>
diff --git a/usr.bin/mkuzip/Makefile b/usr.bin/mkuzip/Makefile
index c5eac20..92ab43e 100644
--- a/usr.bin/mkuzip/Makefile
+++ b/usr.bin/mkuzip/Makefile
@@ -3,8 +3,6 @@
PROG= mkuzip
MAN= mkuzip.8
-DPADD= ${LIBZ}
-LDADD= -lz
-
+LIBADD= z
.include <bsd.prog.mk>
diff --git a/usr.bin/msgs/Makefile b/usr.bin/msgs/Makefile
index 6c5a8d9..3af95c3 100644
--- a/usr.bin/msgs/Makefile
+++ b/usr.bin/msgs/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
PROG= msgs
-DPADD= ${LIBTERMCAPW}
-LDADD= -ltermcapw
+
+LIBADD= ncursesw
.include <bsd.prog.mk>
diff --git a/usr.bin/mt/Makefile b/usr.bin/mt/Makefile
index 25b4af5..b71c2f8 100644
--- a/usr.bin/mt/Makefile
+++ b/usr.bin/mt/Makefile
@@ -2,5 +2,6 @@
# $FreeBSD$
PROG= mt
+LIBADD= mt
.include <bsd.prog.mk>
diff --git a/usr.bin/mt/Makefile.depend b/usr.bin/mt/Makefile.depend
index 96aa2a2..0d771d1 100644
--- a/usr.bin/mt/Makefile.depend
+++ b/usr.bin/mt/Makefile.depend
@@ -10,6 +10,9 @@ DIRDEPS = \
lib/${CSU_DIR} \
lib/libc \
lib/libcompiler_rt \
+ lib/libexpat \
+ lib/libmt \
+ lib/libsbuf \
.include <dirdeps.mk>
diff --git a/usr.bin/mt/mt.1 b/usr.bin/mt/mt.1
index 8e9f63a..33c1c18 100644
--- a/usr.bin/mt/mt.1
+++ b/usr.bin/mt/mt.1
@@ -29,7 +29,7 @@
.\" @(#)mt.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd January 20, 2008
+.Dd March 3, 2014
.Dt MT 1
.Os
.Sh NAME
@@ -71,6 +71,12 @@ which defaults to 1.
Write
.Ar count
end-of-file (EOF) marks at the current position.
+This returns when the file mark has been written to the media.
+.It Cm weofi
+Write
+.Ar count
+end-of-file (EOF) marks at the current position.
+This returns as soon as the command has been validated by the tape drive.
.It Cm smk
Write
.Ar count
@@ -129,6 +135,8 @@ Rewind the tape.
.It Cm offline , rewoffl
Rewind the tape and place the drive off line.
Some drives are never off line.
+.It Cm load
+Load the tape into the drive.
.It Cm retension
Re-tension the tape.
This winds the tape from the current position to the end
@@ -136,7 +144,7 @@ and then to the beginning.
This sometimes improves subsequent reading and writing,
particularly for streaming drives.
Some drives do not support this.
-.It Cm status
+.It Cm ostatus
Output status information about the drive.
For SCSI magnetic tape devices,
the current operating modes of density, blocksize, and whether compression
@@ -149,6 +157,9 @@ Note
that this information is not definitive (only BOT, End of Recorded Media, and
hardware or SCSI logical block position (if the drive supports such) are
considered definitive tape positions).
+.Pp
+Also note that this is the old status command, and will be eliminated in
+favor of the new status command (see below) in a future release.
.It Cm errstat
Output (and clear) error status information about this device.
For every normal
@@ -165,9 +176,12 @@ many filemarks will be written at close if a tape was being written.
.It Cm eod , eom
Wind the tape to the end of the recorded data,
typically after an EOF mark where another file may be written.
+.It Cm rblim
+Report the block limits of the tape drive, including the minimum and
+maximum block size, and the block granularity if any.
.El
.Pp
-The following commands require an
+The following commands may require an
.Ar argument .
.Bl -tag -width ".Cm seteotmodel"
.It Cm sethpos
@@ -199,6 +213,180 @@ You may only choose a value of
.Ar 1
or
.Ar 2 .
+.It Cm status
+Output status information about the drive.
+For SCSI magnetic tape devices,
+the current operating modes of density, blocksize, and whether compression
+is enabled is reported.
+The current state of the driver (what it thinks that
+it is doing with the device) is reported.
+.Pp
+If the driver knows the relative
+position from BOT (in terms of filemarks and records), it outputs that.
+If the tape drive supports the long form report of the
+.Tn SCSI
+READ POSITION command, the Reported File Number and Reported Record Number
+will be numbers other than -1, and there may be Flags reported as well.
+.Pp
+The BOP flag means that the logical position of the drive is at the
+beginning of the partition.
+.Pp
+The EOP flag means that the logical position of the drive is between Early
+Warning and End of Partition.
+.Pp
+The BPEW flag means that the logical position of the drive is in a
+Programmable Early Warning Zone or on the EOP side of Early Warning.
+.Pp
+Note that the Reported Record Number is the tape block or object number
+relative to the beginning of the partition.
+The Calculated Record Number is the tape block or object number relative
+to the previous file mark.
+.Pp
+Note
+that the Calculated File and Record Numbers are not definitive.
+The Reported File and Record Numbers are definitive, if they are numbers
+other than -1.
+.Bl -tag -width 6n
+.It Fl v
+Print additional status information, such as the maximum supported I/O
+size.
+.It Fl x
+Print all available status data to stdout in XML format.
+.El
+.It Cm getdensity
+Report density support information for the tape drive and any media that is
+loaded.
+Most drives will report at least basic density information similar to that
+reported by
+.Nm status
+command.
+Newer tape drives that conform to the T-10 SSC and newer tape
+specifications may report more detailed information about the types of
+tapes they support and the tape currently in the drive.
+.Bl -tag -width 6n
+.It Fl x
+Print all available density data to stdout in XML format.
+Because density information is currently included in the general status XML
+report used for
+.Nm
+status command, this will be the same XML output via
+.Do
+.Nm
+status
+.Fl x
+.Dc
+.El
+.It Cm param
+Display or set parameters.
+One of
+.Fl l ,
+.Fl s ,
+or
+.Fl x
+must be specified to indicate which operation to perform.
+.Bl -tag -width 8n
+.It Fl l
+List parameters, values and descriptions.
+By default all parameters will be displayed.
+To display a specific parameter, specify the parameter with
+.Fl p .
+.It Fl p Ar name
+Specify the parameter name to list (with
+.Fl l )
+or set (with
+.Fl s ) .
+.It Fl q
+Enable quiet mode for parameter listing.
+This will suppress printing of parameter descriptions.
+.It Fl s Ar value
+Specify the parameter value to set.
+The general type of this argument (integer, unsigned integer, string) is
+determined by the type of the variable indicated by the
+.Xr sa 4
+driver.
+More detailed argument checking is done by the
+.Xr sa 4
+driver.
+.It Fl x
+Print out all parameter information in XML format.
+.El
+.It Cm protect
+Display or set drive protection parameters.
+This is used to control checking and reporting a per-block checksum for
+tape drives that support it.
+Some drives may only support some parameters.
+.Bl -tag -width 8n
+.It Fl b Ar 0|1
+Set the Recover Buffered Data Protected bit.
+If set, this indicates that checksums are transferred with the logical
+blocks transferred by the RECOVERED BUFFERED DATA
+.Tn SCSI
+command.
+.It Fl d
+Disable all protection information settings.
+.It Fl e
+Enable all protection information settings.
+The default protection method used is Reed-Solomon CRC (protection method
+1), as specified in ECMA-319.
+The default protection information length used with Reed-Solomon CRC is
+4 bytes.
+To enable all settings except one more more settings, specify the
+.Fl e
+argument and then explicitly disable settings that you do not wish to
+enable.
+For example, specifying
+.Fl e
+.Fl w Ar 0
+will enable all settings except for LBP_W.
+.It Fl l
+List available protection parmeters and their current settings.
+.It Fl L Ar len
+Set the length of the protection information in bytes.
+For Reed-Solomon CRC, the protection information length should be 4 bytes.
+.It Fl m Ar num
+Specify the numeric value for the protection method.
+The numeric value for Reed-Solomon CRC is 1.
+.It Fl r Ar 0|1
+Set the LBP_R parameter.
+When set, this indicates that each block read from the tape drive will
+have a checksum at the end.
+.It Fl v
+Enable verbose mode for parameter listing.
+This will include descriptions of each parameter.
+.It Fl w Ar 0|1
+Set the LBP_W parameter.
+When set, this indicates that each block written to the tape drive will have
+a checksum at the end.
+The drive will verify the checksum before writing the block to tape.
+.El
+.It Cm locate
+Set the tape drive's logical position.
+One of
+.Fl b ,
+.Fl e ,
+.Fl f ,
+or
+.Fl s
+must be specified to indicate the type of position.
+If the partition number is specified, the drive will first relocate to the
+given partition (if it exists) and then to the position indicated within
+that partition.
+If the partition number is not specified, the drive will relocate to the
+given position within the current partition.
+.Bl -tag -width 14n
+.It Fl b Ar block_addr
+Relocate to the given tape block or logical object identifier.
+Note that the block number is the Reported Record Number that is relative
+to the beginning of the partition (or beginning of tape).
+.It Fl e
+Relocate to the end of data.
+.It Fl f Ar fileno
+Relocate to the given file number.
+.It Fl p Ar partition
+Specify the partition to change to.
+.It Fl s Ar setmark
+Relocate to the given set mark.
+.El
.It Cm comp
Set the drive's compression mode.
The non-numeric values of
@@ -234,6 +422,13 @@ If this is not the case (see the
display to see which compression algorithm is currently in use), the user
can manually specify one of the supported compression keywords (above), or
supply a numeric compression value from the drive's specifications.
+.Pp
+Note that for some older tape drives (for example the Exabyte 8200 and 8500
+series drives) it is necessary to switch to a different density to tell the
+drive to record data in its compressed format.
+If the user attempts to turn compression on while the uncompressed density
+is selected, the drive will return an error.
+This is generally not an issue for modern tape drives.
.It Cm density
Set the density for the drive.
For the density codes, see below.
@@ -249,13 +444,14 @@ exactly, an informational message is output about what the given
string has been taken for.
.El
.Pp
-The following density table was taken from the
+The initial version of the density table below was taken from the
.Sq Historical sequential access density codes
table (A-1) in Revision 11 of the SCSI-3 Stream Device Commands (SSC)
working draft, dated November 11, 1997.
+Subsequent additions have come from a number of sources.
.Pp
The density codes are:
-.Bd -literal -offset 3n
+.Bd -literal -offset 2n
0x0 default for device
0xE reserved for ECMA
@@ -278,8 +474,8 @@ Value Width Tracks Density Code Type Reference Note
0x11 6.3 (0.25) 26 630 (16,000) GCR C QIC-320 1,6
0x12 6.3 (0.25) 30 2,034 (51,667) RLL C QIC-1350 1,6
0x13 3.81 (0.15) 1 2,400 (61,000) DDS CS X3B5/88-185A 5
-0x14 8.0 (0.315) 1 1,703 (43,245) RLL CS X3.202-1991 5
-0x15 8.0 (0.315) 1 1,789 (45,434) RLL CS ECMA TC17 5
+0x14 8.0 (0.315) 1 1,703 (43,245) RLL CS X3.202-1991 5,11
+0x15 8.0 (0.315) 1 1,789 (45,434) RLL CS ECMA TC17 5,12
0x16 12.7 (0.5) 48 394 (10,000) MFM C X3.193-1990 1
0x17 12.7 (0.5) 48 1,673 (42,500) MFM C X3B5/91-174 1
0x18 12.7 (0.5) 112 1,673 (42,500) MFM C X3B5/92-50 1
@@ -302,11 +498,34 @@ Value Width Tracks Density Code Type Reference Note
0x29 12.7 (0.5)
0x2A
0x2B 12.7 (0.5) 3 ? ? ? C X3.267 5
+0x40 12.7 (0.5) 384 4,800 (123,952) C LTO-1
0x41 12.7 (0.5) 208 3,868 (98,250) RLL C DLTapeIV(40) 6,7
-0x48 12.7 (0.5) 448 5,236 (133,000) PRML C SDLTapeI(110) 6,8
+0x42 12.7 (0.5) 512 7,398 (187,909) C LTO-2
+0x44 12.7 (0.5) 704 9,638 (244,805) C LTO-3
+0x46 12.7 (0.5) 896 12,725 (323,215) C LTO-4
+0x47 3.81 (0.25) ? 6,417 (163,000) CS DAT-72
+0x48 12.7 (0.5) 448 5,236 (133,000) PRML C SDLTapeI(110) 6,8,13
0x49 12.7 (0.5) 448 7,598 (193,000) PRML C SDLTapeI(160) 6,8
+0x4A 12.7 (0.5) 768 ? C T10000A 10
+0x4B 12.7 (0.5) 1152 ? C T10000B 10
+0x4C 12.7 (0.5) 3584 ? C T10000C 10
+0x4D 12.7 (0.5) 4608 ? C T10000D 10
+0x51 12.7 (0.5) 512 11,800 (299,720) C 3592A1 (unencrypted)
+0x52 12.7 (0.5) 896 11,800 (299,720) C 3592A2 (unencrypted)
+0x53 12.7 (0.5) 1152 13,452 (341,681) C 3592A3 (unencrypted)
+0x54 12.7 (0.5) 2560 19,686 (500,024) C 3592A4 (unencrypted)
+0x55 12.7 (0.5) 5120 20,670 (525,018) C 3592A5 (unencrypted)
+0x58 12.7 (0.5) 1280 15,142 (384,607) C LTO-5
+0x5A 12.7 (0.5) 2176 15,142 (384,607) C LTO-6
+0x71 12.7 (0.5) 512 11,800 (299,720) C 3592A1 (encrypted)
+0x72 12.7 (0.5) 896 11,800 (299,720) C 3592A2 (encrypted)
+0x73 12.7 (0.5) 1152 13,452 (341,681) C 3592A3 (encrypted)
+0x74 12.7 (0.5) 2560 19,686 (500,024) C 3592A4 (encrypted)
+0x75 12.7 (0.5) 5120 20,670 (525,018) C 3592A5 (encrypted)
+0x8c 8.0 (0.315) 1 1,789 (45,434) RLL CS EXB-8500c 5,9
+0x90 8.0 (0.315) 1 1,703 (43,245) RLL CS EXB-8200c 5,9
.Ed
-.Bd -literal -offset 3n
+.Bd -literal -offset 2n
Code Description Type Description
---- -------------------------------------- ---- -----------
NRZI Non return to zero, change on ones R Reel-to-reel
@@ -318,18 +537,27 @@ DDS DAT data storage
RLL Run length limited
PRML Partial Response Maximum Likelihood
.Ed
-.Bd -literal -offset 3n
+.Bd -literal -offset 2n
NOTES
-1. Serial recorded.
-2. Parallel recorded.
-3. Old format known as QIC-11.
-5. Helical scan.
-6. This is not an American National Standard. The reference is based on
- an industry standard definition of the media format.
-7. DLT recording: serially recorded track pairs (DLTapeIII and
- DLTapeIV(20)), or track quads (DLTapeIV(35) and DLTapeIV(40)).
-8. Super DLT (SDLT) recording: 56 serially recorded logical tracks with
- 8 physical tracks each.
+1. Serial recorded.
+2. Parallel recorded.
+3. Old format known as QIC-11.
+5. Helical scan.
+6. This is not an American National Standard. The reference is based
+ on an industry standard definition of the media format.
+7. DLT recording: serially recorded track pairs (DLTapeIII and
+ DLTapeIV(20)), or track quads (DLTapeIV(35) and DLTapeIV(40)).
+8. Super DLT (SDLT) recording: 56 serially recorded logical tracks
+ with 8 physical tracks each.
+9. Vendor-specific Exabyte density code for compressed format.
+10. bpi/bpmm values for the Oracle/StorageTek T10000 tape drives are
+ not listed in the manual. Someone with access to a drive can
+ supply the necessary values by running 'mt getdensity'.
+11. This is Exabyte 8200 uncompressed format. The compressed format
+ density code is 0x90.
+12. This is Exabyte 8500 uncompressed format. The compressed format
+ density code is 0x8c.
+13. This density code (0x48) was also used for DAT-160.
.Ed
.Sh ENVIRONMENT
.Bl -tag -width ".Ev TAPE"
@@ -343,8 +571,6 @@ option.
.El
.Sh FILES
.Bl -tag -width ".Pa /dev/*sa[0-9]*" -compact
-.It Pa /dev/*wt*
-QIC-02/QIC-36 magnetic tape interface
.It Pa /dev/*sa[0-9]*
SCSI magnetic tape interface
.El
@@ -357,7 +583,6 @@ Some undocumented commands support old software.
.Sh SEE ALSO
.Xr dd 1 ,
.Xr ioctl 2 ,
-.Xr ast 4 ,
.Xr mtio 4 ,
.Xr sa 4 ,
.Xr environ 7
diff --git a/usr.bin/mt/mt.c b/usr.bin/mt/mt.c
index 3fbbdf3..8cec707 100644
--- a/usr.bin/mt/mt.c
+++ b/usr.bin/mt/mt.c
@@ -26,6 +26,37 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+/*-
+ * Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * Authors: Ken Merry (Spectra Logic Corporation)
+ */
#ifndef lint
static const char copyright[] =
@@ -49,6 +80,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
+#include <sys/queue.h>
#include <ctype.h>
#include <err.h>
@@ -57,6 +89,16 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stdint.h>
+#include <errno.h>
+#include <bsdxml.h>
+#include <mtlib.h>
+
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_periph.h>
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_sa.h>
/* the appropriate sections of <sys/mtio.h> are also #ifdef'd for FreeBSD */
/* c_flags */
@@ -65,6 +107,7 @@ __FBSDID("$FreeBSD$");
#define IS_DENSITY 0x04
#define DISABLE_THIS 0x08
#define IS_COMP 0x10
+#define USE_GETOPT 0x20
#ifndef TRUE
#define TRUE 1
@@ -72,6 +115,16 @@ __FBSDID("$FreeBSD$");
#ifndef FALSE
#define FALSE 0
#endif
+#ifndef MAX
+#define MAX(a, b) (a > b) ? a : b
+#endif
+#define MT_PLURAL(a) (a == 1) ? "" : "s"
+
+typedef enum {
+ MT_CMD_NONE = MTLOAD + 1,
+ MT_CMD_PROTECT,
+ MT_CMD_GETDENSITY
+} mt_commands;
static const struct commands {
const char *c_name;
@@ -87,10 +140,12 @@ static const struct commands {
{ "fsf", MTFSF, 1, 0 },
{ "fsr", MTFSR, 1, 0 },
{ "offline", MTOFFL, 1, 0 },
+ { "load", MTLOAD, 1, 0 },
{ "rewind", MTREW, 1, 0 },
{ "rewoffl", MTOFFL, 1, 0 },
- { "status", MTNOP, 1, 0 },
+ { "ostatus", MTNOP, 1, 0 },
{ "weof", MTWEOF, 0, ZERO_ALLOWED },
+ { "weofi", MTWEOFI, 0, ZERO_ALLOWED },
{ "erase", MTERASE, 0, ZERO_ALLOWED},
{ "blocksize", MTSETBSIZ, 0, NEED_2ARGS|ZERO_ALLOWED },
{ "density", MTSETDNSTY, 0, NEED_2ARGS|ZERO_ALLOWED|IS_DENSITY },
@@ -111,17 +166,39 @@ static const struct commands {
{ "seteotmodel", MTIOCSETEOTMODEL, 0, NEED_2ARGS|ZERO_ALLOWED },
{ "getmodel", MTIOCGETEOTMODEL, 0, 0 },
{ "geteotmodel", MTIOCGETEOTMODEL, 0, 0 },
+ { "rblim", MTIOCRBLIM, 0, 0},
+ { "getdensity", MT_CMD_GETDENSITY, 0, USE_GETOPT},
+ { "status", MTIOCEXTGET, 0, USE_GETOPT },
+ { "locate", MTIOCEXTLOCATE, 0, USE_GETOPT },
+ { "param", MTIOCPARAMGET, 0, USE_GETOPT },
+ { "protect", MT_CMD_PROTECT, 0, USE_GETOPT },
{ NULL, 0, 0, 0 }
};
+
static const char *getblksiz(int);
static void printreg(const char *, u_int, const char *);
static void status(struct mtget *);
static void usage(void);
-static void st_status(struct mtget *);
-static int stringtodens(const char *s);
-static const char *denstostring(int d);
-static int denstobp(int d, int bpi);
+const char *get_driver_state_str(int dsreg);
+static void st_status (struct mtget *);
+static int mt_locate(int argc, char **argv, int mtfd, const char *tape);
+static int nstatus_print(int argc, char **argv, char *xml_str,
+ struct mt_status_data *status_data);
+static int mt_xml_cmd(unsigned long cmd, int argc, char **argv, int mtfd,
+ const char *tape);
+static int mt_print_density_entry(struct mt_status_entry *density_root, int indent);
+static int mt_print_density_report(struct mt_status_entry *report_root, int indent);
+static int mt_print_density(struct mt_status_entry *density_root, int indent);
+static int mt_getdensity(int argc, char **argv, char *xml_str,
+ struct mt_status_data *status_data);
+static int mt_set_param(int mtfd, struct mt_status_data *status_data,
+ char *param_name, char *param_value);
+static int mt_protect(int argc, char **argv, int mtfd,
+ struct mt_status_data *status_data);
+static int mt_param(int argc, char **argv, int mtfd, char *xml_str,
+ struct mt_status_data *status_data);
+static const char *denstostring (int d);
static u_int32_t stringtocomp(const char *s);
static const char *comptostring(u_int32_t comp);
static void warn_eof(void);
@@ -135,6 +212,8 @@ main(int argc, char *argv[])
int ch, len, mtfd;
const char *p, *tape;
+ bzero(&mt_com, sizeof(mt_com));
+
if ((tape = getenv("TAPE")) == NULL)
tape = DEFTAPE;
@@ -145,13 +224,15 @@ main(int argc, char *argv[])
tape = optarg;
break;
case '?':
- default:
usage();
+ break;
+ default:
+ break;
}
argc -= optind;
argv += optind;
- if (argc < 1 || argc > 2)
+ if (argc < 1)
usage();
len = strlen(p = *argv++);
@@ -166,6 +247,11 @@ main(int argc, char *argv[])
if(comp->c_flags & DISABLE_THIS) {
warn_eof();
}
+ if (comp->c_flags & USE_GETOPT) {
+ argc--;
+ optind = 0;
+ }
+
if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0)
err(1, "%s", tape);
if (comp->c_code != MTNOP) {
@@ -174,7 +260,7 @@ main(int argc, char *argv[])
if (!isdigit(**argv) &&
(comp->c_flags & IS_DENSITY)) {
const char *dcanon;
- mt_com.mt_count = stringtodens(*argv);
+ mt_com.mt_count = mt_density_num(*argv);
if (mt_com.mt_count == 0)
errx(1, "%s: unknown density", *argv);
dcanon = denstostring(mt_com.mt_count);
@@ -191,16 +277,17 @@ main(int argc, char *argv[])
errx(1, "%s: unknown compression",
*argv);
p = "";
- } else {
+ } else if ((comp->c_flags & USE_GETOPT) == 0) {
char *q;
/* allow for hex numbers; useful for density */
mt_com.mt_count = strtol(*argv, &q, 0);
p = q;
}
- if ((mt_com.mt_count <=
- ((comp->c_flags & ZERO_ALLOWED)? -1: 0)
- && ((comp->c_flags & IS_COMP) == 0)
- ) || *p)
+ if (((comp->c_flags & USE_GETOPT) == 0)
+ && (((mt_com.mt_count <=
+ ((comp->c_flags & ZERO_ALLOWED)? -1: 0))
+ && ((comp->c_flags & IS_COMP) == 0))
+ || *p))
errx(1, "%s: illegal count", *argv);
}
else
@@ -289,6 +376,47 @@ main(int argc, char *argv[])
exit(0);
/* NOTREACHED */
}
+ case MTIOCRBLIM:
+ {
+ struct mtrblim rblim;
+
+ bzero(&rblim, sizeof(rblim));
+
+ if (ioctl(mtfd, MTIOCRBLIM, (caddr_t)&rblim) < 0)
+ err(2, "%s", tape);
+ (void)printf("%s:\n"
+ " min blocksize %u byte%s\n"
+ " max blocksize %u byte%s\n"
+ " granularity %u byte%s\n",
+ tape, rblim.min_block_length,
+ MT_PLURAL(rblim.min_block_length),
+ rblim.max_block_length,
+ MT_PLURAL(rblim.max_block_length),
+ (1 << rblim.granularity),
+ MT_PLURAL((1 << rblim.granularity)));
+ exit(0);
+ /* NOTREACHED */
+ }
+ case MTIOCPARAMGET:
+ case MTIOCEXTGET:
+ case MT_CMD_PROTECT:
+ case MT_CMD_GETDENSITY:
+ {
+ int retval = 0;
+
+ retval = mt_xml_cmd(comp->c_code, argc, argv, mtfd,
+ tape);
+
+ exit(retval);
+ }
+ case MTIOCEXTLOCATE:
+ {
+ int retval = 0;
+
+ retval = mt_locate(argc, argv, mtfd, tape);
+
+ exit(retval);
+ }
default:
break;
}
@@ -381,62 +509,6 @@ usage(void)
exit(1);
}
-static const struct densities {
- int dens;
- int bpmm;
- int bpi;
- const char *name;
-} dens[] = {
- /*
- * Taken from T10 Project 997D
- * SCSI-3 Stream Device Commands (SSC)
- * Revision 11, 4-Nov-97
- */
- /*Num. bpmm bpi Reference */
- { 0x1, 32, 800, "X3.22-1983" },
- { 0x2, 63, 1600, "X3.39-1986" },
- { 0x3, 246, 6250, "X3.54-1986" },
- { 0x5, 315, 8000, "X3.136-1986" },
- { 0x6, 126, 3200, "X3.157-1987" },
- { 0x7, 252, 6400, "X3.116-1986" },
- { 0x8, 315, 8000, "X3.158-1987" },
- { 0x9, 491, 37871, "X3.180" },
- { 0xA, 262, 6667, "X3B5/86-199" },
- { 0xB, 63, 1600, "X3.56-1986" },
- { 0xC, 500, 12690, "HI-TC1" },
- { 0xD, 999, 25380, "HI-TC2" },
- { 0xF, 394, 10000, "QIC-120" },
- { 0x10, 394, 10000, "QIC-150" },
- { 0x11, 630, 16000, "QIC-320" },
- { 0x12, 2034, 51667, "QIC-1350" },
- { 0x13, 2400, 61000, "X3B5/88-185A" },
- { 0x14, 1703, 43245, "X3.202-1991" },
- { 0x15, 1789, 45434, "ECMA TC17" },
- { 0x16, 394, 10000, "X3.193-1990" },
- { 0x17, 1673, 42500, "X3B5/91-174" },
- { 0x18, 1673, 42500, "X3B5/92-50" },
- { 0x19, 2460, 62500, "DLTapeIII" },
- { 0x1A, 3214, 81633, "DLTapeIV(20GB)" },
- { 0x1B, 3383, 85937, "DLTapeIV(35GB)" },
- { 0x1C, 1654, 42000, "QIC-385M" },
- { 0x1D, 1512, 38400, "QIC-410M" },
- { 0x1E, 1385, 36000, "QIC-1000C" },
- { 0x1F, 2666, 67733, "QIC-2100C" },
- { 0x20, 2666, 67733, "QIC-6GB(M)" },
- { 0x21, 2666, 67733, "QIC-20GB(C)" },
- { 0x22, 1600, 40640, "QIC-2GB(C)" },
- { 0x23, 2666, 67733, "QIC-875M" },
- { 0x24, 2400, 61000, "DDS-2" },
- { 0x25, 3816, 97000, "DDS-3" },
- { 0x26, 3816, 97000, "DDS-4" },
- { 0x27, 3056, 77611, "Mammoth" },
- { 0x28, 1491, 37871, "X3.224" },
- { 0x41, 3868, 98250, "DLTapeIV(40GB)" },
- { 0x48, 5236, 133000, "SDLTapeI(110)" },
- { 0x49, 7598, 193000, "SDLTapeI(160)" },
- { 0, 0, 0, NULL }
-};
-
static const struct compression_types {
u_int32_t comp_number;
const char *name;
@@ -454,58 +526,15 @@ static const char *
denstostring(int d)
{
static char buf[20];
- const struct densities *sd;
+ const char *name = mt_density_name(d);
- /* densities 0 and 0x7f are handled as special cases */
- if (d == 0)
- return "default";
- if (d == 0x7f)
- return "same";
- for (sd = dens; sd->dens; sd++)
- if (sd->dens == d)
- break;
- if (sd->dens == 0)
+ if (name == NULL)
sprintf(buf, "0x%02x", d);
else
- sprintf(buf, "0x%02x:%s", d, sd->name);
+ sprintf(buf, "0x%02x:%s", d, name);
return buf;
}
-/*
- * Given a specific density number, return either the bits per inch or bits
- * per millimeter for the given density.
- */
-static int
-denstobp(int d, int bpi)
-{
- const struct densities *sd;
-
- for (sd = dens; sd->dens; sd++)
- if (sd->dens == d)
- break;
- if (sd->dens == 0)
- return(0);
- else {
- if (bpi)
- return(sd->bpi);
- else
- return(sd->bpmm);
- }
-}
-
-static int
-stringtodens(const char *s)
-{
- const struct densities *sd;
- size_t l = strlen(s);
-
- for (sd = dens; sd->dens; sd++)
- if (strncasecmp(sd->name, s, l) == 0)
- break;
- return sd->dens;
-}
-
-
static const char *
getblksiz(int bs)
{
@@ -553,6 +582,38 @@ stringtocomp(const char *s)
return(ct->comp_number);
}
+static struct driver_state {
+ int dsreg;
+ const char *desc;
+} driver_states[] = {
+ { MTIO_DSREG_REST, "at rest" },
+ { MTIO_DSREG_RBSY, "Communicating with drive" },
+ { MTIO_DSREG_WR, "Writing" },
+ { MTIO_DSREG_FMK, "Writing Filemarks" },
+ { MTIO_DSREG_ZER, "Erasing" },
+ { MTIO_DSREG_RD, "Reading" },
+ { MTIO_DSREG_FWD, "Spacing Forward" },
+ { MTIO_DSREG_REV, "Spacing Reverse" },
+ { MTIO_DSREG_POS, "Hardware Positioning (direction unknown)" },
+ { MTIO_DSREG_REW, "Rewinding" },
+ { MTIO_DSREG_TEN, "Retensioning" },
+ { MTIO_DSREG_UNL, "Unloading" },
+ { MTIO_DSREG_LD, "Loading" },
+};
+
+const char *
+get_driver_state_str(int dsreg)
+{
+ unsigned int i;
+
+ for (i = 0; i < (sizeof(driver_states)/sizeof(driver_states[0])); i++) {
+ if (driver_states[i].dsreg == dsreg)
+ return (driver_states[i].desc);
+ }
+
+ return (NULL);
+}
+
static void
st_status(struct mtget *bp)
{
@@ -565,73 +626,963 @@ st_status(struct mtget *bp)
"2: %-17s %-12s %-7d %s\n"
"3: %-17s %-12s %-7d %s\n",
denstostring(bp->mt_density), getblksiz(bp->mt_blksiz),
- denstobp(bp->mt_density, TRUE), comptostring(bp->mt_comp),
+ mt_density_bp(bp->mt_density, TRUE), comptostring(bp->mt_comp),
denstostring(bp->mt_density0), getblksiz(bp->mt_blksiz0),
- denstobp(bp->mt_density0, TRUE), comptostring(bp->mt_comp0),
+ mt_density_bp(bp->mt_density0, TRUE), comptostring(bp->mt_comp0),
denstostring(bp->mt_density1), getblksiz(bp->mt_blksiz1),
- denstobp(bp->mt_density1, TRUE), comptostring(bp->mt_comp1),
+ mt_density_bp(bp->mt_density1, TRUE), comptostring(bp->mt_comp1),
denstostring(bp->mt_density2), getblksiz(bp->mt_blksiz2),
- denstobp(bp->mt_density2, TRUE), comptostring(bp->mt_comp2),
+ mt_density_bp(bp->mt_density2, TRUE), comptostring(bp->mt_comp2),
denstostring(bp->mt_density3), getblksiz(bp->mt_blksiz3),
- denstobp(bp->mt_density3, TRUE), comptostring(bp->mt_comp3));
+ mt_density_bp(bp->mt_density3, TRUE), comptostring(bp->mt_comp3));
if (bp->mt_dsreg != MTIO_DSREG_NIL) {
- auto char foo[32];
const char sfmt[] = "Current Driver State: %s.\n";
printf("---------------------------------\n");
- switch (bp->mt_dsreg) {
- case MTIO_DSREG_REST:
- printf(sfmt, "at rest");
+ const char *state_str;
+
+ state_str = get_driver_state_str(bp->mt_dsreg);
+ if (state_str == NULL) {
+ char foo[32];
+ (void) sprintf(foo, "Unknown state 0x%x", bp->mt_dsreg);
+ printf(sfmt, foo);
+ } else {
+ printf(sfmt, state_str);
+ }
+ }
+ if (bp->mt_resid == 0 && bp->mt_fileno == (daddr_t) -1 &&
+ bp->mt_blkno == (daddr_t) -1)
+ return;
+ printf("---------------------------------\n");
+ printf("File Number: %d\tRecord Number: %d\tResidual Count %d\n",
+ bp->mt_fileno, bp->mt_blkno, bp->mt_resid);
+}
+
+static int
+mt_locate(int argc, char **argv, int mtfd, const char *tape)
+{
+ struct mtlocate mtl;
+ uint64_t logical_id = 0;
+ mt_locate_dest_type dest_type = MT_LOCATE_DEST_FILE;
+ int eod = 0, explicit = 0, immediate = 0;
+ int64_t partition = 0;
+ int block_addr_set = 0, partition_set = 0, file_set = 0, set_set = 0;
+ int c, retval;
+
+ retval = 0;
+ bzero(&mtl, sizeof(mtl));
+
+ while ((c = getopt(argc, argv, "b:eEf:ip:s:")) != -1) {
+ switch (c) {
+ case 'b':
+ /* Block address */
+ logical_id = strtoull(optarg, NULL, 0);
+ dest_type = MT_LOCATE_DEST_OBJECT;
+ block_addr_set = 1;
break;
- case MTIO_DSREG_RBSY:
- printf(sfmt, "Communicating with drive");
+ case 'e':
+ /* end of data */
+ eod = 1;
+ dest_type = MT_LOCATE_DEST_EOD;
break;
- case MTIO_DSREG_WR:
- printf(sfmt, "Writing");
+ case 'E':
+ /*
+ * XXX KDM explicit address mode. Should we even
+ * allow this, since the driver doesn't operate in
+ * explicit address mode?
+ */
+ explicit = 1;
break;
- case MTIO_DSREG_FMK:
- printf(sfmt, "Writing Filemarks");
+ case 'f':
+ /* file number */
+ logical_id = strtoull(optarg, NULL, 0);
+ dest_type = MT_LOCATE_DEST_FILE;
+ file_set = 1;
break;
- case MTIO_DSREG_ZER:
- printf(sfmt, "Erasing");
+ case 'i':
+ /*
+ * Immediate address mode. XXX KDM do we want to
+ * implement this? The other commands in the
+ * tape driver will need to be able to handle this.
+ */
+ immediate = 1;
break;
- case MTIO_DSREG_RD:
- printf(sfmt, "Reading");
+ case 'p':
+ /*
+ * Change partition to the given partition.
+ */
+ partition = strtol(optarg, NULL, 0);
+ partition_set = 1;
break;
- case MTIO_DSREG_FWD:
- printf(sfmt, "Spacing Forward");
+ case 's':
+ /* Go to the given set mark */
+ logical_id = strtoull(optarg, NULL, 0);
+ dest_type = MT_LOCATE_DEST_SET;
+ set_set = 1;
break;
- case MTIO_DSREG_REV:
- printf(sfmt, "Spacing Reverse");
+ default:
break;
- case MTIO_DSREG_POS:
- printf(sfmt,
- "Hardware Positioning (direction unknown)");
+ }
+ }
+
+ /*
+ * These options are mutually exclusive. The user may only specify
+ * one.
+ */
+ if ((block_addr_set + file_set + eod + set_set) != 1)
+ errx(1, "You must specify only one of -b, -f, -e, or -s");
+
+ mtl.dest_type = dest_type;
+ switch (dest_type) {
+ case MT_LOCATE_DEST_OBJECT:
+ case MT_LOCATE_DEST_FILE:
+ case MT_LOCATE_DEST_SET:
+ mtl.logical_id = logical_id;
+ break;
+ case MT_LOCATE_DEST_EOD:
+ break;
+ }
+
+ if (immediate != 0)
+ mtl.flags |= MT_LOCATE_FLAG_IMMED;
+
+ if (partition_set != 0) {
+ mtl.flags |= MT_LOCATE_FLAG_CHANGE_PART;
+ mtl.partition = partition;
+ }
+
+ if (explicit != 0)
+ mtl.block_address_mode = MT_LOCATE_BAM_EXPLICIT;
+ else
+ mtl.block_address_mode = MT_LOCATE_BAM_IMPLICIT;
+
+ if (ioctl(mtfd, MTIOCEXTLOCATE, &mtl) == -1)
+ err(1, "MTIOCEXTLOCATE ioctl failed on %s", tape);
+
+ return (retval);
+}
+
+typedef enum {
+ MT_PERIPH_NAME = 0,
+ MT_UNIT_NUMBER = 1,
+ MT_VENDOR = 2,
+ MT_PRODUCT = 3,
+ MT_REVISION = 4,
+ MT_COMPRESSION_SUPPORTED = 5,
+ MT_COMPRESSION_ENABLED = 6,
+ MT_COMPRESSION_ALGORITHM = 7,
+ MT_MEDIA_DENSITY = 8,
+ MT_MEDIA_BLOCKSIZE = 9,
+ MT_CALCULATED_FILENO = 10,
+ MT_CALCULATED_REL_BLKNO = 11,
+ MT_REPORTED_FILENO = 12,
+ MT_REPORTED_BLKNO = 13,
+ MT_PARTITION = 14,
+ MT_BOP = 15,
+ MT_EOP = 16,
+ MT_BPEW = 17,
+ MT_DSREG = 18,
+ MT_RESID = 19,
+ MT_FIXED_MODE = 20,
+ MT_SERIAL_NUM = 21,
+ MT_MAXIO = 22,
+ MT_CPI_MAXIO = 23,
+ MT_MAX_BLK = 24,
+ MT_MIN_BLK = 25,
+ MT_BLK_GRAN = 26,
+ MT_MAX_EFF_IOSIZE = 27
+} status_item_index;
+
+static struct mt_status_items {
+ const char *name;
+ struct mt_status_entry *entry;
+} req_status_items[] = {
+ { "periph_name", NULL },
+ { "unit_number", NULL },
+ { "vendor", NULL },
+ { "product", NULL },
+ { "revision", NULL },
+ { "compression_supported", NULL },
+ { "compression_enabled", NULL },
+ { "compression_algorithm", NULL },
+ { "media_density", NULL },
+ { "media_blocksize", NULL },
+ { "calculated_fileno", NULL },
+ { "calculated_rel_blkno", NULL },
+ { "reported_fileno", NULL },
+ { "reported_blkno", NULL },
+ { "partition", NULL },
+ { "bop", NULL },
+ { "eop", NULL },
+ { "bpew", NULL },
+ { "dsreg", NULL },
+ { "residual", NULL },
+ { "fixed_mode", NULL },
+ { "serial_num", NULL },
+ { "maxio", NULL },
+ { "cpi_maxio", NULL },
+ { "max_blk", NULL },
+ { "min_blk", NULL },
+ { "blk_gran", NULL },
+ { "max_effective_iosize", NULL }
+};
+
+int
+nstatus_print(int argc, char **argv, char *xml_str,
+ struct mt_status_data *status_data)
+{
+ unsigned int i;
+ int64_t calculated_fileno, calculated_rel_blkno;
+ int64_t rep_fileno, rep_blkno, partition, resid;
+ char block_str[32];
+ const char *dens_str;
+ int dsreg, bop, eop, bpew;
+ int xml_dump = 0;
+ size_t dens_len;
+ unsigned int field_width;
+ int verbose = 0;
+ int c;
+
+ while ((c = getopt(argc, argv, "xv")) != -1) {
+ switch (c) {
+ case 'x':
+ xml_dump = 1;
break;
- case MTIO_DSREG_REW:
- printf(sfmt, "Rewinding");
+ case 'v':
+ verbose = 1;
break;
- case MTIO_DSREG_TEN:
- printf(sfmt, "Retensioning");
+ default:
break;
- case MTIO_DSREG_UNL:
- printf(sfmt, "Unloading");
+ }
+ }
+
+ if (xml_dump != 0) {
+ printf("%s", xml_str);
+ return (0);
+ }
+
+ for (i = 0; i < (sizeof(req_status_items)/sizeof(req_status_items[0]));
+ i++) {
+ char *name;
+
+ name = __DECONST(char *, req_status_items[i].name);
+ req_status_items[i].entry = mt_status_entry_find(status_data,
+ name);
+ if (req_status_items[i].entry == NULL) {
+ errx(1, "Cannot find status entry %s",
+ req_status_items[i].name);
+ }
+ }
+
+ printf("Drive: %s%ju: <%s %s %s> Serial Number: %s\n",
+ req_status_items[MT_PERIPH_NAME].entry->value,
+ (uintmax_t)req_status_items[MT_UNIT_NUMBER].entry->value_unsigned,
+ req_status_items[MT_VENDOR].entry->value,
+ req_status_items[MT_PRODUCT].entry->value,
+ req_status_items[MT_REVISION].entry->value,
+ (req_status_items[MT_SERIAL_NUM].entry->value) ?
+ req_status_items[MT_SERIAL_NUM].entry->value : "none");
+ printf("---------------------------------\n");
+
+ /*
+ * We check to see whether we're in fixed mode or not, and don't
+ * just believe the blocksize. If the SILI bit is turned on, the
+ * blocksize will be set to 4, even though we're doing variable
+ * length (well, multiples of 4) blocks.
+ */
+ if (req_status_items[MT_FIXED_MODE].entry->value_signed == 0)
+ snprintf(block_str, sizeof(block_str), "variable");
+ else
+ snprintf(block_str, sizeof(block_str), "%s",
+ getblksiz(req_status_items[
+ MT_MEDIA_BLOCKSIZE].entry->value_unsigned));
+
+ dens_str = denstostring(req_status_items[
+ MT_MEDIA_DENSITY].entry->value_unsigned);
+ if (dens_str == NULL)
+ dens_len = 0;
+ else
+ dens_len = strlen(dens_str);
+ field_width = MAX(dens_len, 17);
+ printf("Mode %-*s Blocksize bpi Compression\n"
+ "Current: %-*s %-12s %-7d ",
+ field_width, "Density", field_width, dens_str, block_str,
+ mt_density_bp(req_status_items[
+ MT_MEDIA_DENSITY].entry->value_unsigned, TRUE));
+
+ if (req_status_items[MT_COMPRESSION_SUPPORTED].entry->value_signed == 0)
+ printf("unsupported\n");
+ else if (req_status_items[
+ MT_COMPRESSION_ENABLED].entry->value_signed == 0)
+ printf("disabled\n");
+ else {
+ printf("enabled (%s)\n",
+ comptostring(req_status_items[
+ MT_COMPRESSION_ALGORITHM].entry->value_unsigned));
+ }
+
+ dsreg = req_status_items[MT_DSREG].entry->value_signed;
+ if (dsreg != MTIO_DSREG_NIL) {
+ const char sfmt[] = "Current Driver State: %s.\n";
+ printf("---------------------------------\n");
+ const char *state_str;
+
+ state_str = get_driver_state_str(dsreg);
+ if (state_str == NULL) {
+ char foo[32];
+ (void) sprintf(foo, "Unknown state 0x%x", dsreg);
+ printf(sfmt, foo);
+ } else {
+ printf(sfmt, state_str);
+ }
+ }
+ resid = req_status_items[MT_RESID].entry->value_signed;
+ calculated_fileno = req_status_items[
+ MT_CALCULATED_FILENO].entry->value_signed;
+ calculated_rel_blkno = req_status_items[
+ MT_CALCULATED_REL_BLKNO].entry->value_signed;
+ rep_fileno = req_status_items[
+ MT_REPORTED_FILENO].entry->value_signed;
+ rep_blkno = req_status_items[
+ MT_REPORTED_BLKNO].entry->value_signed;
+ bop = req_status_items[MT_BOP].entry->value_signed;
+ eop = req_status_items[MT_EOP].entry->value_signed;
+ bpew = req_status_items[MT_BPEW].entry->value_signed;
+ partition = req_status_items[MT_PARTITION].entry->value_signed;
+
+ printf("---------------------------------\n");
+ printf("Partition: %3jd Calc File Number: %3jd "
+ " Calc Record Number: %jd\n"
+ "Residual: %3jd Reported File Number: %3jd "
+ "Reported Record Number: %jd\n", partition, calculated_fileno,
+ calculated_rel_blkno, resid, rep_fileno, rep_blkno);
+
+ printf("Flags: ");
+ if (bop > 0 || eop > 0 || bpew > 0) {
+ int need_comma = 0;
+
+ if (bop > 0) {
+ printf("BOP");
+ need_comma = 1;
+ }
+ if (eop > 0) {
+ if (need_comma != 0)
+ printf(",");
+ printf("EOP");
+ need_comma = 1;
+ }
+ if (bpew > 0) {
+ if (need_comma != 0)
+ printf(",");
+ printf("BPEW");
+ need_comma = 1;
+ }
+ } else {
+ printf("None");
+ }
+ printf("\n");
+ if (verbose != 0) {
+ printf("---------------------------------\n");
+ printf("Tape I/O parameters:\n");
+ for (i = MT_MAXIO; i <= MT_MAX_EFF_IOSIZE; i++) {
+ printf(" %s (%s): %ju bytes\n",
+ req_status_items[i].entry->desc,
+ req_status_items[i].name,
+ req_status_items[i].entry->value_unsigned);
+ }
+ }
+
+ return (0);
+}
+
+int
+mt_xml_cmd(unsigned long cmd, int argc, char **argv, int mtfd, const char *tape)
+{
+ struct mt_status_data status_data;
+#if 0
+ struct mt_status_entry *entry;
+#endif
+ char *xml_str;
+ int retval;
+ unsigned long ioctl_cmd;
+
+ switch (cmd) {
+ case MT_CMD_PROTECT:
+ case MTIOCPARAMGET:
+ ioctl_cmd = MTIOCPARAMGET;
+ break;
+ default:
+ ioctl_cmd = MTIOCEXTGET;
+ break;
+ }
+
+ retval = mt_get_xml_str(mtfd, ioctl_cmd, &xml_str);
+ if (retval != 0)
+ err(1, "Couldn't get mt XML string");
+
+ retval = mt_get_status(xml_str, &status_data);
+ if (retval != XML_STATUS_OK) {
+ warn("Couldn't get mt status for %s", tape);
+ goto bailout;
+ }
+
+ /*
+ * This gets set if there are memory allocation or other errors in
+ * our parsing of the XML.
+ */
+ if (status_data.error != 0) {
+ warnx("%s", status_data.error_str);
+ retval = 1;
+ goto bailout;
+ }
+#if 0
+ STAILQ_FOREACH(entry, &status_data.entries, links)
+ mt_status_tree_print(entry, 0, NULL);
+#endif
+
+ switch (cmd) {
+ case MTIOCEXTGET:
+ retval = nstatus_print(argc, argv, xml_str, &status_data);
+ break;
+ case MTIOCPARAMGET:
+ retval = mt_param(argc, argv, mtfd, xml_str, &status_data);
+ break;
+ case MT_CMD_PROTECT:
+ retval = mt_protect(argc, argv, mtfd, &status_data);
+ break;
+ case MT_CMD_GETDENSITY:
+ retval = mt_getdensity(argc, argv, xml_str, &status_data);
+ break;
+ }
+
+bailout:
+ if (xml_str != NULL)
+ free(xml_str);
+
+ mt_status_free(&status_data);
+
+ return (retval);
+}
+
+static int
+mt_set_param(int mtfd, struct mt_status_data *status_data, char *param_name,
+ char *param_value)
+{
+ struct mt_status_entry *entry;
+ struct mtparamset param_set;
+
+ entry = mt_status_entry_find(status_data,
+ __DECONST(char *, "mtparamget"));
+ if (entry == NULL)
+ errx(1, "Cannot find parameter root node");
+
+ bzero(&param_set, sizeof(param_set));
+ entry = mt_entry_find(entry, param_name);
+ if (entry == NULL)
+ errx(1, "Unknown parameter name \"%s\"", param_name);
+
+ strlcpy(param_set.value_name, param_name, sizeof(param_set.value_name));
+
+ switch (entry->var_type) {
+ case MT_TYPE_INT:
+ param_set.value.value_signed = strtoll(param_value, NULL, 0);
+ param_set.value_type = MT_PARAM_SET_SIGNED;
+ param_set.value_len = entry->size;
+ break;
+ case MT_TYPE_UINT:
+ param_set.value.value_unsigned = strtoull(param_value, NULL, 0);
+ param_set.value_type = MT_PARAM_SET_UNSIGNED;
+ param_set.value_len = entry->size;
+ break;
+ case MT_TYPE_STRING: {
+ size_t param_len;
+
+ param_len = strlen(param_value) + 1;
+ if (param_len > sizeof(param_set.value.value_fixed_str)) {
+ param_set.value_type = MT_PARAM_SET_VAR_STR;
+ param_set.value.value_var_str = param_value;
+ } else {
+ param_set.value_type = MT_PARAM_SET_FIXED_STR;
+ strlcpy(param_set.value.value_fixed_str, param_value,
+ sizeof(param_set.value.value_fixed_str));
+ }
+ param_set.value_len = param_len;
+ break;
+ }
+ default:
+ errx(1, "Unknown parameter type %d for %s", entry->var_type,
+ param_name);
+ break;
+ }
+
+ if (ioctl(mtfd, MTIOCPARAMSET, &param_set) == -1)
+ err(1, "MTIOCPARAMSET");
+
+ if (param_set.status != MT_PARAM_STATUS_OK)
+ errx(1, "Failed to set %s: %s", param_name,
+ param_set.error_str);
+
+ return (0);
+}
+
+
+typedef enum {
+ MT_PP_LBP_R,
+ MT_PP_LBP_W,
+ MT_PP_RBDP,
+ MT_PP_PI_LENGTH,
+ MT_PP_PROT_METHOD
+} mt_protect_param;
+
+static struct mt_protect_info {
+ const char *name;
+ struct mt_status_entry *entry;
+ uint32_t value;
+} mt_protect_list[] = {
+ { "lbp_r", NULL, 0 },
+ { "lbp_w", NULL, 0 },
+ { "rbdp", NULL, 0 },
+ { "pi_length", NULL, 0 },
+ { "prot_method", NULL, 0 }
+};
+
+#define MT_NUM_PROTECT_PARAMS (sizeof(mt_protect_list)/sizeof(mt_protect_list[0]))
+
+#define MT_PROT_NAME "protection"
+
+static int
+mt_protect(int argc, char **argv, int mtfd, struct mt_status_data *status_data)
+{
+ int retval = 0;
+ int do_enable = 0, do_disable = 0, do_list = 0;
+ int rbdp_set = 0, lbp_w_set = 0, lbp_r_set = 0;
+ int prot_method_set = 0, pi_length_set = 0;
+ int verbose = 0;
+ uint32_t rbdp = 0, lbp_w = 0, lbp_r = 0;
+ uint32_t prot_method = 0, pi_length = 0;
+ struct mt_status_entry *prot_entry, *supported_entry;
+ struct mt_status_entry *entry;
+ struct mtparamset params[MT_NUM_PROTECT_PARAMS];
+ struct mtsetlist param_list;
+ unsigned int i;
+ int c;
+
+ while ((c = getopt(argc, argv, "b:delL:m:r:vw:")) != -1) {
+ switch (c) {
+ case 'b':
+ rbdp_set = 1;
+ rbdp = strtoul(optarg, NULL, 0);
+ if ((rbdp != 0) && (rbdp != 1))
+ errx(1, "valid values for -b are 0 and 1");
break;
- case MTIO_DSREG_LD:
- printf(sfmt, "Loading");
+ case 'd':
+ do_disable = 1;
+ break;
+ case 'e':
+ do_enable = 1;
+ break;
+ case 'l':
+ do_list = 1;
+ break;
+ case 'L':
+ pi_length_set = 1;
+ pi_length = strtoul(optarg, NULL, 0);
+ if (pi_length > SA_CTRL_DP_PI_LENGTH_MASK)
+ errx(1, "PI length %u > maximum %u",
+ pi_length, SA_CTRL_DP_PI_LENGTH_MASK);
+ break;
+ case 'm':
+ prot_method_set = 1;
+ prot_method = strtoul(optarg, NULL, 0);
+ if (prot_method > SA_CTRL_DP_METHOD_MAX)
+ errx(1, "Method %u > maximum %u",
+ prot_method, SA_CTRL_DP_METHOD_MAX);
+ break;
+ case 'r':
+ lbp_r_set = 1;
+ lbp_r = strtoul(optarg, NULL, 0);
+ if ((lbp_r != 0) && (lbp_r != 1))
+ errx(1, "valid values for -r are 0 and 1");
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'w':
+ lbp_w_set = 1;
+ lbp_w = strtoul(optarg, NULL, 0);
+ if ((lbp_w != 0) && (lbp_r != 1))
+ errx(1, "valid values for -r are 0 and 1");
break;
default:
- (void) sprintf(foo, "Unknown state 0x%x", bp->mt_dsreg);
- printf(sfmt, foo);
break;
}
}
- if (bp->mt_resid == 0 && bp->mt_fileno == (daddr_t) -1 &&
- bp->mt_blkno == (daddr_t) -1)
- return;
- printf("---------------------------------\n");
- printf("File Number: %d\tRecord Number: %d\tResidual Count %d\n",
- bp->mt_fileno, bp->mt_blkno, bp->mt_resid);
+
+ if ((rbdp_set + do_disable + do_enable + do_list + pi_length_set +
+ prot_method_set + lbp_r_set + lbp_w_set) == 0)
+ errx(1, "Need an argument for protect");
+
+ if ((do_disable + do_enable + do_list) != 1)
+ errx(1, "You must specify only one of -e, -d or -l");
+
+ if (do_list != 0) {
+ retval = mt_protect_print(status_data, verbose);
+ goto bailout;
+ }
+ if (do_enable != 0) {
+ /*
+ * Enable protection, but allow the user to override
+ * settings if he doesn't want everything turned on.
+ */
+ if (rbdp_set == 0)
+ rbdp = 1;
+ if (lbp_w_set == 0)
+ lbp_w = 1;
+ if (lbp_r_set == 0)
+ lbp_r = 1;
+ /*
+ * If the user doesn't override it, we default to enabling
+ * Reed-Solomon checkums.
+ */
+ if (prot_method_set == 0)
+ prot_method = SA_CTRL_DP_REED_SOLOMON;
+ if (pi_length_set == 0)
+ pi_length = SA_CTRL_DP_RS_LENGTH;
+ } else if (do_disable != 0) {
+ /*
+ * If the user wants to disable protection, we ignore any
+ * other parameters he has set. Everything gets set to 0.
+ */
+ rbdp = lbp_w = lbp_r = 0;
+ prot_method = pi_length = 0;
+ }
+
+ prot_entry = mt_status_entry_find(status_data,
+ __DECONST(char *, MT_PROT_NAME));
+ if (prot_entry == NULL)
+ errx(1, "Unable to find protection information status");
+
+ supported_entry = mt_entry_find(prot_entry,
+ __DECONST(char *, "protection_supported"));
+ if (supported_entry == NULL)
+ errx(1, "Unable to find protection support information");
+
+ if (((supported_entry->var_type == MT_TYPE_INT)
+ && (supported_entry->value_signed == 0))
+ || ((supported_entry->var_type == MT_TYPE_UINT)
+ && (supported_entry->value_unsigned == 0)))
+ errx(1, "This device does not support protection information");
+
+ mt_protect_list[MT_PP_LBP_R].value = lbp_r;
+ mt_protect_list[MT_PP_LBP_W].value = lbp_w;
+ mt_protect_list[MT_PP_RBDP].value = rbdp;
+ mt_protect_list[MT_PP_PI_LENGTH].value = pi_length;
+ mt_protect_list[MT_PP_PROT_METHOD].value = prot_method;
+
+ bzero(&params, sizeof(params));
+ bzero(&param_list, sizeof(param_list));
+
+ /*
+ * Go through the list and make sure that we have this parameter,
+ * and that it is still an unsigned integer. If not, we've got a
+ * problem.
+ */
+ for (i = 0; i < MT_NUM_PROTECT_PARAMS; i++) {
+ entry = mt_entry_find(prot_entry,
+ __DECONST(char *, mt_protect_list[i].name));
+ if (entry == NULL) {
+ errx(1, "Unable to find parameter %s",
+ mt_protect_list[i].name);
+ }
+ mt_protect_list[i].entry = entry;
+
+ if (entry->var_type != MT_TYPE_UINT)
+ errx(1, "Parameter %s is type %d, not unsigned, "
+ "cannot proceed", mt_protect_list[i].name,
+ entry->var_type);
+ snprintf(params[i].value_name, sizeof(params[i].value_name),
+ "%s.%s", MT_PROT_NAME, mt_protect_list[i].name);
+ /* XXX KDM unify types here */
+ params[i].value_type = MT_PARAM_SET_UNSIGNED;
+ params[i].value_len = sizeof(mt_protect_list[i].value);
+ params[i].value.value_unsigned = mt_protect_list[i].value;
+
+ }
+ param_list.num_params = MT_NUM_PROTECT_PARAMS;
+ param_list.param_len = sizeof(params);
+ param_list.params = params;
+
+ if (ioctl(mtfd, MTIOCSETLIST, &param_list) == -1)
+ err(1, "error issuing MTIOCSETLIST ioctl");
+
+ for (i = 0; i < MT_NUM_PROTECT_PARAMS; i++) {
+ if (params[i].status != MT_PARAM_STATUS_OK) {
+ warnx("%s", params[i].error_str);
+ retval = 1;
+ }
+ }
+bailout:
+
+ return (retval);
+}
+
+static int
+mt_param(int argc, char **argv, int mtfd, char *xml_str,
+ struct mt_status_data *status_data)
+{
+ int list = 0, do_set = 0, xml_dump = 0;
+ char *param_name = NULL, *param_value = NULL;
+ int retval = 0, quiet = 0;
+ int c;
+
+ while ((c = getopt(argc, argv, "lp:qs:x")) != -1) {
+ switch (c) {
+ case 'l':
+ list = 1;
+ break;
+ case 'p':
+ if (param_name != NULL) {
+ warnx("Only one paramter name may be "
+ "specified");
+ retval = 1;
+ goto bailout;
+ }
+ param_name = strdup(optarg);
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 's':
+ if (param_value != NULL) {
+ warnx("Only one paramter value may be "
+ "specified");
+ retval = 1;
+ goto bailout;
+ }
+ param_value = strdup(optarg);
+ do_set = 1;
+ break;
+ case 'x':
+ xml_dump = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if ((list + do_set + xml_dump) != 1) {
+ warnx("You must specify only one of -s, -l or -x");
+ retval = 1;
+ goto bailout;
+ }
+
+ if (xml_dump != 0) {
+ printf("%s", xml_str);
+ retval = 0;
+ goto bailout;
+ }
+
+ if (do_set != 0) {
+ if (param_name == NULL)
+ errx(1, "You must specify -p with -s");
+
+ retval = mt_set_param(mtfd, status_data, param_name,
+ param_value);
+ } else if (list != 0)
+ retval = mt_param_list(status_data, param_name, quiet);
+
+bailout:
+ free(param_name);
+ free(param_value);
+ return (retval);
+}
+
+int
+mt_print_density_entry(struct mt_status_entry *density_root, int indent)
+{
+ struct mt_status_entry *entry;
+ int retval = 0;
+
+ STAILQ_FOREACH(entry, &density_root->child_entries, links) {
+ if (entry->var_type == MT_TYPE_NODE) {
+ retval = mt_print_density_entry(entry, indent + 2);
+ if (retval != 0)
+ break;
+ else
+ continue;
+ }
+ if ((strcmp(entry->entry_name, "primary_density_code") == 0)
+ || (strcmp(entry->entry_name, "secondary_density_code") == 0)
+ || (strcmp(entry->entry_name, "density_code") == 0)) {
+
+ printf("%*s%s (%s): %s\n", indent, "", entry->desc ?
+ entry->desc : "", entry->entry_name,
+ denstostring(entry->value_unsigned));
+ } else if (strcmp(entry->entry_name, "density_flags") == 0) {
+ printf("%*sMedium Access: ", indent, "");
+ if (entry->value_unsigned & MT_DENS_WRITE_OK) {
+ printf("Read and Write\n");
+ } else {
+ printf("Read Only\n");
+ }
+ printf("%*sDefault Density: %s\n", indent, "",
+ (entry->value_unsigned & MT_DENS_DEFLT) ? "Yes" :
+ "No");
+ printf("%*sDuplicate Density: %s\n", indent, "",
+ (entry->value_unsigned & MT_DENS_DUP) ? "Yes" :
+ "No");
+ } else if (strcmp(entry->entry_name, "media_width") == 0) {
+ printf("%*s%s (%s): %.1f mm\n", indent, "",
+ entry->desc ? entry->desc : "", entry->entry_name,
+ (double)((double)entry->value_unsigned / 10));
+ } else if (strcmp(entry->entry_name, "medium_length") == 0) {
+ printf("%*s%s (%s): %ju m\n", indent, "",
+ entry->desc ? entry->desc : "", entry->entry_name,
+ (uintmax_t)entry->value_unsigned);
+ } else if (strcmp(entry->entry_name, "capacity") == 0) {
+ printf("%*s%s (%s): %ju MB\n", indent, "", entry->desc ?
+ entry->desc : "", entry->entry_name,
+ (uintmax_t)entry->value_unsigned);
+ } else {
+ printf("%*s%s (%s): %s\n", indent, "", entry->desc ?
+ entry->desc : "", entry->entry_name, entry->value);
+ }
+ }
+
+ return (retval);
+}
+
+int
+mt_print_density_report(struct mt_status_entry *report_root, int indent)
+{
+ struct mt_status_entry *mt_report, *media_report;
+ struct mt_status_entry *entry;
+ int retval = 0;
+
+ mt_report = mt_entry_find(report_root,
+ __DECONST(char *, MT_MEDIUM_TYPE_REPORT_NAME));
+ if (mt_report == NULL)
+ return (1);
+
+ media_report = mt_entry_find(report_root,
+ __DECONST(char *, MT_MEDIA_REPORT_NAME));
+ if (media_report == NULL)
+ return (1);
+
+ if ((mt_report->value_signed == 0)
+ && (media_report->value_signed == 0)) {
+ printf("%*sThis tape drive supports the following "
+ "media densities:\n", indent, "");
+ } else if ((mt_report->value_signed == 0)
+ && (media_report->value_signed != 0)) {
+ printf("%*sThe tape currently in this drive supports "
+ "the following media densities:\n", indent, "");
+ } else if ((mt_report->value_signed != 0)
+ && (media_report->value_signed == 0)) {
+ printf("%*sThis tape drive supports the following "
+ "media types:\n", indent, "");
+ } else {
+ printf("%*sThis tape currently in this drive supports "
+ "the following media types:\n", indent, "");
+ }
+
+ STAILQ_FOREACH(entry, &report_root->child_entries, links) {
+ struct mt_status_nv *nv;
+
+ if (strcmp(entry->entry_name, MT_DENSITY_ENTRY_NAME) != 0)
+ continue;
+
+ STAILQ_FOREACH(nv, &entry->nv_list, links) {
+ if (strcmp(nv->name, "num") != 0)
+ continue;
+
+ break;
+ }
+
+ indent += 2;
+
+ printf("%*sDensity Entry", indent, "");
+ if (nv != NULL)
+ printf(" %s", nv->value);
+ printf(":\n");
+
+ retval = mt_print_density_entry(entry, indent + 2);
+
+ indent -= 2;
+ }
+
+ return (retval);
+}
+
+int
+mt_print_density(struct mt_status_entry *density_root, int indent)
+{
+ struct mt_status_entry *entry;
+ int retval = 0;
+
+ /*
+ * We should have this entry for every tape drive. This particular
+ * value is reported via the mode page block header, not the
+ * SCSI REPORT DENSITY SUPPORT command.
+ */
+ entry = mt_entry_find(density_root,
+ __DECONST(char *, MT_MEDIA_DENSITY_NAME));
+ if (entry == NULL)
+ errx(1, "Unable to find node %s", MT_MEDIA_DENSITY_NAME);
+
+ printf("%*sCurrent density: %s\n", indent, "",
+ denstostring(entry->value_unsigned));
+
+ /*
+ * It isn't an error if we don't have any density reports. Tape
+ * drives that don't support the REPORT DENSITY SUPPORT command
+ * won't have any; they will only have the current density entry
+ * above.
+ */
+ STAILQ_FOREACH(entry, &density_root->child_entries, links) {
+ if (strcmp(entry->entry_name, MT_DENSITY_REPORT_NAME) != 0)
+ continue;
+
+ retval = mt_print_density_report(entry, indent);
+ }
+
+ return (retval);
+}
+
+int
+mt_getdensity(int argc, char **argv, char *xml_str,
+ struct mt_status_data *status_data)
+{
+ int retval = 0;
+ int verbose = 0, xml_dump = 0;
+ struct mt_status_entry *density_root = NULL;
+ int c;
+
+ while ((c = getopt(argc, argv, "vx")) != -1) {
+ switch (c) {
+ case 'v':
+ verbose = 1;
+ break;
+ case 'x':
+ xml_dump = 1;
+ break;
+ }
+ }
+
+ if (xml_dump != 0) {
+ printf("%s", xml_str);
+ return (0);
+ }
+
+ density_root = mt_status_entry_find(status_data,
+ __DECONST(char *, MT_DENSITY_ROOT_NAME));
+ if (density_root == NULL)
+ errx(1, "Cannot find density root node %s",
+ MT_DENSITY_ROOT_NAME);
+
+ retval = mt_print_density(density_root, 0);
+
+ return (retval);
}
static void
diff --git a/usr.bin/nc/Makefile b/usr.bin/nc/Makefile
index 17cea06..b24a086 100644
--- a/usr.bin/nc/Makefile
+++ b/usr.bin/nc/Makefile
@@ -6,8 +6,7 @@ PROG= nc
SRCS= netcat.c atomicio.c socks.c
CFLAGS+=-DIPSEC
-LDADD= -lipsec
-DPADD= ${LIBIPSEC}
+LIBADD= ipsec
WARNS?= 2
diff --git a/usr.bin/ncal/Makefile b/usr.bin/ncal/Makefile
index 1422ce1..23b5da2 100644
--- a/usr.bin/ncal/Makefile
+++ b/usr.bin/ncal/Makefile
@@ -4,8 +4,7 @@
PROG= ncal
-DPADD= ${LIBCALENDAR} ${LIBTERMCAPW}
-LDADD= -lcalendar -ltermcapw
+LIBADD= calendar ncursesw
LINKS= ${BINDIR}/ncal ${BINDIR}/cal
MLINKS= ncal.1 cal.1
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile
index 2d50a49..9c70eb4 100644
--- a/usr.bin/netstat/Makefile
+++ b/usr.bin/netstat/Makefile
@@ -33,14 +33,14 @@ CFLAGS+=-DPF
BINGRP= kmem
BINMODE=2555
-DPADD= ${LIBKVM} ${LIBMEMSTAT} ${LIBUTIL}
-LDADD= -lkvm -lmemstat -lutil
+LIBADD= kvm memstat util
.if ${MK_NETGRAPH_SUPPORT} != "no"
SRCS+= netgraph.c
-DPADD+= ${LIBNETGRAPH}
-LDADD+= -lnetgraph
+LIBADD+= netgraph
CFLAGS+=-DNETGRAPH
.endif
+LIBADD+= xo
+
.include <bsd.prog.mk>
diff --git a/usr.bin/netstat/Makefile.depend b/usr.bin/netstat/Makefile.depend
index 225f5f8..cf3f475 100644
--- a/usr.bin/netstat/Makefile.depend
+++ b/usr.bin/netstat/Makefile.depend
@@ -15,6 +15,7 @@ DIRDEPS = \
lib/libmemstat \
lib/libnetgraph \
lib/libutil \
+ lib/libxo \
.include <dirdeps.mk>
diff --git a/usr.bin/netstat/bpf.c b/usr.bin/netstat/bpf.c
index 2ffeacb..60546e3 100644
--- a/usr.bin/netstat/bpf.c
+++ b/usr.bin/netstat/bpf.c
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
#include <sys/user.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/bpf.h>
#include <net/bpfdesc.h>
#include <arpa/inet.h>
@@ -46,8 +45,10 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "netstat.h"
@@ -67,7 +68,7 @@ bpf_pidname(pid_t pid)
size = sizeof(newkp);
error = sysctl(mib, 4, &newkp, &size, NULL, 0);
if (error < 0) {
- warn("kern.proc.pid failed");
+ xo_warn("kern.proc.pid failed");
return (strdup("??????"));
}
return (strdup(newkp.ki_comm));
@@ -86,6 +87,21 @@ bpf_flags(struct xbpf_d *bd, char *flagbuf)
*flagbuf++ = bd->bd_async ? 'a' : '-';
*flagbuf++ = bd->bd_locked ? 'l' : '-';
*flagbuf++ = '\0';
+
+ if (bd->bd_promisc)
+ xo_emit("{e:promiscuous/}");
+ if (bd->bd_immediate)
+ xo_emit("{e:immediate/}");
+ if (bd->bd_hdrcmplt)
+ xo_emit("{e:header-complete/}");
+ xo_emit("{e:direction}", (bd->bd_direction == BPF_D_IN) ? "input" :
+ (bd->bd_direction == BPF_D_OUT) ? "output" : "bidirectional");
+ if (bd->bd_feedback)
+ xo_emit("{e:feedback/}");
+ if (bd->bd_async)
+ xo_emit("{e:async/}");
+ if (bd->bd_locked)
+ xo_emit("{e:locked/}");
}
void
@@ -99,44 +115,55 @@ bpf_stats(char *ifname)
bzero(&zerostat, sizeof(zerostat));
if (sysctlbyname("net.bpf.stats", NULL, NULL,
&zerostat, sizeof(zerostat)) < 0)
- warn("failed to zero bpf counters");
+ xo_warn("failed to zero bpf counters");
return;
}
if (sysctlbyname("net.bpf.stats", NULL, &size,
NULL, 0) < 0) {
- warn("net.bpf.stats");
+ xo_warn("net.bpf.stats");
return;
}
if (size == 0)
return;
bd = malloc(size);
if (bd == NULL) {
- warn("malloc failed");
+ xo_warn("malloc failed");
return;
}
if (sysctlbyname("net.bpf.stats", bd, &size,
NULL, 0) < 0) {
- warn("net.bpf.stats");
+ xo_warn("net.bpf.stats");
free(bd);
return;
}
- (void) printf("%5s %6s %7s %9s %9s %9s %5s %5s %s\n",
- "Pid", "Netif", "Flags", "Recv", "Drop", "Match", "Sblen",
- "Hblen", "Command");
+ xo_emit("{T:/%5s} {T:/%6s} {T:/%7s} {T:/%9s} {T:/%9s} {T:/%9s} "
+ "{T:/%5s} {T:/%5s} {T:/%s}\n",
+ "Pid", "Netif", "Flags", "Recv", "Drop", "Match",
+ "Sblen", "Hblen", "Command");
+ xo_open_container("bpf-statistics");
+ xo_open_list("bpf-entry");
for (d = &bd[0]; d < &bd[size / sizeof(*d)]; d++) {
if (d->bd_structsize != sizeof(*d)) {
- warnx("bpf_stats_extended: version mismatch");
+ xo_warnx("bpf_stats_extended: version mismatch");
return;
}
if (ifname && strcmp(ifname, d->bd_ifname) != 0)
continue;
- bpf_flags(d, flagbuf);
+ xo_open_instance("bpf-entry");
pname = bpf_pidname(d->bd_pid);
- (void) printf("%5d %6s %7s %9ju %9ju %9ju %5d %5d %s\n",
- d->bd_pid, d->bd_ifname, flagbuf,
- d->bd_rcount, d->bd_dcount, d->bd_fcount,
- d->bd_slen, d->bd_hlen, pname);
+ xo_emit("{k:pid/%5d} {k:interface-name/%6s} ",
+ d->bd_pid, d->bd_ifname);
+ bpf_flags(d, flagbuf);
+ xo_emit("{d:flags/%7s} {:received-packets/%9ju} "
+ "{:dropped-packets/%9ju} {:filter-packets/%9ju} "
+ "{:store-buffer-length/%5d} {:hold-buffer-length/%5d} "
+ "{:process/%s}\n",
+ flagbuf, (uintmax_t)d->bd_rcount, (uintmax_t)d->bd_dcount,
+ (uintmax_t)d->bd_fcount, d->bd_slen, d->bd_hlen, pname);
free(pname);
+ xo_close_instance("bpf-entry");
}
+ xo_close_list("bpf-entry");
+ xo_close_container("bpf-statistics");
free(bd);
}
diff --git a/usr.bin/netstat/flowtable.c b/usr.bin/netstat/flowtable.c
index a3d5dd5..a232d80 100644
--- a/usr.bin/netstat/flowtable.c
+++ b/usr.bin/netstat/flowtable.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdbool.h>
#include "netstat.h"
/*
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index a4c86be..109ef2d 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/ethernet.h>
@@ -72,6 +71,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "netstat.h"
@@ -98,14 +98,38 @@ static const char* pfsyncacts[] = {
/* PFSYNC_ACT_EOF */ "end of frame mark",
};
+static const char* pfsyncacts_name[] = {
+ /* PFSYNC_ACT_CLR */ "clear-all-request",
+ /* PFSYNC_ACT_INS */ "state-insert",
+ /* PFSYNC_ACT_INS_ACK */ "state-inserted-ack",
+ /* PFSYNC_ACT_UPD */ "state-update",
+ /* PFSYNC_ACT_UPD_C */ "compressed-state-update",
+ /* PFSYNC_ACT_UPD_REQ */ "uncompressed-state-request",
+ /* PFSYNC_ACT_DEL */ "state-delete",
+ /* PFSYNC_ACT_DEL_C */ "compressed-state-delete",
+ /* PFSYNC_ACT_INS_F */ "fragment-insert",
+ /* PFSYNC_ACT_DEL_F */ "fragment-delete",
+ /* PFSYNC_ACT_BUS */ "bulk-update-mark",
+ /* PFSYNC_ACT_TDB */ "TDB-replay-counter-update",
+ /* PFSYNC_ACT_EOF */ "end-of-frame-mark",
+};
+
static void
-pfsync_acts_stats(const char *fmt, uint64_t *a)
+pfsync_acts_stats(const char *list, const char *desc, uint64_t *a)
{
int i;
- for (i = 0; i < PFSYNC_ACT_MAX; i++, a++)
- if (*a || sflag <= 1)
- printf(fmt, *a, pfsyncacts[i], plural(*a));
+ xo_open_list(list);
+ for (i = 0; i < PFSYNC_ACT_MAX; i++, a++) {
+ if (*a || sflag <= 1) {
+ xo_open_instance(list);
+ xo_emit("\t\t{e:name}{:count/%ju} {N:/%s%s %s}\n",
+ pfsyncacts_name[i], (uintmax_t)(*a),
+ pfsyncacts[i], plural(*a), desc);
+ xo_close_instance(list);
+ }
+ }
+ xo_close_list(list);
}
/*
@@ -129,32 +153,50 @@ pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
} else
kread(off, &pfsyncstat, len);
- printf("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
+ xo_open_container(name);
#define p(f, m) if (pfsyncstat.f || sflag <= 1) \
- printf(m, (uintmax_t)pfsyncstat.f, plural(pfsyncstat.f))
+ xo_emit(m, (uintmax_t)pfsyncstat.f, plural(pfsyncstat.f))
- p(pfsyncs_ipackets, "\t%ju packet%s received (IPv4)\n");
- p(pfsyncs_ipackets6, "\t%ju packet%s received (IPv6)\n");
- pfsync_acts_stats("\t %ju %s%s received\n",
+ p(pfsyncs_ipackets, "\t{:received-inet-packets/%ju} "
+ "{N:/packet%s received (IPv4)}\n");
+ p(pfsyncs_ipackets6, "\t{:received-inet6-packets/%ju} "
+ "{N:/packet%s received (IPv6)}\n");
+ pfsync_acts_stats("input-histogram", "received",
&pfsyncstat.pfsyncs_iacts[0]);
- p(pfsyncs_badif, "\t\t%ju packet%s discarded for bad interface\n");
- p(pfsyncs_badttl, "\t\t%ju packet%s discarded for bad ttl\n");
- p(pfsyncs_hdrops, "\t\t%ju packet%s shorter than header\n");
- p(pfsyncs_badver, "\t\t%ju packet%s discarded for bad version\n");
- p(pfsyncs_badauth, "\t\t%ju packet%s discarded for bad HMAC\n");
- p(pfsyncs_badact,"\t\t%ju packet%s discarded for bad action\n");
- p(pfsyncs_badlen, "\t\t%ju packet%s discarded for short packet\n");
- p(pfsyncs_badval, "\t\t%ju state%s discarded for bad values\n");
- p(pfsyncs_stale, "\t\t%ju stale state%s\n");
- p(pfsyncs_badstate, "\t\t%ju failed state lookup/insert%s\n");
- p(pfsyncs_opackets, "\t%ju packet%s sent (IPv4)\n");
- p(pfsyncs_opackets6, "\t%ju packet%s sent (IPv6)\n");
- pfsync_acts_stats("\t %ju %s%s sent\n",
+ p(pfsyncs_badif, "\t\t/{:dropped-bad-interface/%ju} "
+ "{N:/packet%s discarded for bad interface}\n");
+ p(pfsyncs_badttl, "\t\t{:dropped-bad-ttl/%ju} "
+ "{N:/packet%s discarded for bad ttl}\n");
+ p(pfsyncs_hdrops, "\t\t{:dropped-short-header/%ju} "
+ "{N:/packet%s shorter than header}\n");
+ p(pfsyncs_badver, "\t\t{:dropped-bad-version/%ju} "
+ "{N:/packet%s discarded for bad version}\n");
+ p(pfsyncs_badauth, "\t\t{:dropped-bad-auth/%ju} "
+ "{N:/packet%s discarded for bad HMAC}\n");
+ p(pfsyncs_badact,"\t\t{:dropped-bad-action/%ju} "
+ "{N:/packet%s discarded for bad action}\n");
+ p(pfsyncs_badlen, "\t\t{:dropped-short/%ju} "
+ "{N:/packet%s discarded for short packet}\n");
+ p(pfsyncs_badval, "\t\t{:dropped-bad-values/%ju} "
+ "{N:/state%s discarded for bad values}\n");
+ p(pfsyncs_stale, "\t\t{:dropped-stale-state/%ju} "
+ "{N:/stale state%s}\n");
+ p(pfsyncs_badstate, "\t\t{:dropped-failed-lookup/%ju} "
+ "{N:/failed state lookup\\/insert%s}\n");
+ p(pfsyncs_opackets, "\t{:sent-inet-packets/%ju} "
+ "{N:/packet%s sent (IPv4})\n");
+ p(pfsyncs_opackets6, "\t{:send-inet6-packets/%ju} "
+ "{N:/packet%s sent (IPv6})\n");
+ pfsync_acts_stats("output-histogram", "sent",
&pfsyncstat.pfsyncs_oacts[0]);
- p(pfsyncs_onomem, "\t\t%ju failure%s due to mbuf memory error\n");
- p(pfsyncs_oerrors, "\t\t%ju send error%s\n");
+ p(pfsyncs_onomem, "\t\t{:discarded-no-memory/%ju} "
+ "{N:/failure%s due to mbuf memory error}\n");
+ p(pfsyncs_oerrors, "\t\t{:send-errors/%ju} "
+ "{N:/send error%s}\n");
#undef p
+ xo_close_container(name);
}
#endif /* PF */
@@ -162,10 +204,11 @@ pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
* Display a formatted value, or a '-' in the same space.
*/
static void
-show_stat(const char *fmt, int width, u_long value, short showvalue)
+show_stat(const char *fmt, int width, const char *name,
+ u_long value, short showvalue)
{
const char *lsep, *rsep;
- char newfmt[32];
+ char newfmt[64];
lsep = "";
if (strncmp(fmt, "LS", 2) == 0) {
@@ -179,23 +222,38 @@ show_stat(const char *fmt, int width, u_long value, short showvalue)
}
if (showvalue == 0) {
/* Print just dash. */
- sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
- printf(newfmt, "-");
+ xo_emit("{P:/%s}{D:/%*s}{P:/%s}", lsep, width, "-", rsep);
return;
}
+ /*
+ * XXX: workaround {P:} modifier can't be empty and doesn't seem to
+ * take args... so we need to conditionally include it in the format.
+ */
+#define maybe_pad(pad) do { \
+ if (strlen(pad)) { \
+ snprintf(newfmt, sizeof(newfmt), "{P:%s}", pad); \
+ xo_emit(newfmt); \
+ } \
+} while (0)
+
if (hflag) {
char buf[5];
/* Format in human readable form. */
humanize_number(buf, sizeof(buf), (int64_t)value, "",
HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
- sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
- printf(newfmt, buf);
+ maybe_pad(lsep);
+ snprintf(newfmt, sizeof(newfmt), "{:%s/%%%ds}", name, width);
+ xo_emit(newfmt, buf);
+ maybe_pad(rsep);
} else {
/* Construct the format string. */
- sprintf(newfmt, "%s%%%d%s%s", lsep, width, fmt, rsep);
- printf(newfmt, value);
+ maybe_pad(lsep);
+ snprintf(newfmt, sizeof(newfmt), "{:%s/%%%d%s}",
+ name, width, fmt);
+ xo_emit(newfmt, value);
+ maybe_pad(rsep);
}
}
@@ -235,34 +293,37 @@ intpr(int interval, void (*pfunc)(char *), int af)
if (aflag && getifmaddrs(&ifmap) != 0)
err(EX_OSERR, "getifmaddrs");
+ xo_open_list("interface");
if (!pfunc) {
if (Wflag)
- printf("%-7.7s", "Name");
+ xo_emit("{T:/%-7.7s}", "Name");
else
- printf("%-5.5s", "Name");
- printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s",
+ xo_emit("{T:/%-5.5s}", "Name");
+ xo_emit(" {T:/%5.5s} {T:/%-13.13s} {T:/%-17.17s} {T:/%8.8s} "
+ "{T:/%5.5s} {T:/%5.5s}",
"Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop");
if (bflag)
- printf(" %10.10s","Ibytes");
- printf(" %8.8s %5.5s", "Opkts", "Oerrs");
+ xo_emit(" {T:/%10.10s}","Ibytes");
+ xo_emit(" {T:/%8.8s} {T:/%5.5s}", "Opkts", "Oerrs");
if (bflag)
- printf(" %10.10s","Obytes");
- printf(" %5s", "Coll");
+ xo_emit(" {T:/%10.10s}","Obytes");
+ xo_emit(" {T:/%5s}", "Coll");
if (dflag)
- printf(" %s", "Drop");
- putchar('\n');
+ xo_emit(" {T:/%s}", "Drop");
+ xo_emit("\n");
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
bool network = false, link = false;
+ char *name, *xname, buf[IFNAMSIZ+1];
if (interface != NULL && strcmp(ifa->ifa_name, interface) != 0)
continue;
+ name = ifa->ifa_name;
+
if (pfunc) {
- char *name;
- name = ifa->ifa_name;
(*pfunc)(name);
/*
@@ -278,19 +339,31 @@ intpr(int interval, void (*pfunc)(char *), int af)
if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af)
continue;
+ xo_open_instance("interface");
+
+ if ((ifa->ifa_flags & IFF_UP) == 0) {
+ xname = stpcpy(buf, name);
+ *xname++ = '*';
+ *xname = '\0';
+ xname = buf;
+ } else
+ xname = name;
+
if (Wflag)
- printf("%-7.7s", ifa->ifa_name);
+ xo_emit("{etk:name/%s}{e:flags/0x%x}{d:/%7.7s}",
+ name, ifa->ifa_flags, xname);
else
- printf("%-5.5s", ifa->ifa_name);
+ xo_emit("{etk:name/%s}{e:flags/0x%x}{d:/%5.5s}",
+ name, ifa->ifa_flags, xname);
#define IFA_MTU(ifa) (((struct if_data *)(ifa)->ifa_data)->ifi_mtu)
- show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa));
+ show_stat("lu", 6, "mtu", IFA_MTU(ifa), IFA_MTU(ifa));
#undef IFA_MTU
switch (ifa->ifa_addr->sa_family) {
case AF_UNSPEC:
- printf("%-13.13s ", "none");
- printf("%-15.15s ", "none");
+ xo_emit("{:network/%-13.13s} ", "none");
+ xo_emit("{:address/%-15.15s} ", "none");
break;
case AF_INET:
{
@@ -298,9 +371,10 @@ intpr(int interval, void (*pfunc)(char *), int af)
sin = (struct sockaddr_in *)ifa->ifa_addr;
mask = (struct sockaddr_in *)ifa->ifa_netmask;
- printf("%-13.13s ", netname(sin->sin_addr.s_addr,
+ xo_emit("{t:network/%-13.13s} ",
+ netname(sin->sin_addr.s_addr,
mask->sin_addr.s_addr));
- printf("%-17.17s ",
+ xo_emit("{t:address/%-17.17s} ",
routename(sin->sin_addr.s_addr));
network = true;
@@ -314,67 +388,82 @@ intpr(int interval, void (*pfunc)(char *), int af)
sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
mask = (struct sockaddr_in6 *)ifa->ifa_netmask;
- printf("%-13.13s ", netname6(sin6, &mask->sin6_addr));
+ xo_emit("{t:network/%-13.13s} ",
+ netname6(sin6, &mask->sin6_addr));
getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len,
addr_buf, sizeof(addr_buf), 0, 0, NI_NUMERICHOST);
- printf("%-17.17s ", addr_buf);
+ xo_emit("{t:address/%-17.17s} ", addr_buf);
network = 1;
break;
- }
+ }
#endif /* INET6 */
case AF_LINK:
{
struct sockaddr_dl *sdl;
char *cp, linknum[10];
- int n, m;
+ int len = 32;
+ char buf[len];
+ int n, z;
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
cp = (char *)LLADDR(sdl);
n = sdl->sdl_alen;
sprintf(linknum, "<Link#%d>", sdl->sdl_index);
- m = printf("%-13.13s ", linknum);
-
- while ((--n >= 0) && (m < 30))
- m += printf("%02x%c", *cp++ & 0xff,
- n > 0 ? ':' : ' ');
- m = 32 - m;
- while (m-- > 0)
- putchar(' ');
-
+ xo_emit("{t:network/%-13.13s} ", linknum);
+ buf[0] = '\0';
+ z = 0;
+ while ((--n >= 0) && (z < len)) {
+ snprintf(buf + z, len - z, "%02x%c",
+ *cp++ & 0xff, n > 0 ? ':' : ' ');
+ z += 3;
+ }
+ if (z > 0)
+ xo_emit("{:address/%*s}", 32 - z, buf);
+ else
+ xo_emit("{P: }");
link = 1;
break;
}
}
#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
- show_stat("lu", 8, IFA_STAT(ipackets), link|network);
- show_stat("lu", 5, IFA_STAT(ierrors), link);
- show_stat("lu", 5, IFA_STAT(iqdrops), link);
+ show_stat("lu", 8, "received-packets", IFA_STAT(ipackets),
+ link|network);
+ show_stat("lu", 5, "received-errors", IFA_STAT(ierrors), link);
+ show_stat("lu", 5, "dropped-packets", IFA_STAT(iqdrops), link);
if (bflag)
- show_stat("lu", 10, IFA_STAT(ibytes), link|network);
- show_stat("lu", 8, IFA_STAT(opackets), link|network);
- show_stat("lu", 5, IFA_STAT(oerrors), link);
+ show_stat("lu", 10, "received-bytes", IFA_STAT(ibytes),
+ link|network);
+ show_stat("lu", 8, "sent-packets", IFA_STAT(opackets),
+ link|network);
+ show_stat("lu", 5, "send-errors", IFA_STAT(oerrors), link);
if (bflag)
- show_stat("lu", 10, IFA_STAT(obytes), link|network);
- show_stat("NRSlu", 5, IFA_STAT(collisions), link);
+ show_stat("lu", 10, "sent-bytes", IFA_STAT(obytes),
+ link|network);
+ show_stat("NRSlu", 5, "collisions", IFA_STAT(collisions), link);
if (dflag)
- show_stat("LSlu", 5, IFA_STAT(oqdrops), link);
- putchar('\n');
+ show_stat("LSlu", 5, "dropped-packets",
+ IFA_STAT(oqdrops), link);
+ xo_emit("\n");
- if (!aflag)
+ if (!aflag) {
+ xo_close_instance("interface");
continue;
+ }
/*
* Print family's multicast addresses.
*/
+ xo_open_list("multicast-address");
for (ifma = next_ifma(ifmap, ifa->ifa_name,
- ifa->ifa_addr->sa_family);
- ifma != NULL;
- ifma = next_ifma(ifma, ifa->ifa_name,
- ifa->ifa_addr->sa_family)) {
+ ifa->ifa_addr->sa_family);
+ ifma != NULL;
+ ifma = next_ifma(ifma, ifa->ifa_name,
+ ifa->ifa_addr->sa_family)) {
const char *fmt = NULL;
+ xo_open_instance("multicast-address");
switch (ifma->ifma_addr->sa_family) {
case AF_INET:
{
@@ -391,7 +480,7 @@ intpr(int interval, void (*pfunc)(char *), int af)
getnameinfo(ifma->ifma_addr,
ifma->ifma_addr->sa_len, addr_buf,
sizeof(addr_buf), 0, 0, NI_NUMERICHOST);
- printf("%*s %s\n",
+ xo_emit("{P:/%*s }{t:address/%-19.19s}",
Wflag ? 27 : 25, "", addr_buf);
break;
#endif /* INET6 */
@@ -412,21 +501,24 @@ intpr(int interval, void (*pfunc)(char *), int af)
}
if (fmt) {
- printf("%*s %-17.17s",
+ xo_emit("{P:/%*s }{t:address/%-17.17s/}",
Wflag ? 27 : 25, "", fmt);
if (ifma->ifma_addr->sa_family == AF_LINK) {
- printf(" %8ju",
- (uintmax_t )IFA_STAT(imcasts));
- printf("%*s", bflag ? 17 : 6, "");
- printf(" %8ju",
- (uintmax_t )IFA_STAT(omcasts));
- }
- putchar('\n');
+ xo_emit(" {:received-packets/%8lu}",
+ IFA_STAT(imcasts));
+ xo_emit("{P:/%*s}", bflag? 17 : 6, "");
+ xo_emit(" {:sent-packets/%8lu}",
+ IFA_STAT(omcasts));
+ }
+ xo_emit("\n");
}
-
+ xo_close_instance("multicast-address");
ifma = ifma->ifma_next;
}
+ xo_close_list("multicast-address");
+ xo_close_instance("interface");
}
+ xo_close_list("interface");
freeifaddrs(ifap);
if (aflag)
@@ -455,7 +547,7 @@ fill_iftot(struct iftot *st)
bool found = false;
if (getifaddrs(&ifap) != 0)
- err(EX_OSERR, "getifaddrs");
+ xo_err(EX_OSERR, "getifaddrs");
bzero(st, sizeof(*st));
@@ -481,7 +573,7 @@ fill_iftot(struct iftot *st)
}
if (interface && found == false)
- err(EX_DATAERR, "interface %s not found", interface);
+ xo_err(EX_DATAERR, "interface %s not found", interface);
freeifaddrs(ifap);
}
@@ -520,23 +612,26 @@ sidewaysintpr(int interval)
interval_it.it_interval.tv_usec = 0;
interval_it.it_value = interval_it.it_interval;
setitimer(ITIMER_REAL, &interval_it, NULL);
+ xo_open_list("interface-statistics");
banner:
- printf("%17s %14s %16s", "input",
+ xo_emit("{T:/%17s} {T:/%14s} {T:/%16s}\n", "input",
interface != NULL ? interface : "(Total)", "output");
- putchar('\n');
- printf("%10s %5s %5s %10s %10s %5s %10s %5s",
+ xo_emit("{T:/%10s} {T:/%5s} {T:/%5s} {T:/%10s} {T:/%10s} {T:/%5s} "
+ "{T:/%10s} {T:/%5s}",
"packets", "errs", "idrops", "bytes", "packets", "errs", "bytes",
"colls");
if (dflag)
- printf(" %5.5s", "drops");
- putchar('\n');
- fflush(stdout);
+ xo_emit(" {T:/%5.5s}", "drops");
+ xo_emit("\n");
+ xo_flush();
line = 0;
loop:
- if ((noutputs != 0) && (--noutputs == 0))
- exit(0);
+ if ((noutputs != 0) && (--noutputs == 0)) {
+ xo_close_list("interface-statistics");
+ return;
+ }
oldmask = sigblock(sigmask(SIGALRM));
while (!signalled)
sigpause(0);
@@ -546,18 +641,29 @@ loop:
fill_iftot(new);
- show_stat("lu", 10, new->ift_ip - old->ift_ip, 1);
- show_stat("lu", 5, new->ift_ie - old->ift_ie, 1);
- show_stat("lu", 5, new->ift_id - old->ift_id, 1);
- show_stat("lu", 10, new->ift_ib - old->ift_ib, 1);
- show_stat("lu", 10, new->ift_op - old->ift_op, 1);
- show_stat("lu", 5, new->ift_oe - old->ift_oe, 1);
- show_stat("lu", 10, new->ift_ob - old->ift_ob, 1);
- show_stat("NRSlu", 5, new->ift_co - old->ift_co, 1);
+ xo_open_instance("stats");
+ show_stat("lu", 10, "received-packets",
+ new->ift_ip - old->ift_ip, 1);
+ show_stat("lu", 5, "received-errors",
+ new->ift_ie - old->ift_ie, 1);
+ show_stat("lu", 5, "dropped-packets",
+ new->ift_id - old->ift_id, 1);
+ show_stat("lu", 10, "received-bytes",
+ new->ift_ib - old->ift_ib, 1);
+ show_stat("lu", 10, "sent-packets",
+ new->ift_op - old->ift_op, 1);
+ show_stat("lu", 5, "send-errors",
+ new->ift_oe - old->ift_oe, 1);
+ show_stat("lu", 10, "sent-bytes",
+ new->ift_ob - old->ift_ob, 1);
+ show_stat("NRSlu", 5, "collisions",
+ new->ift_co - old->ift_co, 1);
if (dflag)
- show_stat("LSlu", 5, new->ift_od - old->ift_od, 1);
- putchar('\n');
- fflush(stdout);
+ show_stat("LSlu", 5, "dropped-packets",
+ new->ift_od - old->ift_od, 1);
+ xo_close_instance("stats");
+ xo_emit("\n");
+ xo_flush();
if (new == &ift[0]) {
new = &ift[1];
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 10d0698..c966bf4 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -78,12 +78,14 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "netstat.h"
char *inetname(struct in_addr *);
-void inetprint(struct in_addr *, int, const char *, int);
+void inetprint(const char *, struct in_addr *, int, const char *, int);
#ifdef INET6
static int udp_done, tcp_done, sdp_done;
#endif /* INET6 */
@@ -114,15 +116,15 @@ pcblist_sysctl(int proto, const char *name, char **bufp, int istcp __unused)
len = 0;
if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: %s", mibvar);
+ xo_warn("sysctl: %s", mibvar);
return (0);
}
if ((buf = malloc(len)) == 0) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return (0);
}
if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
- warn("sysctl: %s", mibvar);
+ xo_warn("sysctl: %s", mibvar);
free(buf);
return (0);
}
@@ -137,7 +139,7 @@ pcblist_sysctl(int proto, const char *name, char **bufp, int istcp __unused)
static void
sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
{
- xsb->sb_cc = sb->sb_cc;
+ xsb->sb_cc = sb->sb_ccc;
xsb->sb_hiwat = sb->sb_hiwat;
xsb->sb_mbcnt = sb->sb_mbcnt;
xsb->sb_mcnt = sb->sb_mcnt;
@@ -205,14 +207,14 @@ pcblist_kvm(u_long off, char **bufp, int istcp)
(pcbinfo.ipi_count + pcbinfo.ipi_count / 8) *
sizeof(struct xinpcb);
if ((buf = malloc(len)) == 0) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return (0);
}
p = buf;
#define COPYOUT(obj, size) do { \
if (len < (size)) { \
- warnx("buffer size exceeded"); \
+ xo_warnx("buffer size exceeded"); \
goto fail; \
} \
bcopy((obj), p, (size)); \
@@ -349,8 +351,8 @@ protopr(u_long off, const char *name, int af1, int proto)
oxig = xig = (struct xinpgen *)buf;
for (xig = (struct xinpgen *)((char *)xig + xig->xig_len);
- xig->xig_len > sizeof(struct xinpgen);
- xig = (struct xinpgen *)((char *)xig + xig->xig_len)) {
+ xig->xig_len > sizeof(struct xinpgen);
+ xig = (struct xinpgen *)((char *)xig + xig->xig_len)) {
if (istcp) {
timer = &((struct xtcpcb *)xig)->xt_timer;
tp = &((struct xtcpcb *)xig)->xt_tp;
@@ -403,185 +405,218 @@ protopr(u_long off, const char *name, int af1, int proto)
if (first) {
if (!Lflag) {
- printf("Active Internet connections");
+ xo_emit("Active Internet connections");
if (aflag)
- printf(" (including servers)");
+ xo_emit(" (including servers)");
} else
- printf(
+ xo_emit(
"Current listen queue sizes (qlen/incqlen/maxqlen)");
- putchar('\n');
+ xo_emit("\n");
if (Aflag)
- printf("%-*s ", 2 * (int)sizeof(void *), "Tcpcb");
+ xo_emit("{T:/%-*s} ", 2 * (int)sizeof(void *),
+ "Tcpcb");
if (Lflag)
- printf((Aflag && !Wflag) ?
- "%-5.5s %-14.14s %-18.18s" :
- "%-5.5s %-14.14s %-22.22s",
+ xo_emit((Aflag && !Wflag) ?
+ "{T:/%-5.5s} {T:/%-14.14s} {T:/%-18.18s}" :
+ "{T:/%-5.5s} {T:/%-14.14s} {T:/%-22.22s}",
"Proto", "Listen", "Local Address");
else if (Tflag)
- printf((Aflag && !Wflag) ?
- "%-5.5s %-6.6s %-6.6s %-6.6s %-18.18s %s" :
- "%-5.5s %-6.6s %-6.6s %-6.6s %-22.22s %s",
+ xo_emit((Aflag && !Wflag) ?
+ "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%s}" :
+ "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%s}",
"Proto", "Rexmit", "OOORcv", "0-win",
"Local Address", "Foreign Address");
else {
- printf((Aflag && !Wflag) ?
- "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s" :
- "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s",
- "Proto", "Recv-Q", "Send-Q",
- "Local Address", "Foreign Address");
+ xo_emit((Aflag && !Wflag) ?
+ "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%-18.18s}" :
+ "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%-22.22s}",
+ "Proto", "Recv-Q", "Send-Q",
+ "Local Address", "Foreign Address");
if (!xflag && !Rflag)
- printf(" (state)");
+ xo_emit(" (state)");
}
if (xflag) {
- printf(" %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s",
- "R-MBUF", "S-MBUF", "R-CLUS",
- "S-CLUS", "R-HIWA", "S-HIWA",
- "R-LOWA", "S-LOWA", "R-BCNT",
- "S-BCNT", "R-BMAX", "S-BMAX");
- printf(" %7.7s %7.7s %7.7s %7.7s %7.7s %7.7s",
- "rexmt", "persist", "keep",
- "2msl", "delack", "rcvtime");
+ xo_emit(" {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} "
+ "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} "
+ "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} "
+ "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s}",
+ "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS",
+ "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA",
+ "R-BCNT", "S-BCNT", "R-BMAX", "S-BMAX");
+ xo_emit(" {T:/%7.7s} {T:/%7.7s} {T:/%7.7s} "
+ "{T:/%7.7s} {T:/%7.7s} {T:/%7.7s}",
+ "rexmt", "persist", "keep", "2msl",
+ "delack", "rcvtime");
} else if (Rflag) {
- printf (" %8.8s %5.5s",
+ xo_emit(" {T:/%8.8s} {T:/%5.5s}",
"flowid", "ftype");
}
- putchar('\n');
+ xo_emit("\n");
first = 0;
}
if (Lflag && so->so_qlimit == 0)
continue;
+ xo_open_instance("socket");
if (Aflag) {
if (istcp)
- printf("%*lx ", 2 * (int)sizeof(void *), (u_long)inp->inp_ppcb);
+ xo_emit("{q:address/%*lx} ",
+ 2 * (int)sizeof(void *),
+ (u_long)inp->inp_ppcb);
else
- printf("%*lx ", 2 * (int)sizeof(void *), (u_long)so->so_pcb);
+ xo_emit("{q:adddress/%*lx} ",
+ 2 * (int)sizeof(void *),
+ (u_long)so->so_pcb);
}
#ifdef INET6
if ((inp->inp_vflag & INP_IPV6) != 0)
vchar = ((inp->inp_vflag & INP_IPV4) != 0) ?
- "46" : "6 ";
+ "46" : "6";
else
#endif
vchar = ((inp->inp_vflag & INP_IPV4) != 0) ?
- "4 " : " ";
+ "4" : "";
if (istcp && (tp->t_flags & TF_TOE) != 0)
- printf("%-3.3s%-2.2s ", "toe", vchar);
+ xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", "toe", vchar);
else
- printf("%-3.3s%-2.2s ", name, vchar);
+ xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", name, vchar);
if (Lflag) {
char buf1[15];
snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
so->so_incqlen, so->so_qlimit);
- printf("%-14.14s ", buf1);
+ xo_emit("{:listen-queue-sizes/%-14.14s} ", buf1);
} else if (Tflag) {
if (istcp)
- printf("%6u %6u %6u ", tp->t_sndrexmitpack,
- tp->t_rcvoopack, tp->t_sndzerowin);
+ xo_emit("{:sent-retransmit-packets/%6u} "
+ "{:received-out-of-order-packets/%6u} "
+ "{:sent-zero-window/%6u} ",
+ tp->t_sndrexmitpack, tp->t_rcvoopack,
+ tp->t_sndzerowin);
} else {
- printf("%6u %6u ", so->so_rcv.sb_cc, so->so_snd.sb_cc);
+ xo_emit("{:receive-bytes-waiting/%6u} "
+ "{:send-bytes-waiting/%6u} ",
+ so->so_rcv.sb_cc, so->so_snd.sb_cc);
}
if (numeric_port) {
if (inp->inp_vflag & INP_IPV4) {
- inetprint(&inp->inp_laddr, (int)inp->inp_lport,
- name, 1);
+ inetprint("local", &inp->inp_laddr,
+ (int)inp->inp_lport, name, 1);
if (!Lflag)
- inetprint(&inp->inp_faddr,
+ inetprint("remote", &inp->inp_faddr,
(int)inp->inp_fport, name, 1);
}
#ifdef INET6
else if (inp->inp_vflag & INP_IPV6) {
- inet6print(&inp->in6p_laddr,
+ inet6print("local", &inp->in6p_laddr,
(int)inp->inp_lport, name, 1);
if (!Lflag)
- inet6print(&inp->in6p_faddr,
+ inet6print("remote", &inp->in6p_faddr,
(int)inp->inp_fport, name, 1);
} /* else nothing printed now */
#endif /* INET6 */
} else if (inp->inp_flags & INP_ANONPORT) {
if (inp->inp_vflag & INP_IPV4) {
- inetprint(&inp->inp_laddr, (int)inp->inp_lport,
- name, 1);
+ inetprint("local", &inp->inp_laddr,
+ (int)inp->inp_lport, name, 1);
if (!Lflag)
- inetprint(&inp->inp_faddr,
+ inetprint("remote", &inp->inp_faddr,
(int)inp->inp_fport, name, 0);
}
#ifdef INET6
else if (inp->inp_vflag & INP_IPV6) {
- inet6print(&inp->in6p_laddr,
+ inet6print("local", &inp->in6p_laddr,
(int)inp->inp_lport, name, 1);
if (!Lflag)
- inet6print(&inp->in6p_faddr,
+ inet6print("remote", &inp->in6p_faddr,
(int)inp->inp_fport, name, 0);
} /* else nothing printed now */
#endif /* INET6 */
} else {
if (inp->inp_vflag & INP_IPV4) {
- inetprint(&inp->inp_laddr, (int)inp->inp_lport,
- name, 0);
+ inetprint("local", &inp->inp_laddr,
+ (int)inp->inp_lport, name, 0);
if (!Lflag)
- inetprint(&inp->inp_faddr,
+ inetprint("remote", &inp->inp_faddr,
(int)inp->inp_fport, name,
inp->inp_lport != inp->inp_fport);
}
#ifdef INET6
else if (inp->inp_vflag & INP_IPV6) {
- inet6print(&inp->in6p_laddr,
+ inet6print("local", &inp->in6p_laddr,
(int)inp->inp_lport, name, 0);
if (!Lflag)
- inet6print(&inp->in6p_faddr,
+ inet6print("remote", &inp->in6p_faddr,
(int)inp->inp_fport, name,
inp->inp_lport != inp->inp_fport);
} /* else nothing printed now */
#endif /* INET6 */
}
if (xflag) {
- printf("%6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u",
- so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
- so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
- so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
- so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
- so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
- so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
+ xo_emit("{:receive-mbufs/%6u} {:send-mbufs/%6u} "
+ "{:receive-clusters/%6u} {:send-clusters/%6u} "
+ "{:receive-high-water/%6u} {:send-high-water/%6u} "
+ "{:receive-low-water/%6u} {:send-low-water/%6u} "
+ "{:receive-mbuf-bytes/%6u} {:send-mbuf-bytes/%6u} "
+ "{:receive-mbuf-bytes-max/%6u} "
+ "{:send-mbuf-bytes-max/%6u}",
+ so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
+ so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
+ so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
+ so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
+ so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
+ so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
if (timer != NULL)
- printf(" %4d.%02d %4d.%02d %4d.%02d %4d.%02d %4d.%02d %4d.%02d",
- timer->tt_rexmt / 1000, (timer->tt_rexmt % 1000) / 10,
- timer->tt_persist / 1000, (timer->tt_persist % 1000) / 10,
- timer->tt_keep / 1000, (timer->tt_keep % 1000) / 10,
- timer->tt_2msl / 1000, (timer->tt_2msl % 1000) / 10,
- timer->tt_delack / 1000, (timer->tt_delack % 1000) / 10,
- timer->t_rcvtime / 1000, (timer->t_rcvtime % 1000) / 10);
+ xo_emit(" {:retransmit-timer/%4d.%02d} "
+ "{:persist-timer/%4d.%02d} "
+ "{:keepalive-timer/%4d.%02d} "
+ "{:msl2-timer/%4d.%02d} "
+ "{:delay-ack-timer/%4d.%02d} "
+ "{:inactivity-timer/%4d.%02d}",
+ timer->tt_rexmt / 1000,
+ (timer->tt_rexmt % 1000) / 10,
+ timer->tt_persist / 1000,
+ (timer->tt_persist % 1000) / 10,
+ timer->tt_keep / 1000,
+ (timer->tt_keep % 1000) / 10,
+ timer->tt_2msl / 1000,
+ (timer->tt_2msl % 1000) / 10,
+ timer->tt_delack / 1000,
+ (timer->tt_delack % 1000) / 10,
+ timer->t_rcvtime / 1000,
+ (timer->t_rcvtime % 1000) / 10);
}
if (istcp && !Lflag && !xflag && !Tflag && !Rflag) {
if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES)
- printf("%d", tp->t_state);
+ xo_emit("{:tcp-state/%d}", tp->t_state);
else {
- printf("%s", tcpstates[tp->t_state]);
+ xo_emit("{:tcp-state/%s}",
+ tcpstates[tp->t_state]);
#if defined(TF_NEEDSYN) && defined(TF_NEEDFIN)
/* Show T/TCP `hidden state' */
if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN))
- putchar('*');
+ xo_emit("{:need-syn-or-fin/*}");
#endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */
}
}
if (Rflag) {
- printf(" %08x %5d",
+ /* XXX: is this right Alfred */
+ xo_emit(" {:flow-id/%08x} {:flow-type/%5d}",
inp->inp_flowid,
inp->inp_flowtype);
}
- putchar('\n');
+ xo_emit("\n");
+ xo_close_instance("socket");
}
if (xig != oxig && xig->xig_gen != oxig->xig_gen) {
if (oxig->xig_count > xig->xig_count) {
- printf("Some %s sockets may have been deleted.\n",
- name);
+ xo_emit("Some {d:lost/%s} sockets may have been "
+ "deleted.\n", name);
} else if (oxig->xig_count < xig->xig_count) {
- printf("Some %s sockets may have been created.\n",
- name);
+ xo_emit("Some {d:created/%s} sockets may have been "
+ "created.\n", name);
} else {
- printf(
- "Some %s sockets may have been created or deleted.\n",
- name);
+ xo_emit("Some {d:changed/%s} sockets may have been "
+ "created or deleted.\n", name);
}
}
free(buf);
@@ -608,146 +643,216 @@ tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
memset(&zerostat, 0, len);
if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.tcp.stats");
+ xo_warn("sysctl: net.inet.tcp.stats");
return;
}
} else
kread_counters(off, &tcpstat, len);
- printf ("%s:\n", name);
+ xo_open_container("tcp");
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (tcpstat.f || sflag <= 1) \
- printf(m, (uintmax_t )tcpstat.f, plural(tcpstat.f))
-
+ xo_emit(m, (uintmax_t )tcpstat.f, plural(tcpstat.f))
#define p1a(f, m) if (tcpstat.f || sflag <= 1) \
- printf(m, (uintmax_t )tcpstat.f)
-
+ xo_emit(m, (uintmax_t )tcpstat.f)
#define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
- printf(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \
+ xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \
(uintmax_t )tcpstat.f2, plural(tcpstat.f2))
-
#define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
- printf(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \
+ xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \
(uintmax_t )tcpstat.f2)
-
#define p3(f, m) if (tcpstat.f || sflag <= 1) \
- printf(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f))
-
- p(tcps_sndtotal, "\t%ju packet%s sent\n");
- p2(tcps_sndpack,tcps_sndbyte, "\t\t%ju data packet%s (%ju byte%s)\n");
- p2(tcps_sndrexmitpack, tcps_sndrexmitbyte,
- "\t\t%ju data packet%s (%ju byte%s) retransmitted\n");
- p(tcps_sndrexmitbad,
- "\t\t%ju data packet%s unnecessarily retransmitted\n");
- p(tcps_mturesent, "\t\t%ju resend%s initiated by MTU discovery\n");
- p2a(tcps_sndacks, tcps_delack,
- "\t\t%ju ack-only packet%s (%ju delayed)\n");
- p(tcps_sndurg, "\t\t%ju URG only packet%s\n");
- p(tcps_sndprobe, "\t\t%ju window probe packet%s\n");
- p(tcps_sndwinup, "\t\t%ju window update packet%s\n");
- p(tcps_sndctrl, "\t\t%ju control packet%s\n");
- p(tcps_rcvtotal, "\t%ju packet%s received\n");
- p2(tcps_rcvackpack, tcps_rcvackbyte,
- "\t\t%ju ack%s (for %ju byte%s)\n");
- p(tcps_rcvdupack, "\t\t%ju duplicate ack%s\n");
- p(tcps_rcvacktoomuch, "\t\t%ju ack%s for unsent data\n");
- p2(tcps_rcvpack, tcps_rcvbyte,
- "\t\t%ju packet%s (%ju byte%s) received in-sequence\n");
- p2(tcps_rcvduppack, tcps_rcvdupbyte,
- "\t\t%ju completely duplicate packet%s (%ju byte%s)\n");
- p(tcps_pawsdrop, "\t\t%ju old duplicate packet%s\n");
- p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte,
- "\t\t%ju packet%s with some dup. data (%ju byte%s duped)\n");
- p2(tcps_rcvoopack, tcps_rcvoobyte,
- "\t\t%ju out-of-order packet%s (%ju byte%s)\n");
- p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin,
- "\t\t%ju packet%s (%ju byte%s) of data after window\n");
- p(tcps_rcvwinprobe, "\t\t%ju window probe%s\n");
- p(tcps_rcvwinupd, "\t\t%ju window update packet%s\n");
- p(tcps_rcvafterclose, "\t\t%ju packet%s received after close\n");
- p(tcps_rcvbadsum, "\t\t%ju discarded for bad checksum%s\n");
- p(tcps_rcvbadoff, "\t\t%ju discarded for bad header offset field%s\n");
- p1a(tcps_rcvshort, "\t\t%ju discarded because packet too short\n");
- p1a(tcps_rcvreassfull,
- "\t\t%ju discarded due to no space in reassembly queue\n");
- p(tcps_connattempt, "\t%ju connection request%s\n");
- p(tcps_accepts, "\t%ju connection accept%s\n");
- p(tcps_badsyn, "\t%ju bad connection attempt%s\n");
- p(tcps_listendrop, "\t%ju listen queue overflow%s\n");
- p(tcps_badrst, "\t%ju ignored RSTs in the window%s\n");
- p(tcps_connects, "\t%ju connection%s established (including accepts)\n");
- p2(tcps_closed, tcps_drops,
- "\t%ju connection%s closed (including %ju drop%s)\n");
- p(tcps_cachedrtt, "\t\t%ju connection%s updated cached RTT on close\n");
- p(tcps_cachedrttvar,
- "\t\t%ju connection%s updated cached RTT variance on close\n");
- p(tcps_cachedssthresh,
- "\t\t%ju connection%s updated cached ssthresh on close\n");
- p(tcps_conndrops, "\t%ju embryonic connection%s dropped\n");
- p2(tcps_rttupdated, tcps_segstimed,
- "\t%ju segment%s updated rtt (of %ju attempt%s)\n");
- p(tcps_rexmttimeo, "\t%ju retransmit timeout%s\n");
- p(tcps_timeoutdrop, "\t\t%ju connection%s dropped by rexmit timeout\n");
- p(tcps_persisttimeo, "\t%ju persist timeout%s\n");
- p(tcps_persistdrop, "\t\t%ju connection%s dropped by persist timeout\n");
- p(tcps_finwait2_drops,
- "\t%ju Connection%s (fin_wait_2) dropped because of timeout\n");
- p(tcps_keeptimeo, "\t%ju keepalive timeout%s\n");
- p(tcps_keepprobe, "\t\t%ju keepalive probe%s sent\n");
- p(tcps_keepdrops, "\t\t%ju connection%s dropped by keepalive\n");
- p(tcps_predack, "\t%ju correct ACK header prediction%s\n");
- p(tcps_preddat, "\t%ju correct data packet header prediction%s\n");
-
- p3(tcps_sc_added, "\t%ju syncache entr%s added\n");
- p1a(tcps_sc_retransmitted, "\t\t%ju retransmitted\n");
- p1a(tcps_sc_dupsyn, "\t\t%ju dupsyn\n");
- p1a(tcps_sc_dropped, "\t\t%ju dropped\n");
- p1a(tcps_sc_completed, "\t\t%ju completed\n");
- p1a(tcps_sc_bucketoverflow, "\t\t%ju bucket overflow\n");
- p1a(tcps_sc_cacheoverflow, "\t\t%ju cache overflow\n");
- p1a(tcps_sc_reset, "\t\t%ju reset\n");
- p1a(tcps_sc_stale, "\t\t%ju stale\n");
- p1a(tcps_sc_aborted, "\t\t%ju aborted\n");
- p1a(tcps_sc_badack, "\t\t%ju badack\n");
- p1a(tcps_sc_unreach, "\t\t%ju unreach\n");
- p(tcps_sc_zonefail, "\t\t%ju zone failure%s\n");
- p(tcps_sc_sendcookie, "\t%ju cookie%s sent\n");
- p(tcps_sc_recvcookie, "\t%ju cookie%s received\n");
-
- p3(tcps_hc_added, "\t%ju hostcache entr%s added\n");
- p1a(tcps_hc_bucketoverflow, "\t\t%ju bucket overflow\n");
-
- p(tcps_sack_recovery_episode, "\t%ju SACK recovery episode%s\n");
- p(tcps_sack_rexmits,
- "\t%ju segment rexmit%s in SACK recovery episodes\n");
- p(tcps_sack_rexmit_bytes,
- "\t%ju byte rexmit%s in SACK recovery episodes\n");
- p(tcps_sack_rcv_blocks,
- "\t%ju SACK option%s (SACK blocks) received\n");
- p(tcps_sack_send_blocks, "\t%ju SACK option%s (SACK blocks) sent\n");
- p1a(tcps_sack_sboverflow, "\t%ju SACK scoreboard overflow\n");
-
- p(tcps_ecn_ce, "\t%ju packet%s with ECN CE bit set\n");
- p(tcps_ecn_ect0, "\t%ju packet%s with ECN ECT(0) bit set\n");
- p(tcps_ecn_ect1, "\t%ju packet%s with ECN ECT(1) bit set\n");
- p(tcps_ecn_shs, "\t%ju successful ECN handshake%s\n");
- p(tcps_ecn_rcwnd, "\t%ju time%s ECN reduced the congestion window\n");
-
- p(tcps_sig_rcvgoodsig,
- "\t%ju packet%s with valid tcp-md5 signature received\n");
- p(tcps_sig_rcvbadsig,
- "\t%ju packet%s with invalid tcp-md5 signature received\n");
- p(tcps_sig_err_buildsig,
- "\t%ju packet%s with tcp-md5 signature mismatch\n");
- p(tcps_sig_err_sigopt,
- "\t%ju packet%s with unexpected tcp-md5 signature received\n");
- p(tcps_sig_err_nosigopt,
- "\t%ju packet%s without expected tcp-md5 signature received\n");
-#undef p
-#undef p1a
-#undef p2
-#undef p2a
-#undef p3
+ xo_emit(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f))
+
+ p(tcps_sndtotal, "\t{:sent-packets/%ju} {N:/packet%s sent}\n");
+ p2(tcps_sndpack,tcps_sndbyte, "\t\t{:sent-data-packets/%ju} "
+ "{N:/data packet%s} ({:sent-data-bytes/%ju} {N:/byte%s})\n");
+ p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t"
+ "{:sent-retransmitted-packets/%ju} {N:/data packet%s} "
+ "({:sent-retransmitted-bytes/%ju} {N:/byte%s}) "
+ "{N:retransmitted}\n");
+ p(tcps_sndrexmitbad, "\t\t"
+ "{:sent-unnecessary-retransmitted-packets/%ju} "
+ "{N:/data packet%s unnecessarily retransmitted}\n");
+ p(tcps_mturesent, "\t\t{:sent-resends-by-mtu-discovery/%ju} "
+ "{N:/resend%s initiated by MTU discovery}\n");
+ p2a(tcps_sndacks, tcps_delack, "\t\t{:sent-ack-only-packets/%ju} "
+ "{N:/ack-only packet%s/} ({:sent-packets-delayed/%ju} "
+ "{N:delayed})\n");
+ p(tcps_sndurg, "\t\t{:sent-urg-only-packets/%ju} "
+ "{N:/URG only packet%s}\n");
+ p(tcps_sndprobe, "\t\t{:sent-window-probe-packets/%ju} "
+ "{N:/window probe packet%s}\n");
+ p(tcps_sndwinup, "\t\t{:sent-window-update-packets/%ju} "
+ "{N:/window update packet%s}\n");
+ p(tcps_sndctrl, "\t\t{:sent-control-packets/%ju} "
+ "{N:/control packet%s}\n");
+ p(tcps_rcvtotal, "\t{:received-packets/%ju} "
+ "{N:/packet%s received}\n");
+ p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t"
+ "{:received-ack-packets/%ju} {N:/ack%s} "
+ "{N:(for} {:received-ack-bytes/%ju} {N:/byte%s})\n");
+ p(tcps_rcvdupack, "\t\t{:received-duplicate-acks/%ju} "
+ "{N:/duplicate ack%s}\n");
+ p(tcps_rcvacktoomuch, "\t\t{:received-acks-for-unsent-data/%ju} "
+ "{N:/ack%s for unsent data}\n");
+ p2(tcps_rcvpack, tcps_rcvbyte, "\t\t"
+ "{:received-in-sequence-packets/%ju} {N:/packet%s} "
+ "({:received-in-sequence-bytes/%ju} {N:/byte%s}) "
+ "{N:received in-sequence}\n");
+ p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t"
+ "{:received-completely-duplicate-packets/%ju} "
+ "{N:/completely duplicate packet%s} "
+ "({:received-completely-duplicate-bytes/%ju} {N:/byte%s})\n");
+ p(tcps_pawsdrop, "\t\t{:received-old-duplicate-packets/%ju} "
+ "{N:/old duplicate packet%s}\n");
+ p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t"
+ "{:received-some-duplicate-packets/%ju} "
+ "{N:/packet%s with some dup. data} "
+ "({:received-some-duplicate-bytes/%ju} {N:/byte%s duped/})\n");
+ p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t{:received-out-of-order/%ju} "
+ "{N:/out-of-order packet%s} "
+ "({:received-out-of-order-bytes/%ju} {N:/byte%s})\n");
+ p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t"
+ "{:received-after-window-packets/%ju} {N:/packet%s} "
+ "({:received-after-window-bytes/%ju} {N:/byte%s}) "
+ "{N:of data after window}\n");
+ p(tcps_rcvwinprobe, "\t\t{:received-window-probes/%ju} "
+ "{N:/window probe%s}\n");
+ p(tcps_rcvwinupd, "\t\t{:receive-window-update-packets/%ju} "
+ "{N:/window update packet%s}\n");
+ p(tcps_rcvafterclose, "\t\t{:received-after-close-packets/%ju} "
+ "{N:/packet%s received after close}\n");
+ p(tcps_rcvbadsum, "\t\t{:discard-bad-checksum/%ju} "
+ "{N:/discarded for bad checksum%s}\n");
+ p(tcps_rcvbadoff, "\t\t{:discard-bad-header-offset/%ju} "
+ "{N:/discarded for bad header offset field%s}\n");
+ p1a(tcps_rcvshort, "\t\t{:discard-too-short/%ju} "
+ "{N:discarded because packet too short}\n");
+ p1a(tcps_rcvmemdrop, "\t\t{:discard-memory-problems/%ju} "
+ "{N:discarded due to memory problems}\n");
+ p(tcps_connattempt, "\t{:connection-requests/%ju} "
+ "{N:/connection request%s}\n");
+ p(tcps_accepts, "\t{:connections-accepts/%ju} "
+ "{N:/connection accept%s}\n");
+ p(tcps_badsyn, "\t{:bad-connection-attempts/%ju} "
+ "{N:/bad connection attempt%s}\n");
+ p(tcps_listendrop, "\t{:listen-queue-overflows/%ju} "
+ "{N:/listen queue overflow%s}\n");
+ p(tcps_badrst, "\t{:ignored-in-window-resets/%ju} "
+ "{N:/ignored RSTs in the window%s}\n");
+ p(tcps_connects, "\t{:connections-established/%ju} "
+ "{N:/connection%s established (including accepts)}\n");
+ p2(tcps_closed, tcps_drops, "\t{:connections-closed/%ju} "
+ "{N:/connection%s closed (including} "
+ "{:connection-drops/%ju} {N:/drop%s})\n");
+ p(tcps_cachedrtt, "\t\t{:connections-updated-rtt-on-close/%ju} "
+ "{N:/connection%s updated cached RTT on close}\n");
+ p(tcps_cachedrttvar, "\t\t"
+ "{:connections-updated-variance-on-close/%ju} "
+ "{N:/connection%s updated cached RTT variance on close}\n");
+ p(tcps_cachedssthresh, "\t\t"
+ "{:connections-updated-ssthresh-on-close/%ju} "
+ "{N:/connection%s updated cached ssthresh on close}\n");
+ p(tcps_conndrops, "\t{:embryonic-connections-dropped/%ju} "
+ "{N:/embryonic connection%s dropped}\n");
+ p2(tcps_rttupdated, tcps_segstimed, "\t{:segments-updated-rtt/%ju} "
+ "{N:/segment%s updated rtt (of} "
+ "{:segment-update-attempts/%ju} {N:/attempt%s})\n");
+ p(tcps_rexmttimeo, "\t{:retransmit-timeouts/%ju} "
+ "{N:/retransmit timeout%s}\n");
+ p(tcps_timeoutdrop, "\t\t"
+ "{:connections-dropped-by-retransmit-timeout/%ju} "
+ "{N:/connection%s dropped by rexmit timeout}\n");
+ p(tcps_persisttimeo, "\t{:persist-timeout/%ju} "
+ "{N:/persist timeout%s}\n");
+ p(tcps_persistdrop, "\t\t"
+ "{:connections-dropped-by-persist-timeout/%ju} "
+ "{N:/connection%s dropped by persist timeout}\n");
+ p(tcps_finwait2_drops, "\t"
+ "{:connections-dropped-by-finwait2-timeout/%ju} "
+ "{N:/Connection%s (fin_wait_2) dropped because of timeout}\n");
+ p(tcps_keeptimeo, "\t{:keepalive-timeout/%ju} "
+ "{N:/keepalive timeout%s}\n");
+ p(tcps_keepprobe, "\t\t{:keepalive-probes/%ju} "
+ "{N:/keepalive probe%s sent}\n");
+ p(tcps_keepdrops, "\t\t{:connections-dropped-by-keepalives/%ju} "
+ "{N:/connection%s dropped by keepalive}\n");
+ p(tcps_predack, "\t{:ack-header-predictions/%ju} "
+ "{N:/correct ACK header prediction%s}\n");
+ p(tcps_preddat, "\t{:data-packet-header-predictions/%ju} "
+ "{N:/correct data packet header prediction%s}\n");
+
+ xo_open_container("syncache");
+
+ p3(tcps_sc_added, "\t{:entries-added/%ju} "
+ "{N:/syncache entr%s added}\n");
+ p1a(tcps_sc_retransmitted, "\t\t{:retransmitted/%ju} "
+ "{N:/retransmitted}\n");
+ p1a(tcps_sc_dupsyn, "\t\t{:duplicates/%ju} {N:/dupsyn}\n");
+ p1a(tcps_sc_dropped, "\t\t{:dropped/%ju} {N:/dropped}\n");
+ p1a(tcps_sc_completed, "\t\t{:completed/%ju} {N:/completed}\n");
+ p1a(tcps_sc_bucketoverflow, "\t\t{:bucket-overflow/%ju} "
+ "{N:/bucket overflow}\n");
+ p1a(tcps_sc_cacheoverflow, "\t\t{:cache-overflow/%ju} "
+ "{N:/cache overflow}\n");
+ p1a(tcps_sc_reset, "\t\t{:reset/%ju} {N:/reset}\n");
+ p1a(tcps_sc_stale, "\t\t{:stale/%ju} {N:/stale}\n");
+ p1a(tcps_sc_aborted, "\t\t{:aborted/%ju} {N:/aborted}\n");
+ p1a(tcps_sc_badack, "\t\t{:bad-ack/%ju} {N:/badack}\n");
+ p1a(tcps_sc_unreach, "\t\t{:unreachable/%ju} {N:/unreach}\n");
+ p(tcps_sc_zonefail, "\t\t{:zone-failures/%ju} {N:/zone failure%s}\n");
+ p(tcps_sc_sendcookie, "\t{:sent-cookies/%ju} {N:/cookie%s sent}\n");
+ p(tcps_sc_recvcookie, "\t{:receivd-cookies/%ju} "
+ "{N:/cookie%s received}\n");
+
+ xo_close_container("syncache");
+
+ xo_open_container("hostcache");
+
+ p3(tcps_hc_added, "\t{:entries-added/%ju} "
+ "{N:/hostcache entr%s added}\n");
+ p1a(tcps_hc_bucketoverflow, "\t\t{:buffer-overflows/%ju} "
+ "{N:/bucket overflow}\n");
+
+ xo_close_container("hostcache");
+
+ xo_open_container("sack");
+
+ p(tcps_sack_recovery_episode, "\t{:recovery-episodes/%ju} "
+ "{N:/SACK recovery episode%s}\n");
+ p(tcps_sack_rexmits, "\t{:segment-retransmits/%ju} "
+ "{N:/segment rexmit%s in SACK recovery episodes}\n");
+ p(tcps_sack_rexmit_bytes, "\t{:byte-retransmits/%ju} "
+ "{N:/byte rexmit%s in SACK recovery episodes}\n");
+ p(tcps_sack_rcv_blocks, "\t{:received-blocks/%ju} "
+ "{N:/SACK option%s (SACK blocks) received}\n");
+ p(tcps_sack_send_blocks, "\t{:sent-option-blocks/%ju} "
+ "{N:/SACK option%s (SACK blocks) sent}\n");
+ p1a(tcps_sack_sboverflow, "\t{:scoreboard-overflows/%ju} "
+ "{N:/SACK scoreboard overflow}\n");
+
+ xo_close_container("sack");
+ xo_open_container("ecn");
+
+ p(tcps_ecn_ce, "\t{:ce-packets/%ju} "
+ "{N:/packet%s with ECN CE bit set}\n");
+ p(tcps_ecn_ect0, "\t{:ect0-packets/%ju} "
+ "{N:/packet%s with ECN ECT(0) bit set}\n");
+ p(tcps_ecn_ect1, "\t{:ect1-packets/%ju} "
+ "{N:/packet%s with ECN ECT(1) bit set}\n");
+ p(tcps_ecn_shs, "\t{:handshakes/%ju} "
+ "{N:/successful ECN handshake%s}\n");
+ p(tcps_ecn_rcwnd, "\t{:congestion-reductions/%ju} "
+ "{N:/time%s ECN reduced the congestion window}\n");
+ #undef p
+ #undef p1a
+ #undef p2
+ #undef p2a
+ #undef p3
+ xo_close_container("ecn");
+ xo_close_container("tcp");
}
/*
@@ -772,27 +877,38 @@ udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
memset(&zerostat, 0, len);
if (sysctlbyname("net.inet.udp.stats", &udpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.udp.stats");
+ xo_warn("sysctl: net.inet.udp.stats");
return;
}
} else
kread_counters(off, &udpstat, len);
- printf("%s:\n", name);
+ xo_open_container("udp");
+ xo_emit("{T:/%s}:\n", name);
+
#define p(f, m) if (udpstat.f || sflag <= 1) \
- printf("\t%ju " m, (uintmax_t)udpstat.f, plural(udpstat.f))
+ xo_emit("\t" m, (uintmax_t)udpstat.f, plural(udpstat.f))
#define p1a(f, m) if (udpstat.f || sflag <= 1) \
- printf("\t%ju " m, (uintmax_t)udpstat.f)
- p(udps_ipackets, "datagram%s received\n");
- p1a(udps_hdrops, "with incomplete header\n");
- p1a(udps_badlen, "with bad data length field\n");
- p1a(udps_badsum, "with bad checksum\n");
- p1a(udps_nosum, "with no checksum\n");
- p1a(udps_noport, "dropped due to no socket\n");
- p(udps_noportbcast,
- "broadcast/multicast datagram%s undelivered\n");
- p1a(udps_fullsock, "dropped due to full socket buffers\n");
- p1a(udpps_pcbhashmiss, "not for hashed pcb\n");
+ xo_emit("\t" m, (uintmax_t)udpstat.f)
+
+ p(udps_ipackets, "{:received-datagrams/%ju} "
+ "{N:/datagram%s received}\n");
+ p1a(udps_hdrops, "{:dropped-incomplete-headers/%ju} "
+ "{N:/with incomplete header}\n");
+ p1a(udps_badlen, "{:dropped-bad-data-length/%ju} "
+ "{N:/with bad data length field}\n");
+ p1a(udps_badsum, "{:dropped-bad-checksum/%ju} "
+ "{N:/with bad checksum}\n");
+ p1a(udps_nosum, "{:dropped-no-checksum/%ju} "
+ "{N:/with no checksum}\n");
+ p1a(udps_noport, "{:dropped-no-socket/%ju} "
+ "{N:/dropped due to no socket}\n");
+ p(udps_noportbcast, "{:dropped-broadcast-multicast/%ju} "
+ "{N:/broadcast\\/multicast datagram%s undelivered}\n");
+ p1a(udps_fullsock, "{:dropped-full-socket-buffer/%ju} "
+ "{N:/dropped due to full socket buffers}\n");
+ p1a(udpps_pcbhashmiss, "{:not-for-hashed-pcb/%ju} "
+ "{N:/not for hashed pcb}\n");
delivered = udpstat.udps_ipackets -
udpstat.udps_hdrops -
udpstat.udps_badlen -
@@ -801,13 +917,15 @@ udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
udpstat.udps_noportbcast -
udpstat.udps_fullsock;
if (delivered || sflag <= 1)
- printf("\t%ju delivered\n", (uint64_t)delivered);
- p(udps_opackets, "datagram%s output\n");
+ xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n",
+ (uint64_t)delivered);
+ p(udps_opackets, "{:output-packets/%ju} {N:/datagram%s output}\n");
/* the next statistic is cumulative in udps_noportbcast */
- p(udps_filtermcast,
- "time%s multicast source filter matched\n");
+ p(udps_filtermcast, "{:multicast-source-filter-matches/%ju} "
+ "{N:/time%s multicast source filter matched}\n");
#undef p
#undef p1a
+ xo_close_container("udp");
}
/*
@@ -825,7 +943,7 @@ carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet.carp.stats", &carpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet.carp.stats");
+ xo_warn("sysctl: net.inet.carp.stats");
return;
}
} else {
@@ -834,31 +952,47 @@ carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
kread_counters(off, &carpstat, len);
}
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (carpstat.f || sflag <= 1) \
- printf(m, (uintmax_t)carpstat.f, plural(carpstat.f))
+ xo_emit(m, (uintmax_t)carpstat.f, plural(carpstat.f))
#define p2(f, m) if (carpstat.f || sflag <= 1) \
- printf(m, (uintmax_t)carpstat.f)
-
- p(carps_ipackets, "\t%ju packet%s received (IPv4)\n");
- p(carps_ipackets6, "\t%ju packet%s received (IPv6)\n");
- p(carps_badttl, "\t\t%ju packet%s discarded for wrong TTL\n");
- p(carps_hdrops, "\t\t%ju packet%s shorter than header\n");
- p(carps_badsum, "\t\t%ju discarded for bad checksum%s\n");
- p(carps_badver, "\t\t%ju discarded packet%s with a bad version\n");
- p2(carps_badlen, "\t\t%ju discarded because packet too short\n");
- p2(carps_badauth, "\t\t%ju discarded for bad authentication\n");
- p2(carps_badvhid, "\t\t%ju discarded for bad vhid\n");
- p2(carps_badaddrs, "\t\t%ju discarded because of a bad address list\n");
- p(carps_opackets, "\t%ju packet%s sent (IPv4)\n");
- p(carps_opackets6, "\t%ju packet%s sent (IPv6)\n");
- p2(carps_onomem, "\t\t%ju send failed due to mbuf memory error\n");
+ xo_emit(m, (uintmax_t)carpstat.f)
+
+ p(carps_ipackets, "\t{:received-inet-packets/%ju} "
+ "{N:/packet%s received (IPv4)}\n");
+ p(carps_ipackets6, "\t{:received-inet6-packets/%ju} "
+ "{N:/packet%s received (IPv6)}\n");
+ p(carps_badttl, "\t\t{:dropped-wrong-ttl/%ju} "
+ "{N:/packet%s discarded for wrong TTL}\n");
+ p(carps_hdrops, "\t\t{:dropped-short-header/%ju} "
+ "{N:/packet%s shorter than header}\n");
+ p(carps_badsum, "\t\t{:dropped-bad-checksum/%ju} "
+ "{N:/discarded for bad checksum%s}\n");
+ p(carps_badver, "\t\t{:dropped-bad-version/%ju} "
+ "{N:/discarded packet%s with a bad version}\n");
+ p2(carps_badlen, "\t\t{:dropped-short-packet/%ju} "
+ "{N:/discarded because packet too short}\n");
+ p2(carps_badauth, "\t\t{:dropped-bad-authentication/%ju} "
+ "{N:/discarded for bad authentication}\n");
+ p2(carps_badvhid, "\t\t{:dropped-bad-vhid/%ju} "
+ "{N:/discarded for bad vhid}\n");
+ p2(carps_badaddrs, "\t\t{:dropped-bad-address-list/%ju} "
+ "{N:/discarded because of a bad address list}\n");
+ p(carps_opackets, "\t{:sent-inet-packets/%ju} "
+ "{N:/packet%s sent (IPv4)}\n");
+ p(carps_opackets6, "\t{:sent-inet6-packets/%ju} "
+ "{N:/packet%s sent (IPv6)}\n");
+ p2(carps_onomem, "\t\t{:send-failed-memory-error/%ju} "
+ "{N:/send failed due to mbuf memory error}\n");
#if notyet
- p(carps_ostates, "\t\t%s state update%s sent\n");
+ p(carps_ostates, "\t\t{:send-state-updates/%s} "
+ "{N:/state update%s sent}\n");
#endif
#undef p
#undef p2
+ xo_close_container(name);
}
/*
@@ -875,54 +1009,83 @@ ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
memset(&zerostat, 0, len);
if (sysctlbyname("net.inet.ip.stats", &ipstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.ip.stats");
+ xo_warn("sysctl: net.inet.ip.stats");
return;
}
} else
kread_counters(off, &ipstat, len);
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (ipstat.f || sflag <= 1) \
- printf(m, (uintmax_t )ipstat.f, plural(ipstat.f))
+ xo_emit(m, (uintmax_t )ipstat.f, plural(ipstat.f))
#define p1a(f, m) if (ipstat.f || sflag <= 1) \
- printf(m, (uintmax_t )ipstat.f)
-
- p(ips_total, "\t%ju total packet%s received\n");
- p(ips_badsum, "\t%ju bad header checksum%s\n");
- p1a(ips_toosmall, "\t%ju with size smaller than minimum\n");
- p1a(ips_tooshort, "\t%ju with data size < data length\n");
- p1a(ips_toolong, "\t%ju with ip length > max ip packet size\n");
- p1a(ips_badhlen, "\t%ju with header length < data size\n");
- p1a(ips_badlen, "\t%ju with data length < header length\n");
- p1a(ips_badoptions, "\t%ju with bad options\n");
- p1a(ips_badvers, "\t%ju with incorrect version number\n");
- p(ips_fragments, "\t%ju fragment%s received\n");
- p(ips_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n");
- p(ips_fragtimeout, "\t%ju fragment%s dropped after timeout\n");
- p(ips_reassembled, "\t%ju packet%s reassembled ok\n");
- p(ips_delivered, "\t%ju packet%s for this host\n");
- p(ips_noproto, "\t%ju packet%s for unknown/unsupported protocol\n");
- p(ips_forward, "\t%ju packet%s forwarded");
- p(ips_fastforward, " (%ju packet%s fast forwarded)");
+ xo_emit(m, (uintmax_t )ipstat.f)
+
+ p(ips_total, "\t{:received-packets/%ju} "
+ "{N:/total packet%s received}\n");
+ p(ips_badsum, "\t{:dropped-bad-checksum/%ju} "
+ "{N:/bad header checksum%s}\n");
+ p1a(ips_toosmall, "\t{:dropped-below-minimum-size/%ju} "
+ "{N:/with size smaller than minimum}\n");
+ p1a(ips_tooshort, "\t{:dropped-short-packets/%ju} "
+ "{N:/with data size < data length}\n");
+ p1a(ips_toolong, "\t{:dropped-too-long/%ju} "
+ "{N:/with ip length > max ip packet size}\n");
+ p1a(ips_badhlen, "\t{:dropped-short-header-length/%ju} "
+ "{N:/with header length < data size}\n");
+ p1a(ips_badlen, "\t{:dropped-short-data/%ju} "
+ "{N:/with data length < header length}\n");
+ p1a(ips_badoptions, "\t{:dropped-bad-options/%ju} "
+ "{N:/with bad options}\n");
+ p1a(ips_badvers, "\t{:dropped-bad-version/%ju} "
+ "{N:/with incorrect version number}\n");
+ p(ips_fragments, "\t{:received-fragments/%ju} "
+ "{N:/fragment%s received}\n");
+ p(ips_fragdropped, "\t{:dropped-fragments/%ju} "
+ "{N:/fragment%s dropped (dup or out of space)}\n");
+ p(ips_fragtimeout, "\t{:dropped-fragments-after-timeout/%ju} "
+ "{N:/fragment%s dropped after timeout}\n");
+ p(ips_reassembled, "\t{:reassembled-packets/%ju} "
+ "{N:/packet%s reassembled ok}\n");
+ p(ips_delivered, "\t{:received-local-packets/%ju} "
+ "{N:/packet%s for this host}\n");
+ p(ips_noproto, "\t{:dropped-unknown-protocol/%ju} "
+ "{N:/packet%s for unknown\\/unsupported protocol}\n");
+ p(ips_forward, "\t{:forwarded-packets/%ju} "
+ "{N:/packet%s forwarded}");
+ p(ips_fastforward, " ({:fast-forwarded-packets/%ju} "
+ "{N:/packet%s fast forwarded})");
if (ipstat.ips_forward || sflag <= 1)
- putchar('\n');
- p(ips_cantforward, "\t%ju packet%s not forwardable\n");
- p(ips_notmember,
- "\t%ju packet%s received for unknown multicast group\n");
- p(ips_redirectsent, "\t%ju redirect%s sent\n");
- p(ips_localout, "\t%ju packet%s sent from this host\n");
- p(ips_rawout, "\t%ju packet%s sent with fabricated ip header\n");
- p(ips_odropped,
- "\t%ju output packet%s dropped due to no bufs, etc.\n");
- p(ips_noroute, "\t%ju output packet%s discarded due to no route\n");
- p(ips_fragmented, "\t%ju output datagram%s fragmented\n");
- p(ips_ofragments, "\t%ju fragment%s created\n");
- p(ips_cantfrag, "\t%ju datagram%s that can't be fragmented\n");
- p(ips_nogif, "\t%ju tunneling packet%s that can't find gif\n");
- p(ips_badaddr, "\t%ju datagram%s with bad address in header\n");
+ xo_emit("\n");
+ p(ips_cantforward, "\t{:packets-cannot-forward/%ju} "
+ "{N:/packet%s not forwardable}\n");
+ p(ips_notmember, "\t{:received-unknown-multicast-group/%ju} "
+ "{N:/packet%s received for unknown multicast group}\n");
+ p(ips_redirectsent, "\t{:redirects-sent/%ju} "
+ "{N:/redirect%s sent}\n");
+ p(ips_localout, "\t{:sent-packets/%ju} "
+ "{N:/packet%s sent from this host}\n");
+ p(ips_rawout, "\t{:send-packets-fabricated-header/%ju} "
+ "{N:/packet%s sent with fabricated ip header}\n");
+ p(ips_odropped, "\t{:discard-no-mbufs/%ju} "
+ "{N:/output packet%s dropped due to no bufs, etc.}\n");
+ p(ips_noroute, "\t{:discard-no-route/%ju} "
+ "{N:/output packet%s discarded due to no route}\n");
+ p(ips_fragmented, "\t{:sent-fragments/%ju} "
+ "{N:/output datagram%s fragmented}\n");
+ p(ips_ofragments, "\t{:fragments-created/%ju} "
+ "{N:/fragment%s created}\n");
+ p(ips_cantfrag, "\t{:discard-cannot-fragment/%ju} "
+ "{N:/datagram%s that can't be fragmented}\n");
+ p(ips_nogif, "\t{:discard-tunnel-no-gif/%ju} "
+ "{N:/tunneling packet%s that can't find gif}\n");
+ p(ips_badaddr, "\t{:discard-bad-address/%ju} "
+ "{N:/datagram%s with bad address in header}\n");
#undef p
#undef p1a
+ xo_close_container(name);
}
/*
@@ -939,29 +1102,37 @@ arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
memset(&zerostat, 0, len);
if (sysctlbyname("net.link.ether.arp.stats", &arpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.link.ether.arp.stats");
+ xo_warn("sysctl: net.link.ether.arp.stats");
return;
}
} else
kread_counters(off, &arpstat, len);
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (arpstat.f || sflag <= 1) \
- printf("\t%ju " m, (uintmax_t)arpstat.f, plural(arpstat.f))
+ xo_emit("\t" m, (uintmax_t)arpstat.f, plural(arpstat.f))
#define p2(f, m) if (arpstat.f || sflag <= 1) \
- printf("\t%ju " m, (uintmax_t)arpstat.f, pluralies(arpstat.f))
-
- p(txrequests, "ARP request%s sent\n");
- p2(txreplies, "ARP repl%s sent\n");
- p(rxrequests, "ARP request%s received\n");
- p2(rxreplies, "ARP repl%s received\n");
- p(received, "ARP packet%s received\n");
- p(dropped, "total packet%s dropped due to no ARP entry\n");
- p(timeouts, "ARP entry%s timed out\n");
- p(dupips, "Duplicate IP%s seen\n");
+ xo_emit("\t" m, (uintmax_t)arpstat.f, pluralies(arpstat.f))
+
+ p(txrequests, "{:sent-requests/%ju} {N:/ARP request%s sent}\n");
+ p2(txreplies, "{:sent-replies/%ju} {N:/ARP repl%s sent}\n");
+ p(rxrequests, "{:received-requests/%ju} "
+ "{N:/ARP request%s received}\n");
+ p2(rxreplies, "{:received-replies/%ju} "
+ "{N:/ARP repl%s received}\n");
+ p(received, "{:received-packers/%ju} "
+ "{N:/ARP packet%s received}\n");
+ p(dropped, "{:dropped-no-entry/%ju} "
+ "{N:/total packet%s dropped due to no ARP entry}\n");
+ p(timeouts, "{:entries-timeout/%ju} "
+ "{N:/ARP entry%s timed out}\n");
+ p(dupips, "{:dropped-duplicate-address/%ju} "
+ "{N:/Duplicate IP%s seen}\n");
#undef p
#undef p2
+ xo_close_container(name);
}
@@ -1026,59 +1197,89 @@ icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
memset(&zerostat, 0, len);
if (sysctlbyname("net.inet.icmp.stats", &icmpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.icmp.stats");
+ xo_warn("sysctl: net.inet.icmp.stats");
return;
}
} else
kread_counters(off, &icmpstat, len);
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (icmpstat.f || sflag <= 1) \
- printf(m, icmpstat.f, plural(icmpstat.f))
+ xo_emit(m, icmpstat.f, plural(icmpstat.f))
#define p1a(f, m) if (icmpstat.f || sflag <= 1) \
- printf(m, icmpstat.f)
+ xo_emit(m, icmpstat.f)
#define p2(f, m) if (icmpstat.f || sflag <= 1) \
- printf(m, icmpstat.f, plurales(icmpstat.f))
+ xo_emit(m, icmpstat.f, plurales(icmpstat.f))
- p(icps_error, "\t%lu call%s to icmp_error\n");
- p(icps_oldicmp,
- "\t%lu error%s not generated in response to an icmp message\n");
- for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
+ p(icps_error, "\t{:icmp-calls/%lu} "
+ "{N:/call%s to icmp_error}\n");
+ p(icps_oldicmp, "\t{:errors-not-from-message/%lu} "
+ "{N:/error%s not generated in response to an icmp message}\n");
+
+ for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) {
if (icmpstat.icps_outhist[i] != 0) {
if (first) {
- printf("\tOutput histogram:\n");
+ xo_open_list("output-histogram");
+ xo_emit("\tOutput histogram:\n");
first = 0;
}
+ xo_open_instance("output-histogram");
if (icmpnames[i] != NULL)
- printf("\t\t%s: %lu\n", icmpnames[i],
- icmpstat.icps_outhist[i]);
+ xo_emit("\t\t{k:name/%s}: {:count/%lu}\n",
+ icmpnames[i], icmpstat.icps_outhist[i]);
else
- printf("\t\tunknown ICMP #%d: %lu\n", i,
- icmpstat.icps_outhist[i]);
+ xo_emit("\t\tunknown ICMP #{k:name/%d}: "
+ "{:count/%lu}\n",
+ i, icmpstat.icps_outhist[i]);
+ xo_close_instance("output-histogram");
}
- p(icps_badcode, "\t%lu message%s with bad code fields\n");
- p(icps_tooshort, "\t%lu message%s less than the minimum length\n");
- p(icps_checksum, "\t%lu message%s with bad checksum\n");
- p(icps_badlen, "\t%lu message%s with bad length\n");
- p1a(icps_bmcastecho, "\t%lu multicast echo requests ignored\n");
- p1a(icps_bmcasttstamp, "\t%lu multicast timestamp requests ignored\n");
- for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
+ }
+ if (!first)
+ xo_close_list("output-histogram");
+
+ p(icps_badcode, "\t{:dropped-bad-code/%lu} "
+ "{N:/message%s with bad code fields}\n");
+ p(icps_tooshort, "\t{:dropped-too-short/%lu} "
+ "{N:/message%s less than the minimum length}\n");
+ p(icps_checksum, "\t{:dropped-bad-checksum/%lu} "
+ "{N:/message%s with bad checksum}\n");
+ p(icps_badlen, "\t{:dropped-bad-length/%lu} "
+ "{N:/message%s with bad length}\n");
+ p1a(icps_bmcastecho, "\t{:dropped-multicast-echo/%lu} "
+ "{N:/multicast echo requests ignored}\n");
+ p1a(icps_bmcasttstamp, "\t{:dropped-multicast-timestamp/%lu} "
+ "{N:/multicast timestamp requests ignored}\n");
+
+ for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) {
if (icmpstat.icps_inhist[i] != 0) {
if (first) {
- printf("\tInput histogram:\n");
+ xo_open_list("input-histogram");
+ xo_emit("\tInput histogram:\n");
first = 0;
}
+ xo_open_instance("input-histogram");
if (icmpnames[i] != NULL)
- printf("\t\t%s: %lu\n", icmpnames[i],
- icmpstat.icps_inhist[i]);
+ xo_emit("\t\t{k:name/%s}: {:count/%lu}\n",
+ icmpnames[i],
+ icmpstat.icps_inhist[i]);
else
- printf("\t\tunknown ICMP #%d: %lu\n", i,
- icmpstat.icps_inhist[i]);
+ xo_emit(
+ "\t\tunknown ICMP #{k:name/%d}: {:count/%lu}\n",
+ i, icmpstat.icps_inhist[i]);
+ xo_close_instance("input-histogram");
}
- p(icps_reflect, "\t%lu message response%s generated\n");
- p2(icps_badaddr, "\t%lu invalid return address%s\n");
- p(icps_noroute, "\t%lu no return route%s\n");
+ }
+ if (!first)
+ xo_close_list("input-histogram");
+
+ p(icps_reflect, "\t{:sent-packets/%lu} "
+ "{N:/message response%s generated}\n");
+ p2(icps_badaddr, "\t{:discard-invalid-return-address/%lu} "
+ "{N:/invalid return address%s}\n");
+ p(icps_noroute, "\t{:discard-no-route/%lu} "
+ "{N:/no return route%s}\n");
#undef p
#undef p1a
#undef p2
@@ -1087,51 +1288,12 @@ icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet.icmp.maskrepl", &i, &len, NULL, 0) <
0)
return;
- printf("\tICMP address mask responses are %sabled\n",
- i ? "en" : "dis");
+ xo_emit("\tICMP address mask responses are "
+ "{q:icmp-address-responses/%sabled}\n", i ? "en" : "dis");
}
-}
-#ifndef BURN_BRIDGES
-/*
- * Dump IGMP statistics structure (pre 8.x kernel).
- */
-static void
-igmp_stats_live_old(const char *name)
-{
- struct oigmpstat oigmpstat, zerostat;
- size_t len = sizeof(oigmpstat);
-
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.igmp.stats", &oigmpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
-
- printf("%s:\n", name);
-
-#define p(f, m) if (oigmpstat.f || sflag <= 1) \
- printf(m, oigmpstat.f, plural(oigmpstat.f))
-#define py(f, m) if (oigmpstat.f || sflag <= 1) \
- printf(m, oigmpstat.f, oigmpstat.f != 1 ? "ies" : "y")
- p(igps_rcv_total, "\t%u message%s received\n");
- p(igps_rcv_tooshort, "\t%u message%s received with too few bytes\n");
- p(igps_rcv_badsum, "\t%u message%s received with bad checksum\n");
- py(igps_rcv_queries, "\t%u membership quer%s received\n");
- py(igps_rcv_badqueries,
- "\t%u membership quer%s received with invalid field(s)\n");
- p(igps_rcv_reports, "\t%u membership report%s received\n");
- p(igps_rcv_badreports,
- "\t%u membership report%s received with invalid field(s)\n");
- p(igps_rcv_ourreports,
-"\t%u membership report%s received for groups to which we belong\n");
- p(igps_snd_reports, "\t%u membership report%s sent\n");
-#undef p
-#undef py
+ xo_close_container(name);
}
-#endif /* !BURN_BRIDGES */
/*
* Dump IGMP statistics structure.
@@ -1142,34 +1304,13 @@ igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
struct igmpstat igmpstat, zerostat;
size_t len;
-#ifndef BURN_BRIDGES
- if (live) {
- /*
- * Detect if we are being run against a pre-IGMPv3 kernel.
- * We cannot do this for a core file as the legacy
- * struct igmpstat has no size field, nor does it
- * export it in any readily-available symbols.
- */
- len = 0;
- if (sysctlbyname("net.inet.igmp.stats", NULL, &len, NULL,
- 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
- if (len < sizeof(igmpstat)) {
- igmp_stats_live_old(name);
- return;
- }
- }
-#endif /* !BURN_BRIDGES */
-
len = sizeof(igmpstat);
if (live) {
if (zflag)
memset(&zerostat, 0, len);
if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
+ xo_warn("sysctl: net.inet.igmp.stats");
return;
}
} else {
@@ -1178,41 +1319,59 @@ igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
}
if (igmpstat.igps_version != IGPS_VERSION_3) {
- warnx("%s: version mismatch (%d != %d)", __func__,
+ xo_warnx("%s: version mismatch (%d != %d)", __func__,
igmpstat.igps_version, IGPS_VERSION_3);
}
if (igmpstat.igps_len != IGPS_VERSION3_LEN) {
- warnx("%s: size mismatch (%d != %d)", __func__,
+ xo_warnx("%s: size mismatch (%d != %d)", __func__,
igmpstat.igps_len, IGPS_VERSION3_LEN);
}
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p64(f, m) if (igmpstat.f || sflag <= 1) \
- printf(m, (uintmax_t) igmpstat.f, plural(igmpstat.f))
+ xo_emit(m, (uintmax_t) igmpstat.f, plural(igmpstat.f))
#define py64(f, m) if (igmpstat.f || sflag <= 1) \
- printf(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f))
- p64(igps_rcv_total, "\t%ju message%s received\n");
- p64(igps_rcv_tooshort, "\t%ju message%s received with too few bytes\n");
- p64(igps_rcv_badttl, "\t%ju message%s received with wrong TTL\n");
- p64(igps_rcv_badsum, "\t%ju message%s received with bad checksum\n");
- py64(igps_rcv_v1v2_queries, "\t%ju V1/V2 membership quer%s received\n");
- py64(igps_rcv_v3_queries, "\t%ju V3 membership quer%s received\n");
- py64(igps_rcv_badqueries,
- "\t%ju membership quer%s received with invalid field(s)\n");
- py64(igps_rcv_gen_queries, "\t%ju general quer%s received\n");
- py64(igps_rcv_group_queries, "\t%ju group quer%s received\n");
- py64(igps_rcv_gsr_queries, "\t%ju group-source quer%s received\n");
- py64(igps_drop_gsr_queries, "\t%ju group-source quer%s dropped\n");
- p64(igps_rcv_reports, "\t%ju membership report%s received\n");
- p64(igps_rcv_badreports,
- "\t%ju membership report%s received with invalid field(s)\n");
- p64(igps_rcv_ourreports,
-"\t%ju membership report%s received for groups to which we belong\n");
- p64(igps_rcv_nora, "\t%ju V3 report%s received without Router Alert\n");
- p64(igps_snd_reports, "\t%ju membership report%s sent\n");
+ xo_emit(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f))
+
+ p64(igps_rcv_total, "\t{:received-messages/%ju} "
+ "{N:/message%s received}\n");
+ p64(igps_rcv_tooshort, "\t{:dropped-too-short/%ju} "
+ "{N:/message%s received with too few bytes}\n");
+ p64(igps_rcv_badttl, "\t{:dropped-wrong-ttl/%ju} "
+ "{N:/message%s received with wrong TTL}\n");
+ p64(igps_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
+ "{N:/message%s received with bad checksum}\n");
+ py64(igps_rcv_v1v2_queries, "\t{:received-membership-queries/%ju} "
+ "{N:/V1\\/V2 membership quer%s received}\n");
+ py64(igps_rcv_v3_queries, "\t{:received-v3-membership-queries/%ju} "
+ "{N:/V3 membership quer%s received}\n");
+ py64(igps_rcv_badqueries, "\t{:dropped-membership-queries/%ju} "
+ "{N:/membership quer%s received with invalid field(s)}\n");
+ py64(igps_rcv_gen_queries, "\t{:received-general-queries/%ju} "
+ "{N:/general quer%s received}\n");
+ py64(igps_rcv_group_queries, "\t{:received-group-queries/%ju} "
+ "{N:/group quer%s received}\n");
+ py64(igps_rcv_gsr_queries, "\t{:received-group-source-queries/%ju} "
+ "{N:/group-source quer%s received}\n");
+ py64(igps_drop_gsr_queries, "\t{:dropped-group-source-queries/%ju} "
+ "{N:/group-source quer%s dropped}\n");
+ p64(igps_rcv_reports, "\t{:received-membership-requests/%ju} "
+ "{N:/membership report%s received}\n");
+ p64(igps_rcv_badreports, "\t{:dropped-membership-reports/%ju} "
+ "{N:/membership report%s received with invalid field(s)}\n");
+ p64(igps_rcv_ourreports, "\t"
+ "{:received-membership-reports-matching/%ju} "
+ "{N:/membership report%s received for groups to which we belong}"
+ "\n");
+ p64(igps_rcv_nora, "\t{:received-v3-reports-no-router-alert/%ju} "
+ "{N:/V3 report%s received without Router Alert}\n");
+ p64(igps_snd_reports, "\t{:sent-membership-reports/%ju} "
+ "{N:/membership report%s sent}\n");
#undef p64
#undef py64
+ xo_close_container(name);
}
/*
@@ -1231,7 +1390,7 @@ pim_stats(u_long off __unused, const char *name, int af1 __unused,
if (sysctlbyname("net.inet.pim.stats", &pimstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet.pim.stats");
+ xo_warn("sysctl: net.inet.pim.stats");
return;
}
} else {
@@ -1240,38 +1399,56 @@ pim_stats(u_long off __unused, const char *name, int af1 __unused,
kread_counters(off, &pimstat, len);
}
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (pimstat.f || sflag <= 1) \
- printf(m, (uintmax_t)pimstat.f, plural(pimstat.f))
+ xo_emit(m, (uintmax_t)pimstat.f, plural(pimstat.f))
#define py(f, m) if (pimstat.f || sflag <= 1) \
- printf(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y")
- p(pims_rcv_total_msgs, "\t%ju message%s received\n");
- p(pims_rcv_total_bytes, "\t%ju byte%s received\n");
- p(pims_rcv_tooshort, "\t%ju message%s received with too few bytes\n");
- p(pims_rcv_badsum, "\t%ju message%s received with bad checksum\n");
- p(pims_rcv_badversion, "\t%ju message%s received with bad version\n");
- p(pims_rcv_registers_msgs, "\t%ju data register message%s received\n");
- p(pims_rcv_registers_bytes, "\t%ju data register byte%s received\n");
- p(pims_rcv_registers_wrongiif,
- "\t%ju data register message%s received on wrong iif\n");
- p(pims_rcv_badregisters, "\t%ju bad register%s received\n");
- p(pims_snd_registers_msgs, "\t%ju data register message%s sent\n");
- p(pims_snd_registers_bytes, "\t%ju data register byte%s sent\n");
+ xo_emit(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y")
+
+ p(pims_rcv_total_msgs, "\t{:received-messages/%ju} "
+ "{N:/message%s received}\n");
+ p(pims_rcv_total_bytes, "\t{:received-bytes/%ju} "
+ "{N:/byte%s received}\n");
+ p(pims_rcv_tooshort, "\t{:dropped-too-short/%ju} "
+ "{N:/message%s received with too few bytes}\n");
+ p(pims_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
+ "{N:/message%s received with bad checksum}\n");
+ p(pims_rcv_badversion, "\t{:dropped-bad-version/%ju} "
+ "{N:/message%s received with bad version}\n");
+ p(pims_rcv_registers_msgs, "\t{:received-data-register-messages/%ju} "
+ "{N:/data register message%s received}\n");
+ p(pims_rcv_registers_bytes, "\t{:received-data-register-bytes/%ju} "
+ "{N:/data register byte%s received}\n");
+ p(pims_rcv_registers_wrongiif, "\t"
+ "{:received-data-register-wrong-interface/%ju} "
+ "{N:/data register message%s received on wrong iif}\n");
+ p(pims_rcv_badregisters, "\t{:received-bad-registers/%ju} "
+ "{N:/bad register%s received}\n");
+ p(pims_snd_registers_msgs, "\t{:sent-data-register-messages/%ju} "
+ "{N:/data register message%s sent}\n");
+ p(pims_snd_registers_bytes, "\t{:sent-data-register-bytes/%ju} "
+ "{N:/data register byte%s sent}\n");
#undef p
#undef py
+ xo_close_container(name);
}
/*
* Pretty print an Internet address (net address + port).
*/
void
-inetprint(struct in_addr *in, int port, const char *proto, int num_port)
+inetprint(const char *container, struct in_addr *in, int port,
+ const char *proto, int num_port)
{
struct servent *sp = 0;
char line[80], *cp;
int width;
+ if (container)
+ xo_open_container(container);
+
if (Wflag)
sprintf(line, "%s.", inetname(in));
else
@@ -1285,9 +1462,16 @@ inetprint(struct in_addr *in, int port, const char *proto, int num_port)
sprintf(cp, "%d ", ntohs((u_short)port));
width = (Aflag && !Wflag) ? 18 : 22;
if (Wflag)
- printf("%-*s ", width, line);
+ xo_emit("{d:target/%-*s} ", width, line);
else
- printf("%-*.*s ", width, width, line);
+ xo_emit("{d:target/%-*.*s} ", width, width, line);
+
+ int alen = cp - line - 1, plen = strlen(cp) - 1;
+ xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
+ plen, cp);
+
+ if (container)
+ xo_close_container(container);
}
/*
diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index 96fdcaf..3535f45 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <net/route.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
#include <netinet/icmp6.h>
@@ -65,9 +64,11 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "netstat.h"
struct socket sockb;
@@ -372,153 +373,246 @@ ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet6.ip6.stats");
+ xo_warn("sysctl: net.inet6.ip6.stats");
return;
}
} else
kread_counters(off, &ip6stat, len);
-
- printf("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (ip6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
+ xo_emit(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
#define p1a(f, m) if (ip6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ip6stat.f)
-
- p(ip6s_total, "\t%ju total packet%s received\n");
- p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n");
- p1a(ip6s_tooshort, "\t%ju with data size < data length\n");
- p1a(ip6s_badoptions, "\t%ju with bad options\n");
- p1a(ip6s_badvers, "\t%ju with incorrect version number\n");
- p(ip6s_fragments, "\t%ju fragment%s received\n");
- p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n");
- p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n");
- p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n");
- p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n");
- p(ip6s_delivered, "\t%ju packet%s for this host\n");
- p(ip6s_forward, "\t%ju packet%s forwarded\n");
- p(ip6s_cantforward, "\t%ju packet%s not forwardable\n");
- p(ip6s_redirectsent, "\t%ju redirect%s sent\n");
- p(ip6s_localout, "\t%ju packet%s sent from this host\n");
- p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n");
- p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n");
- p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n");
- p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n");
- p(ip6s_ofragments, "\t%ju fragment%s created\n");
- p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n");
- p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n");
- p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n");
+ xo_emit(m, (uintmax_t)ip6stat.f)
+
+ p(ip6s_total, "\t{:received-packets/%ju} "
+ "{N:/total packet%s received}\n");
+ p1a(ip6s_toosmall, "\t{:dropped-below-minimum-size/%ju} "
+ "{N:/with size smaller than minimum}\n");
+ p1a(ip6s_tooshort, "\t{:dropped-short-packets/%ju} "
+ "{N:/with data size < data length}\n");
+ p1a(ip6s_badoptions, "\t{:dropped-bad-options/%ju} "
+ "{N:/with bad options}\n");
+ p1a(ip6s_badvers, "\t{:dropped-bad-version/%ju} "
+ "{N:/with incorrect version number}\n");
+ p(ip6s_fragments, "\t{:received-fragments/%ju} "
+ "{N:/fragment%s received}\n");
+ p(ip6s_fragdropped, "\t{:dropped-fragment/%ju} "
+ "{N:/fragment%s dropped (dup or out of space)}\n");
+ p(ip6s_fragtimeout, "\t{:dropped-fragment-after-timeout/%ju} "
+ "{N:/fragment%s dropped after timeout}\n");
+ p(ip6s_fragoverflow, "\t{:dropped-fragments-overflow/%ju} "
+ "{N:/fragment%s that exceeded limit}\n");
+ p(ip6s_reassembled, "\t{:reassembled-packets/%ju} "
+ "{N:/packet%s reassembled ok}\n");
+ p(ip6s_delivered, "\t{:received-local-packets/%ju} "
+ "{N:/packet%s for this host}\n");
+ p(ip6s_forward, "\t{:forwarded-packets/%ju} "
+ "{N:/packet%s forwarded}\n");
+ p(ip6s_cantforward, "\t{:packets-not-forwardable/%ju} "
+ "{N:/packet%s not forwardable}\n");
+ p(ip6s_redirectsent, "\t{:sent-redirects/%ju} "
+ "{N:/redirect%s sent}\n");
+ p(ip6s_localout, "\t{:sent-packets/%ju} "
+ "{N:/packet%s sent from this host}\n");
+ p(ip6s_rawout, "\t{:send-packets-fabricated-header/%ju} "
+ "{N:/packet%s sent with fabricated ip header}\n");
+ p(ip6s_odropped, "\t{:discard-no-mbufs/%ju} "
+ "{N:/output packet%s dropped due to no bufs, etc.}\n");
+ p(ip6s_noroute, "\t{:discard-no-route/%ju} "
+ "{N:/output packet%s discarded due to no route}\n");
+ p(ip6s_fragmented, "\t{:sent-fragments/%ju} "
+ "{N:/output datagram%s fragmented}\n");
+ p(ip6s_ofragments, "\t{:fragments-created/%ju} "
+ "{N:/fragment%s created}\n");
+ p(ip6s_cantfrag, "\t{:discard-cannot-fragment/%ju} "
+ "{N:/datagram%s that can't be fragmented}\n");
+ p(ip6s_badscope, "\t{:discard-scope-violations/%ju} "
+ "{N:/packet%s that violated scope rules}\n");
+ p(ip6s_notmember, "\t{:multicast-no-join-packets/%ju} "
+ "{N:/multicast packet%s which we don't join}\n");
for (first = 1, i = 0; i < IP6S_HDRCNT; i++)
if (ip6stat.ip6s_nxthist[i] != 0) {
if (first) {
- printf("\tInput histogram:\n");
+ xo_emit("\t{T:Input histogram}:\n");
+ xo_open_list("input-histogram");
first = 0;
}
- printf("\t\t%s: %ju\n", ip6nh[i],
+ xo_open_instance("input-histogram");
+ xo_emit("\t\t{k:name/%s}: {:count/%ju}\n", ip6nh[i],
(uintmax_t)ip6stat.ip6s_nxthist[i]);
+ xo_close_instance("input-histogram");
}
- printf("\tMbuf statistics:\n");
- printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1);
+ if (!first)
+ xo_close_list("input-histogram");
+
+ xo_open_container("mbuf-statistics");
+ xo_emit("\t{T:Mbuf statistics}:\n");
+ xo_emit("\t\t{:one-mbuf/%ju} {N:/one mbuf}\n",
+ (uintmax_t)ip6stat.ip6s_m1);
for (first = 1, i = 0; i < IP6S_M2MMAX; i++) {
char ifbuf[IFNAMSIZ];
if (ip6stat.ip6s_m2m[i] != 0) {
if (first) {
- printf("\t\ttwo or more mbuf:\n");
+ xo_emit("\t\t{N:two or more mbuf}:\n");
+ xo_open_list("mbuf-data");
first = 0;
}
- printf("\t\t\t%s= %ju\n",
+ xo_open_instance("mbuf-data");
+ xo_emit("\t\t\t{k:name/%s}= {:count/%ju}\n",
if_indextoname(i, ifbuf),
(uintmax_t)ip6stat.ip6s_m2m[i]);
+ xo_close_instance("mbuf-data");
}
}
- printf("\t\t%ju one ext mbuf\n",
+ if (!first)
+ xo_close_list("mbuf-data");
+ xo_emit("\t\t{:one-extra-mbuf/%ju} {N:one ext mbuf}\n",
(uintmax_t)ip6stat.ip6s_mext1);
- printf("\t\t%ju two or more ext mbuf\n",
- (uintmax_t)ip6stat.ip6s_mext2m);
- p(ip6s_exthdrtoolong,
- "\t%ju packet%s whose headers are not contiguous\n");
- p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n");
- p(ip6s_toomanyhdr,
- "\t%ju packet%s discarded because of too many headers\n");
+ xo_emit("\t\t{:two-or-more-extra-mbufs/%ju} "
+ "{N:/two or more ext mbuf}\n", (uintmax_t)ip6stat.ip6s_mext2m);
+ xo_close_container("mbuf-statistics");
+
+ p(ip6s_exthdrtoolong, "\t{:dropped-header-too-long/%ju} "
+ "{N:/packet%s whose headers are not contiguous}\n");
+ p(ip6s_nogif, "\t{:discard-tunnel-no-gif/%ju} "
+ "{N:/tunneling packet%s that can't find gif}\n");
+ p(ip6s_toomanyhdr, "\t{:dropped-too-many-headers/%ju} "
+ "{N:/packet%s discarded because of too many headers}\n");
/* for debugging source address selection */
#define PRINT_SCOPESTAT(s,i) do {\
switch(i) { /* XXX hardcoding in each case */\
case 1:\
- p(s, "\t\t%ju interface-local%s\n");\
+ p(s, "\t\t{ke:name/interface-locals}{:count/%ju} " \
+ "{N:/interface-local%s}\n"); \
break;\
case 2:\
- p(s,"\t\t%ju link-local%s\n");\
+ p(s,"\t\t{ke:name/link-locals}{:count/%ju} " \
+ "{N:/link-local%s}\n"); \
break;\
case 5:\
- p(s,"\t\t%ju site-local%s\n");\
+ p(s,"\t\t{ke:name/site-locals}{:count/%ju} " \
+ "{N:/site-local%s}\n");\
break;\
case 14:\
- p(s,"\t\t%ju global%s\n");\
+ p(s,"\t\t{ke:name/globals}{:count/%ju} " \
+ "{N:/global%s}\n");\
break;\
default:\
- printf("\t\t%ju addresses scope=%x\n",\
- (uintmax_t)ip6stat.s, i);\
+ xo_emit("\t\t{qke:name/%x}{:count/%ju} " \
+ "addresses scope=%x\n",\
+ i, (uintmax_t)ip6stat.s, i); \
}\
} while (0);
- p(ip6s_sources_none,
- "\t%ju failure%s of source address selection\n");
+ xo_open_container("source-address-selection");
+ p(ip6s_sources_none, "\t{:address-selection-failures/%ju} "
+ "{N:/failure%s of source address selection}\n");
+
for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
if (ip6stat.ip6s_sources_sameif[i]) {
if (first) {
- printf("\tsource addresses on an outgoing I/F\n");
+ xo_open_list("outgoing-interface");
+ xo_emit("\tsource addresses on an outgoing "
+ "I/F\n");
first = 0;
}
+ xo_open_instance("outgoing-interface");
PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
+ xo_close_instance("outgoing-interface");
}
}
+ if (!first)
+ xo_close_list("outgoing-interface");
+
for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
if (ip6stat.ip6s_sources_otherif[i]) {
if (first) {
- printf("\tsource addresses on a non-outgoing I/F\n");
+ xo_open_list("non-outgoing-interface");
+ xo_emit("\tsource addresses on a non-outgoing "
+ "I/F\n");
first = 0;
}
+ xo_open_instance("non-outgoing-interface");
PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
+ xo_close_instance("non-outgoing-interface");
}
}
+ if (!first)
+ xo_close_list("non-outgoing-interface");
+
for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
if (ip6stat.ip6s_sources_samescope[i]) {
if (first) {
- printf("\tsource addresses of same scope\n");
+ xo_open_list("same-source");
+ xo_emit("\tsource addresses of same scope\n");
first = 0;
}
+ xo_open_instance("same-source");
PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
+ xo_close_instance("same-source");
}
}
+ if (!first)
+ xo_close_list("same-source");
+
for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
if (ip6stat.ip6s_sources_otherscope[i]) {
if (first) {
- printf("\tsource addresses of a different scope\n");
+ xo_open_list("different-scope");
+ xo_emit("\tsource addresses of a different "
+ "scope\n");
first = 0;
}
+ xo_open_instance("different-scope");
PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
+ xo_close_instance("different-scope");
}
}
+ if (!first)
+ xo_close_list("different-scope");
+
for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
if (ip6stat.ip6s_sources_deprecated[i]) {
if (first) {
- printf("\tdeprecated source addresses\n");
+ xo_open_list("deprecated-source");
+ xo_emit("\tdeprecated source addresses\n");
first = 0;
}
+ xo_open_instance("deprecated-source");
PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
+ xo_close_instance("deprecated-source");
}
}
+ if (!first)
+ xo_close_list("deprecated-source");
- printf("\tSource addresses selection rule applied:\n");
- for (i = 0; i < IP6S_RULESMAX; i++) {
- if (ip6stat.ip6s_sources_rule[i])
- printf("\t\t%ju %s\n",
- (uintmax_t)ip6stat.ip6s_sources_rule[i],
- srcrule_str[i]);
+ for (first = 1, i = 0; i < IP6S_RULESMAX; i++) {
+ if (ip6stat.ip6s_sources_rule[i]) {
+ if (first) {
+ xo_open_list("rules-applied");
+ xo_emit("\t{T:Source addresses selection "
+ "rule applied}:\n");
+ first = 0;
+ }
+ xo_open_instance("rules-applied");
+ xo_emit("\t\t{ke:name/%s}{:count/%ju} {d:name/%s}\n",
+ srcrule_str[i],
+ (uintmax_t)ip6stat.ip6s_sources_rule[i],
+ srcrule_str[i]);
+ xo_close_instance("rules-applied");
+ }
}
+ if (!first)
+ xo_close_list("rules-applied");
+
+ xo_close_container("source-address-selection");
+
#undef p
#undef p1a
+ xo_close_container(name);
}
/*
@@ -529,52 +623,74 @@ ip6_ifstats(char *ifname)
{
struct in6_ifreq ifr;
int s;
-#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f))
-#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ip6stat.f)
+
+#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
+ xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, \
+ plural(ifr.ifr_ifru.ifru_stat.f))
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- perror("Warning: socket(AF_INET6)");
+ xo_warn("Warning: socket(AF_INET6)");
return;
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
if (errno != EPFNOSUPPORT)
- perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
+ xo_warn("Warning: ioctl(SIOCGIFSTAT_IN6)");
goto end;
}
- printf("ip6 on %s:\n", ifr.ifr_name);
- p(ifs6_in_receive, "\t%ju total input datagram%s\n");
- p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n");
- p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n");
- p(ifs6_in_noroute, "\t%ju datagram%s with no route received\n");
- p(ifs6_in_addrerr, "\t%ju datagram%s with invalid dst received\n");
- p(ifs6_in_protounknown, "\t%ju datagram%s with unknown proto received\n");
- p(ifs6_in_truncated, "\t%ju truncated datagram%s received\n");
- p(ifs6_in_discard, "\t%ju input datagram%s discarded\n");
- p(ifs6_in_deliver,
- "\t%ju datagram%s delivered to an upper layer protocol\n");
- p(ifs6_out_forward, "\t%ju datagram%s forwarded to this interface\n");
- p(ifs6_out_request,
- "\t%ju datagram%s sent from an upper layer protocol\n");
- p(ifs6_out_discard, "\t%ju total discarded output datagram%s\n");
- p(ifs6_out_fragok, "\t%ju output datagram%s fragmented\n");
- p(ifs6_out_fragfail, "\t%ju output datagram%s failed on fragment\n");
- p(ifs6_out_fragcreat, "\t%ju output datagram%s succeeded on fragment\n");
- p(ifs6_reass_reqd, "\t%ju incoming datagram%s fragmented\n");
- p(ifs6_reass_ok, "\t%ju datagram%s reassembled\n");
- p(ifs6_reass_fail, "\t%ju datagram%s failed on reassembly\n");
- p(ifs6_in_mcast, "\t%ju multicast datagram%s received\n");
- p(ifs6_out_mcast, "\t%ju multicast datagram%s sent\n");
-
- end:
- close(s);
+ xo_emit("{T:/ip6 on %s}:\n", ifr.ifr_name);
+
+ xo_open_instance("ip6-interface-statistics");
+ xo_emit("{ke:name/%s}", ifr.ifr_name);
+
+ p(ifs6_in_receive, "\t{:received-packets/%ju} "
+ "{N:/total input datagram%s}\n");
+ p(ifs6_in_hdrerr, "\t{:dropped-invalid-header/%ju} "
+ "{N:/datagram%s with invalid header received}\n");
+ p(ifs6_in_toobig, "\t{:dropped-mtu-exceeded/%ju} "
+ "{N:/datagram%s exceeded MTU received}\n");
+ p(ifs6_in_noroute, "\t{:dropped-no-route/%ju} "
+ "{N:/datagram%s with no route received}\n");
+ p(ifs6_in_addrerr, "\t{:dropped-invalid-destination/%ju} "
+ "{N:/datagram%s with invalid dst received}\n");
+ p(ifs6_in_protounknown, "\t{:dropped-unknown-protocol/%ju} "
+ "{N:/datagram%s with unknown proto received}\n");
+ p(ifs6_in_truncated, "\t{:dropped-truncated/%ju} "
+ "{N:/truncated datagram%s received}\n");
+ p(ifs6_in_discard, "\t{:dropped-discarded/%ju} "
+ "{N:/input datagram%s discarded}\n");
+ p(ifs6_in_deliver, "\t{:received-valid-packets/%ju} "
+ "{N:/datagram%s delivered to an upper layer protocol}\n");
+ p(ifs6_out_forward, "\t{:sent-forwarded/%ju} "
+ "{N:/datagram%s forwarded to this interface}\n");
+ p(ifs6_out_request, "\t{:sent-packets/%ju} "
+ "{N:/datagram%s sent from an upper layer protocol}\n");
+ p(ifs6_out_discard, "\t{:discard-packets/%ju} "
+ "{N:/total discarded output datagram%s}\n");
+ p(ifs6_out_fragok, "\t{:discard-fragments/%ju} "
+ "{N:/output datagram%s fragmented}\n");
+ p(ifs6_out_fragfail, "\t{:fragments-failed/%ju} "
+ "{N:/output datagram%s failed on fragment}\n");
+ p(ifs6_out_fragcreat, "\t{:fragments-created/%ju} "
+ "{N:/output datagram%s succeeded on fragment}\n");
+ p(ifs6_reass_reqd, "\t{:reassembly-required/%ju} "
+ "{N:/incoming datagram%s fragmented}\n");
+ p(ifs6_reass_ok, "\t{:reassembled-packets/%ju} "
+ "{N:/datagram%s reassembled}\n");
+ p(ifs6_reass_fail, "\t{:reassembly-failed/%ju} "
+ "{N:/datagram%s failed on reassembly}\n");
+ p(ifs6_in_mcast, "\t{:received-multicast/%ju} "
+ "{N:/multicast datagram%s received}\n");
+ p(ifs6_out_mcast, "\t{:sent-multicast/%ju} "
+ "{N:/multicast datagram%s sent}\n");
+
+ end:
+ xo_close_instance("ip6-interface-statistics");
+ close(s);
#undef p
-#undef p_5
}
static const char *icmp6names[] = {
@@ -854,76 +970,118 @@ icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet6.icmp6.stats");
+ xo_warn("sysctl: net.inet6.icmp6.stats");
return;
}
} else
kread_counters(off, &icmp6stat, len);
- printf("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
+ xo_open_container(name);
#define p(f, m) if (icmp6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
+ xo_emit(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
#define p_5(f, m) if (icmp6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)icmp6stat.f)
+ xo_emit(m, (uintmax_t)icmp6stat.f)
- p(icp6s_error, "\t%ju call%s to icmp6_error\n");
- p(icp6s_canterror,
- "\t%ju error%s not generated in response to an icmp6 message\n");
- p(icp6s_toofreq,
- "\t%ju error%s not generated because of rate limitation\n");
+ p(icp6s_error, "\t{:icmp6-calls/%ju} "
+ "{N:/call%s to icmp6_error}\n");
+ p(icp6s_canterror, "\t{:errors-not-generated-from-message/%ju} "
+ "{N:/error%s not generated in response to an icmp6 message}\n");
+ p(icp6s_toofreq, "\t{:errors-discarded-by-rate-limitation/%ju} "
+ "{N:/error%s not generated because of rate limitation}\n");
#define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
for (first = 1, i = 0; i < NELEM; i++)
if (icmp6stat.icp6s_outhist[i] != 0) {
if (first) {
- printf("\tOutput histogram:\n");
+ xo_open_list("output-histogram");
+ xo_emit("\t{T:Output histogram}:\n");
first = 0;
}
- printf("\t\t%s: %ju\n", icmp6names[i],
+ xo_open_instance("output-histogram");
+ xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
+ icmp6names[i],
(uintmax_t)icmp6stat.icp6s_outhist[i]);
+ xo_close_instance("output-histogram");
}
+ if (!first)
+ xo_close_list("output-histogram");
#undef NELEM
- p(icp6s_badcode, "\t%ju message%s with bad code fields\n");
- p(icp6s_tooshort, "\t%ju message%s < minimum length\n");
- p(icp6s_checksum, "\t%ju bad checksum%s\n");
- p(icp6s_badlen, "\t%ju message%s with bad length\n");
+
+ p(icp6s_badcode, "\t{:dropped-bad-code/%ju} "
+ "{N:/message%s with bad code fields}\n");
+ p(icp6s_tooshort, "\t{:dropped-too-short/%ju} "
+ "{N:/message%s < minimum length}\n");
+ p(icp6s_checksum, "\t{:dropped-bad-checksum/%ju} "
+ "{N:/bad checksum%s}\n");
+ p(icp6s_badlen, "\t{:dropped-bad-length/%ju} "
+ "{N:/message%s with bad length}\n");
#define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
for (first = 1, i = 0; i < NELEM; i++)
if (icmp6stat.icp6s_inhist[i] != 0) {
if (first) {
- printf("\tInput histogram:\n");
+ xo_open_list("input-histogram");
+ xo_emit("\t{T:Input histogram}:\n");
first = 0;
}
- printf("\t\t%s: %ju\n", icmp6names[i],
+ xo_open_instance("input-histogram");
+ xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
+ icmp6names[i],
(uintmax_t)icmp6stat.icp6s_inhist[i]);
+ xo_close_instance("input-histogram");
}
+ if (!first)
+ xo_close_list("input-histogram");
#undef NELEM
- printf("\tHistogram of error messages to be generated:\n");
- p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n");
- p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n");
- p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n");
- p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n");
- p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n");
- p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n");
- p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n");
- p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n");
- p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n");
- p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n");
- p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n");
- p_5(icp6s_oredirect, "\t\t%ju redirect\n");
- p_5(icp6s_ounknown, "\t\t%ju unknown\n");
-
- p(icp6s_reflect, "\t%ju message response%s generated\n");
- p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n");
- p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n");
- p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n");
- p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n");
- p(icp6s_badrs, "\t%ju bad router solicitation message%s\n");
- p(icp6s_badra, "\t%ju bad router advertisement message%s\n");
- p(icp6s_badredirect, "\t%ju bad redirect message%s\n");
- p(icp6s_pmtuchg, "\t%ju path MTU change%s\n");
+ xo_emit("\t{T:Histogram of error messages to be generated}:\n");
+ xo_open_container("errors");
+ p_5(icp6s_odst_unreach_noroute, "\t\t{:no-route/%ju} "
+ "{N:/no route}\n");
+ p_5(icp6s_odst_unreach_admin, "\t\t{:admin-prohibited/%ju} "
+ "{N:/administratively prohibited}\n");
+ p_5(icp6s_odst_unreach_beyondscope, "\t\t{:beyond-scope/%ju} "
+ "{N:/beyond scope}\n");
+ p_5(icp6s_odst_unreach_addr, "\t\t{:address-unreachable/%ju} "
+ "{N:/address unreachable}\n");
+ p_5(icp6s_odst_unreach_noport, "\t\t{:port-unreachable/%ju} "
+ "{N:/port unreachable}\n");
+ p_5(icp6s_opacket_too_big, "\t\t{:packet-too-big/%ju} "
+ "{N:/packet too big}\n");
+ p_5(icp6s_otime_exceed_transit, "\t\t{:time-exceed-transmit/%ju} "
+ "{N:/time exceed transit}\n");
+ p_5(icp6s_otime_exceed_reassembly, "\t\t{:time-exceed-reassembly/%ju} "
+ "{N:/time exceed reassembly}\n");
+ p_5(icp6s_oparamprob_header, "\t\t{:bad-header/%ju} "
+ "{N:/erroneous header field}\n");
+ p_5(icp6s_oparamprob_nextheader, "\t\t{:bad-next-header/%ju} "
+ "{N:/unrecognized next header}\n");
+ p_5(icp6s_oparamprob_option, "\t\t{:bad-option/%ju} "
+ "{N:/unrecognized option}\n");
+ p_5(icp6s_oredirect, "\t\t{:redirects/%ju} "
+ "{N:/redirect}\n");
+ p_5(icp6s_ounknown, "\t\t{:unknown/%ju} {N:unknown}\n");
+
+ p(icp6s_reflect, "\t{:reflect/%ju} "
+ "{N:/message response%s generated}\n");
+ p(icp6s_nd_toomanyopt, "\t{:too-many-nd-options/%ju} "
+ "{N:/message%s with too many ND options}\n");
+ p(icp6s_nd_badopt, "\t{:bad-nd-options/%ju} "
+ "{N:/message%s with bad ND options}\n");
+ p(icp6s_badns, "\t{:bad-neighbor-solicitation/%ju} "
+ "{N:/bad neighbor solicitation message%s}\n");
+ p(icp6s_badna, "\t{:bad-neighbor-advertisement/%ju} "
+ "{N:/bad neighbor advertisement message%s}\n");
+ p(icp6s_badrs, "\t{:bad-router-solicitation/%ju} "
+ "{N:/bad router solicitation message%s}\n");
+ p(icp6s_badra, "\t{:bad-router-advertisement/%ju} "
+ "{N:/bad router advertisement message%s}\n");
+ p(icp6s_badredirect, "\t{:bad-redirect/%ju} "
+ "{N:/bad redirect message%s}\n");
+ xo_close_container("errors");
+ p(icp6s_pmtuchg, "\t{:path-mtu-changes/%ju} {N:/path MTU change%s}\n");
#undef p
#undef p_5
+ xo_close_container(name);
}
/*
@@ -934,61 +1092,102 @@ icmp6_ifstats(char *ifname)
{
struct in6_ifreq ifr;
int s;
-#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f))
-#define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
+
+#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
+ xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, \
+ plural(ifr.ifr_ifru.ifru_icmp6stat.f))
+#define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
+ xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, \
+ pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- perror("Warning: socket(AF_INET6)");
+ xo_warn("Warning: socket(AF_INET6)");
return;
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
if (errno != EPFNOSUPPORT)
- perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
+ xo_warn("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
goto end;
}
- printf("icmp6 on %s:\n", ifr.ifr_name);
- p(ifs6_in_msg, "\t%ju total input message%s\n");
- p(ifs6_in_error, "\t%ju total input error message%s\n");
- p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n");
- p(ifs6_in_adminprohib, "\t%ju input administratively prohibited error%s\n");
- p(ifs6_in_timeexceed, "\t%ju input time exceeded error%s\n");
- p(ifs6_in_paramprob, "\t%ju input parameter problem error%s\n");
- p(ifs6_in_pkttoobig, "\t%ju input packet too big error%s\n");
- p(ifs6_in_echo, "\t%ju input echo request%s\n");
- p2(ifs6_in_echoreply, "\t%ju input echo repl%s\n");
- p(ifs6_in_routersolicit, "\t%ju input router solicitation%s\n");
- p(ifs6_in_routeradvert, "\t%ju input router advertisement%s\n");
- p(ifs6_in_neighborsolicit, "\t%ju input neighbor solicitation%s\n");
- p(ifs6_in_neighboradvert, "\t%ju input neighbor advertisement%s\n");
- p(ifs6_in_redirect, "\t%ju input redirect%s\n");
- p2(ifs6_in_mldquery, "\t%ju input MLD quer%s\n");
- p(ifs6_in_mldreport, "\t%ju input MLD report%s\n");
- p(ifs6_in_mlddone, "\t%ju input MLD done%s\n");
-
- p(ifs6_out_msg, "\t%ju total output message%s\n");
- p(ifs6_out_error, "\t%ju total output error message%s\n");
- p(ifs6_out_dstunreach, "\t%ju output destination unreachable error%s\n");
- p(ifs6_out_adminprohib, "\t%ju output administratively prohibited error%s\n");
- p(ifs6_out_timeexceed, "\t%ju output time exceeded error%s\n");
- p(ifs6_out_paramprob, "\t%ju output parameter problem error%s\n");
- p(ifs6_out_pkttoobig, "\t%ju output packet too big error%s\n");
- p(ifs6_out_echo, "\t%ju output echo request%s\n");
- p2(ifs6_out_echoreply, "\t%ju output echo repl%s\n");
- p(ifs6_out_routersolicit, "\t%ju output router solicitation%s\n");
- p(ifs6_out_routeradvert, "\t%ju output router advertisement%s\n");
- p(ifs6_out_neighborsolicit, "\t%ju output neighbor solicitation%s\n");
- p(ifs6_out_neighboradvert, "\t%ju output neighbor advertisement%s\n");
- p(ifs6_out_redirect, "\t%ju output redirect%s\n");
- p2(ifs6_out_mldquery, "\t%ju output MLD quer%s\n");
- p(ifs6_out_mldreport, "\t%ju output MLD report%s\n");
- p(ifs6_out_mlddone, "\t%ju output MLD done%s\n");
-
- end:
+ xo_emit("{T:/icmp6 on %s}:\n", ifr.ifr_name);
+
+ xo_open_instance("icmp6-interface-statistics");
+ xo_emit("{ke:name/%s}", ifr.ifr_name);
+ p(ifs6_in_msg, "\t{:received-packets/%ju} "
+ "{N:/total input message%s}\n");
+ p(ifs6_in_error, "\t{:received-errors/%ju} "
+ "{N:/total input error message%s}\n");
+ p(ifs6_in_dstunreach, "\t{:received-destination-unreachable/%ju} "
+ "{N:/input destination unreachable error%s}\n");
+ p(ifs6_in_adminprohib, "\t{:received-admin-prohibited/%ju} "
+ "{N:/input administratively prohibited error%s}\n");
+ p(ifs6_in_timeexceed, "\t{:received-time-exceeded/%ju} "
+ "{N:/input time exceeded error%s}\n");
+ p(ifs6_in_paramprob, "\t{:received-bad-parameter/%ju} "
+ "{N:/input parameter problem error%s}\n");
+ p(ifs6_in_pkttoobig, "\t{:received-packet-too-big/%ju} "
+ "{N:/input packet too big error%s}\n");
+ p(ifs6_in_echo, "\t{:received-echo-requests/%ju} "
+ "{N:/input echo request%s}\n");
+ p2(ifs6_in_echoreply, "\t{:received-echo-replies/%ju} "
+ "{N:/input echo repl%s}\n");
+ p(ifs6_in_routersolicit, "\t{:received-router-solicitation/%ju} "
+ "{N:/input router solicitation%s}\n");
+ p(ifs6_in_routeradvert, "\t{:received-router-advertisement/%ju} "
+ "{N:/input router advertisement%s}\n");
+ p(ifs6_in_neighborsolicit, "\t{:received-neighbor-solicitation/%ju} "
+ "{N:/input neighbor solicitation%s}\n");
+ p(ifs6_in_neighboradvert, "\t{:received-neighbor-advertisement/%ju} "
+ "{N:/input neighbor advertisement%s}\n");
+ p(ifs6_in_redirect, "\t{received-redirects/%ju} "
+ "{N:/input redirect%s}\n");
+ p2(ifs6_in_mldquery, "\t{:received-mld-queries/%ju} "
+ "{N:/input MLD quer%s}\n");
+ p(ifs6_in_mldreport, "\t{:received-mld-reports/%ju} "
+ "{N:/input MLD report%s}\n");
+ p(ifs6_in_mlddone, "\t{:received-mld-done/%ju} "
+ "{N:/input MLD done%s}\n");
+
+ p(ifs6_out_msg, "\t{:sent-packets/%ju} "
+ "{N:/total output message%s}\n");
+ p(ifs6_out_error, "\t{:sent-errors/%ju} "
+ "{N:/total output error message%s}\n");
+ p(ifs6_out_dstunreach, "\t{:sent-destination-unreachable/%ju} "
+ "{N:/output destination unreachable error%s}\n");
+ p(ifs6_out_adminprohib, "\t{:sent-admin-prohibited/%ju} "
+ "{N:/output administratively prohibited error%s}\n");
+ p(ifs6_out_timeexceed, "\t{:sent-time-exceeded/%ju} "
+ "{N:/output time exceeded error%s}\n");
+ p(ifs6_out_paramprob, "\t{:sent-bad-parameter/%ju} "
+ "{N:/output parameter problem error%s}\n");
+ p(ifs6_out_pkttoobig, "\t{:sent-packet-too-big/%ju} "
+ "{N:/output packet too big error%s}\n");
+ p(ifs6_out_echo, "\t{:sent-echo-requests/%ju} "
+ "{N:/output echo request%s}\n");
+ p2(ifs6_out_echoreply, "\t{:sent-echo-replies/%ju} "
+ "{N:/output echo repl%s}\n");
+ p(ifs6_out_routersolicit, "\t{:sent-router-solicitation/%ju} "
+ "{N:/output router solicitation%s}\n");
+ p(ifs6_out_routeradvert, "\t{:sent-router-advertisement/%ju} "
+ "{N:/output router advertisement%s}\n");
+ p(ifs6_out_neighborsolicit, "\t{:sent-neighbor-solicitation/%ju} "
+ "{N:/output neighbor solicitation%s}\n");
+ p(ifs6_out_neighboradvert, "\t{:sent-neighbor-advertisement/%ju} "
+ "{N:/output neighbor advertisement%s}\n");
+ p(ifs6_out_redirect, "\t{:sent-redirects/%ju} "
+ "{N:/output redirect%s}\n");
+ p2(ifs6_out_mldquery, "\t{:sent-mld-queries/%ju} "
+ "{N:/output MLD quer%s}\n");
+ p(ifs6_out_mldreport, "\t{:sent-mld-reports/%ju} "
+ "{N:/output MLD report%s}\n");
+ p(ifs6_out_mlddone, "\t{:sent-mld-dones/%ju} "
+ "{N:/output MLD done%s}\n");
+
+end:
+ xo_close_instance("icmp6-interface-statistics");
close(s);
#undef p
}
@@ -1008,7 +1207,7 @@ pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet6.pim.stats");
+ xo_warn("sysctl: net.inet6.pim.stats");
return;
}
} else {
@@ -1017,18 +1216,28 @@ pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
kread(off, &pim6stat, len);
}
- printf("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
+ xo_open_container(name);
#define p(f, m) if (pim6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
- p(pim6s_rcv_total, "\t%ju message%s received\n");
- p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n");
- p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n");
- p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n");
- p(pim6s_rcv_registers, "\t%ju register%s received\n");
- p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n");
- p(pim6s_snd_registers, "\t%ju register%s sent\n");
+ xo_emit(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
+
+ p(pim6s_rcv_total, "\t{:received-packets/%ju} "
+ "{N:/message%s received}\n");
+ p(pim6s_rcv_tooshort, "\t{:dropped-too-short/%ju} "
+ "{N:/message%s received with too few bytes}\n");
+ p(pim6s_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
+ "{N:/message%s received with bad checksum}\n");
+ p(pim6s_rcv_badversion, "\t{:dropped-bad-version/%ju} "
+ "{N:/message%s received with bad version}\n");
+ p(pim6s_rcv_registers, "\t{:received-registers/%ju} "
+ "{N:/register%s received}\n");
+ p(pim6s_rcv_badregisters, "\t{:received-bad-registers/%ju} "
+ "{N:/bad register%s received}\n");
+ p(pim6s_snd_registers, "\t{:sent-registers/%ju} "
+ "{N:/register%s sent}\n");
#undef p
+ xo_close_container(name);
}
/*
@@ -1048,33 +1257,42 @@ rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet6.ip6.rip6stats", &rip6stat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet6.ip6.rip6stats");
+ xo_warn("sysctl: net.inet6.ip6.rip6stats");
return;
}
} else
kread_counters(off, &rip6stat, len);
- printf("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
+ xo_open_container(name);
#define p(f, m) if (rip6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)rip6stat.f, plural(rip6stat.f))
- p(rip6s_ipackets, "\t%ju message%s received\n");
- p(rip6s_isum, "\t%ju checksum calculation%s on inbound\n");
- p(rip6s_badsum, "\t%ju message%s with bad checksum\n");
- p(rip6s_nosock, "\t%ju message%s dropped due to no socket\n");
- p(rip6s_nosockmcast,
- "\t%ju multicast message%s dropped due to no socket\n");
- p(rip6s_fullsock,
- "\t%ju message%s dropped due to full socket buffers\n");
+ xo_emit(m, (uintmax_t)rip6stat.f, plural(rip6stat.f))
+
+ p(rip6s_ipackets, "\t{:received-packets/%ju} "
+ "{N:/message%s received}\n");
+ p(rip6s_isum, "\t{:input-checksum-computation/%ju} "
+ "{N:/checksum calculation%s on inbound}\n");
+ p(rip6s_badsum, "\t{:received-bad-checksum/%ju} "
+ "{N:/message%s with bad checksum}\n");
+ p(rip6s_nosock, "\t{:dropped-no-socket/%ju} "
+ "{N:/message%s dropped due to no socket}\n");
+ p(rip6s_nosockmcast, "\t{:dropped-multicast-no-socket/%ju} "
+ "{N:/multicast message%s dropped due to no socket}\n");
+ p(rip6s_fullsock, "\t{:dropped-full-socket-buffer/%ju} "
+ "{N:/message%s dropped due to full socket buffers}\n");
delivered = rip6stat.rip6s_ipackets -
rip6stat.rip6s_badsum -
rip6stat.rip6s_nosock -
rip6stat.rip6s_nosockmcast -
rip6stat.rip6s_fullsock;
if (delivered || sflag <= 1)
- printf("\t%ju delivered\n", (uintmax_t)delivered);
- p(rip6s_opackets, "\t%ju datagram%s output\n");
+ xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n",
+ (uintmax_t)delivered);
+ p(rip6s_opackets, "\t{:sent-packets/%ju} "
+ "{N:/datagram%s output}\n");
#undef p
+ xo_close_container(name);
}
/*
@@ -1092,14 +1310,18 @@ rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
};
void
-inet6print(struct in6_addr *in6, int port, const char *proto, int numeric)
+inet6print(const char *container, struct in6_addr *in6, int port,
+ const char *proto, int numeric)
{
struct servent *sp = 0;
char line[80], *cp;
int width;
- sprintf(line, "%.*s.", Wflag ? 39 :
- (Aflag && !numeric) ? 12 : 16, inet6name(in6));
+ if (container)
+ xo_open_container(container);
+
+ sprintf(line, "%.*s.", Wflag ? 39 : (Aflag && !numeric) ? 12 : 16,
+ inet6name(in6));
cp = strchr(line, '\0');
if (!numeric && port)
GETSERVBYPORT6(port, proto, sp);
@@ -1108,7 +1330,15 @@ inet6print(struct in6_addr *in6, int port, const char *proto, int numeric)
else
sprintf(cp, "%d", ntohs((u_short)port));
width = Wflag ? 45 : Aflag ? 18 : 22;
- printf("%-*.*s ", width, width, line);
+
+ xo_emit("{d:target/%-*.*s} ", width, width, line);
+
+ int alen = cp - line - 1, plen = strlen(cp) - 1;
+ xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
+ plen, cp);
+
+ if (container)
+ xo_close_container(container);
}
/*
@@ -1142,7 +1372,7 @@ inet6name(struct in6_addr *in6p)
memset(&sin6, 0, sizeof(sin6));
memcpy(&sin6.sin6_addr, in6p, sizeof(*in6p));
sin6.sin6_family = AF_INET6;
- /* XXX: in6p.s6_addr[2] can contain scopeid. */
+ /* XXX: in6p.s6_addr[2] can contain scopeid. */
in6_fillscopeid(&sin6);
flags = (numeric_addr) ? NI_NUMERICHOST : 0;
error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), hbuf,
diff --git a/usr.bin/netstat/ipsec.c b/usr.bin/netstat/ipsec.c
index b4014ad..137a26c 100644
--- a/usr.bin/netstat/ipsec.c
+++ b/usr.bin/netstat/ipsec.c
@@ -107,8 +107,10 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "netstat.h"
#ifdef IPSEC
@@ -171,27 +173,39 @@ static void print_ipsecstats(const struct ipsecstat *ipsecstat);
static void
print_ipsecstats(const struct ipsecstat *ipsecstat)
{
+ xo_open_container("ipsec-statistics");
+
#define p(f, m) if (ipsecstat->f || sflag <= 1) \
- printf(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f))
- p(ips_in_polvio, "\t%ju inbound packet%s violated process "
- "security policy\n");
- p(ips_in_nomem, "\t%ju inbound packet%s failed due to "
- "insufficient memory\n");
- p(ips_in_inval, "\t%ju invalid inbound packet%s\n");
- p(ips_out_polvio, "\t%ju outbound packet%s violated process "
- "security policy\n");
- p(ips_out_nosa, "\t%ju outbound packet%s with no SA available\n");
- p(ips_out_nomem, "\t%ju outbound packet%s failed due to "
- "insufficient memory\n");
- p(ips_out_noroute, "\t%ju outbound packet%s with no route "
- "available\n");
- p(ips_out_inval, "\t%ju invalid outbound packet%s\n");
- p(ips_out_bundlesa, "\t%ju outbound packet%s with bundled SAs\n");
- p(ips_mbcoalesced, "\t%ju mbuf%s coalesced during clone\n");
- p(ips_clcoalesced, "\t%ju cluster%s coalesced during clone\n");
- p(ips_clcopied, "\t%ju cluster%s copied during clone\n");
- p(ips_mbinserted, "\t%ju mbuf%s inserted during makespace\n");
+ xo_emit(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f))
+
+ p(ips_in_polvio, "\t{:dropped-policy-violation/%ju} "
+ "{N:/inbound packet%s violated process security policy}\n");
+ p(ips_in_nomem, "\t{:dropped-no-memory/%ju} "
+ "{N:/inbound packet%s failed due to insufficient memory}\n");
+ p(ips_in_inval, "\t{:dropped-invalid/%ju} "
+ "{N:/invalid inbound packet%s}\n");
+ p(ips_out_polvio, "\t{:discarded-policy-violation/%ju} "
+ "{N:/outbound packet%s violated process security policy}\n");
+ p(ips_out_nosa, "\t{:discarded-no-sa/%ju} "
+ "{N:/outbound packet%s with no SA available}\n");
+ p(ips_out_nomem, "\t{:discarded-no-memory/%ju} "
+ "{N:/outbound packet%s failed due to insufficient memory}\n");
+ p(ips_out_noroute, "\t{:discarded-no-route/%ju} "
+ "{N:/outbound packet%s with no route available}\n");
+ p(ips_out_inval, "\t{:discarded-invalid/%ju} "
+ "{N:/invalid outbound packet%s}\n");
+ p(ips_out_bundlesa, "\t{:send-bundled-sa/%ju} "
+ "{N:/outbound packet%s with bundled SAs}\n");
+ p(ips_mbcoalesced, "\t{:mbufs-coalesced-during-clone/%ju} "
+ "{N:/mbuf%s coalesced during clone}\n");
+ p(ips_clcoalesced, "\t{:clusters-coalesced-during-clone/%ju} "
+ "{N:/cluster%s coalesced during clone}\n");
+ p(ips_clcopied, "\t{:clusters-copied-during-clone/%ju} "
+ "{N:/cluster%s copied during clone}\n");
+ p(ips_mbinserted, "\t{:mbufs-inserted/%ju} "
+ "{N:/mbuf%s inserted during makespace}\n");
#undef p
+ xo_close_container("ipsec-statistics");
}
void
@@ -201,15 +215,13 @@ ipsec_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (off == 0)
return;
- printf ("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
kread_counters(off, (char *)&ipsecstat, sizeof(ipsecstat));
print_ipsecstats(&ipsecstat);
}
-static void ipsec_hist_new(const uint64_t *hist, size_t histmax,
- const struct val2str *name, const char *title);
static void print_ahstats(const struct ahstat *ahstat);
static void print_espstats(const struct espstat *espstat);
static void print_ipcompstats(const struct ipcompstat *ipcompstat);
@@ -219,7 +231,7 @@ static void print_ipcompstats(const struct ipcompstat *ipcompstat);
*/
static void
ipsec_hist_new(const uint64_t *hist, size_t histmax,
- const struct val2str *name, const char *title)
+ const struct val2str *name, const char *title, const char *cname)
{
int first;
size_t proto;
@@ -230,54 +242,72 @@ ipsec_hist_new(const uint64_t *hist, size_t histmax,
if (hist[proto] <= 0)
continue;
if (first) {
- printf("\t%s histogram:\n", title);
+ xo_open_list(cname);
+ xo_emit("\t{T:/%s histogram}:\n", title);
first = 0;
}
+ xo_open_instance(cname);
for (p = name; p && p->str; p++) {
if (p->val == (int)proto)
break;
}
if (p && p->str) {
- printf("\t\t%s: %ju\n", p->str,
+ xo_emit("\t\t{k:name}: {:count/%ju}\n", p->str,
(uintmax_t)hist[proto]);
} else {
- printf("\t\t#%lu: %ju\n", (unsigned long)proto,
- (uintmax_t)hist[proto]);
+ xo_emit("\t\t#{k:name/%lu}: {:count/%ju}\n",
+ (unsigned long)proto, (uintmax_t)hist[proto]);
}
+ xo_close_instance(cname);
}
+ if (!first)
+ xo_close_list(cname);
}
static void
print_ahstats(const struct ahstat *ahstat)
{
-#define p(f, m) if (ahstat->f || sflag <= 1) \
- printf("\t%ju" m, (uintmax_t)ahstat->f, plural(ahstat->f))
-#define hist(f, n, t) \
- ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));
-
- p(ahs_hdrops, " packet%s shorter than header shows\n");
- p(ahs_nopf, " packet%s dropped; protocol family not supported\n");
- p(ahs_notdb, " packet%s dropped; no TDB\n");
- p(ahs_badkcr, " packet%s dropped; bad KCR\n");
- p(ahs_qfull, " packet%s dropped; queue full\n");
- p(ahs_noxform, " packet%s dropped; no transform\n");
- p(ahs_wrap, " replay counter wrap%s\n");
- p(ahs_badauth, " packet%s dropped; bad authentication detected\n");
- p(ahs_badauthl, " packet%s dropped; bad authentication length\n");
- p(ahs_replay, " possible replay packet%s detected\n");
- p(ahs_input, " packet%s in\n");
- p(ahs_output, " packet%s out\n");
- p(ahs_invalid, " packet%s dropped; invalid TDB\n");
- p(ahs_ibytes, " byte%s in\n");
- p(ahs_obytes, " byte%s out\n");
- p(ahs_toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
- p(ahs_pdrops, " packet%s blocked due to policy\n");
- p(ahs_crypto, " crypto processing failure%s\n");
- p(ahs_tunnel, " tunnel sanity check failure%s\n");
- hist(ahstat->ahs_hist, ipsec_ahnames, "AH output");
+ xo_open_container("ah-statictics");
+
+#define p(f, n, m) if (ahstat->f || sflag <= 1) \
+ xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
+ (uintmax_t)ahstat->f, plural(ahstat->f))
+#define hist(f, n, t, c) \
+ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c))
+
+ p(ahs_hdrops, "dropped-short-header",
+ "packet%s shorter than header shows");
+ p(ahs_nopf, "dropped-bad-protocol",
+ "packet%s dropped; protocol family not supported");
+ p(ahs_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
+ p(ahs_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
+ p(ahs_qfull, "dropped-queue-full", "packet%s dropped; queue full");
+ p(ahs_noxform, "dropped-no-transform",
+ "packet%s dropped; no transform");
+ p(ahs_wrap, "replay-counter-wraps", "replay counter wrap%s");
+ p(ahs_badauth, "dropped-bad-auth",
+ "packet%s dropped; bad authentication detected");
+ p(ahs_badauthl, "dropped-bad-auth-level",
+ "packet%s dropped; bad authentication length");
+ p(ahs_replay, "possile-replay-detected",
+ "possible replay packet%s detected");
+ p(ahs_input, "received-packets", "packet%s in");
+ p(ahs_output, "send-packets", "packet%s out");
+ p(ahs_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
+ p(ahs_ibytes, "received-bytes", "byte%s in");
+ p(ahs_obytes, "send-bytes", "byte%s out");
+ p(ahs_toobig, "dropped-too-large",
+ "packet%s dropped; larger than IP_MAXPACKET");
+ p(ahs_pdrops, "dropped-policy-violation",
+ "packet%s blocked due to policy");
+ p(ahs_crypto, "crypto-failures", "crypto processing failure%s");
+ p(ahs_tunnel, "tunnel-failures", "tunnel sanity check failure%s");
+ hist(ahstat->ahs_hist, ipsec_ahnames,
+ "AH output", "ah-output-histogram");
#undef p
#undef hist
+ xo_close_container("ah-statictics");
}
void
@@ -287,7 +317,7 @@ ah_stats(u_long off, const char *name, int family __unused, int proto __unused)
if (off == 0)
return;
- printf ("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
kread_counters(off, (char *)&ahstat, sizeof(ahstat));
print_ahstats(&ahstat);
@@ -296,35 +326,47 @@ ah_stats(u_long off, const char *name, int family __unused, int proto __unused)
static void
print_espstats(const struct espstat *espstat)
{
-#define p(f, m) if (espstat->f || sflag <= 1) \
- printf("\t%ju" m, (uintmax_t)espstat->f, plural(espstat->f))
-#define hist(f, n, t) \
- ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));
-
- p(esps_hdrops, " packet%s shorter than header shows\n");
- p(esps_nopf, " packet%s dropped; protocol family not supported\n");
- p(esps_notdb, " packet%s dropped; no TDB\n");
- p(esps_badkcr, " packet%s dropped; bad KCR\n");
- p(esps_qfull, " packet%s dropped; queue full\n");
- p(esps_noxform, " packet%s dropped; no transform\n");
- p(esps_badilen, " packet%s dropped; bad ilen\n");
- p(esps_wrap, " replay counter wrap%s\n");
- p(esps_badenc, " packet%s dropped; bad encryption detected\n");
- p(esps_badauth, " packet%s dropped; bad authentication detected\n");
- p(esps_replay, " possible replay packet%s detected\n");
- p(esps_input, " packet%s in\n");
- p(esps_output, " packet%s out\n");
- p(esps_invalid, " packet%s dropped; invalid TDB\n");
- p(esps_ibytes, " byte%s in\n");
- p(esps_obytes, " byte%s out\n");
- p(esps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
- p(esps_pdrops, " packet%s blocked due to policy\n");
- p(esps_crypto, " crypto processing failure%s\n");
- p(esps_tunnel, " tunnel sanity check failure%s\n");
- hist(espstat->esps_hist, ipsec_espnames, "ESP output");
+ xo_open_container("esp-statictics");
+#define p(f, n, m) if (espstat->f || sflag <= 1) \
+ xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
+ (uintmax_t)espstat->f, plural(espstat->f))
+#define hist(f, n, t, c) \
+ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c));
+
+ p(esps_hdrops, "dropped-short-header",
+ "packet%s shorter than header shows");
+ p(esps_nopf, "dropped-bad-protocol",
+ "packet%s dropped; protocol family not supported");
+ p(esps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
+ p(esps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
+ p(esps_qfull, "dropped-queue-full", "packet%s dropped; queue full");
+ p(esps_noxform, "dropped-no-transform",
+ "packet%s dropped; no transform");
+ p(esps_badilen, "dropped-bad-length", "packet%s dropped; bad ilen");
+ p(esps_wrap, "replay-counter-wraps", "replay counter wrap%s");
+ p(esps_badenc, "dropped-bad-crypto",
+ "packet%s dropped; bad encryption detected");
+ p(esps_badauth, "dropped-bad-auth",
+ "packet%s dropped; bad authentication detected");
+ p(esps_replay, "possible-replay-detected",
+ "possible replay packet%s detected");
+ p(esps_input, "received-packets", "packet%s in");
+ p(esps_output, "sent-packets", "packet%s out");
+ p(esps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
+ p(esps_ibytes, "receieve-bytes", "byte%s in");
+ p(esps_obytes, "sent-bytes", "byte%s out");
+ p(esps_toobig, "dropped-too-large",
+ "packet%s dropped; larger than IP_MAXPACKET");
+ p(esps_pdrops, "dropped-policy-violation",
+ "packet%s blocked due to policy");
+ p(esps_crypto, "crypto-failures", "crypto processing failure%s");
+ p(esps_tunnel, "tunnel-failures", "tunnel sanity check failure%s");
+ hist(espstat->esps_hist, ipsec_espnames,
+ "ESP output", "esp-output-histogram");
#undef p
#undef hist
+ xo_close_container("esp-statictics");
}
void
@@ -334,7 +376,7 @@ esp_stats(u_long off, const char *name, int family __unused, int proto __unused)
if (off == 0)
return;
- printf ("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
kread_counters(off, (char *)&espstat, sizeof(espstat));
print_espstats(&espstat);
@@ -343,32 +385,44 @@ esp_stats(u_long off, const char *name, int family __unused, int proto __unused)
static void
print_ipcompstats(const struct ipcompstat *ipcompstat)
{
-#define p(f, m) if (ipcompstat->f || sflag <= 1) \
- printf("\t%ju" m, (uintmax_t)ipcompstat->f, plural(ipcompstat->f))
-#define hist(f, n, t) \
- ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));
-
- p(ipcomps_hdrops, " packet%s shorter than header shows\n");
- p(ipcomps_nopf, " packet%s dropped; protocol family not supported\n");
- p(ipcomps_notdb, " packet%s dropped; no TDB\n");
- p(ipcomps_badkcr, " packet%s dropped; bad KCR\n");
- p(ipcomps_qfull, " packet%s dropped; queue full\n");
- p(ipcomps_noxform, " packet%s dropped; no transform\n");
- p(ipcomps_wrap, " replay counter wrap%s\n");
- p(ipcomps_input, " packet%s in\n");
- p(ipcomps_output, " packet%s out\n");
- p(ipcomps_invalid, " packet%s dropped; invalid TDB\n");
- p(ipcomps_ibytes, " byte%s in\n");
- p(ipcomps_obytes, " byte%s out\n");
- p(ipcomps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
- p(ipcomps_pdrops, " packet%s blocked due to policy\n");
- p(ipcomps_crypto, " crypto processing failure%s\n");
- hist(ipcompstat->ipcomps_hist, ipsec_compnames, "COMP output");
- p(ipcomps_threshold, " packet%s sent uncompressed; size < compr. algo. threshold\n");
- p(ipcomps_uncompr, " packet%s sent uncompressed; compression was useless\n");
+ xo_open_container("ipcomp-statictics");
+
+#define p(f, n, m) if (ipcompstat->f || sflag <= 1) \
+ xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \
+ (uintmax_t)ipcompstat->f, plural(ipcompstat->f))
+#define hist(f, n, t, c) \
+ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c));
+
+ p(ipcomps_hdrops, "dropped-short-header",
+ "packet%s shorter than header shows");
+ p(ipcomps_nopf, "dropped-bad-protocol",
+ "packet%s dropped; protocol family not supported");
+ p(ipcomps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB");
+ p(ipcomps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR");
+ p(ipcomps_qfull, "dropped-queue-full", "packet%s dropped; queue full");
+ p(ipcomps_noxform, "dropped-no-transform",
+ "packet%s dropped; no transform");
+ p(ipcomps_wrap, "replay-counter-wraps", "replay counter wrap%s");
+ p(ipcomps_input, "receieve-packets", "packet%s in");
+ p(ipcomps_output, "sent-packets", "packet%s out");
+ p(ipcomps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB");
+ p(ipcomps_ibytes, "receieved-bytes", "byte%s in");
+ p(ipcomps_obytes, "sent-bytes", "byte%s out");
+ p(ipcomps_toobig, "dropped-too-large",
+ "packet%s dropped; larger than IP_MAXPACKET");
+ p(ipcomps_pdrops, "dropped-policy-violation",
+ "packet%s blocked due to policy");
+ p(ipcomps_crypto, "crypto-failure", "crypto processing failure%s");
+ hist(ipcompstat->ipcomps_hist, ipsec_compnames,
+ "COMP output", "comp-output-histogram");
+ p(ipcomps_threshold, "sent-uncompressed-small-packets",
+ "packet%s sent uncompressed; size < compr. algo. threshold");
+ p(ipcomps_uncompr, "sent-uncompressed-useless-packets",
+ "packet%s sent uncompressed; compression was useless");
#undef p
#undef hist
+ xo_close_container("ipcomp-statictics");
}
void
@@ -379,7 +433,7 @@ ipcomp_stats(u_long off, const char *name, int family __unused,
if (off == 0)
return;
- printf ("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
kread_counters(off, (char *)&ipcompstat, sizeof(ipcompstat));
print_ipcompstats(&ipcompstat);
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 8fc2b4e..acc27f7 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -65,9 +65,11 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include "netstat.h"
+#include <libxo/xo.h>
static struct nlist nl[] = {
#define N_RTSTAT 0
@@ -146,7 +148,7 @@ static struct nlist nl[] = {
{ .n_name = "_sctpstat" },
#define N_MFCTABLESIZE 37
{ .n_name = "_mfctablesize" },
-#define N_ARPSTAT 38
+#define N_ARPSTAT 38
{ .n_name = "_arpstat" },
#define N_UNP_SPHEAD 39
{ .n_name = "unp_sphead" },
@@ -271,7 +273,7 @@ struct protox *protoprotox[] = {
#endif
NULL };
-static void printproto(struct protox *, const char *);
+static void printproto(struct protox *, const char *, bool *);
static void usage(void);
static struct protox *name2protox(const char *);
static struct protox *knownname(const char *);
@@ -317,9 +319,12 @@ main(int argc, char *argv[])
int ch;
int fib = -1;
char *endptr;
+ bool first = true;
af = AF_UNSPEC;
+ argc = xo_parse_args(argc, argv);
+
while ((ch = getopt(argc, argv, "46AaBbdF:f:ghI:iLlM:mN:np:Qq:RrSTsuWw:xz"))
!= -1)
switch(ch) {
@@ -356,7 +361,7 @@ main(int argc, char *argv[])
fib = strtol(optarg, &endptr, 0);
if (*endptr != '\0' ||
(fib == 0 && (errno == EINVAL || errno == ERANGE)))
- errx(1, "%s: invalid fib", optarg);
+ xo_errx(1, "%s: invalid fib", optarg);
break;
case 'f':
if (strcmp(optarg, "inet") == 0)
@@ -379,7 +384,8 @@ main(int argc, char *argv[])
else if (strcmp(optarg, "link") == 0)
af = AF_LINK;
else {
- errx(1, "%s: unknown address family", optarg);
+ xo_errx(1, "%s: unknown address family",
+ optarg);
}
break;
case 'g':
@@ -417,9 +423,8 @@ main(int argc, char *argv[])
break;
case 'p':
if ((tp = name2protox(optarg)) == NULL) {
- errx(1,
- "%s: unknown or uninstrumented protocol",
- optarg);
+ xo_errx(1, "%s: unknown or uninstrumented "
+ "protocol", optarg);
}
pflag = 1;
break;
@@ -496,13 +501,14 @@ main(int argc, char *argv[])
if (!live)
setgid(getgid());
- if (xflag && Tflag)
- errx(1, "-x and -T are incompatible, pick one.");
+ if (xflag && Tflag)
+ xo_errx(1, "-x and -T are incompatible, pick one.");
if (Bflag) {
if (!live)
usage();
bpf_stats(interface);
+ xo_finish();
exit(0);
}
if (mflag) {
@@ -511,6 +517,7 @@ main(int argc, char *argv[])
mbpr(kvmd, nl[N_SFSTAT].n_value);
} else
mbpr(NULL, 0);
+ xo_finish();
exit(0);
}
if (Qflag) {
@@ -519,6 +526,7 @@ main(int argc, char *argv[])
netisr_stats(kvmd);
} else
netisr_stats(NULL);
+ xo_finish();
exit(0);
}
#if 0
@@ -536,19 +544,26 @@ main(int argc, char *argv[])
*/
#endif
if (iflag && !sflag) {
+ xo_open_container("statistics");
intpr(interval, NULL, af);
+ xo_close_container("statistics");
+ xo_finish();
exit(0);
}
if (rflag) {
+ xo_open_container("statistics");
if (sflag) {
rt_stats();
flowtable_stats();
} else
routepr(fib, af);
+ xo_close_container("statistics");
+ xo_finish();
exit(0);
}
if (gflag) {
+ xo_open_container("statistics");
if (sflag) {
if (af == AF_INET || af == AF_UNSPEC)
mrt_stats();
@@ -564,6 +579,8 @@ main(int argc, char *argv[])
mroute6pr();
#endif
}
+ xo_close_container("statistics");
+ xo_finish();
exit(0);
}
@@ -571,31 +588,43 @@ main(int argc, char *argv[])
kresolve_list(nl);
if (tp) {
- printproto(tp, tp->pr_name);
+ xo_open_container("statistics");
+ printproto(tp, tp->pr_name, &first);
+ if (!first)
+ xo_close_list("socket");
+ xo_close_container("statistics");
+ xo_finish();
exit(0);
}
+
+ xo_open_container("statistics");
if (af == AF_INET || af == AF_UNSPEC)
for (tp = protox; tp->pr_name; tp++)
- printproto(tp, tp->pr_name);
+ printproto(tp, tp->pr_name, &first);
#ifdef INET6
if (af == AF_INET6 || af == AF_UNSPEC)
for (tp = ip6protox; tp->pr_name; tp++)
- printproto(tp, tp->pr_name);
+ printproto(tp, tp->pr_name, &first);
#endif /*INET6*/
#ifdef IPSEC
if (af == PF_KEY || af == AF_UNSPEC)
for (tp = pfkeyprotox; tp->pr_name; tp++)
- printproto(tp, tp->pr_name);
+ printproto(tp, tp->pr_name, &first);
#endif /*IPSEC*/
#ifdef NETGRAPH
if (af == AF_NETGRAPH || af == AF_UNSPEC)
for (tp = netgraphprotox; tp->pr_name; tp++)
- printproto(tp, tp->pr_name);
+ printproto(tp, tp->pr_name, &first);
#endif /* NETGRAPH */
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value,
nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value,
- nl[N_UNP_SPHEAD].n_value);
+ nl[N_UNP_SPHEAD].n_value, &first);
+
+ if (!first)
+ xo_close_list("socket");
+ xo_close_container("statistics");
+ xo_finish();
exit(0);
}
@@ -605,24 +634,25 @@ main(int argc, char *argv[])
* is not in the namelist, ignore this one.
*/
static void
-printproto(struct protox *tp, const char *name)
+printproto(struct protox *tp, const char *name, bool *first)
{
void (*pr)(u_long, const char *, int, int);
u_long off;
+ bool doingdblocks = false;
if (sflag) {
if (iflag) {
if (tp->pr_istats)
intpr(interval, tp->pr_istats, af);
else if (pflag)
- printf("%s: no per-interface stats routine\n",
+ xo_message("%s: no per-interface stats routine",
tp->pr_name);
return;
} else {
pr = tp->pr_stats;
if (!pr) {
if (pflag)
- printf("%s: no stats routine\n",
+ xo_message("%s: no stats routine",
tp->pr_name);
return;
}
@@ -630,34 +660,39 @@ printproto(struct protox *tp, const char *name)
off = 0;
else if (tp->pr_sindex < 0) {
if (pflag)
- printf(
- "%s: stats routine doesn't work on cores\n",
- tp->pr_name);
+ xo_message("%s: stats routine doesn't "
+ "work on cores", tp->pr_name);
return;
} else
off = nl[tp->pr_sindex].n_value;
}
} else {
+ doingdblocks = true;
pr = tp->pr_cblocks;
if (!pr) {
if (pflag)
- printf("%s: no PCB routine\n", tp->pr_name);
+ xo_message("%s: no PCB routine", tp->pr_name);
return;
}
if (tp->pr_usesysctl && live)
off = 0;
else if (tp->pr_index < 0) {
if (pflag)
- printf(
- "%s: PCB routine doesn't work on cores\n",
- tp->pr_name);
+ xo_message("%s: PCB routine doesn't work on "
+ "cores", tp->pr_name);
return;
} else
off = nl[tp->pr_index].n_value;
}
if (pr != NULL && (off || (live && tp->pr_usesysctl) ||
- af != AF_UNSPEC))
+ af != AF_UNSPEC)) {
+ if (doingdblocks && *first) {
+ xo_open_list("socket");
+ *first = false;
+ }
+
(*pr)(off, name, af, tp->pr_protocol);
+ }
}
static int
@@ -672,7 +707,7 @@ kvmd_init(void)
setgid(getgid());
if (kvmd == NULL) {
- warnx("kvm not available: %s", errbuf);
+ xo_warnx("kvm not available: %s", errbuf);
return (-1);
}
@@ -694,10 +729,10 @@ kresolve_list(struct nlist *_nl)
if (kvm_nlist(kvmd, _nl) < 0) {
if (nlistf)
- errx(1, "%s: kvm_nlist: %s", nlistf,
- kvm_geterr(kvmd));
+ xo_errx(1, "%s: kvm_nlist: %s", nlistf,
+ kvm_geterr(kvmd));
else
- errx(1, "kvm_nlist: %s", kvm_geterr(kvmd));
+ xo_errx(1, "kvm_nlist: %s", kvm_geterr(kvmd));
}
return (0);
@@ -716,7 +751,7 @@ kread(u_long addr, void *buf, size_t size)
if (!buf)
return (0);
if (kvm_read(kvmd, addr, buf, size) != (ssize_t)size) {
- warnx("%s", kvm_geterr(kvmd));
+ xo_warnx("%s", kvm_geterr(kvmd));
return (-1);
}
return (0);
@@ -823,7 +858,7 @@ name2protox(const char *name)
static void
usage(void)
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
+ (void)xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
"usage: netstat [-46AaLnRSTWx] [-f protocol_family | -p protocol]\n"
" [-M core] [-N system]",
" netstat -i | -I interface [-46abdhnW] [-f address_family]\n"
@@ -842,5 +877,6 @@ usage(void)
" netstat -g [-46W] [-f address_family] [-M core] [-N system]",
" netstat -gs [-46s] [-f address_family] [-M core] [-N system]",
" netstat -Q");
+ xo_finish();
exit(1);
}
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c
index ebd843f..26b7095 100644
--- a/usr.bin/netstat/mbuf.c
+++ b/usr.bin/netstat/mbuf.c
@@ -56,7 +56,9 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
+#include <libxo/xo.h>
#include "netstat.h"
/*
@@ -88,7 +90,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtlp = memstat_mtl_alloc();
if (mtlp == NULL) {
- warn("memstat_mtl_alloc");
+ xo_warn("memstat_mtl_alloc");
return;
}
@@ -98,7 +100,7 @@ mbpr(void *kvmd, u_long mbaddr)
*/
if (live) {
if (memstat_sysctl_all(mtlp, 0) < 0) {
- warnx("memstat_sysctl_all: %s",
+ xo_warnx("memstat_sysctl_all: %s",
memstat_strerror(memstat_mtl_geterror(mtlp)));
goto out;
}
@@ -106,10 +108,10 @@ mbpr(void *kvmd, u_long mbaddr)
if (memstat_kvm_all(mtlp, kvmd) < 0) {
error = memstat_mtl_geterror(mtlp);
if (error == MEMSTAT_ERROR_KVM)
- warnx("memstat_kvm_all: %s",
+ xo_warnx("memstat_kvm_all: %s",
kvm_geterr(kvmd));
else
- warnx("memstat_kvm_all: %s",
+ xo_warnx("memstat_kvm_all: %s",
memstat_strerror(error));
goto out;
}
@@ -117,7 +119,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: zone %s not found", MBUF_MEM_NAME);
+ xo_warnx("memstat_mtl_find: zone %s not found", MBUF_MEM_NAME);
goto out;
}
mbuf_count = memstat_get_count(mtp);
@@ -129,7 +131,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_PACKET_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: zone %s not found",
+ xo_warnx("memstat_mtl_find: zone %s not found",
MBUF_PACKET_MEM_NAME);
goto out;
}
@@ -141,7 +143,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: zone %s not found",
+ xo_warnx("memstat_mtl_find: zone %s not found",
MBUF_CLUSTER_MEM_NAME);
goto out;
}
@@ -154,7 +156,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_MALLOC, MBUF_TAG_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: malloc type %s not found",
+ xo_warnx("memstat_mtl_find: malloc type %s not found",
MBUF_TAG_MEM_NAME);
goto out;
}
@@ -162,7 +164,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBOP_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: zone %s not found",
+ xo_warnx("memstat_mtl_find: zone %s not found",
MBUF_JUMBOP_MEM_NAME);
goto out;
}
@@ -175,7 +177,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO9_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: zone %s not found",
+ xo_warnx("memstat_mtl_find: zone %s not found",
MBUF_JUMBO9_MEM_NAME);
goto out;
}
@@ -188,7 +190,7 @@ mbpr(void *kvmd, u_long mbaddr)
mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO16_MEM_NAME);
if (mtp == NULL) {
- warnx("memstat_mtl_find: zone %s not found",
+ xo_warnx("memstat_mtl_find: zone %s not found",
MBUF_JUMBO16_MEM_NAME);
goto out;
}
@@ -199,36 +201,44 @@ mbpr(void *kvmd, u_long mbaddr)
jumbo16_sleeps = memstat_get_sleeps(mtp);
jumbo16_size = memstat_get_size(mtp);
- printf("%ju/%ju/%ju mbufs in use (current/cache/total)\n",
+ xo_open_container("mbuf-statistics");
+
+ xo_emit("{:mbuf-current/%ju}/{:mbuf-cache/%ju}/{:mbuf-total/%ju} "
+ "{N:mbufs in use (current\\/cache\\/total)}\n",
mbuf_count + packet_count, mbuf_free + packet_free,
mbuf_count + packet_count + mbuf_free + packet_free);
- printf("%ju/%ju/%ju/%ju mbuf clusters in use "
- "(current/cache/total/max)\n",
+ xo_emit("{:cluster-current/%ju}/{:cluster-cache/%ju}/"
+ "{:cluster-total/%ju}/{:cluster-max/%ju} "
+ "{N:mbuf clusters in use (current\\/cache\\/total\\/max)}\n",
cluster_count - packet_free, cluster_free + packet_free,
cluster_count + cluster_free, cluster_limit);
- printf("%ju/%ju mbuf+clusters out of packet secondary zone in use "
- "(current/cache)\n",
+ xo_emit("{:packet-count/%ju}/{:packet-free/%ju} "
+ "{N:mbuf+clusters out of packet secondary zone in use "
+ "(current\\/cache)}\n",
packet_count, packet_free);
- printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use "
- "(current/cache/total/max)\n",
+ xo_emit("{:jumbo-count/%ju}/{:jumbo-cache/%ju}/{:jumbo-total/%ju}/"
+ "{:jumbo-max/%ju} {:jumbo-page-size/%ju}{U:k} {N:(page size)} "
+ "{N:jumbo clusters in use (current\\/cache\\/total\\/max)}\n",
jumbop_count, jumbop_free, jumbop_count + jumbop_free,
jumbop_limit, jumbop_size / 1024);
- printf("%ju/%ju/%ju/%ju 9k jumbo clusters in use "
- "(current/cache/total/max)\n",
+ xo_emit("{:jumbo9-count/%ju}/{:jumbo9-cache/%ju}/"
+ "{:jumbo9-total/%ju}/{:jumbo9-max/%ju} "
+ "{N:9k jumbo clusters in use (current\\/cache\\/total\\/max)}\n",
jumbo9_count, jumbo9_free, jumbo9_count + jumbo9_free,
jumbo9_limit);
- printf("%ju/%ju/%ju/%ju 16k jumbo clusters in use "
- "(current/cache/total/max)\n",
+ xo_emit("{:jumbo16-count/%ju}/{:jumbo16-cache/%ju}/"
+ "{:jumbo16-total/%ju}/{:jumbo16-limit/%ju} "
+ "{N:16k jumbo clusters in use (current\\/cache\\/total\\/max)}\n",
jumbo16_count, jumbo16_free, jumbo16_count + jumbo16_free,
jumbo16_limit);
#if 0
- printf("%ju mbuf tags in use\n", tag_count);
+ xo_emit("{:tag-count/%ju} {N:mbuf tags in use}\n", tag_count);
#endif
/*-
@@ -276,23 +286,29 @@ mbpr(void *kvmd, u_long mbaddr)
*/
bytes_total = bytes_inuse + bytes_incache;
- printf("%juK/%juK/%juK bytes allocated to network "
- "(current/cache/total)\n", bytes_inuse / 1024,
- bytes_incache / 1024, bytes_total / 1024);
+ xo_emit("{:bytes-in-use/%ju}{U:K}/{:bytes-in-cache/%ju}{U:K}/"
+ "{:bytes-total/%ju}{U:K} "
+ "{N:bytes allocated to network (current\\/cache\\/total)}\n",
+ bytes_inuse / 1024, bytes_incache / 1024, bytes_total / 1024);
- printf("%ju/%ju/%ju requests for mbufs denied (mbufs/clusters/"
- "mbuf+clusters)\n", mbuf_failures, cluster_failures,
- packet_failures);
- printf("%ju/%ju/%ju requests for mbufs delayed (mbufs/clusters/"
- "mbuf+clusters)\n", mbuf_sleeps, cluster_sleeps,
- packet_sleeps);
+ xo_emit("{:mbuf-failures/%ju}/{:cluster-failures/%ju}/"
+ "{:packet-failures/%ju} {N:requests for mbufs denied "
+ "(mbufs\\/clusters\\/mbuf+clusters)}\n",
+ mbuf_failures, cluster_failures, packet_failures);
+ xo_emit("{:mbuf-sleeps/%ju}/{:cluster-sleeps/%ju}/{:packet-sleeps/%ju} "
+ "{N:requests for mbufs delayed "
+ "(mbufs\\/clusters\\/mbuf+clusters)}\n",
+ mbuf_sleeps, cluster_sleeps, packet_sleeps);
- printf("%ju/%ju/%ju requests for jumbo clusters delayed "
- "(%juk/9k/16k)\n", jumbop_sleeps, jumbo9_sleeps,
- jumbo16_sleeps, jumbop_size / 1024);
- printf("%ju/%ju/%ju requests for jumbo clusters denied "
- "(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures,
- jumbo16_failures, jumbop_size / 1024);
+ xo_emit("{:jumbop-sleeps/%ju}/{:jumbo9-sleeps/%ju}/"
+ "{:jumbo16-sleeps/%ju} {N:/requests for jumbo clusters delayed "
+ "(%juk\\/9k\\/16k)}\n",
+ jumbop_sleeps, jumbo9_sleeps, jumbo16_sleeps, jumbop_size / 1024);
+ xo_emit("{:jumbop-failures/%ju}/{:jumbo9-failures/%ju}/"
+ "{:jumbo16-failures/%ju} {N:/requests for jumbo clusters denied "
+ "(%juk\\/9k\\/16k)}\n",
+ jumbop_failures, jumbo9_failures, jumbo16_failures,
+ jumbop_size / 1024);
if (live) {
mlen = sizeof(nsfbufs);
@@ -302,23 +318,27 @@ mbpr(void *kvmd, u_long mbaddr)
&mlen, NULL, 0) &&
!sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak,
&mlen, NULL, 0))
- printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
+ xo_emit("{:nsfbufs-current/%d}/{:nsfbufs-peak/%d}/"
+ "{:nsfbufs/%d} "
+ "{N:sfbufs in use (current\\/peak\\/max)}\n",
nsfbufsused, nsfbufspeak, nsfbufs);
mlen = sizeof(sfstat);
if (sysctlbyname("kern.ipc.sfstat", &sfstat, &mlen, NULL, 0)) {
- warn("kern.ipc.sfstat");
+ xo_warn("kern.ipc.sfstat");
goto out;
}
} else {
if (kread_counters(mbaddr, (char *)&sfstat, sizeof sfstat) != 0)
goto out;
}
- printf("%ju requests for sfbufs denied\n",
+ xo_emit("{:sfbufs-alloc-failed/%ju} {N:requests for sfbufs denied}\n",
(uintmax_t)sfstat.sf_allocfail);
- printf("%ju requests for sfbufs delayed\n",
+ xo_emit("{:sfbufs-alloc-wait/%ju} {N:requests for sfbufs delayed}\n",
(uintmax_t)sfstat.sf_allocwait);
- printf("%ju requests for I/O initiated by sendfile\n",
+ xo_emit("{:sfbufs-io-count/%ju} "
+ "{N:requests for I\\/O initiated by sendfile}\n",
(uintmax_t)sfstat.sf_iocnt);
out:
+ xo_close_container("mbuf-statistics");
memstat_mtl_free(mtlp);
}
diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c
index 3ec716d..37c8868 100644
--- a/usr.bin/netstat/mroute.c
+++ b/usr.bin/netstat/mroute.c
@@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
+#include <libxo/xo.h>
#include "netstat.h"
/*
@@ -92,77 +94,85 @@ static void print_mfc(struct mfc *, int, int *);
static void
print_bw_meter(struct bw_meter *bw_meter, int *banner_printed)
{
- char s0[256], s1[256], s2[256], s3[256];
+ char s1[256], s2[256], s3[256];
struct timeval now, end, delta;
gettimeofday(&now, NULL);
if (! *banner_printed) {
- printf(" Bandwidth Meters\n");
- printf(" %-30s", "Measured(Start|Packets|Bytes)");
- printf(" %s", "Type");
- printf(" %-30s", "Thresh(Interval|Packets|Bytes)");
- printf(" Remain");
- printf("\n");
+ xo_open_list("bandwidth-meter");
+ xo_emit(" {T:Bandwidth Meters}\n");
+ xo_emit(" {T:/%-30s}", "Measured(Start|Packets|Bytes)");
+ xo_emit(" {T:/%s}", "Type");
+ xo_emit(" {T:/%-30s}", "Thresh(Interval|Packets|Bytes)");
+ xo_emit(" {T:Remain}");
+ xo_emit("\n");
*banner_printed = 1;
}
+ xo_open_instance("bandwidth-meter");
+
/* The measured values */
- if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
+ if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) {
sprintf(s1, "%ju", (uintmax_t)bw_meter->bm_measured.b_packets);
- else
+ xo_emit("{e:measured-packets/%ju}",
+ (uintmax_t)bw_meter->bm_measured.b_packets);
+ } else
sprintf(s1, "?");
- if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
+ if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) {
sprintf(s2, "%ju", (uintmax_t)bw_meter->bm_measured.b_bytes);
- else
+ xo_emit("{e:measured-bytes/%ju}",
+ (uintmax_t)bw_meter->bm_measured.b_bytes);
+ } else
sprintf(s2, "?");
- sprintf(s0, "%lu.%lu|%s|%s",
- (u_long)bw_meter->bm_start_time.tv_sec,
- (u_long)bw_meter->bm_start_time.tv_usec,
- s1, s2);
- printf(" %-30s", s0);
+ xo_emit(" {[:-30}{:start-time/%lu.%06lu}|{q:measured-packets/%s}"
+ "|{q:measured-bytes%s}{]:}",
+ (u_long)bw_meter->bm_start_time.tv_sec,
+ (u_long)bw_meter->bm_start_time.tv_usec, s1, s2);
/* The type of entry */
- sprintf(s0, "%s", "?");
- if (bw_meter->bm_flags & BW_METER_GEQ)
- sprintf(s0, "%s", ">=");
- else if (bw_meter->bm_flags & BW_METER_LEQ)
- sprintf(s0, "%s", "<=");
- printf(" %-3s", s0);
+ xo_emit(" {t:type/%-3s}", (bw_meter->bm_flags & BW_METER_GEQ) ? ">=" :
+ (bw_meter->bm_flags & BW_METER_LEQ) ? "<=" : "?");
/* The threshold values */
- if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
+ if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) {
sprintf(s1, "%ju", (uintmax_t)bw_meter->bm_threshold.b_packets);
- else
+ xo_emit("{e:threshold-packets/%ju}",
+ (uintmax_t)bw_meter->bm_threshold.b_packets);
+ } else
sprintf(s1, "?");
- if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
+ if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) {
sprintf(s2, "%ju", (uintmax_t)bw_meter->bm_threshold.b_bytes);
- else
+ xo_emit("{e:threshold-bytes/%ju}",
+ (uintmax_t)bw_meter->bm_threshold.b_bytes);
+ } else
sprintf(s2, "?");
- sprintf(s0, "%lu.%lu|%s|%s",
- (u_long)bw_meter->bm_threshold.b_time.tv_sec,
- (u_long)bw_meter->bm_threshold.b_time.tv_usec,
- s1, s2);
- printf(" %-30s", s0);
+
+ xo_emit(" {[:-30}{:threshold-time/%lu.%06lu}|{q:threshold-packets/%s}"
+ "|{q:threshold-bytes%s}{]:}",
+ (u_long)bw_meter->bm_threshold.b_time.tv_sec,
+ (u_long)bw_meter->bm_threshold.b_time.tv_usec, s1, s2);
/* Remaining time */
timeradd(&bw_meter->bm_start_time,
&bw_meter->bm_threshold.b_time, &end);
if (timercmp(&now, &end, <=)) {
timersub(&end, &now, &delta);
- sprintf(s3, "%lu.%lu",
+ sprintf(s3, "%lu.%06lu",
(u_long)delta.tv_sec,
(u_long)delta.tv_usec);
} else {
/* Negative time */
timersub(&now, &end, &delta);
- sprintf(s3, "-%lu.%lu",
+ sprintf(s3, "-%lu.06%lu",
(u_long)delta.tv_sec,
(u_long)delta.tv_usec);
}
- printf(" %s", s3);
+ xo_emit(" {:remaining-time/%s}", s3);
- printf("\n");
+ xo_open_instance("bandwidth-meter");
+
+ xo_emit("\n");
}
static void
@@ -176,21 +186,29 @@ print_mfc(struct mfc *m, int maxvif, int *banner_printed)
bw_banner_printed = 0;
if (! *banner_printed) {
- printf("\nIPv4 Multicast Forwarding Table\n"
- " Origin Group "
- " Packets In-Vif Out-Vifs:Ttls\n");
+ xo_open_list("multicast-forwarding-entry");
+ xo_emit("\n{T:IPv4 Multicast Forwarding Table}\n"
+ " {T:Origin} {T:Group} "
+ " {T:Packets In-Vif} {T:Out-Vifs:Ttls}\n");
*banner_printed = 1;
}
- printf(" %-15.15s", routename(m->mfc_origin.s_addr));
- printf(" %-15.15s", routename(m->mfc_mcastgrp.s_addr));
- printf(" %9lu", m->mfc_pkt_cnt);
- printf(" %3d ", m->mfc_parent);
+ xo_emit(" {:origin-address/%-15.15s}", routename(m->mfc_origin.s_addr));
+ xo_emit(" {:group-address/%-15.15s}",
+ routename(m->mfc_mcastgrp.s_addr));
+ xo_emit(" {:sent-packets/%9lu}", m->mfc_pkt_cnt);
+ xo_emit(" {:parent/%3d} ", m->mfc_parent);
+ xo_open_list("vif-ttl");
for (vifi = 0; vifi <= maxvif; vifi++) {
- if (m->mfc_ttls[vifi] > 0)
- printf(" %u:%u", vifi, m->mfc_ttls[vifi]);
+ if (m->mfc_ttls[vifi] > 0) {
+ xo_open_instance("vif-ttl");
+ xo_emit(" {k:vif/%u}:{:ttl/%u}", vifi,
+ m->mfc_ttls[vifi]);
+ xo_close_instance("vif-ttl");
+ }
}
- printf("\n");
+ xo_close_list("vif-ttl");
+ xo_emit("\n");
/*
* XXX We break the rules and try to use KVM to read the
@@ -205,6 +223,8 @@ print_mfc(struct mfc *m, int maxvif, int *banner_printed)
print_bw_meter(&bw_meter, &bw_banner_printed);
bwm = bw_meter.bm_mfc_next;
}
+ if (banner_printed)
+ xo_close_list("bandwidth-meter");
}
void
@@ -242,7 +262,7 @@ mroutepr()
if (live) {
if (sysctlbyname("net.inet.ip.viftable", viftable, &len, NULL,
0) < 0) {
- warn("sysctl: net.inet.ip.viftable");
+ xo_warn("sysctl: net.inet.ip.viftable");
return;
}
} else {
@@ -252,7 +272,7 @@ mroutepr()
pviftbl = mrl[N_VIFTABLE].n_value;
if (pmfchashtbl == 0 || pmfctablesize == 0 || pviftbl == 0) {
- fprintf(stderr, "No IPv4 MROUTING kernel support.\n");
+ xo_warnx("No IPv4 MROUTING kernel support.");
return;
}
@@ -266,23 +286,29 @@ mroutepr()
maxvif = vifi;
if (!banner_printed) {
- printf("\nIPv4 Virtual Interface Table\n"
- " Vif Thresh Local-Address "
- "Remote-Address Pkts-In Pkts-Out\n");
+ xo_emit("\n{T:IPv4 Virtual Interface Table\n"
+ " Vif Thresh Local-Address "
+ "Remote-Address Pkts-In Pkts-Out}\n");
banner_printed = 1;
+ xo_open_list("vif");
}
- printf(" %2u %6u %-15.15s",
+ xo_open_instance("vif");
+ xo_emit(" {:vif/%2u} {:threshold/%6u} {:route/%-15.15s}",
/* opposite math of add_vif() */
vifi, v->v_threshold,
routename(v->v_lcl_addr.s_addr));
- printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ?
+ xo_emit(" {:source/%-15.15s}", (v->v_flags & VIFF_TUNNEL) ?
routename(v->v_rmt_addr.s_addr) : "");
- printf(" %9lu %9lu\n", v->v_pkt_in, v->v_pkt_out);
+ xo_emit(" {:received-packets/%9lu} {:sent-packets/%9lu}\n",
+ v->v_pkt_in, v->v_pkt_out);
+ xo_close_instance("vif");
}
- if (!banner_printed)
- printf("\nIPv4 Virtual Interface Table is empty\n");
+ if (banner_printed)
+ xo_close_list("vif");
+ else
+ xo_emit("\n{T:IPv4 Virtual Interface Table is empty}\n");
banner_printed = 0;
@@ -302,19 +328,19 @@ mroutepr()
len = 0;
if (sysctlbyname("net.inet.ip.mfctable", NULL, &len, NULL,
0) < 0) {
- warn("sysctl: net.inet.ip.mfctable");
+ xo_warn("sysctl: net.inet.ip.mfctable");
return;
}
mfctable = malloc(len);
if (mfctable == NULL) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return;
}
if (sysctlbyname("net.inet.ip.mfctable", mfctable, &len, NULL,
0) < 0) {
free(mfctable);
- warn("sysctl: net.inet.ip.mfctable");
+ xo_warn("sysctl: net.inet.ip.mfctable");
return;
}
@@ -323,8 +349,10 @@ mroutepr()
print_mfc(m++, maxvif, &banner_printed);
len -= sizeof(*m);
}
+ if (banner_printed)
+ xo_close_list("multicast-forwarding-entry");
if (len != 0)
- warnx("print_mfc: %lu trailing bytes", (u_long)len);
+ xo_warnx("print_mfc: %lu trailing bytes", (u_long)len);
free(mfctable);
} else {
@@ -336,14 +364,14 @@ mroutepr()
error = kread(pmfctablesize, (char *)&mfctablesize,
sizeof(u_long));
if (error) {
- warn("kread: mfctablesize");
+ xo_warn("kread: mfctablesize");
return;
}
len = sizeof(*mfchashtbl) * mfctablesize;
mfchashtbl = malloc(len);
if (mfchashtbl == NULL) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return;
}
kread(pmfchashtbl, (char *)&mfchashtbl, len);
@@ -354,14 +382,16 @@ mroutepr()
print_mfc(m, maxvif, &banner_printed);
}
}
+ if (banner_printed)
+ xo_close_list("multicast-forwarding-entry");
free(mfchashtbl);
}
if (!banner_printed)
- printf("\nIPv4 Multicast Forwarding Table is empty\n");
+ xo_emit("\n{T:IPv4 Multicast Forwarding Table is empty}\n");
- printf("\n");
+ xo_emit("\n");
numeric_addr = saved_numeric_addr;
}
@@ -383,33 +413,48 @@ mrt_stats()
if (live) {
if (sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, NULL,
0) < 0) {
- warn("sysctl: net.inet.ip.mrtstat failed.");
+ xo_warn("sysctl: net.inet.ip.mrtstat failed.");
return;
}
} else
kread_counters(mstaddr, &mrtstat, len);
- printf("IPv4 multicast forwarding:\n");
+ xo_emit("{T:IPv4 multicast forwarding}:\n");
#define p(f, m) if (mrtstat.f || sflag <= 1) \
- printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f))
+ xo_emit(m, (uintmax_t)mrtstat.f, plural(mrtstat.f))
#define p2(f, m) if (mrtstat.f || sflag <= 1) \
- printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f))
-
- p(mrts_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n");
- p2(mrts_mfc_misses, "\t%ju multicast forwarding cache miss%s\n");
- p(mrts_upcalls, "\t%ju upcall%s to multicast routing daemon\n");
- p(mrts_upq_ovflw, "\t%ju upcall queue overflow%s\n");
+ xo_emit(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f))
+
+ xo_open_container("multicast-statistics");
+
+ p(mrts_mfc_lookups, "\t{:cache-lookups/%ju} "
+ "{N:/multicast forwarding cache lookup%s}\n");
+ p2(mrts_mfc_misses, "\t{:cache-misses/%ju} "
+ "{N:/multicast forwarding cache miss%s}\n");
+ p(mrts_upcalls, "\t{:upcalls-total/%ju} "
+ "{N:/upcall%s to multicast routing daemon}\n");
+ p(mrts_upq_ovflw, "\t{:upcall-overflows/%ju} "
+ "{N:/upcall queue overflow%s}\n");
p(mrts_upq_sockfull,
- "\t%ju upcall%s dropped due to full socket buffer\n");
- p(mrts_cache_cleanups, "\t%ju cache cleanup%s\n");
- p(mrts_no_route, "\t%ju datagram%s with no route for origin\n");
- p(mrts_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n");
- p(mrts_cant_tunnel, "\t%ju datagram%s could not be tunneled\n");
- p(mrts_wrong_if, "\t%ju datagram%s arrived on wrong interface\n");
- p(mrts_drop_sel, "\t%ju datagram%s selectively dropped\n");
- p(mrts_q_overflow, "\t%ju datagram%s dropped due to queue overflow\n");
- p(mrts_pkt2large, "\t%ju datagram%s dropped for being too large\n");
+ "\t{:upcalls-dropped-full-buffer/%ju} "
+ "{N:/upcall%s dropped due to full socket buffer}\n");
+ p(mrts_cache_cleanups, "\t{:cache-cleanups/%ju} "
+ "{N:/cache cleanup%s}\n");
+ p(mrts_no_route, "\t{:dropped-no-origin/%ju} "
+ "{N:/datagram%s with no route for origin}\n");
+ p(mrts_bad_tunnel, "\t{:dropped-bad-tunnel/%ju} "
+ "{N:/datagram%s arrived with bad tunneling}\n");
+ p(mrts_cant_tunnel, "\t{:dropped-could-not-tunnel/%ju} "
+ "{N:/datagram%s could not be tunneled}\n");
+ p(mrts_wrong_if, "\t{:dropped-wrong-incoming-interface/%ju} "
+ "{N:/datagram%s arrived on wrong interface}\n");
+ p(mrts_drop_sel, "\t{:dropped-selectively/%ju} "
+ "{N:/datagram%s selectively dropped}\n");
+ p(mrts_q_overflow, "\t{:dropped-queue-overflow/%ju} "
+ "{N:/datagram%s dropped due to queue overflow}\n");
+ p(mrts_pkt2large, "\t{:dropped-too-large/%ju} "
+ "{N:/datagram%s dropped for being too large}\n");
#undef p2
#undef p
diff --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c
index ac31f5e..d9c127a 100644
--- a/usr.bin/netstat/mroute6.c
+++ b/usr.bin/netstat/mroute6.c
@@ -79,16 +79,16 @@ __FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/route.h>
#include <netinet/in.h>
#include <err.h>
-#include <nlist.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
+#include <libxo/xo.h>
#define KERNEL 1
#include <netinet6/ip6_mroute.h>
@@ -96,20 +96,6 @@ __FBSDID("$FreeBSD$");
#include "netstat.h"
-/*
- * kvm(3) bindings for every needed symbol
- */
-static struct nlist mrl[] = {
-#define N_MF6CTABLE 0
- { .n_name = "_mf6ctable" },
-#define N_MIF6TABLE 1
- { .n_name = "_mif6table" },
-#define N_MRT6STAT 2
- { .n_name = "_mrt6stat" },
- { .n_name = NULL },
-};
-
-
#define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */
#define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */
@@ -117,11 +103,10 @@ void
mroute6pr()
{
struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
- struct mif6 mif6table[MAXMIFS];
+ struct mif6_sctl mif6table[MAXMIFS];
struct mf6c mfc;
struct rtdetq rte, *rtep;
- struct mif6 *mifp;
- u_long mfcaddr, mifaddr;
+ struct mif6_sctl *mifp;
mifi_t mifi;
int i;
int banner_printed;
@@ -130,67 +115,56 @@ mroute6pr()
long int waitings;
size_t len;
- kresolve_list(mrl);
- mfcaddr = mrl[N_MF6CTABLE].n_value;
- mifaddr = mrl[N_MIF6TABLE].n_value;
-
- if (mfcaddr == 0 || mifaddr == 0) {
- fprintf(stderr, "No IPv6 MROUTING kernel support.\n");
+ if (live == 0)
return;
- }
len = sizeof(mif6table);
- if (live) {
- if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len,
- NULL, 0) < 0) {
- warn("sysctl: net.inet6.ip6.mif6table");
- return;
- }
- } else
- kread(mifaddr, (char *)mif6table, sizeof(mif6table));
+ if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, NULL, 0) <
+ 0) {
+ xo_warn("sysctl: net.inet6.ip6.mif6table");
+ return;
+ }
saved_numeric_addr = numeric_addr;
numeric_addr = 1;
banner_printed = 0;
for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
- struct ifnet ifnet;
char ifname[IFNAMSIZ];
- if (mifp->m6_ifp == NULL)
+ if (mifp->m6_ifp == 0)
continue;
- /* XXX KVM */
- kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
-
maxmif = mifi;
if (!banner_printed) {
- printf("\nIPv6 Multicast Interface Table\n"
- " Mif Rate PhyIF "
- "Pkts-In Pkts-Out\n");
+ xo_open_list("multicast-interface");
+ xo_emit("\n{T:IPv6 Multicast Interface Table}\n"
+ "{T: Mif Rate PhyIF Pkts-In Pkts-Out}\n");
banner_printed = 1;
}
- printf(" %2u %4d",
- mifi, mifp->m6_rate_limit);
- printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ?
- "reg0" : if_indextoname(ifnet.if_index, ifname));
+ xo_open_instance("multicast-interface");
+ xo_emit(" {:mif/%2u} {:rate-limit/%4d}",
+ mifi, mifp->m6_rate_limit);
+ xo_emit(" {:ifname/%5s}", (mifp->m6_flags & MIFF_REGISTER) ?
+ "reg0" : if_indextoname(mifp->m6_ifp, ifname));
- printf(" %9ju %9ju\n", (uintmax_t)mifp->m6_pkt_in,
+ xo_emit(" {:received-packets/%9ju} {:sent-packets/%9ju}\n",
+ (uintmax_t)mifp->m6_pkt_in,
(uintmax_t)mifp->m6_pkt_out);
+ xo_close_instance("multicast-interface");
}
- if (!banner_printed)
- printf("\nIPv6 Multicast Interface Table is empty\n");
+ if (banner_printed)
+ xo_open_list("multicast-interface");
+ else
+ xo_emit("\n{T:IPv6 Multicast Interface Table is empty}\n");
len = sizeof(mf6ctable);
- if (live) {
- if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len,
- NULL, 0) < 0) {
- warn("sysctl: net.inet6.ip6.mf6ctable");
- return;
- }
- } else
- kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable));
+ if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, NULL, 0) <
+ 0) {
+ xo_warn("sysctl: net.inet6.ip6.mf6ctable");
+ return;
+ }
banner_printed = 0;
@@ -199,19 +173,24 @@ mroute6pr()
while(mfcp) {
kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
if (!banner_printed) {
- printf ("\nIPv6 Multicast Forwarding Cache\n");
- printf(" %-*.*s %-*.*s %s",
- WID_ORG, WID_ORG, "Origin",
- WID_GRP, WID_GRP, "Group",
- " Packets Waits In-Mif Out-Mifs\n");
+ xo_open_list("multicast-forwarding-cache");
+ xo_emit("\n"
+ "{T:IPv6 Multicast Forwarding Cache}\n");
+ xo_emit(" {T:%-*.*s} {T:%-*.*s} {T:%s}",
+ WID_ORG, WID_ORG, "Origin",
+ WID_GRP, WID_GRP, "Group",
+ " Packets Waits In-Mif Out-Mifs\n");
banner_printed = 1;
}
- printf(" %-*.*s", WID_ORG, WID_ORG,
- routename6(&mfc.mf6c_origin));
- printf(" %-*.*s", WID_GRP, WID_GRP,
- routename6(&mfc.mf6c_mcastgrp));
- printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt);
+ xo_open_instance("multicast-forwarding-cache");
+
+ xo_emit(" {:origin/%-*.*s}", WID_ORG, WID_ORG,
+ routename6(&mfc.mf6c_origin));
+ xo_emit(" {:group/%-*.*s}", WID_GRP, WID_GRP,
+ routename6(&mfc.mf6c_mcastgrp));
+ xo_emit(" {:total-packets/%9ju}",
+ (uintmax_t)mfc.mf6c_pkt_cnt);
for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
waitings++;
@@ -219,25 +198,30 @@ mroute6pr()
kread((u_long)rtep, (char *)&rte, sizeof(rte));
rtep = rte.next;
}
- printf(" %3ld", waitings);
+ xo_emit(" {:waitings/%3ld}", waitings);
if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
- printf(" --- ");
+ xo_emit(" --- ");
else
- printf(" %3d ", mfc.mf6c_parent);
+ xo_emit(" {:parent/%3d} ", mfc.mf6c_parent);
+ xo_open_list("mif");
for (mifi = 0; mifi <= maxmif; mifi++) {
if (IF_ISSET(mifi, &mfc.mf6c_ifset))
- printf(" %u", mifi);
+ xo_emit(" {l:%u}", mifi);
}
- printf("\n");
+ xo_close_list("mif");
+ xo_emit("\n");
mfcp = mfc.mf6c_next;
+ xo_close_instance("multicast-forwarding-cache");
}
}
- if (!banner_printed)
- printf("\nIPv6 Multicast Forwarding Table is empty\n");
+ if (banner_printed)
+ xo_close_list("multicast-forwarding-cache");
+ else
+ xo_emit("\n{T:IPv6 Multicast Forwarding Table is empty}\n");
- printf("\n");
+ xo_emit("\n");
numeric_addr = saved_numeric_addr;
}
@@ -245,50 +229,51 @@ void
mrt6_stats()
{
struct mrt6stat mrtstat;
- u_long mstaddr;
size_t len = sizeof mrtstat;
- kresolve_list(mrl);
- mstaddr = mrl[N_MRT6STAT].n_value;
-
- if (mstaddr == 0) {
- fprintf(stderr, "No IPv6 MROUTING kernel support.\n");
+ if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, NULL, 0) <
+ 0) {
+ xo_warn("sysctl: net.inet6.ip6.mrt6stat");
return;
}
- if (live) {
- if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len,
- NULL, 0) < 0) {
- warn("sysctl: net.inet6.ip6.mrt6stat");
- return;
- }
- } else
- kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
-
- printf("IPv6 multicast forwarding:\n");
+ xo_open_container("multicast-statistics");
+ xo_emit("{T:IPv6 multicast forwarding}:\n");
#define p(f, m) if (mrtstat.f || sflag <= 1) \
- printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f))
+ xo_emit(m, (uintmax_t)mrtstat.f, plural(mrtstat.f))
#define p2(f, m) if (mrtstat.f || sflag <= 1) \
- printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f))
-
- p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n");
- p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n");
- p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n");
- p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n");
- p(mrt6s_upq_sockfull,
- "\t%ju upcall%s dropped due to full socket buffer\n");
- p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n");
- p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n");
- p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n");
- p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n");
- p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n");
- p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n");
- p(mrt6s_q_overflow,
- "\t%ju datagram%s dropped due to queue overflow\n");
- p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n");
+ xo_emit(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f))
+
+ p(mrt6s_mfc_lookups, "\t{:cache-lookups/%ju} "
+ "{N:/multicast forwarding cache lookup%s}\n");
+ p2(mrt6s_mfc_misses, "\t{:cache-misses/%ju} "
+ "{N:/multicast forwarding cache miss%s}\n");
+ p(mrt6s_upcalls, "\t{:upcalls/%ju} "
+ "{N:/upcall%s to multicast routing daemon}\n");
+ p(mrt6s_upq_ovflw, "\t{:upcall-overflows/%ju} "
+ "{N:/upcall queue overflow%s}\n");
+ p(mrt6s_upq_sockfull, "\t{:upcalls-dropped-full-buffer/%ju} "
+ "{N:/upcall%s dropped due to full socket buffer}\n");
+ p(mrt6s_cache_cleanups, "\t{:cache-cleanups/%ju} "
+ "{N:/cache cleanup%s}\n");
+ p(mrt6s_no_route, "\t{:dropped-no-origin/%ju} "
+ "{N:/datagram%s with no route for origin}\n");
+ p(mrt6s_bad_tunnel, "\t{:dropped-bad-tunnel/%ju} "
+ "{N:/datagram%s arrived with bad tunneling}\n");
+ p(mrt6s_cant_tunnel, "\t{:dropped-could-not-tunnel/%ju} "
+ "{N:/datagram%s could not be tunneled}\n");
+ p(mrt6s_wrong_if, "\t{:dropped-wrong-incoming-interface/%ju} "
+ "{N:/datagram%s arrived on wrong interface}\n");
+ p(mrt6s_drop_sel, "\t{:dropped-selectively/%ju} "
+ "{N:/datagram%s selectively dropped}\n");
+ p(mrt6s_q_overflow, "\t{:dropped-queue-overflow/%ju} "
+ "{N:/datagram%s dropped due to queue overflow}\n");
+ p(mrt6s_pkt2large, "\t{:dropped-too-large/%ju} "
+ "{N:/datagram%s dropped for being too large}\n");
#undef p2
#undef p
+ xo_close_container("multicast-statistics");
}
#endif /*INET6*/
diff --git a/usr.bin/netstat/netgraph.c b/usr.bin/netstat/netgraph.c
index 95578af..e28de2c 100644
--- a/usr.bin/netstat/netgraph.c
+++ b/usr.bin/netstat/netgraph.c
@@ -53,9 +53,11 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
+#include <libxo/xo.h>
#include "netstat.h"
static int first = 1;
@@ -73,8 +75,7 @@ netgraphprotopr(u_long off, const char *name, int af1 __unused,
/* If symbol not found, try looking in the KLD module */
if (off == 0) {
if (debug)
- fprintf(stderr,
- "Error reading symbols from ng_socket.ko");
+ xo_warnx("Error reading symbols from ng_socket.ko");
return;
}
@@ -106,20 +107,22 @@ netgraphprotopr(u_long off, const char *name, int af1 __unused,
/* Do headline */
if (first) {
- printf("Netgraph sockets\n");
+ xo_emit("{T:Netgraph sockets}\n");
if (Aflag)
- printf("%-8.8s ", "PCB");
- printf("%-5.5s %-6.6s %-6.6s %-14.14s %s\n",
- "Type", "Recv-Q", "Send-Q",
- "Node Address", "#Hooks");
+ xo_emit("{T:/%-8.8s} ", "PCB");
+ xo_emit("{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} "
+ "{T:/%-14.14s} {T:/%s}\n",
+ "Type", "Recv-Q", "Send-Q", "Node Address",
+ "#Hooks");
first = 0;
}
/* Show socket */
if (Aflag)
- printf("%8lx ", (u_long) this);
- printf("%-5.5s %6u %6u ",
- name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
+ xo_emit("{:address/%8lx} ", (u_long) this);
+ xo_emit("{t:name/%-5.5s} {:receive-bytes-waiting/%6u} "
+ "{:send-byte-waiting/%6u} ",
+ name, sockb.so_rcv.sb_ccc, sockb.so_snd.sb_ccc);
/* Get info on associated node */
if (ngpcb.node_id == 0 || csock == -1)
@@ -134,9 +137,9 @@ netgraphprotopr(u_long off, const char *name, int af1 __unused,
/* Display associated node info */
if (*ni->name != '\0')
snprintf(path, sizeof(path), "%s:", ni->name);
- printf("%-14.14s %4d", path, ni->hooks);
+ xo_emit("{t:path/%-14.14s} {:hooks/%4d}", path, ni->hooks);
finish:
- putchar('\n');
+ xo_emit("\n");
}
}
diff --git a/usr.bin/netstat/netisr.c b/usr.bin/netstat/netisr.c
index 6c945c3..8f6fe3d 100644
--- a/usr.bin/netstat/netisr.c
+++ b/usr.bin/netstat/netisr.c
@@ -46,8 +46,9 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
-
+#include <libxo/xo.h>
#include "netstat.h"
/*
@@ -112,13 +113,13 @@ netisr_load_kvm_uint(kvm_t *kd, const char *name, u_int *p)
ret = kvm_nlist(kd, nl);
if (ret < 0)
- errx(-1, "%s: kvm_nlist(%s): %s", __func__, name,
+ xo_errx(-1, "%s: kvm_nlist(%s): %s", __func__, name,
kvm_geterr(kd));
if (ret != 0)
- errx(-1, "%s: kvm_nlist(%s): unresolved symbol", __func__,
+ xo_errx(-1, "%s: kvm_nlist(%s): unresolved symbol", __func__,
name);
if (kvm_read(kd, nl[0].n_value, p, sizeof(*p)) != sizeof(*p))
- errx(-1, "%s: kvm_read(%s): %s", __func__, name,
+ xo_errx(-1, "%s: kvm_read(%s): %s", __func__, name,
kvm_geterr(kd));
}
@@ -134,7 +135,7 @@ netisr_load_kvm_string(kvm_t *kd, uintptr_t addr, char *dest, u_int limit)
for (i = 0; i < limit; i++) {
if (kvm_read(kd, addr + i, &dest[i], sizeof(dest[i])) !=
sizeof(dest[i]))
- err(-1, "%s: kvm_read: %s", __func__,
+ xo_err(-1, "%s: kvm_read: %s", __func__,
kvm_geterr(kd));
if (dest[i] == '\0')
break;
@@ -190,9 +191,9 @@ netisr_load_sysctl_uint(const char *name, u_int *p)
retlen = sizeof(u_int);
if (sysctlbyname(name, p, &retlen, NULL, 0) < 0)
- err(-1, "%s", name);
+ xo_err(-1, "%s", name);
if (retlen != sizeof(u_int))
- errx(-1, "%s: invalid len %ju", name, (uintmax_t)retlen);
+ xo_errx(-1, "%s: invalid len %ju", name, (uintmax_t)retlen);
}
static void
@@ -202,7 +203,7 @@ netisr_load_sysctl_string(const char *name, char *p, size_t len)
retlen = len;
if (sysctlbyname(name, p, &retlen, NULL, 0) < 0)
- err(-1, "%s", name);
+ xo_err(-1, "%s", name);
p[len - 1] = '\0';
}
@@ -241,21 +242,21 @@ netisr_load_kvm_proto(kvm_t *kd)
*/
netisr_load_kvm_uint(kd, "_netisr_maxprot", &maxprot);
if (maxprot != NETISR_MAXPROT)
- errx(-1, "%s: NETISR_MAXPROT mismatch", __func__);
+ xo_errx(-1, "%s: NETISR_MAXPROT mismatch", __func__);
len = maxprot * sizeof(*np_array);
np_array = malloc(len);
if (np_array == NULL)
- err(-1, "%s: malloc", __func__);
+ xo_err(-1, "%s: malloc", __func__);
ret = kvm_nlist(kd, nl);
if (ret < 0)
- errx(-1, "%s: kvm_nlist(_netisr_proto): %s", __func__,
+ xo_errx(-1, "%s: kvm_nlist(_netisr_proto): %s", __func__,
kvm_geterr(kd));
if (ret != 0)
- errx(-1, "%s: kvm_nlist(_netisr_proto): unresolved symbol",
+ xo_errx(-1, "%s: kvm_nlist(_netisr_proto): unresolved symbol",
__func__);
if (kvm_read(kd, nl[NLIST_NETISR_PROTO].n_value, np_array, len) !=
(ssize_t)len)
- errx(-1, "%s: kvm_read(_netisr_proto): %s", __func__,
+ xo_errx(-1, "%s: kvm_read(_netisr_proto): %s", __func__,
kvm_geterr(kd));
/*
@@ -301,21 +302,21 @@ netisr_load_sysctl_proto(void)
size_t len;
if (sysctlbyname("net.isr.proto", NULL, &len, NULL, 0) < 0)
- err(-1, "net.isr.proto: query len");
+ xo_err(-1, "net.isr.proto: query len");
if (len % sizeof(*proto_array) != 0)
- errx(-1, "net.isr.proto: invalid len");
+ xo_errx(-1, "net.isr.proto: invalid len");
proto_array = malloc(len);
if (proto_array == NULL)
- err(-1, "malloc");
+ xo_err(-1, "malloc");
if (sysctlbyname("net.isr.proto", proto_array, &len, NULL, 0) < 0)
- err(-1, "net.isr.proto: query data");
+ xo_err(-1, "net.isr.proto: query data");
if (len % sizeof(*proto_array) != 0)
- errx(-1, "net.isr.proto: invalid len");
+ xo_errx(-1, "net.isr.proto: invalid len");
proto_array_len = len / sizeof(*proto_array);
if (proto_array_len < 1)
- errx(-1, "net.isr.proto: no data");
+ xo_errx(-1, "net.isr.proto: no data");
if (proto_array[0].snp_version != sizeof(proto_array[0]))
- errx(-1, "net.isr.proto: invalid version");
+ xo_errx(-1, "net.isr.proto: invalid version");
}
static void
@@ -338,41 +339,41 @@ netisr_load_kvm_workstream(kvm_t *kd)
len = numthreads * sizeof(*nws_array);
nws_array = malloc(len);
if (nws_array == NULL)
- err(-1, "malloc");
+ xo_err(-1, "malloc");
ret = kvm_nlist(kd, nl);
if (ret < 0)
- errx(-1, "%s: kvm_nlist: %s", __func__, kvm_geterr(kd));
+ xo_errx(-1, "%s: kvm_nlist: %s", __func__, kvm_geterr(kd));
if (ret != 0)
- errx(-1, "%s: kvm_nlist: unresolved symbol", __func__);
+ xo_errx(-1, "%s: kvm_nlist: unresolved symbol", __func__);
if (kvm_read(kd, nl[NLIST_NWS_ARRAY].n_value, nws_array, len) !=
(ssize_t)len)
- errx(-1, "%s: kvm_read(_nws_array): %s", __func__,
+ xo_errx(-1, "%s: kvm_read(_nws_array): %s", __func__,
kvm_geterr(kd));
workstream_array = calloc(numthreads, sizeof(*workstream_array));
if (workstream_array == NULL)
- err(-1, "calloc");
+ xo_err(-1, "calloc");
workstream_array_len = numthreads;
work_array = calloc(numthreads * proto_array_len, sizeof(*work_array));
if (work_array == NULL)
- err(-1, "calloc");
+ xo_err(-1, "calloc");
counter = 0;
for (wsid = 0; wsid < numthreads; wsid++) {
cpuid = nws_array[wsid];
if (kvm_dpcpu_setcpu(kd, cpuid) < 0)
- errx(-1, "%s: kvm_dpcpu_setcpu(%u): %s", __func__,
+ xo_errx(-1, "%s: kvm_dpcpu_setcpu(%u): %s", __func__,
cpuid, kvm_geterr(kd));
bzero(nl_nws, sizeof(nl_nws));
nl_nws[0].n_name = "_nws";
ret = kvm_nlist(kd, nl_nws);
if (ret < 0)
- errx(-1, "%s: kvm_nlist looking up nws on CPU %u: %s",
- __func__, cpuid, kvm_geterr(kd));
+ xo_errx(-1, "%s: kvm_nlist looking up nws on CPU "
+ "%u: %s", __func__, cpuid, kvm_geterr(kd));
if (ret != 0)
- errx(-1, "%s: kvm_nlist(nws): unresolved symbol on "
+ xo_errx(-1, "%s: kvm_nlist(nws): unresolved symbol on "
"CPU %u", __func__, cpuid);
if (kvm_read(kd, nl_nws[0].n_value, &nws, sizeof(nws)) !=
sizeof(nws))
- errx(-1, "%s: kvm_read(nw): %s", __func__,
+ xo_errx(-1, "%s: kvm_read(nw): %s", __func__,
kvm_geterr(kd));
snwsp = &workstream_array[wsid];
snwsp->snws_version = sizeof(*snwsp);
@@ -384,7 +385,7 @@ netisr_load_kvm_workstream(kvm_t *kd)
/*
* Extract the CPU's per-protocol work information.
*/
- printf("counting to maxprot: %u\n", maxprot);
+ xo_emit("counting to maxprot: {:maxprot/%u}\n", maxprot);
for (proto = 0; proto < maxprot; proto++) {
if (!netisr_protoispresent(proto))
continue;
@@ -413,22 +414,22 @@ netisr_load_sysctl_workstream(void)
size_t len;
if (sysctlbyname("net.isr.workstream", NULL, &len, NULL, 0) < 0)
- err(-1, "net.isr.workstream: query len");
+ xo_err(-1, "net.isr.workstream: query len");
if (len % sizeof(*workstream_array) != 0)
- errx(-1, "net.isr.workstream: invalid len");
+ xo_errx(-1, "net.isr.workstream: invalid len");
workstream_array = malloc(len);
if (workstream_array == NULL)
- err(-1, "malloc");
+ xo_err(-1, "malloc");
if (sysctlbyname("net.isr.workstream", workstream_array, &len, NULL,
0) < 0)
- err(-1, "net.isr.workstream: query data");
+ xo_err(-1, "net.isr.workstream: query data");
if (len % sizeof(*workstream_array) != 0)
- errx(-1, "net.isr.workstream: invalid len");
+ xo_errx(-1, "net.isr.workstream: invalid len");
workstream_array_len = len / sizeof(*workstream_array);
if (workstream_array_len < 1)
- errx(-1, "net.isr.workstream: no data");
+ xo_errx(-1, "net.isr.workstream: no data");
if (workstream_array[0].snws_version != sizeof(workstream_array[0]))
- errx(-1, "net.isr.workstream: invalid version");
+ xo_errx(-1, "net.isr.workstream: invalid version");
}
static void
@@ -437,21 +438,21 @@ netisr_load_sysctl_work(void)
size_t len;
if (sysctlbyname("net.isr.work", NULL, &len, NULL, 0) < 0)
- err(-1, "net.isr.work: query len");
+ xo_err(-1, "net.isr.work: query len");
if (len % sizeof(*work_array) != 0)
- errx(-1, "net.isr.work: invalid len");
+ xo_errx(-1, "net.isr.work: invalid len");
work_array = malloc(len);
if (work_array == NULL)
- err(-1, "malloc");
+ xo_err(-1, "malloc");
if (sysctlbyname("net.isr.work", work_array, &len, NULL, 0) < 0)
- err(-1, "net.isr.work: query data");
+ xo_err(-1, "net.isr.work: query data");
if (len % sizeof(*work_array) != 0)
- errx(-1, "net.isr.work: invalid len");
+ xo_errx(-1, "net.isr.work: invalid len");
work_array_len = len / sizeof(*work_array);
if (work_array_len < 1)
- errx(-1, "net.isr.work: no data");
+ xo_errx(-1, "net.isr.work: no data");
if (work_array[0].snw_version != sizeof(work_array[0]))
- errx(-1, "net.isr.work: invalid version");
+ xo_errx(-1, "net.isr.work: invalid version");
}
static void
@@ -459,17 +460,17 @@ netisr_print_proto(struct sysctl_netisr_proto *snpp)
{
char tmp[20];
- printf("%-6s", snpp->snp_name);
- printf(" %5u", snpp->snp_proto);
- printf(" %6u", snpp->snp_qlimit);
- printf(" %6s",
+ xo_emit("{[:-6}{k:name/%s}{]:}", snpp->snp_name);
+ xo_emit(" {:protocol/%5u}", snpp->snp_proto);
+ xo_emit(" {:queue-limit/%6u}", snpp->snp_qlimit);
+ xo_emit(" {:policy-type/%6s}",
(snpp->snp_policy == NETISR_POLICY_SOURCE) ? "source" :
(snpp->snp_policy == NETISR_POLICY_FLOW) ? "flow" :
(snpp->snp_policy == NETISR_POLICY_CPU) ? "cpu" : "-");
netisr_dispatch_policy_to_string(snpp->snp_dispatch, tmp,
sizeof(tmp));
- printf(" %8s", tmp);
- printf(" %s%s%s\n",
+ xo_emit(" {:policy/%8s}", tmp);
+ xo_emit(" {:flags/%s%s%s}\n",
(snpp->snp_flags & NETISR_SNP_FLAGS_M2CPUID) ? "C" : "-",
(snpp->snp_flags & NETISR_SNP_FLAGS_DRAINEDCPU) ? "D" : "-",
(snpp->snp_flags & NETISR_SNP_FLAGS_M2FLOW) ? "F" : "-");
@@ -481,23 +482,28 @@ netisr_print_workstream(struct sysctl_netisr_workstream *snwsp)
struct sysctl_netisr_work *snwp;
u_int i;
+ xo_open_list("work");
for (i = 0; i < work_array_len; i++) {
snwp = &work_array[i];
if (snwp->snw_wsid != snwsp->snws_wsid)
continue;
- printf("%4u ", snwsp->snws_wsid);
- printf("%3u ", snwsp->snws_cpu);
- printf("%2s", "");
- printf("%-6s", netisr_proto2name(snwp->snw_proto));
- printf(" %5u", snwp->snw_len);
- printf(" %5u", snwp->snw_watermark);
- printf(" %8ju", snwp->snw_dispatched);
- printf(" %8ju", snwp->snw_hybrid_dispatched);
- printf(" %8ju", snwp->snw_qdrops);
- printf(" %8ju", snwp->snw_queued);
- printf(" %8ju", snwp->snw_handled);
- printf("\n");
+ xo_open_instance("work");
+ xo_emit("{t:workstream/%4u} ", snwsp->snws_wsid);
+ xo_emit("{t:cpu/%3u} ", snwsp->snws_cpu);
+ xo_emit("{P: }");
+ xo_emit("{t:name/%-6s}", netisr_proto2name(snwp->snw_proto));
+ xo_emit(" {t:length/%5u}", snwp->snw_len);
+ xo_emit(" {t:watermark/%5u}", snwp->snw_watermark);
+ xo_emit(" {t:dispatched/%8ju}", snwp->snw_dispatched);
+ xo_emit(" {t:hybrid-dispatched/%8ju}",
+ snwp->snw_hybrid_dispatched);
+ xo_emit(" {t:queue-drops/%8ju}", snwp->snw_qdrops);
+ xo_emit(" {t:queued/%8ju}", snwp->snw_queued);
+ xo_emit(" {t:handled/%8ju}", snwp->snw_handled);
+ xo_emit("\n");
+ xo_close_instance("work");
}
+ xo_close_list("work");
}
void
@@ -515,39 +521,55 @@ netisr_stats(void *kvmd)
netisr_load_sysctl_work();
} else {
if (kd == NULL)
- errx(-1, "netisr_stats: !live but !kd");
+ xo_errx(-1, "netisr_stats: !live but !kd");
netisr_load_kvm_config(kd);
netisr_load_kvm_proto(kd);
netisr_load_kvm_workstream(kd); /* Also does work. */
}
- printf("Configuration:\n");
- printf("%-25s %12s %12s\n", "Setting", "Current", "Limit");
- printf("%-25s %12u %12u\n", "Thread count", numthreads, maxthreads);
- printf("%-25s %12u %12u\n", "Default queue limit", defaultqlimit,
- maxqlimit);
- printf("%-25s %12s %12s\n", "Dispatch policy", dispatch_policy,
+ xo_open_container("netisr");
+
+ xo_emit("{T:Configuration}:\n");
+ xo_emit("{T:/%-25s} {T:/%12s} {T:/%12s}\n",
+ "Setting", "Current", "Limit");
+ xo_emit("{T:/%-25s} {T:/%12u} {T:/%12u}\n",
+ "Thread count", numthreads, maxthreads);
+ xo_emit("{T:/%-25s} {T:/%12u} {T:/%12u}\n",
+ "Default queue limit", defaultqlimit, maxqlimit);
+ xo_emit("{T:/%-25s} {T:/%12s} {T:/%12s}\n",
+ "Dispatch policy", dispatch_policy, "n/a");
+ xo_emit("{T:/%-25s} {T:/%12s} {T:/%12s}\n",
+ "Threads bound to CPUs", bindthreads ? "enabled" : "disabled",
"n/a");
- printf("%-25s %12s %12s\n", "Threads bound to CPUs",
- bindthreads ? "enabled" : "disabled", "n/a");
- printf("\n");
+ xo_emit("\n");
- printf("Protocols:\n");
- printf("%-6s %5s %6s %-6s %-8s %-5s\n", "Name", "Proto", "QLimit",
- "Policy", "Dispatch", "Flags");
+ xo_emit("{T:Protocols}:\n");
+ xo_emit("{T:/%-6s} {T:/%5s} {T:/%6s} {T:/%-6s} {T:/%-8s} {T:/%-5s}\n",
+ "Name", "Proto", "QLimit", "Policy", "Dispatch", "Flags");
+ xo_open_list("protocol");
for (i = 0; i < proto_array_len; i++) {
+ xo_open_instance("protocol");
snpp = &proto_array[i];
netisr_print_proto(snpp);
+ xo_close_instance("protocol");
}
- printf("\n");
-
- printf("Workstreams:\n");
- printf("%4s %3s ", "WSID", "CPU");
- printf("%2s", "");
- printf("%-6s %5s %5s %8s %8s %8s %8s %8s\n", "Name", "Len", "WMark",
- "Disp'd", "HDisp'd", "QDrops", "Queued", "Handled");
+ xo_close_list("protocol");
+ xo_emit("\n");
+
+ xo_emit("{T:Workstreams}:\n");
+ xo_emit("{T:/%4s} {T:/%3s} ", "WSID", "CPU");
+ xo_emit("{P:/%2s}", "");
+ xo_emit("{T:/%-6s} {T:/%5s} {T:/%5s} {T:/%8s} {T:/%8s} {T:/%8s} "
+ "{T:/%8s} {T:/%8s}\n",
+ "Name", "Len", "WMark", "Disp'd", "HDisp'd", "QDrops", "Queued",
+ "Handled");
+ xo_open_list("workstream");
for (i = 0; i < workstream_array_len; i++) {
+ xo_open_instance("workstream");
snwsp = &workstream_array[i];
netisr_print_workstream(snwsp);
+ xo_close_instance("workstream");
}
+ xo_close_list("workstream");
+ xo_close_container("netisr");
}
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 1f2bb01..c9d3e42 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -28,7 +28,7 @@
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd June 4, 2014
+.Dd April 7, 2015
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -38,58 +38,66 @@
.Bk -words
.Bl -tag -width "netstat"
.It Nm
+.Op Fl -libxo
.Op Fl 46AaLnRSTWx
.Op Fl f Ar protocol_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl i | I Ar interface
+.Op Fl -libxo
.Op Fl 46abdhnW
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl w Ar wait
+.Op Fl -libxo
.Op Fl I Ar interface
.Op Fl 46d
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl q Ar howmany
.It Nm Fl s
+.Op Fl -libxo
.Op Fl 46sz
.Op Fl f Ar protocol_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl i | I Ar interface Fl s
+.Op Fl -libxo
.Op Fl 46s
.Op Fl f Ar protocol_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl m
+.Op Fl -libxo
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl B
+.Op Fl -libxo
.Op Fl z
.Op Fl I Ar interface
.It Nm Fl r
-.Op Fl 46AnW
+.Op Fl -libxo
+.Op Fl 46nW
.Op Fl F Ar fibnum
.Op Fl f Ar address_family
-.Op Fl M Ar core
-.Op Fl N Ar system
.It Nm Fl rs
+.Op Fl -libxo
.Op Fl s
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl g
+.Op Fl -libxo
.Op Fl 46W
.Op Fl f Ar address_family
-.Op Fl M Ar core
-.Op Fl N Ar system
.It Nm Fl gs
+.Op Fl -libxo
.Op Fl 46s
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
.It Nm Fl Q
+.Op Fl -libxo
.El
.Ek
.Sh DESCRIPTION
@@ -571,9 +579,6 @@ See
Show IPv6 only.
See
.Sx GENERAL OPTIONS .
-.It Fl A
-Show the contents of the internal Patricia tree
-structures; used for debugging.
.It Fl n
Do not resolve numeric addresses and port numbers to names.
See
@@ -784,6 +789,8 @@ and display them symbolically.
.Xr procstat 1 ,
.Xr ps 1 ,
.Xr sockstat 1 ,
+.Xr libxo 3 ,
+.Xr xo_parse_args 3 ,
.Xr bpf 4 ,
.Xr inet 4 ,
.Xr route 4 ,
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index cb46c0f..29e4d0f 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -108,7 +108,7 @@ struct in6_addr;
void in6_fillscopeid(struct sockaddr_in6 *);
char *routename6(struct sockaddr_in6 *);
const char *netname6(struct sockaddr_in6 *, struct in6_addr *);
-void inet6print(struct in6_addr *, int, const char *, int);
+void inet6print(const char *, struct in6_addr *, int, const char *, int);
#endif /*INET6*/
#ifdef IPSEC
@@ -143,7 +143,7 @@ void nserr_stats(u_long, const char *, int, int);
void netgraphprotopr(u_long, const char *, int, int);
#endif
-void unixpr(u_long, u_long, u_long, u_long, u_long);
+void unixpr(u_long, u_long, u_long, u_long, u_long, bool *);
void esis_stats(u_long, const char *, int, int);
void clnp_stats(u_long, const char *, int, int);
diff --git a/usr.bin/netstat/pfkey.c b/usr.bin/netstat/pfkey.c
index da81485..fbf330f 100644
--- a/usr.bin/netstat/pfkey.c
+++ b/usr.bin/netstat/pfkey.c
@@ -81,6 +81,8 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdbool.h>
+#include <libxo/xo.h>
#include "netstat.h"
#ifdef IPSEC
@@ -118,59 +120,89 @@ pfkey_stats(u_long off, const char *name, int family __unused,
if (off == 0)
return;
- printf ("%s:\n", name);
+ xo_emit("{T:/%s}:\n", name);
+ xo_open_container(name);
kread_counters(off, (char *)&pfkeystat, sizeof(pfkeystat));
#define p(f, m) if (pfkeystat.f || sflag <= 1) \
- printf(m, (uintmax_t)pfkeystat.f, plural(pfkeystat.f))
+ xo_emit(m, (uintmax_t)pfkeystat.f, plural(pfkeystat.f))
/* userland -> kernel */
- p(out_total, "\t%ju request%s sent from userland\n");
- p(out_bytes, "\t%ju byte%s sent from userland\n");
+ p(out_total, "\t{:sent-requests//%ju} "
+ "{N:/request%s sent from userland}\n");
+ p(out_bytes, "\t{:sent-bytes/%ju} "
+ "{N:/byte%s sent from userland}\n");
for (first = 1, type = 0;
- type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
- type++) {
+ type<sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
+ type++) {
if (pfkeystat.out_msgtype[type] <= 0)
continue;
if (first) {
- printf("\thistogram by message type:\n");
+ xo_open_list("output-histogram");
+ xo_emit("\t{T:histogram by message type}:\n");
first = 0;
}
- printf("\t\t%s: %ju\n", pfkey_msgtype_names(type),
- (uintmax_t)pfkeystat.out_msgtype[type]);
+ xo_open_instance("output-histogram");
+ xo_emit("\t\t{k::type/%s}: {:count/%ju}\n",
+ pfkey_msgtype_names(type),
+ (uintmax_t)pfkeystat.out_msgtype[type]);
+ xo_close_instance("output-histogram");
}
- p(out_invlen, "\t%ju message%s with invalid length field\n");
- p(out_invver, "\t%ju message%s with invalid version field\n");
- p(out_invmsgtype, "\t%ju message%s with invalid message type field\n");
- p(out_tooshort, "\t%ju message%s too short\n");
- p(out_nomem, "\t%ju message%s with memory allocation failure\n");
- p(out_dupext, "\t%ju message%s with duplicate extension\n");
- p(out_invexttype, "\t%ju message%s with invalid extension type\n");
- p(out_invsatype, "\t%ju message%s with invalid sa type\n");
- p(out_invaddr, "\t%ju message%s with invalid address extension\n");
+ if (!first)
+ xo_close_list("output-histogram");
+
+ p(out_invlen, "\t{:dropped-bad-length/%ju} "
+ "{N:/message%s with invalid length field}\n");
+ p(out_invver, "\t{:dropped-bad-version/%ju} "
+ "{N:/message%s with invalid version field}\n");
+ p(out_invmsgtype, "\t{:dropped-bad-type/%ju} "
+ "{N:/message%s with invalid message type field}\n");
+ p(out_tooshort, "\t{:dropped-too-short/%ju} "
+ "{N:/message%s too short}\n");
+ p(out_nomem, "\t{:dropped-no-memory/%ju} "
+ "{N:/message%s with memory allocation failure}\n");
+ p(out_dupext, "\t{:dropped-duplicate-extension/%ju} "
+ "{N:/message%s with duplicate extension}\n");
+ p(out_invexttype, "\t{:dropped-bad-extension/%ju} "
+ "{N:/message%s with invalid extension type}\n");
+ p(out_invsatype, "\t:dropped-bad-sa-type/%ju} "
+ "{N:/message%s with invalid sa type}\n");
+ p(out_invaddr, "\t{:dropped-bad-address-extension/%ju} "
+ "{N:/message%s with invalid address extension}\n");
/* kernel -> userland */
- p(in_total, "\t%ju request%s sent to userland\n");
- p(in_bytes, "\t%ju byte%s sent to userland\n");
+ p(in_total, "\t{:received-requests/%ju} "
+ "{N:/request%s sent to userland}\n");
+ p(in_bytes, "\t{:received-bytes/%ju} "
+ "{N:/byte%s sent to userland}\n");
for (first = 1, type = 0;
- type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
- type++) {
+ type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
+ type++) {
if (pfkeystat.in_msgtype[type] <= 0)
continue;
if (first) {
- printf("\thistogram by message type:\n");
+ xo_open_list("input-histogram");
+ xo_emit("\t{T:histogram by message type}:\n");
first = 0;
}
- printf("\t\t%s: %ju\n", pfkey_msgtype_names(type),
- (uintmax_t)pfkeystat.in_msgtype[type]);
+ xo_open_instance("input-histogram");
+ xo_emit("\t\t{k:type/%s}: {:count/%ju}\n",
+ pfkey_msgtype_names(type),
+ (uintmax_t)pfkeystat.in_msgtype[type]);
+ xo_close_instance("input-histogram");
}
- p(in_msgtarget[KEY_SENDUP_ONE],
- "\t%ju message%s toward single socket\n");
- p(in_msgtarget[KEY_SENDUP_ALL],
- "\t%ju message%s toward all sockets\n");
+ if (!first)
+ xo_close_list("input-histogram");
+ p(in_msgtarget[KEY_SENDUP_ONE], "\t{:received-one-socket/%ju} "
+ "{N:/message%s toward single socket}\n");
+ p(in_msgtarget[KEY_SENDUP_ALL], "\t{:received-all-sockets/%ju} "
+ "{N:/message%s toward all sockets}\n");
p(in_msgtarget[KEY_SENDUP_REGISTERED],
- "\t%ju message%s toward registered sockets\n");
- p(in_nomem, "\t%ju message%s with memory allocation failure\n");
+ "\t{:received-registered-sockets/%ju} "
+ "{N:/message%s toward registered sockets}\n");
+ p(in_nomem, "\t{:discarded-no-memory/%ju} "
+ "{N:/message%s with memory allocation failure}\n");
#undef p
+ xo_close_container(name);
}
#endif /* IPSEC */
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 7555615..ab5a3ed 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -40,22 +40,18 @@ __FBSDID("$FreeBSD$");
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/sysctl.h>
#include <sys/time.h>
#include <net/ethernet.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/if_types.h>
-#include <net/radix.h>
-#define _WANT_RTENTRY
#include <net/route.h>
#include <netinet/in.h>
#include <netgraph/ng_socket.h>
-#include <sys/sysctl.h>
-
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <libutil.h>
@@ -64,39 +60,40 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#include <err.h>
+#include <libxo/xo.h>
#include "netstat.h"
-#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
-
/*
* Definitions for showing gateway flags.
*/
struct bits {
u_long b_mask;
char b_val;
+ const char *b_name;
} bits[] = {
- { RTF_UP, 'U' },
- { RTF_GATEWAY, 'G' },
- { RTF_HOST, 'H' },
- { RTF_REJECT, 'R' },
- { RTF_DYNAMIC, 'D' },
- { RTF_MODIFIED, 'M' },
- { RTF_DONE, 'd' }, /* Completed -- for routing messages only */
- { RTF_XRESOLVE, 'X' },
- { RTF_STATIC, 'S' },
- { RTF_PROTO1, '1' },
- { RTF_PROTO2, '2' },
- { RTF_PROTO3, '3' },
- { RTF_BLACKHOLE,'B' },
- { RTF_BROADCAST,'b' },
+ { RTF_UP, 'U', "up" },
+ { RTF_GATEWAY, 'G', "gateway" },
+ { RTF_HOST, 'H', "host" },
+ { RTF_REJECT, 'R', "reject" },
+ { RTF_DYNAMIC, 'D', "dynamic" },
+ { RTF_MODIFIED, 'M', "modified" },
+ { RTF_DONE, 'd', "done" }, /* Completed -- for routing msgs only */
+ { RTF_XRESOLVE, 'X', "xresolve" },
+ { RTF_STATIC, 'S', "static" },
+ { RTF_PROTO1, '1', "proto1" },
+ { RTF_PROTO2, '2', "proto2" },
+ { RTF_PROTO3, '3', "proto3" },
+ { RTF_BLACKHOLE,'B', "blackhole" },
+ { RTF_BROADCAST,'b', "broadcast" },
#ifdef RTF_LLINFO
- { RTF_LLINFO, 'L' },
+ { RTF_LLINFO, 'L', "llinfo" },
#endif
- { 0 , 0 }
+ { 0 , 0, NULL }
};
/*
@@ -105,9 +102,7 @@ struct bits {
static struct nlist rl[] = {
#define N_RTSTAT 0
{ .n_name = "_rtstat" },
-#define N_RTREE 1
- { .n_name = "_rt_tables"},
-#define N_RTTRASH 2
+#define N_RTTRASH 1
{ .n_name = "_rttrash" },
{ .n_name = NULL },
};
@@ -118,39 +113,21 @@ typedef union {
u_short u_data[128];
} sa_u;
-static sa_u pt_u;
-
struct ifmap_entry {
char ifname[IFNAMSIZ];
};
-
static struct ifmap_entry *ifmap;
static int ifmap_size;
-
-int do_rtent = 0;
-struct rtentry rtentry;
-struct radix_node rnode;
-struct radix_mask rmask;
-
-int NewTree = 1;
-
struct timespec uptime;
-static struct sockaddr *kgetsa(struct sockaddr *);
-static void size_cols(int ef, struct radix_node *rn);
-static void size_cols_tree(struct radix_node *rn);
-static void size_cols_rtentry(struct rtentry *rt);
-static void p_rtnode_kvm(void);
static void p_rtable_sysctl(int, int);
-static void p_rtable_kvm(int, int );
-static void p_rtree_kvm(struct radix_node *);
-static void p_rtentry_sysctl(struct rt_msghdr *);
-static void p_sockaddr(struct sockaddr *, struct sockaddr *, int, int);
+static void p_rtentry_sysctl(const char *name, struct rt_msghdr *);
+static void p_sockaddr(const char *name, struct sockaddr *, struct sockaddr *,
+ int, int);
static const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask,
int flags);
static void p_flags(int, const char *);
static const char *fmt_flags(int f);
-static void p_rtentry_kvm(struct rtentry *);
static void domask(char *, in_addr_t, u_long);
/*
@@ -162,6 +139,9 @@ routepr(int fibnum, int af)
size_t intsize;
int numfibs;
+ if (live == 0)
+ return;
+
intsize = sizeof(int);
if (fibnum == -1 &&
sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1)
@@ -178,15 +158,13 @@ routepr(int fibnum, int af)
if (clock_gettime(CLOCK_UPTIME, &uptime) < 0)
err(EX_OSERR, "clock_gettime() failed");
- printf("Routing tables");
+ xo_open_container("route-information");
+ xo_emit("{T:Routing tables}");
if (fibnum)
- printf(" (fib: %d)", fibnum);
- printf("\n");
-
- if (Aflag == 0 && live != 0 && NewTree)
- p_rtable_sysctl(fibnum, af);
- else
- p_rtable_kvm(fibnum, af);
+ xo_emit(" ({L:fib}: {:fib/%d})", fibnum);
+ xo_emit("\n");
+ p_rtable_sysctl(fibnum, af);
+ xo_close_container("route-information");
}
@@ -221,9 +199,9 @@ pr_family(int af1)
break;
}
if (afname)
- printf("\n%s:\n", afname);
+ xo_emit("\n{k:address-family/%s}:\n", afname);
else
- printf("\nProtocol Family %d:\n", af1);
+ xo_emit("\n{L:Protocol Family} {k:address-family/%d}:\n", af1);
}
/* column widths; each followed by one space */
@@ -247,100 +225,6 @@ static int wid_mtu;
static int wid_if;
static int wid_expire;
-static void
-size_cols(int ef, struct radix_node *rn)
-{
- wid_dst = WID_DST_DEFAULT(ef);
- wid_gw = WID_GW_DEFAULT(ef);
- wid_flags = 6;
- wid_pksent = 8;
- wid_mtu = 6;
- wid_if = WID_IF_DEFAULT(ef);
- wid_expire = 6;
-
- if (Wflag && rn != NULL)
- size_cols_tree(rn);
-}
-
-static void
-size_cols_tree(struct radix_node *rn)
-{
-again:
- if (kget(rn, rnode) != 0)
- return;
- if (!(rnode.rn_flags & RNF_ACTIVE))
- return;
- if (rnode.rn_bit < 0) {
- if ((rnode.rn_flags & RNF_ROOT) == 0) {
- if (kget(rn, rtentry) != 0)
- return;
- size_cols_rtentry(&rtentry);
- }
- if ((rn = rnode.rn_dupedkey))
- goto again;
- } else {
- rn = rnode.rn_right;
- size_cols_tree(rnode.rn_left);
- size_cols_tree(rn);
- }
-}
-
-static void
-size_cols_rtentry(struct rtentry *rt)
-{
- static struct ifnet ifnet, *lastif;
- static char buffer[100];
- const char *bp;
- struct sockaddr *sa;
- sa_u addr, mask;
- int len;
-
- bzero(&addr, sizeof(addr));
- if ((sa = kgetsa(rt_key(rt))))
- bcopy(sa, &addr, sa->sa_len);
- bzero(&mask, sizeof(mask));
- if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
- bcopy(sa, &mask, sa->sa_len);
- bp = fmt_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags);
- len = strlen(bp);
- wid_dst = MAX(len, wid_dst);
-
- bp = fmt_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST);
- len = strlen(bp);
- wid_gw = MAX(len, wid_gw);
-
- bp = fmt_flags(rt->rt_flags);
- len = strlen(bp);
- wid_flags = MAX(len, wid_flags);
-
- if (Wflag) {
- len = snprintf(buffer, sizeof(buffer), "%ju",
- (uintmax_t )kread_counter((u_long )rt->rt_pksent));
- wid_pksent = MAX(len, wid_pksent);
- }
- if (rt->rt_ifp) {
- if (rt->rt_ifp != lastif) {
- if (kget(rt->rt_ifp, ifnet) == 0)
- len = strlen(ifnet.if_xname);
- else
- len = strlen("---");
- lastif = rt->rt_ifp;
- wid_if = MAX(len, wid_if);
- }
- if (rt->rt_expire) {
- time_t expire_time;
-
- if ((expire_time =
- rt->rt_expire - uptime.tv_sec) > 0) {
- len = snprintf(buffer, sizeof(buffer), "%d",
- (int)expire_time);
- wid_expire = MAX(len, wid_expire);
- }
- }
- }
-}
-
-
/*
* Print header for routing table columns.
*/
@@ -349,9 +233,10 @@ pr_rthdr(int af1)
{
if (Aflag)
- printf("%-8.8s ","Address");
+ xo_emit("{T:/%-8.8s} ","Address");
if (Wflag) {
- printf("%-*.*s %-*.*s %-*.*s %*.*s %*.*s %*.*s %*s\n",
+ xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} "
+ "{T:/%*.*s} {T:/%*.*s} {T:/%*s}\n",
wid_dst, wid_dst, "Destination",
wid_gw, wid_gw, "Gateway",
wid_flags, wid_flags, "Flags",
@@ -360,7 +245,8 @@ pr_rthdr(int af1)
wid_if, wid_if, "Netif",
wid_expire, "Expire");
} else {
- printf("%-*.*s %-*.*s %-*.*s %*.*s %*s\n",
+ xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} "
+ "{T:/%*s}\n",
wid_dst, wid_dst, "Destination",
wid_gw, wid_gw, "Gateway",
wid_flags, wid_flags, "Flags",
@@ -369,168 +255,6 @@ pr_rthdr(int af1)
}
}
-static struct sockaddr *
-kgetsa(struct sockaddr *dst)
-{
-
- if (kget(dst, pt_u.u_sa) != 0)
- return (NULL);
- if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
- kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len);
- return (&pt_u.u_sa);
-}
-
-/*
- * Print kernel routing tables for given fib
- * using debugging kvm(3) interface.
- */
-static void
-p_rtable_kvm(int fibnum, int af)
-{
- struct radix_node_head **rnhp, *rnh, head;
- struct radix_node_head **rt_tables;
- u_long rtree;
- int fam, af_size;
-
- kresolve_list(rl);
- if ((rtree = rl[N_RTREE].n_value) == 0) {
- printf("rt_tables: symbol not in namelist\n");
- return;
- }
-
- af_size = (AF_MAX + 1) * sizeof(struct radix_node_head *);
- rt_tables = calloc(1, af_size);
- if (rt_tables == NULL)
- err(EX_OSERR, "memory allocation failed");
-
- if (kread((u_long)(rtree), (char *)(rt_tables) + fibnum * af_size,
- af_size) != 0)
- err(EX_OSERR, "error retrieving radix pointers");
- for (fam = 0; fam <= AF_MAX; fam++) {
- int tmpfib;
-
- switch (fam) {
- case AF_INET6:
- case AF_INET:
- tmpfib = fibnum;
- break;
- default:
- tmpfib = 0;
- }
- rnhp = (struct radix_node_head **)*rt_tables;
- /* Calculate the in-kernel address. */
- rnhp += tmpfib * (AF_MAX + 1) + fam;
- /* Read the in kernel rhn pointer. */
- if (kget(rnhp, rnh) != 0)
- continue;
- if (rnh == NULL)
- continue;
- /* Read the rnh data. */
- if (kget(rnh, head) != 0)
- continue;
- if (fam == AF_UNSPEC) {
- if (Aflag && af == 0) {
- printf("Netmasks:\n");
- p_rtree_kvm(head.rnh_treetop);
- }
- } else if (af == AF_UNSPEC || af == fam) {
- size_cols(fam, head.rnh_treetop);
- pr_family(fam);
- do_rtent = 1;
- pr_rthdr(fam);
- p_rtree_kvm(head.rnh_treetop);
- }
- }
-
- free(rt_tables);
-}
-
-/*
- * Print given kernel radix tree using
- * debugging kvm(3) interface.
- */
-static void
-p_rtree_kvm(struct radix_node *rn)
-{
-
-again:
- if (kget(rn, rnode) != 0)
- return;
- if (!(rnode.rn_flags & RNF_ACTIVE))
- return;
- if (rnode.rn_bit < 0) {
- if (Aflag)
- printf("%-8.8lx ", (u_long)rn);
- if (rnode.rn_flags & RNF_ROOT) {
- if (Aflag)
- printf("(root node)%s",
- rnode.rn_dupedkey ? " =>\n" : "\n");
- } else if (do_rtent) {
- if (kget(rn, rtentry) == 0) {
- p_rtentry_kvm(&rtentry);
- if (Aflag)
- p_rtnode_kvm();
- }
- } else {
- p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
- NULL, 0, 44);
- putchar('\n');
- }
- if ((rn = rnode.rn_dupedkey))
- goto again;
- } else {
- if (Aflag && do_rtent) {
- printf("%-8.8lx ", (u_long)rn);
- p_rtnode_kvm();
- }
- rn = rnode.rn_right;
- p_rtree_kvm(rnode.rn_left);
- p_rtree_kvm(rn);
- }
-}
-
-char nbuf[20];
-
-static void
-p_rtnode_kvm(void)
-{
- struct radix_mask *rm = rnode.rn_mklist;
-
- if (rnode.rn_bit < 0) {
- if (rnode.rn_mask) {
- printf("\t mask ");
- p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask),
- NULL, 0, -1);
- } else if (rm == 0)
- return;
- } else {
- sprintf(nbuf, "(%d)", rnode.rn_bit);
- printf("%6.6s %8.8lx : %8.8lx", nbuf, (u_long)rnode.rn_left, (u_long)rnode.rn_right);
- }
- while (rm) {
- if (kget(rm, rmask) != 0)
- break;
- sprintf(nbuf, " %d refs, ", rmask.rm_refs);
- printf(" mk = %8.8lx {(%d),%s",
- (u_long)rm, -1 - rmask.rm_bit, rmask.rm_refs ? nbuf : " ");
- if (rmask.rm_flags & RNF_NORMAL) {
- struct radix_node rnode_aux;
- printf(" <normal>, ");
- if (kget(rmask.rm_leaf, rnode_aux) == 0)
- p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask),
- NULL, 0, -1);
- else
- p_sockaddr(NULL, NULL, 0, -1);
- } else
- p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask),
- NULL, 0, -1);
- putchar('}');
- if ((rm = rmask.rm_mklist))
- printf(" ->");
- }
- putchar('\n');
-}
-
static void
p_rtable_sysctl(int fibnum, int af)
{
@@ -539,7 +263,8 @@ p_rtable_sysctl(int fibnum, int af)
char *buf, *next, *lim;
struct rt_msghdr *rtm;
struct sockaddr *sa;
- int fam = 0, ifindex = 0, size;
+ int fam = AF_UNSPEC, ifindex = 0, size;
+ int need_table_close = false;
struct ifaddrs *ifap, *ifa;
struct sockaddr_dl *sdl;
@@ -566,7 +291,7 @@ p_rtable_sysctl(int fibnum, int af)
errx(2, "realloc(%d) failed", size);
memset(&ifmap[ifmap_size], 0,
size - ifmap_size *
- sizeof(struct ifmap_entry));
+ sizeof(struct ifmap_entry));
ifmap_size = roundup(ifindex + 1, 32);
}
@@ -594,6 +319,8 @@ p_rtable_sysctl(int fibnum, int af)
if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0)
err(1, "sysctl: net.route.0.%d.dump.%d", af, fibnum);
lim = buf + needed;
+ xo_open_container("route-table");
+ xo_open_list("rt-family");
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
if (rtm->rtm_version != RTM_VERSION)
@@ -602,19 +329,41 @@ p_rtable_sysctl(int fibnum, int af)
* Peek inside header to determine AF
*/
sa = (struct sockaddr *)(rtm + 1);
+ /* Only print family first time. */
if (fam != sa->sa_family) {
+ if (need_table_close) {
+ xo_close_list("rt-entry");
+ xo_close_instance("rt-family");
+ }
+ need_table_close = true;
+
fam = sa->sa_family;
- size_cols(fam, NULL);
+ wid_dst = WID_DST_DEFAULT(fam);
+ wid_gw = WID_GW_DEFAULT(fam);
+ wid_flags = 6;
+ wid_pksent = 8;
+ wid_mtu = 6;
+ wid_if = WID_IF_DEFAULT(fam);
+ wid_expire = 6;
+ xo_open_instance("rt-family");
pr_family(fam);
+ xo_open_list("rt-entry");
+
pr_rthdr(fam);
}
- p_rtentry_sysctl(rtm);
+ p_rtentry_sysctl("rt-entry", rtm);
}
+ if (need_table_close) {
+ xo_close_list("rt-entry");
+ xo_close_instance("rt-family");
+ }
+ xo_close_list("rt-family");
+ xo_close_container("route-table");
free(buf);
}
static void
-p_rtentry_sysctl(struct rt_msghdr *rtm)
+p_rtentry_sysctl(const char *name, struct rt_msghdr *rtm)
{
struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
char buffer[128];
@@ -622,6 +371,8 @@ p_rtentry_sysctl(struct rt_msghdr *rtm)
sa_u addr, mask, gw;
unsigned int l;
+ xo_open_instance(name);
+
#define GETSA(_s, _f) { \
bzero(&(_s), sizeof(_s)); \
if (rtm->rtm_addrs & _f) { \
@@ -634,18 +385,20 @@ p_rtentry_sysctl(struct rt_msghdr *rtm)
GETSA(addr, RTA_DST);
GETSA(gw, RTA_GATEWAY);
GETSA(mask, RTA_NETMASK);
- p_sockaddr(&addr.u_sa, &mask.u_sa, rtm->rtm_flags, wid_dst);
- p_sockaddr(&gw.u_sa, NULL, RTF_HOST, wid_gw);
- snprintf(buffer, sizeof(buffer), "%%-%d.%ds ", wid_flags, wid_flags);
+ p_sockaddr("destination", &addr.u_sa, &mask.u_sa, rtm->rtm_flags,
+ wid_dst);
+ p_sockaddr("gateway", &gw.u_sa, NULL, RTF_HOST, wid_gw);
+ snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ",
+ wid_flags);
p_flags(rtm->rtm_flags, buffer);
if (Wflag) {
- printf("%*lu ", wid_pksent, rtm->rtm_rmx.rmx_pksent);
+ xo_emit("{t:use/%*lu} ", wid_pksent, rtm->rtm_rmx.rmx_pksent);
if (rtm->rtm_rmx.rmx_mtu != 0)
- printf("%*lu ", wid_mtu, rtm->rtm_rmx.rmx_mtu);
+ xo_emit("{t:mtu/%*lu} ", wid_mtu, rtm->rtm_rmx.rmx_mtu);
else
- printf("%*s ", wid_mtu, "");
+ xo_emit("{P:/%*s} ", wid_mtu, "");
}
memset(prettyname, 0, sizeof(prettyname));
@@ -656,32 +409,41 @@ p_rtentry_sysctl(struct rt_msghdr *rtm)
strlcpy(prettyname, "---", sizeof(prettyname));
}
- printf("%*.*s", wid_if, wid_if, prettyname);
+ xo_emit("{t:interface-name/%*.*s}", wid_if, wid_if, prettyname);
if (rtm->rtm_rmx.rmx_expire) {
time_t expire_time;
- if ((expire_time =
- rtm->rtm_rmx.rmx_expire - uptime.tv_sec) > 0)
- printf(" %*d", wid_expire, (int)expire_time);
+ if ((expire_time = rtm->rtm_rmx.rmx_expire - uptime.tv_sec) > 0)
+ xo_emit(" {:expire-time/%*d}", wid_expire,
+ (int)expire_time);
}
- putchar('\n');
+ xo_emit("\n");
+ xo_close_instance(name);
}
static void
-p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width)
+p_sockaddr(const char *name, struct sockaddr *sa, struct sockaddr *mask,
+ int flags, int width)
{
const char *cp;
+ char buf[128];
cp = fmt_sockaddr(sa, mask, flags);
- if (width < 0 )
- printf("%s ", cp);
- else {
- if (numeric_addr)
- printf("%-*s ", width, cp);
- else
- printf("%-*.*s ", width, width, cp);
+ if (width < 0) {
+ snprintf(buf, sizeof(buf), "{:%s/%%s} ", name);
+ xo_emit(buf, cp);
+ } else {
+ if (numeric_addr) {
+ snprintf(buf, sizeof(buf), "{[:%d}{:%s/%%s}{]:} ",
+ -width, name);
+ xo_emit(buf, cp);
+ } else {
+ snprintf(buf, sizeof(buf), "{[:%d}{:%s/%%-.*s}{]:} ",
+ -width, name);
+ xo_emit(buf, width, cp);
+ }
}
}
@@ -742,7 +504,7 @@ fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags)
case AF_NETGRAPH:
{
strlcpy(workbuf, ((struct sockaddr_ng *)sa)->sg_data,
- sizeof(workbuf));
+ sizeof(workbuf));
cp = workbuf;
break;
}
@@ -798,7 +560,15 @@ fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags)
static void
p_flags(int f, const char *format)
{
- printf(format, fmt_flags(f));
+ struct bits *p;
+
+ xo_emit(format, fmt_flags(f));
+
+ xo_open_list("flags_pretty");
+ for (p = bits; p->b_mask; p++)
+ if (p->b_mask & f)
+ xo_emit("{le:flags_pretty/%s}", p->b_name);
+ xo_close_list("flags_pretty");
}
static const char *
@@ -815,57 +585,6 @@ fmt_flags(int f)
return (name);
}
-static void
-p_rtentry_kvm(struct rtentry *rt)
-{
- static struct ifnet ifnet, *lastif;
- static char buffer[128];
- static char prettyname[128];
- struct sockaddr *sa;
- sa_u addr, mask;
-
- bzero(&addr, sizeof(addr));
- if ((sa = kgetsa(rt_key(rt))))
- bcopy(sa, &addr, sa->sa_len);
- bzero(&mask, sizeof(mask));
- if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
- bcopy(sa, &mask, sa->sa_len);
- p_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags, wid_dst);
- p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST, wid_gw);
- snprintf(buffer, sizeof(buffer), "%%-%d.%ds ", wid_flags, wid_flags);
- p_flags(rt->rt_flags, buffer);
- if (Wflag) {
- printf("%*ju ", wid_pksent,
- (uintmax_t )kread_counter((u_long )rt->rt_pksent));
-
- if (rt->rt_mtu != 0)
- printf("%*lu ", wid_mtu, rt->rt_mtu);
- else
- printf("%*s ", wid_mtu, "");
- }
- if (rt->rt_ifp) {
- if (rt->rt_ifp != lastif) {
- if (kget(rt->rt_ifp, ifnet) == 0)
- strlcpy(prettyname, ifnet.if_xname,
- sizeof(prettyname));
- else
- strlcpy(prettyname, "---", sizeof(prettyname));
- lastif = rt->rt_ifp;
- }
- printf("%*.*s", wid_if, wid_if, prettyname);
- if (rt->rt_expire) {
- time_t expire_time;
-
- if ((expire_time =
- rt->rt_expire - uptime.tv_sec) > 0)
- printf(" %*d", wid_expire, (int)expire_time);
- }
- if (rt->rt_nodes[0].rn_dupedkey)
- printf(" =>");
- }
- putchar('\n');
-}
-
char *
routename(in_addr_t in)
{
@@ -1022,7 +741,7 @@ netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask)
}
}
if (illegal)
- fprintf(stderr, "illegal prefixlen\n");
+ xo_error("illegal prefixlen\n");
}
else
masklen = 128;
@@ -1077,28 +796,34 @@ rt_stats(void)
kresolve_list(rl);
if ((rtsaddr = rl[N_RTSTAT].n_value) == 0) {
- printf("rtstat: symbol not in namelist\n");
+ xo_emit("{W:rtstat: symbol not in namelist}\n");
return;
}
if ((rttaddr = rl[N_RTTRASH].n_value) == 0) {
- printf("rttrash: symbol not in namelist\n");
+ xo_emit("{W:rttrash: symbol not in namelist}\n");
return;
}
kread(rtsaddr, (char *)&rtstat, sizeof (rtstat));
kread(rttaddr, (char *)&rttrash, sizeof (rttrash));
- printf("routing:\n");
+ xo_emit("{T:routing}:\n");
#define p(f, m) if (rtstat.f || sflag <= 1) \
- printf(m, rtstat.f, plural(rtstat.f))
-
- p(rts_badredirect, "\t%hu bad routing redirect%s\n");
- p(rts_dynamic, "\t%hu dynamically created route%s\n");
- p(rts_newgateway, "\t%hu new gateway%s due to redirects\n");
- p(rts_unreach, "\t%hu destination%s found unreachable\n");
- p(rts_wildcard, "\t%hu use%s of a wildcard route\n");
+ xo_emit(m, rtstat.f, plural(rtstat.f))
+
+ p(rts_badredirect, "\t{:bad-redirects/%hu} "
+ "{N:/bad routing redirect%s}\n");
+ p(rts_dynamic, "\t{:dynamically-created/%hu} "
+ "{N:/dynamically created route%s}\n");
+ p(rts_newgateway, "\t{:new-gateways/%hu} "
+ "{N:/new gateway%s due to redirects}\n");
+ p(rts_unreach, "\t{:unreachable-destination/%hu} "
+ "{N:/destination%s found unreachable}\n");
+ p(rts_wildcard, "\t{:wildcard-uses/%hu} "
+ "{N:/use%s of a wildcard route}\n");
#undef p
if (rttrash || sflag <= 1)
- printf("\t%u route%s not in table but not freed\n",
+ xo_emit("\t{:unused-but-not-freed/%u} "
+ "{N:/route%s not in table but not freed}\n",
rttrash, plural(rttrash));
}
diff --git a/usr.bin/netstat/sctp.c b/usr.bin/netstat/sctp.c
index a2ef7d568..cdbbc49 100644
--- a/usr.bin/netstat/sctp.c
+++ b/usr.bin/netstat/sctp.c
@@ -58,9 +58,11 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include "netstat.h"
+#include <libxo/xo.h>
#ifdef SCTP
@@ -98,8 +100,8 @@ struct xladdr_entry {
LIST_HEAD(xraddr_list, xraddr_entry) xraddr_head;
struct xraddr_entry {
- struct xsctp_raddr *xraddr;
- LIST_ENTRY(xraddr_entry) xraddr_entries;
+ struct xsctp_raddr *xraddr;
+ LIST_ENTRY(xraddr_entry) xraddr_entries;
};
/*
@@ -192,12 +194,16 @@ inet6name(struct in6_addr *in6p)
#endif
static void
-sctp_print_address(union sctp_sockstore *address, int port, int num_port)
+sctp_print_address(const char *container, union sctp_sockstore *address,
+ int port, int num_port)
{
struct servent *sp = 0;
char line[80], *cp;
int width;
+ if (container)
+ xo_open_container(container);
+
switch (address->sa.sa_family) {
#ifdef INET
case AF_INET:
@@ -221,7 +227,14 @@ sctp_print_address(union sctp_sockstore *address, int port, int num_port)
else
sprintf(cp, "%d ", ntohs((u_short)port));
width = Wflag ? 45 : 22;
- printf("%-*.*s ", width, width, line);
+ xo_emit("{d:target/%-*.*s} ", width, width, line);
+
+ int alen = cp - line - 1, plen = strlen(cp) - 1;
+ xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
+ plen, cp);
+
+ if (container)
+ xo_close_container(container);
}
static int
@@ -297,7 +310,7 @@ sctp_process_tcb(struct xsctp_tcb *xstcb,
prev_xl = xl;
xl = malloc(sizeof(struct xladdr_entry));
if (xl == NULL) {
- warnx("malloc %lu bytes",
+ xo_warnx("malloc %lu bytes",
(u_long)sizeof(struct xladdr_entry));
goto out;
}
@@ -318,7 +331,7 @@ sctp_process_tcb(struct xsctp_tcb *xstcb,
prev_xr = xr;
xr = malloc(sizeof(struct xraddr_entry));
if (xr == NULL) {
- warnx("malloc %lu bytes",
+ xo_warnx("malloc %lu bytes",
(u_long)sizeof(struct xraddr_entry));
goto out;
}
@@ -333,26 +346,29 @@ sctp_process_tcb(struct xsctp_tcb *xstcb,
/*
* Let's print the address infos.
*/
+ xo_open_list("address");
xl = LIST_FIRST(&xladdr_head);
xr = LIST_FIRST(&xraddr_head);
x_max = (xl_total > xr_total) ? xl_total : xr_total;
for (i = 0; i < x_max; i++) {
+ xo_open_instance("address");
+
if (((*indent == 0) && i > 0) || *indent > 0)
- printf("%-12s ", " ");
+ xo_emit("{P:/%-12s} ", " ");
if (xl != NULL) {
- sctp_print_address(&(xl->xladdr->address),
+ sctp_print_address("local", &(xl->xladdr->address),
htons(xstcb->local_port), numeric_port);
} else {
if (Wflag) {
- printf("%-45s ", " ");
+ xo_emit("{P:/%-45s} ", " ");
} else {
- printf("%-22s ", " ");
+ xo_emit("{P:/%-22s} ", " ");
}
}
if (xr != NULL && !Lflag) {
- sctp_print_address(&(xr->xraddr->address),
+ sctp_print_address("remote", &(xr->xraddr->address),
htons(xstcb->remote_port), numeric_port);
}
@@ -365,7 +381,8 @@ sctp_process_tcb(struct xsctp_tcb *xstcb,
sctp_statesprint(xstcb->state);
if (i < x_max)
- putchar('\n');
+ xo_emit("\n");
+ xo_close_instance("address");
}
out:
@@ -404,23 +421,26 @@ sctp_process_inpcb(struct xsctp_inpcb *xinpcb,
if (first) {
if (!Lflag) {
- printf("Active SCTP associations");
+ xo_emit("Active SCTP associations");
if (aflag)
- printf(" (including servers)");
+ xo_emit(" (including servers)");
} else
- printf("Current listen queue sizes (qlen/maxqlen)");
- putchar('\n');
+ xo_emit("Current listen queue sizes (qlen/maxqlen)");
+ xo_emit("\n");
if (Lflag)
- printf("%-6.6s %-5.5s %-8.8s %-22.22s\n",
+ xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-8.8s} "
+ "{T:/%-22.22s}\n",
"Proto", "Type", "Listen", "Local Address");
else
if (Wflag)
- printf("%-6.6s %-5.5s %-45.45s %-45.45s %s\n",
+ xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-45.45s} "
+ "{T:/%-45.45s} {T:/%s}\n",
"Proto", "Type",
"Local Address", "Foreign Address",
"(state)");
else
- printf("%-6.6s %-5.5s %-22.22s %-22.22s %s\n",
+ xo_emit("{T:/%-6.6s} {T:/%-5.5s} {T:/%-22.22s} "
+ "{T:/%-22.22s} {T:/%s}\n",
"Proto", "Type",
"Local Address", "Foreign Address",
"(state)");
@@ -450,27 +470,38 @@ sctp_process_inpcb(struct xsctp_inpcb *xinpcb,
char buf1[9];
snprintf(buf1, 9, "%hu/%hu", xinpcb->qlen, xinpcb->maxqlen);
- printf("%-6.6s %-5.5s ", pname, tname);
- printf("%-8.8s ", buf1);
+ xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
+ pname, tname);
+ xo_emit("{d:queues/%-8.8s}{e:queue-len/%hu}"
+ "{e:max-queue-len/%hu} ",
+ buf1, xinpcb->qlen, xinpcb->maxqlen);
}
offset_laddr = *offset;
process_closed = 0;
+
+ xo_open_list("local-address");
retry:
while (*offset < buflen) {
xladdr = (struct xsctp_laddr *)(buf + *offset);
*offset += sizeof(struct xsctp_laddr);
if (xladdr->last) {
if (aflag && !Lflag && (xladdr_total == 0) && process_closed) {
- printf("%-6.6s %-5.5s ", pname, tname);
+ xo_open_instance("local-address");
+
+ xo_emit("{:protocol/%-6.6s/%s} "
+ "{:type/%-5.5s/%s} ", pname, tname);
if (Wflag) {
- printf("%-91.91s CLOSED", " ");
+ xo_emit("{P:/%-91.91s/%s} "
+ "{:state/CLOSED}", " ");
} else {
- printf("%-45.45s CLOSED", " ");
+ xo_emit("{P:/%-45.45s/%s} "
+ "{:state/CLOSED}", " ");
}
+ xo_close_instance("local-address");
}
if (process_closed || is_listening) {
- putchar('\n');
+ xo_emit("\n");
}
break;
}
@@ -478,31 +509,39 @@ retry:
if (!Lflag && !is_listening && !process_closed)
continue;
+ xo_open_instance("local-address");
+
if (xladdr_total == 0) {
- printf("%-6.6s %-5.5s ", pname, tname);
+ xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
+ pname, tname);
} else {
- putchar('\n');
- printf((Lflag) ?
- "%-21.21s " : "%-12.12s ", " ");
+ xo_emit("\n");
+ xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ",
+ " ");
}
- sctp_print_address(&(xladdr->address),
+ sctp_print_address("local", &(xladdr->address),
htons(xinpcb->local_port), numeric_port);
if (aflag && !Lflag && xladdr_total == 0) {
if (Wflag) {
if (process_closed) {
- printf("%-45.45s CLOSED", " ");
+ xo_emit("{P:/%-45.45s} "
+ "{:state/CLOSED}", " ");
} else {
- printf("%-45.45s LISTEN", " ");
+ xo_emit("{P:/%-45.45s} "
+ "{:state:LISTEN}", " ");
}
} else {
if (process_closed) {
- printf("%-22.22s CLOSED", " ");
+ xo_emit("{P:/%-22.22s} "
+ "{:state/CLOSED}", " ");
} else {
- printf("%-22.22s LISTEN", " ");
+ xo_emit("{P:/%-22.22s} "
+ "{:state/LISTEN}", " ");
}
}
}
xladdr_total++;
+ xo_close_instance("local-address");
}
xstcb = (struct xsctp_tcb *)(buf + *offset);
@@ -513,12 +552,15 @@ retry:
goto retry;
}
while (xstcb->last == 0 && *offset < buflen) {
- printf("%-6.6s %-5.5s ", pname, tname);
+ xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
+ pname, tname);
sctp_process_tcb(xstcb, buf, buflen, offset, &indent);
indent++;
xstcb = (struct xsctp_tcb *)(buf + *offset);
*offset += sizeof(struct xsctp_tcb);
}
+
+ xo_close_list("local-address");
}
/*
@@ -540,15 +582,15 @@ sctp_protopr(u_long off __unused,
if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: %s", mibvar);
+ xo_warn("sysctl: %s", mibvar);
return;
}
if ((buf = malloc(len)) == 0) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return;
}
if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
- warn("sysctl: %s", mibvar);
+ xo_warn("sysctl: %s", mibvar);
free(buf);
return;
}
@@ -594,11 +636,11 @@ sctp_statesprint(uint32_t state)
idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING;
break;
default:
- printf("UNKNOWN 0x%08x", state);
+ xo_emit("UNKNOWN {:state/0x%08x}", state);
return;
}
- printf("%s", sctpstates[idx]);
+ xo_emit("{:state/%s}", sctpstates[idx]);
}
/*
@@ -616,96 +658,160 @@ sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
if (sysctlbyname("net.inet.sctp.stats", &sctpstat, &len,
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: net.inet.sctp.stats");
+ xo_warn("sysctl: net.inet.sctp.stats");
return;
}
} else
kread(off, &sctpstat, len);
- printf ("%s:\n", name);
+ xo_open_container(name);
+ xo_emit("{T:/%s}:\n", name);
#define p(f, m) if (sctpstat.f || sflag <= 1) \
- printf(m, (uintmax_t)sctpstat.f, plural(sctpstat.f))
+ xo_emit(m, (uintmax_t)sctpstat.f, plural(sctpstat.f))
#define p1a(f, m) if (sctpstat.f || sflag <= 1) \
- printf(m, (uintmax_t)sctpstat.f)
+ xo_emit(m, (uintmax_t)sctpstat.f)
/*
* input statistics
*/
- p(sctps_recvpackets, "\t%ju input packet%s\n");
- p(sctps_recvdatagrams, "\t\t%ju datagram%s\n");
- p(sctps_recvpktwithdata, "\t\t%ju packet%s that had data\n");
- p(sctps_recvsacks, "\t\t%ju input SACK chunk%s\n");
- p(sctps_recvdata, "\t\t%ju input DATA chunk%s\n");
- p(sctps_recvdupdata, "\t\t%ju duplicate DATA chunk%s\n");
- p(sctps_recvheartbeat, "\t\t%ju input HB chunk%s\n");
- p(sctps_recvheartbeatack, "\t\t%ju HB-ACK chunk%s\n");
- p(sctps_recvecne, "\t\t%ju input ECNE chunk%s\n");
- p(sctps_recvauth, "\t\t%ju input AUTH chunk%s\n");
- p(sctps_recvauthmissing, "\t\t%ju chunk%s missing AUTH\n");
- p(sctps_recvivalhmacid, "\t\t%ju invalid HMAC id%s received\n");
- p(sctps_recvivalkeyid, "\t\t%ju invalid secret id%s received\n");
- p1a(sctps_recvauthfailed, "\t\t%ju auth failed\n");
- p1a(sctps_recvexpress, "\t\t%ju fast path receives all one chunk\n");
- p1a(sctps_recvexpressm, "\t\t%ju fast path multi-part data\n");
+ p(sctps_recvpackets, "\t{:received-packets/%ju} "
+ "{N:/input packet%s}\n");
+ p(sctps_recvdatagrams, "\t\t{:received-datagrams/%ju} "
+ "{N:/datagram%s}\n");
+ p(sctps_recvpktwithdata, "\t\t{:received-with-data/%ju} "
+ "{N:/packet%s that had data}\n");
+ p(sctps_recvsacks, "\t\t{:received-sack-chunks/%ju} "
+ "{N:/input SACK chunk%s}\n");
+ p(sctps_recvdata, "\t\t{:received-data-chunks/%ju} "
+ "{N:/input DATA chunk%s}\n");
+ p(sctps_recvdupdata, "\t\t{:received-duplicate-data-chunks/%ju} "
+ "{N:/duplicate DATA chunk%s}\n");
+ p(sctps_recvheartbeat, "\t\t{:received-hb-chunks/%ju} "
+ "{N:/input HB chunk%s}\n");
+ p(sctps_recvheartbeatack, "\t\t{:received-hb-ack-chunks/%ju} "
+ "{N:/HB-ACK chunk%s}\n");
+ p(sctps_recvecne, "\t\t{:received-ecne-chunks/%ju} "
+ "{N:/input ECNE chunk%s}\n");
+ p(sctps_recvauth, "\t\t{:received-auth-chunks/%ju} "
+ "{N:/input AUTH chunk%s}\n");
+ p(sctps_recvauthmissing, "\t\t{:dropped-missing-auth/%ju} "
+ "{N:/chunk%s missing AUTH}\n");
+ p(sctps_recvivalhmacid, "\t\t{:dropped-invalid-hmac/%ju} "
+ "{N:/invalid HMAC id%s received}\n");
+ p(sctps_recvivalkeyid, "\t\t{:dropped-invalid-secret/%ju} "
+ "{N:/invalid secret id%s received}\n");
+ p1a(sctps_recvauthfailed, "\t\t{:dropped-auth-failed/%ju} "
+ "{N:/auth failed}\n");
+ p1a(sctps_recvexpress, "\t\t{:received-fast-path/%ju} "
+ "{N:/fast path receives all one chunk}\n");
+ p1a(sctps_recvexpressm, "\t\t{:receives-fast-path-multipart/%ju} "
+ "{N:/fast path multi-part data}\n");
/*
* output statistics
*/
- p(sctps_sendpackets, "\t%ju output packet%s\n");
- p(sctps_sendsacks, "\t\t%ju output SACK%s\n");
- p(sctps_senddata, "\t\t%ju output DATA chunk%s\n");
- p(sctps_sendretransdata, "\t\t%ju retransmitted DATA chunk%s\n");
- p(sctps_sendfastretrans, "\t\t%ju fast retransmitted DATA chunk%s\n");
- p(sctps_sendmultfastretrans, "\t\t%ju FR'%s that happened more "
- "than once to same chunk\n");
- p(sctps_sendheartbeat, "\t\t%ju output HB chunk%s\n");
- p(sctps_sendecne, "\t\t%ju output ECNE chunk%s\n");
- p(sctps_sendauth, "\t\t%ju output AUTH chunk%s\n");
- p1a(sctps_senderrors, "\t\t%ju ip_output error counter\n");
+ p(sctps_sendpackets, "\t{:sent-packets/%ju} "
+ "{N:/output packet%s}\n");
+ p(sctps_sendsacks, "\t\t{:sent-sacks/%ju} "
+ "{N:/output SACK%s}\n");
+ p(sctps_senddata, "\t\t{:sent-data-chunks/%ju} "
+ "{N:/output DATA chunk%s}\n");
+ p(sctps_sendretransdata, "\t\t{:sent-retransmitted-data-chunks/%ju} "
+ "{N:/retransmitted DATA chunk%s}\n");
+ p(sctps_sendfastretrans, "\t\t"
+ "{:sent-fast-retransmitted-data-chunks/%ju} "
+ "{N:/fast retransmitted DATA chunk%s}\n");
+ p(sctps_sendmultfastretrans, "\t\t"
+ "{:sent-fast-retransmitted-data-chunk-multiple-times/%ju} "
+ "{N:/FR'%s that happened more than once to same chunk}\n");
+ p(sctps_sendheartbeat, "\t\t{:sent-hb-chunks/%ju} "
+ "{N:/output HB chunk%s}\n");
+ p(sctps_sendecne, "\t\t{:sent-ecne-chunks/%ju} "
+ "{N:/output ECNE chunk%s}\n");
+ p(sctps_sendauth, "\t\t{:sent-auth-chunks/%ju} "
+ "{N:/output AUTH chunk%s}\n");
+ p1a(sctps_senderrors, "\t\t{:send-errors/%ju} "
+ "{N:/ip_output error counter}\n");
/*
* PCKDROPREP statistics
*/
- printf("\tPacket drop statistics:\n");
- p1a(sctps_pdrpfmbox, "\t\t%ju from middle box\n");
- p1a(sctps_pdrpfehos, "\t\t%ju from end host\n");
- p1a(sctps_pdrpmbda, "\t\t%ju with data\n");
- p1a(sctps_pdrpmbct, "\t\t%ju non-data, non-endhost\n");
- p1a(sctps_pdrpbwrpt, "\t\t%ju non-endhost, bandwidth rep only\n");
- p1a(sctps_pdrpcrupt, "\t\t%ju not enough for chunk header\n");
- p1a(sctps_pdrpnedat, "\t\t%ju not enough data to confirm\n");
- p1a(sctps_pdrppdbrk, "\t\t%ju where process_chunk_drop said break\n");
- p1a(sctps_pdrptsnnf, "\t\t%ju failed to find TSN\n");
- p1a(sctps_pdrpdnfnd, "\t\t%ju attempt reverse TSN lookup\n");
- p1a(sctps_pdrpdiwnp, "\t\t%ju e-host confirms zero-rwnd\n");
- p1a(sctps_pdrpdizrw, "\t\t%ju midbox confirms no space\n");
- p1a(sctps_pdrpbadd, "\t\t%ju data did not match TSN\n");
- p(sctps_pdrpmark, "\t\t%ju TSN'%s marked for Fast Retran\n");
+ xo_emit("\t{T:Packet drop statistics}:\n");
+ xo_open_container("drop-statistics");
+ p1a(sctps_pdrpfmbox, "\t\t{:middle-box/%ju} "
+ "{N:/from middle box}\n");
+ p1a(sctps_pdrpfehos, "\t\t{:end-host/%ju} "
+ "{N:/from end host}\n");
+ p1a(sctps_pdrpmbda, "\t\t{:with-data/%ju} "
+ "{N:/with data}\n");
+ p1a(sctps_pdrpmbct, "\t\t{:non-data/%ju} "
+ "{N:/non-data, non-endhost}\n");
+ p1a(sctps_pdrpbwrpt, "\t\t{:non-endhost/%ju} "
+ "{N:/non-endhost, bandwidth rep only}\n");
+ p1a(sctps_pdrpcrupt, "\t\t{:short-header/%ju} "
+ "{N:/not enough for chunk header}\n");
+ p1a(sctps_pdrpnedat, "\t\t{:short-data/%ju} "
+ "{N:/not enough data to confirm}\n");
+ p1a(sctps_pdrppdbrk, "\t\t{:chunk-break/%ju} "
+ "{N:/where process_chunk_drop said break}\n");
+ p1a(sctps_pdrptsnnf, "\t\t{:tsn-not-found/%ju} "
+ "{N:/failed to find TSN}\n");
+ p1a(sctps_pdrpdnfnd, "\t\t{:reverse-tsn/%ju} "
+ "{N:/attempt reverse TSN lookup}\n");
+ p1a(sctps_pdrpdiwnp, "\t\t{:confirmed-zero-window/%ju} "
+ "{N:/e-host confirms zero-rwnd}\n");
+ p1a(sctps_pdrpdizrw, "\t\t{:middle-box-no-space/%ju} "
+ "{N:/midbox confirms no space}\n");
+ p1a(sctps_pdrpbadd, "\t\t{:bad-data/%ju} "
+ "{N:/data did not match TSN}\n");
+ p(sctps_pdrpmark, "\t\t{:tsn-marked-fast-retransmission/%ju} "
+ "{N:/TSN'%s marked for Fast Retran}\n");
+ xo_close_container("drop-statistics");
/*
* Timeouts
*/
- printf("\tTimeouts:\n");
- p(sctps_timoiterator, "\t\t%ju iterator timer%s fired\n");
- p(sctps_timodata, "\t\t%ju T3 data time out%s\n");
- p(sctps_timowindowprobe, "\t\t%ju window probe (T3) timer%s fired\n");
- p(sctps_timoinit, "\t\t%ju INIT timer%s fired\n");
- p(sctps_timosack, "\t\t%ju sack timer%s fired\n");
- p(sctps_timoshutdown, "\t\t%ju shutdown timer%s fired\n");
- p(sctps_timoheartbeat, "\t\t%ju heartbeat timer%s fired\n");
- p1a(sctps_timocookie, "\t\t%ju a cookie timeout fired\n");
- p1a(sctps_timosecret, "\t\t%ju an endpoint changed its cookie"
+ xo_emit("\t{T:Timeouts}:\n");
+ xo_open_container("timeouts");
+ p(sctps_timoiterator, "\t\t{:iterator/%ju} "
+ "{N:/iterator timer%s fired}\n");
+ p(sctps_timodata, "\t\t{:t3-data/%ju} "
+ "{N:/T3 data time out%s}\n");
+ p(sctps_timowindowprobe, "\t\t{:window-probe/%ju} "
+ "{N:/window probe (T3) timer%s fired}\n");
+ p(sctps_timoinit, "\t\t{:init-timer/%ju} "
+ "{N:/INIT timer%s fired}\n");
+ p(sctps_timosack, "\t\t{:sack-timer/%ju} "
+ "{N:/sack timer%s fired}\n");
+ p(sctps_timoshutdown, "\t\t{:shutdown-timer/%ju} "
+ "{N:/shutdown timer%s fired}\n");
+ p(sctps_timoheartbeat, "\t\t{:heartbeat-timer/%ju} "
+ "{N:/heartbeat timer%s fired}\n");
+ p1a(sctps_timocookie, "\t\t{:cookie-timer/%ju} "
+ "{N:/a cookie timeout fired}\n");
+ p1a(sctps_timosecret, "\t\t{:endpoint-changed-cookie/%ju} "
+ "{N:/an endpoint changed its cook}ie"
"secret\n");
- p(sctps_timopathmtu, "\t\t%ju PMTU timer%s fired\n");
- p(sctps_timoshutdownack, "\t\t%ju shutdown ack timer%s fired\n");
- p(sctps_timoshutdownguard, "\t\t%ju shutdown guard timer%s fired\n");
- p(sctps_timostrmrst, "\t\t%ju stream reset timer%s fired\n");
- p(sctps_timoearlyfr, "\t\t%ju early FR timer%s fired\n");
- p1a(sctps_timoasconf, "\t\t%ju an asconf timer fired\n");
- p1a(sctps_timoautoclose, "\t\t%ju auto close timer fired\n");
- p(sctps_timoassockill, "\t\t%ju asoc free timer%s expired\n");
- p(sctps_timoinpkill, "\t\t%ju inp free timer%s expired\n");
+ p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} "
+ "{N:/PMTU timer%s fired}\n");
+ p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} "
+ "{N:/shutdown ack timer%s fired}\n");
+ p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} "
+ "{N:/shutdown guard timer%s fired}\n");
+ p(sctps_timostrmrst, "\t\t{:stream-reset-timer/%ju} "
+ "{N:/stream reset timer%s fired}\n");
+ p(sctps_timoearlyfr, "\t\t{:early-fast-retransmission-timer/%ju} "
+ "{N:/early FR timer%s fired}\n");
+ p1a(sctps_timoasconf, "\t\t{:asconf-timer/%ju} "
+ "{N:/an asconf timer fired}\n");
+ p1a(sctps_timoautoclose, "\t\t{:auto-close-timer/%ju} "
+ "{N:/auto close timer fired}\n");
+ p(sctps_timoassockill, "\t\t{:asoc-free-timer/%ju} "
+ "{N:/asoc free timer%s expired}\n");
+ p(sctps_timoinpkill, "\t\t{:input-free-timer/%ju} "
+ "{N:/inp free timer%s expired}\n");
+ xo_close_container("timeouts");
#if 0
/*
@@ -727,60 +833,86 @@ sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
/*
* Others
*/
- p1a(sctps_hdrops, "\t%ju packet shorter than header\n");
- p1a(sctps_badsum, "\t%ju checksum error\n");
- p1a(sctps_noport, "\t%ju no endpoint for port\n");
- p1a(sctps_badvtag, "\t%ju bad v-tag\n");
- p1a(sctps_badsid, "\t%ju bad SID\n");
- p1a(sctps_nomem, "\t%ju no memory\n");
- p1a(sctps_fastretransinrtt, "\t%ju number of multiple FR in a RTT "
- "window\n");
+ p1a(sctps_hdrops, "\t{:dropped-too-short/%ju} "
+ "{N:/packet shorter than header}\n");
+ p1a(sctps_badsum, "\t{:dropped-bad-checksum/%ju} "
+ "{N:/checksum error}\n");
+ p1a(sctps_noport, "\t{:dropped-no-endpoint/%ju} "
+ "{N:/no endpoint for port}\n");
+ p1a(sctps_badvtag, "\t{:dropped-bad-v-tag/%ju} "
+ "{N:/bad v-tag}\n");
+ p1a(sctps_badsid, "\t{:dropped-bad-sid/%ju} "
+ "{N:/bad SID}\n");
+ p1a(sctps_nomem, "\t{:dropped-no-memory/%ju} "
+ "{N:/no memory}\n");
+ p1a(sctps_fastretransinrtt, "\t{:multiple-fast-retransmits-in-rtt/%ju} "
+ "{N:/number of multiple FR in a RT}T window\n");
#if 0
p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n");
#endif
- p1a(sctps_naglesent, "\t%ju RFC813 allowed sending\n");
- p1a(sctps_naglequeued, "\t%ju RFC813 does not allow sending\n");
- p1a(sctps_maxburstqueued, "\t%ju times max burst prohibited sending\n");
- p1a(sctps_ifnomemqueued, "\t%ju look ahead tells us no memory in "
- "interface\n");
- p(sctps_windowprobed, "\t%ju number%s of window probes sent\n");
- p(sctps_lowlevelerr, "\t%ju time%s an output error to clamp "
- "down on next user send\n");
- p(sctps_lowlevelerrusr, "\t%ju time%s sctp_senderrors were "
- "caused from a user\n");
- p(sctps_datadropchklmt, "\t%ju number of in data drop%s due to "
- "chunk limit reached\n");
- p(sctps_datadroprwnd, "\t%ju number of in data drop%s due to rwnd "
- "limit reached\n");
- p(sctps_ecnereducedcwnd, "\t%ju time%s a ECN reduced "
- "the cwnd\n");
- p1a(sctps_vtagexpress, "\t%ju used express lookup via vtag\n");
- p1a(sctps_vtagbogus, "\t%ju collision in express lookup\n");
- p(sctps_primary_randry, "\t%ju time%s the sender ran dry "
- "of user data on primary\n");
- p1a(sctps_cmt_randry, "\t%ju same for above\n");
- p(sctps_slowpath_sack, "\t%ju sack%s the slow way\n");
- p(sctps_wu_sacks_sent, "\t%ju window update only sack%s sent\n");
- p(sctps_sends_with_flags, "\t%ju send%s with sinfo_flags !=0\n");
- p(sctps_sends_with_unord, "\t%ju unordered send%s\n");
- p(sctps_sends_with_eof, "\t%ju send%s with EOF flag set\n");
- p(sctps_sends_with_abort, "\t%ju send%s with ABORT flag set\n");
- p(sctps_protocol_drain_calls, "\t%ju time%s protocol drain called\n");
- p(sctps_protocol_drains_done, "\t%ju time%s we did a protocol "
- "drain\n");
- p(sctps_read_peeks, "\t%ju time%s recv was called with peek\n");
- p(sctps_cached_chk, "\t%ju cached chunk%s used\n");
- p1a(sctps_cached_strmoq, "\t%ju cached stream oq's used\n");
- p(sctps_left_abandon, "\t%ju unread message%s abandonded by close\n");
- p1a(sctps_send_burst_avoid, "\t%ju send burst avoidance, already "
- "max burst inflight to net\n");
- p1a(sctps_send_cwnd_avoid, "\t%ju send cwnd full avoidance, already "
- "max burst inflight to net\n");
- p(sctps_fwdtsn_map_over, "\t%ju number of map array over-run%s via "
- "fwd-tsn's\n");
+ p1a(sctps_naglesent, "\t{:rfc813-sent/%ju} "
+ "{N:/RFC813 allowed sending}\n");
+ p1a(sctps_naglequeued, "\t{:rfc813-queued/%ju} "
+ "{N:/RFC813 does not allow sending}\n");
+ p1a(sctps_maxburstqueued, "\t{:max-burst-queued/%ju} "
+ "{N:/times max burst prohibited sending}\n");
+ p1a(sctps_ifnomemqueued, "\t{:no-memory-in-interface/%ju} "
+ "{N:/look ahead tells us no memory in interface}\n");
+ p(sctps_windowprobed, "\t{:sent-window-probes/%ju} "
+ "{N:/number%s of window probes sent}\n");
+ p(sctps_lowlevelerr, "\t{:low-level-err/%ju} "
+ "{N:/time%s an output error to clamp down on next user send}\n");
+ p(sctps_lowlevelerrusr, "\t{:low-level-user-error/%ju} "
+ "{N:/time%s sctp_senderrors were caused from a user}\n");
+ p(sctps_datadropchklmt, "\t{:dropped-chunk-limit/%ju} "
+ "{N:/number of in data drop%s due to chunk limit reached}\n");
+ p(sctps_datadroprwnd, "\t{:dropped-rwnd-limit/%ju} "
+ "{N:/number of in data drop%s due to rwnd limit reached}\n");
+ p(sctps_ecnereducedcwnd, "\t{:ecn-reduced-cwnd/%ju} "
+ "{N:/time%s a ECN reduced the cwnd}\n");
+ p1a(sctps_vtagexpress, "\t{:v-tag-express-lookup/%ju} "
+ "{N:/used express lookup via vtag}\n");
+ p1a(sctps_vtagbogus, "\t{:v-tag-collision/%ju} "
+ "{N:/collision in express lookup}\n");
+ p(sctps_primary_randry, "\t{:sender-ran-dry/%ju} "
+ "{N:/time%s the sender ran dry of user data on primary}\n");
+ p1a(sctps_cmt_randry, "\t{:cmt-ran-dry/%ju} "
+ "{N:/same for above}\n");
+ p(sctps_slowpath_sack, "\t{:slow-path-sack/%ju} "
+ "{N:/sack%s the slow way}\n");
+ p(sctps_wu_sacks_sent, "\t{:sent-window-update-only-sack/%ju} "
+ "{N:/window update only sack%s sent}\n");
+ p(sctps_sends_with_flags, "\t{:sent-with-sinfo/%ju} "
+ "{N:/send%s with sinfo_flags !=0}\n");
+ p(sctps_sends_with_unord, "\t{:sent-with-unordered/%ju} "
+ "{N:/unordered send%s}\n");
+ p(sctps_sends_with_eof, "\t{:sent-with-eof/%ju} "
+ "{N:/send%s with EOF flag set}\n");
+ p(sctps_sends_with_abort, "\t{:sent-with-abort/%ju} "
+ "{N:/send%s with ABORT flag set}\n");
+ p(sctps_protocol_drain_calls, "\t{:protocol-drain-called/%ju} "
+ "{N:/time%s protocol drain called}\n");
+ p(sctps_protocol_drains_done, "\t{:protocol-drain/%ju} "
+ "{N:/time%s we did a protocol drain}\n");
+ p(sctps_read_peeks, "\t{:read-with-peek/%ju} "
+ "{N:/time%s recv was called with peek}\n");
+ p(sctps_cached_chk, "\t{:cached-chunks/%ju} "
+ "{N:/cached chunk%s used}\n");
+ p1a(sctps_cached_strmoq, "\t{:cached-output-queue-used/%ju} "
+ "{N:/cached stream oq's used}\n");
+ p(sctps_left_abandon, "\t{:messages-abandoned/%ju} "
+ "{N:/unread message%s abandonded by close}\n");
+ p1a(sctps_send_burst_avoid, "\t{:send-burst-avoidance/%ju} "
+ "{N:/send burst avoidance, already max burst inflight to net}\n");
+ p1a(sctps_send_cwnd_avoid, "\t{:send-cwnd-avoidance/%ju} "
+ "{N:/send cwnd full avoidance, already max burst inflight "
+ "to net}\n");
+ p(sctps_fwdtsn_map_over, "\t{:tsn-map-overruns/%ju} "
+ "{N:/number of map array over-run%s via fwd-tsn's}\n");
#undef p
#undef p1a
+ xo_close_container(name);
}
#endif /* SCTP */
diff --git a/usr.bin/netstat/unix.c b/usr.bin/netstat/unix.c
index 027e812..a7503f5 100644
--- a/usr.bin/netstat/unix.c
+++ b/usr.bin/netstat/unix.c
@@ -57,8 +57,10 @@ __FBSDID("$FreeBSD$");
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <strings.h>
#include <kvm.h>
+#include <libxo/xo.h>
#include "netstat.h"
static void unixdomainpr(struct xunpcb *, struct xsocket *);
@@ -78,15 +80,15 @@ pcblist_sysctl(int type, char **bufp)
len = 0;
if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
if (errno != ENOENT)
- warn("sysctl: %s", mibvar);
+ xo_warn("sysctl: %s", mibvar);
return (-1);
}
if ((buf = malloc(len)) == 0) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return (-2);
}
if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
- warn("sysctl: %s", mibvar);
+ xo_warn("sysctl: %s", mibvar);
free(buf);
return (-2);
}
@@ -115,14 +117,14 @@ pcblist_kvm(u_long count_off, u_long gencnt_off, u_long head_off, char **bufp)
kread(count_off, &unp_count, sizeof(unp_count));
len = 2 * sizeof(xug) + (unp_count + unp_count / 8) * sizeof(xu);
if ((buf = malloc(len)) == 0) {
- warnx("malloc %lu bytes", (u_long)len);
+ xo_warnx("malloc %lu bytes", (u_long)len);
return (-2);
}
p = buf;
#define COPYOUT(obj, size) do { \
if (len < (size)) { \
- warnx("buffer size exceeded"); \
+ xo_warnx("buffer size exceeded"); \
goto fail; \
} \
bcopy((obj), p, (size)); \
@@ -190,7 +192,7 @@ fail:
void
unixpr(u_long count_off, u_long gencnt_off, u_long dhead_off, u_long shead_off,
- u_long sphead_off)
+ u_long sphead_off, bool *first)
{
char *buf;
int ret, type;
@@ -228,26 +230,35 @@ unixpr(u_long count_off, u_long gencnt_off, u_long dhead_off, u_long shead_off,
oxug = xug = (struct xunpgen *)buf;
for (xug = (struct xunpgen *)((char *)xug + xug->xug_len);
- xug->xug_len > sizeof(struct xunpgen);
- xug = (struct xunpgen *)((char *)xug + xug->xug_len)) {
+ xug->xug_len > sizeof(struct xunpgen);
+ xug = (struct xunpgen *)((char *)xug + xug->xug_len)) {
xunp = (struct xunpcb *)xug;
so = &xunp->xu_socket;
/* Ignore PCBs which were freed during copyout. */
if (xunp->xu_unp.unp_gencnt > oxug->xug_gen)
continue;
+ if (*first) {
+ xo_open_list("socket");
+ *first = false;
+ }
+ xo_open_instance("socket");
unixdomainpr(xunp, so);
+ xo_close_instance("socket");
}
if (xug != oxug && xug->xug_gen != oxug->xug_gen) {
if (oxug->xug_count > xug->xug_count) {
- printf("Some %s sockets may have been deleted.\n",
- socktype[type]);
+ xo_emit("Some {:type/%s} sockets may have "
+ "been {:action/deleted}.\n",
+ socktype[type]);
} else if (oxug->xug_count < xug->xug_count) {
- printf("Some %s sockets may have been created.\n",
- socktype[type]);
+ xo_emit("Some {:type/%s} sockets may have "
+ "been {:action/created}.\n",
+ socktype[type]);
} else {
- printf("Some %s sockets may have been created or deleted",
- socktype[type]);
+ xo_emit("Some {:type/%s} sockets may have "
+ "been {:action/created or deleted}",
+ socktype[type]);
}
}
free(buf);
@@ -261,6 +272,25 @@ unixdomainpr(struct xunpcb *xunp, struct xsocket *so)
struct sockaddr_un *sa;
static int first = 1;
char buf1[15];
+ static const char *titles[2] = {
+ "{T:/%-8.8s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%8.8s} "
+ "{T:/%8.8s} {T:/%8.8s} {T:/%8.8s} {T:Addr}\n",
+ "{T:/%-16.16s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%16.16s} "
+ "{T:/%16.16s} {T:/%16.16s} {T:/%16.16s} {T:Addr}\n"
+ };
+ static const char *format[2] = {
+ "{q:address/%8lx} {t:type/%-6.6s} "
+ "{:receive-bytes-waiting/%6u} "
+ "{:send-bytes-waiting/%6u} "
+ "{q:vnode/%8lx} {q:connection/%8lx} "
+ "{q:first-reference/%8lx} {q:next-reference/%8lx}",
+ "{q:address/%16lx} {t:type/%-6.6s} "
+ "{:receive-bytes-waiting/%6u} "
+ "{:send-bytes-waiting/%6u} "
+ "{q:vnode/%16lx} {q:connection/%16lx} "
+ "{q:first-reference/%16lx} {q:next-reference/%16lx}"
+ };
+ int fmt = (sizeof(void *) == 8) ? 1 : 0;
unp = &xunp->xu_unp;
if (unp->unp_addr)
@@ -269,9 +299,8 @@ unixdomainpr(struct xunpcb *xunp, struct xsocket *so)
sa = (struct sockaddr_un *)0;
if (first && !Lflag) {
- printf("Active UNIX domain sockets\n");
- printf(
-"%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
+ xo_emit("{T:Active UNIX domain sockets}\n");
+ xo_emit(titles[fmt],
"Address", "Type", "Recv-Q", "Send-Q",
"Inode", "Conn", "Refs", "Nextref");
first = 0;
@@ -283,17 +312,20 @@ unixdomainpr(struct xunpcb *xunp, struct xsocket *so)
if (Lflag) {
snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
so->so_incqlen, so->so_qlimit);
- printf("unix %-14.14s", buf1);
+ xo_emit("unix {d:socket/%-14.14s}{e:queue-length/%d}"
+ "{e:incomplete-queue-length/%d}{e:queue-limit/%d}",
+ buf1, so->so_qlen, so->so_incqlen, so->so_qlimit);
} else {
- printf("%8lx %-6.6s %6u %6u %8lx %8lx %8lx %8lx",
+ xo_emit(format[fmt],
(long)so->so_pcb, socktype[so->so_type], so->so_rcv.sb_cc,
- so->so_snd.sb_cc, (long)unp->unp_vnode, (long)unp->unp_conn,
+ so->so_snd.sb_cc, (long)unp->unp_vnode,
+ (long)unp->unp_conn,
(long)LIST_FIRST(&unp->unp_refs),
(long)LIST_NEXT(unp, unp_reflink));
}
if (sa)
- printf(" %.*s",
+ xo_emit(" {:path/%.*s}",
(int)(sa->sun_len - offsetof(struct sockaddr_un, sun_path)),
sa->sun_path);
- putchar('\n');
+ xo_emit("\n");
}
diff --git a/usr.bin/newgrp/Makefile b/usr.bin/newgrp/Makefile
index 8195348..0a8e4a8 100644
--- a/usr.bin/newgrp/Makefile
+++ b/usr.bin/newgrp/Makefile
@@ -1,8 +1,8 @@
# $FreeBSD$
PROG= newgrp
-DPADD= ${LIBCRYPT} ${LIBUTIL}
-LDADD= -lcrypt -lutil
+
+LIBADD= crypt util
.if defined(ENABLE_SUID_NEWGRP)
BINMODE= 4555
diff --git a/usr.bin/newkey/Makefile b/usr.bin/newkey/Makefile
index bf46513..be1ea37 100644
--- a/usr.bin/newkey/Makefile
+++ b/usr.bin/newkey/Makefile
@@ -8,7 +8,6 @@ SRCS= newkey.c generic.c update.c
CFLAGS+= -DYP
.endif
MAN= newkey.8
-DPADD= ${LIBRPCSVC} ${LIBMP} ${LIBCRYPTO}
-LDADD= -lrpcsvc -lmp -lcrypto
+LIBADD= rpcsvc mp
.include <bsd.prog.mk>
diff --git a/usr.bin/nfsstat/Makefile b/usr.bin/nfsstat/Makefile
index d31db0a..fc92008 100644
--- a/usr.bin/nfsstat/Makefile
+++ b/usr.bin/nfsstat/Makefile
@@ -3,9 +3,7 @@
PROG= nfsstat
CFLAGS+=-DNFS
-DPADD= ${LIBKVM}
-LDADD= -lkvm
-WARNS?= 3
+LIBADD= kvm
.include <bsd.prog.mk>
diff --git a/usr.bin/nfsstat/nfsstat.1 b/usr.bin/nfsstat/nfsstat.1
index 5ec048f..6568c6a 100644
--- a/usr.bin/nfsstat/nfsstat.1
+++ b/usr.bin/nfsstat/nfsstat.1
@@ -28,7 +28,7 @@
.\" From: @(#)nfsstat.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd May 1, 2013
+.Dd April 23, 2015
.Dt NFSSTAT 1
.Os
.Sh NAME
@@ -38,7 +38,7 @@
statistics
.Sh SYNOPSIS
.Nm
-.Op Fl cemoszW
+.Op Fl cemszW
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl w Ar wait
@@ -58,10 +58,8 @@ The options are as follows:
.It Fl c
Only display client side statistics.
.It Fl e
-Report the extra statistics collected by the new NFS client and
+Report the extra statistics collected by the NFS client and
server for NFSv4.
-This option is incompatible with
-.Fl o .
.It Fl M
Extract values associated with the name list from the specified core
instead of the default
@@ -75,10 +73,6 @@ This option is only supported by the new NFS client.
.It Fl N
Extract the name list from the specified system instead of the default
.Pa /boot/kernel/kernel .
-.It Fl o
-Report statistics for the old NFS client and/or server.
-Without this
-option statistics for the new NFS client and/or server will be reported.
.It Fl s
Only display server side statistics.
.It Fl W
diff --git a/usr.bin/nfsstat/nfsstat.c b/usr.bin/nfsstat/nfsstat.c
index a5537f7..32fbc96 100644
--- a/usr.bin/nfsstat/nfsstat.c
+++ b/usr.bin/nfsstat/nfsstat.c
@@ -70,31 +70,19 @@ static const char rcsid[] =
#include <paths.h>
#include <err.h>
-struct nlist nl[] = {
-#define N_NFSSTAT 0
- { .n_name = "nfsstats" },
-#define N_NFSRVSTAT 1
- { .n_name = "nfsrvstats" },
- { .n_name = NULL },
-};
-kvm_t *kd;
-
-static int deadkernel = 0;
static int widemode = 0;
static int zflag = 0;
-static int run_v4 = 1;
static int printtitle = 1;
static struct ext_nfsstats ext_nfsstats;
static int extra_output = 0;
-void intpr(int, int);
-void printhdr(int, int);
-void sidewaysintpr(u_int, int, int);
-void usage(void);
-char *sperc1(int, int);
-char *sperc2(int, int);
-void exp_intpr(int, int);
-void exp_sidewaysintpr(u_int, int, int);
+static void intpr(int, int);
+static void printhdr(int, int);
+static void usage(void);
+static char *sperc1(int, int);
+static char *sperc2(int, int);
+static void exp_intpr(int, int);
+static void exp_sidewaysintpr(u_int, int, int);
#define DELTA(field) (nfsstats.field - lastst.field)
@@ -106,7 +94,6 @@ main(int argc, char **argv)
int serverOnly = -1;
int ch;
char *memf, *nlistf;
- char errbuf[_POSIX2_LINE_MAX];
int mntlen, i;
char buf[1024];
struct statfs *mntbuf;
@@ -114,7 +101,7 @@ main(int argc, char **argv)
interval = 0;
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "cesWM:mN:ow:z")) != -1)
+ while ((ch = getopt(argc, argv, "cesWM:mN:w:z")) != -1)
switch(ch) {
case 'M':
memf = optarg;
@@ -162,14 +149,7 @@ main(int argc, char **argv)
case 'z':
zflag = 1;
break;
- case 'o':
- if (extra_output != 0)
- err(1, "-o incompatible with -e");
- run_v4 = 0;
- break;
case 'e':
- if (run_v4 == 0)
- err(1, "-e incompatible with -o");
extra_output = 1;
break;
case '?':
@@ -190,26 +170,11 @@ main(int argc, char **argv)
}
}
#endif
- if (run_v4 != 0 && modfind("nfscommon") < 0)
- errx(1, "new client/server not loaded");
-
- if (run_v4 == 0 && (nlistf != NULL || memf != NULL)) {
- deadkernel = 1;
-
- if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
- errbuf)) == 0) {
- errx(1, "kvm_openfiles: %s", errbuf);
- }
- if (kvm_nlist(kd, nl) != 0) {
- errx(1, "kvm_nlist: can't get names");
- }
- }
+ if (modfind("nfscommon") < 0)
+ errx(1, "NFS client/server not loaded");
if (interval) {
- if (run_v4 > 0)
- exp_sidewaysintpr(interval, clientOnly, serverOnly);
- else
- sidewaysintpr(interval, clientOnly, serverOnly);
+ exp_sidewaysintpr(interval, clientOnly, serverOnly);
} else {
if (extra_output != 0)
exp_intpr(clientOnly, serverOnly);
@@ -220,441 +185,160 @@ main(int argc, char **argv)
}
/*
- * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
- * for dead ones.
- */
-static void
-readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
-{
- union {
- struct nfsstats client;
- struct nfsrvstats server;
- } zerostat;
- size_t buflen;
-
- if (deadkernel) {
- if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
- *stp, sizeof(struct nfsstats)) < 0) {
- *stp = NULL;
- }
- if (*srvstp != NULL && kvm_read(kd,
- (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
- sizeof(struct nfsrvstats)) < 0) {
- *srvstp = NULL;
- }
- } else {
- if (zero)
- bzero(&zerostat, sizeof(zerostat));
- buflen = sizeof(struct nfsstats);
- if (*stp != NULL && sysctlbyname("vfs.oldnfs.nfsstats", *stp,
- &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
- if (errno != ENOENT)
- err(1, "sysctl: vfs.oldnfs.nfsstats");
- *stp = NULL;
- }
- buflen = sizeof(struct nfsrvstats);
- if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
- *srvstp, &buflen, zero ? &zerostat : NULL,
- zero ? buflen : 0) < 0) {
- if (errno != ENOENT)
- err(1, "sysctl: vfs.nfsrv.nfsrvstats");
- *srvstp = NULL;
- }
- }
-}
-
-/*
* Print a description of the nfs stats.
*/
-void
+static void
intpr(int clientOnly, int serverOnly)
{
- struct nfsstats nfsstats, *nfsstatsp;
- struct nfsrvstats nfsrvstats, *nfsrvstatsp;
int nfssvc_flag;
- if (run_v4 == 0) {
- /*
- * Only read the stats we are going to display to avoid zeroing
- * stats the user didn't request.
- */
- if (clientOnly)
- nfsstatsp = &nfsstats;
- else
- nfsstatsp = NULL;
- if (serverOnly)
- nfsrvstatsp = &nfsrvstats;
- else
- nfsrvstatsp = NULL;
-
- readstats(&nfsstatsp, &nfsrvstatsp, zflag);
-
- if (clientOnly && !nfsstatsp) {
- printf("Client not present!\n");
- clientOnly = 0;
- }
- } else {
- nfssvc_flag = NFSSVC_GETSTATS;
- if (zflag != 0) {
- if (clientOnly != 0)
- nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
- if (serverOnly != 0)
- nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
- }
- if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
- err(1, "Can't get stats");
+ nfssvc_flag = NFSSVC_GETSTATS;
+ if (zflag != 0) {
+ if (clientOnly != 0)
+ nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
+ if (serverOnly != 0)
+ nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
}
+ if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
+ err(1, "Can't get stats");
if (clientOnly) {
printf("Client Info:\n");
printf("Rpc Counts:\n");
printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
"Getattr", "Setattr", "Lookup", "Readlink", "Read",
"Write", "Create", "Remove");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- nfsstats.rpccnt[NFSPROC_GETATTR],
- nfsstats.rpccnt[NFSPROC_SETATTR],
- nfsstats.rpccnt[NFSPROC_LOOKUP],
- nfsstats.rpccnt[NFSPROC_READLINK],
- nfsstats.rpccnt[NFSPROC_READ],
- nfsstats.rpccnt[NFSPROC_WRITE],
- nfsstats.rpccnt[NFSPROC_CREATE],
- nfsstats.rpccnt[NFSPROC_REMOVE]);
- else
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- ext_nfsstats.rpccnt[NFSPROC_GETATTR],
- ext_nfsstats.rpccnt[NFSPROC_SETATTR],
- ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
- ext_nfsstats.rpccnt[NFSPROC_READLINK],
- ext_nfsstats.rpccnt[NFSPROC_READ],
- ext_nfsstats.rpccnt[NFSPROC_WRITE],
- ext_nfsstats.rpccnt[NFSPROC_CREATE],
- ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
+ printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+ ext_nfsstats.rpccnt[NFSPROC_GETATTR],
+ ext_nfsstats.rpccnt[NFSPROC_SETATTR],
+ ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
+ ext_nfsstats.rpccnt[NFSPROC_READLINK],
+ ext_nfsstats.rpccnt[NFSPROC_READ],
+ ext_nfsstats.rpccnt[NFSPROC_WRITE],
+ ext_nfsstats.rpccnt[NFSPROC_CREATE],
+ ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
"Rename", "Link", "Symlink", "Mkdir", "Rmdir",
"Readdir", "RdirPlus", "Access");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- nfsstats.rpccnt[NFSPROC_RENAME],
- nfsstats.rpccnt[NFSPROC_LINK],
- nfsstats.rpccnt[NFSPROC_SYMLINK],
- nfsstats.rpccnt[NFSPROC_MKDIR],
- nfsstats.rpccnt[NFSPROC_RMDIR],
- nfsstats.rpccnt[NFSPROC_READDIR],
- nfsstats.rpccnt[NFSPROC_READDIRPLUS],
- nfsstats.rpccnt[NFSPROC_ACCESS]);
- else
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- ext_nfsstats.rpccnt[NFSPROC_RENAME],
- ext_nfsstats.rpccnt[NFSPROC_LINK],
- ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
- ext_nfsstats.rpccnt[NFSPROC_MKDIR],
- ext_nfsstats.rpccnt[NFSPROC_RMDIR],
- ext_nfsstats.rpccnt[NFSPROC_READDIR],
- ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
- ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
+ printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+ ext_nfsstats.rpccnt[NFSPROC_RENAME],
+ ext_nfsstats.rpccnt[NFSPROC_LINK],
+ ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
+ ext_nfsstats.rpccnt[NFSPROC_MKDIR],
+ ext_nfsstats.rpccnt[NFSPROC_RMDIR],
+ ext_nfsstats.rpccnt[NFSPROC_READDIR],
+ ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
+ ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
"Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d\n",
- nfsstats.rpccnt[NFSPROC_MKNOD],
- nfsstats.rpccnt[NFSPROC_FSSTAT],
- nfsstats.rpccnt[NFSPROC_FSINFO],
- nfsstats.rpccnt[NFSPROC_PATHCONF],
- nfsstats.rpccnt[NFSPROC_COMMIT]);
- else
- printf("%9d %9d %9d %9d %9d\n",
- ext_nfsstats.rpccnt[NFSPROC_MKNOD],
- ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
- ext_nfsstats.rpccnt[NFSPROC_FSINFO],
- ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
- ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
+ printf("%9d %9d %9d %9d %9d\n",
+ ext_nfsstats.rpccnt[NFSPROC_MKNOD],
+ ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
+ ext_nfsstats.rpccnt[NFSPROC_FSINFO],
+ ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
+ ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
printf("Rpc Info:\n");
printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
"TimedOut", "Invalid", "X Replies", "Retries",
"Requests");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d\n",
- nfsstats.rpctimeouts,
- nfsstats.rpcinvalid,
- nfsstats.rpcunexpected,
- nfsstats.rpcretries,
- nfsstats.rpcrequests);
- else
- printf("%9d %9d %9d %9d %9d\n",
- ext_nfsstats.rpctimeouts,
- ext_nfsstats.rpcinvalid,
- ext_nfsstats.rpcunexpected,
- ext_nfsstats.rpcretries,
- ext_nfsstats.rpcrequests);
+ printf("%9d %9d %9d %9d %9d\n",
+ ext_nfsstats.rpctimeouts,
+ ext_nfsstats.rpcinvalid,
+ ext_nfsstats.rpcunexpected,
+ ext_nfsstats.rpcretries,
+ ext_nfsstats.rpcrequests);
printf("Cache Info:\n");
printf("%9.9s %9.9s %9.9s %9.9s",
"Attr Hits", "Misses", "Lkup Hits", "Misses");
printf(" %9.9s %9.9s %9.9s %9.9s\n",
"BioR Hits", "Misses", "BioW Hits", "Misses");
- if (run_v4 == 0) {
- printf("%9d %9d %9d %9d",
- nfsstats.attrcache_hits,
- nfsstats.attrcache_misses,
- nfsstats.lookupcache_hits,
- nfsstats.lookupcache_misses);
- printf(" %9d %9d %9d %9d\n",
- nfsstats.biocache_reads-nfsstats.read_bios,
- nfsstats.read_bios,
- nfsstats.biocache_writes-nfsstats.write_bios,
- nfsstats.write_bios);
- } else {
- printf("%9d %9d %9d %9d",
- ext_nfsstats.attrcache_hits,
- ext_nfsstats.attrcache_misses,
- ext_nfsstats.lookupcache_hits,
- ext_nfsstats.lookupcache_misses);
- printf(" %9d %9d %9d %9d\n",
- ext_nfsstats.biocache_reads -
- ext_nfsstats.read_bios,
- ext_nfsstats.read_bios,
- ext_nfsstats.biocache_writes -
- ext_nfsstats.write_bios,
- ext_nfsstats.write_bios);
- }
+ printf("%9d %9d %9d %9d",
+ ext_nfsstats.attrcache_hits,
+ ext_nfsstats.attrcache_misses,
+ ext_nfsstats.lookupcache_hits,
+ ext_nfsstats.lookupcache_misses);
+ printf(" %9d %9d %9d %9d\n",
+ ext_nfsstats.biocache_reads -
+ ext_nfsstats.read_bios,
+ ext_nfsstats.read_bios,
+ ext_nfsstats.biocache_writes -
+ ext_nfsstats.write_bios,
+ ext_nfsstats.write_bios);
printf("%9.9s %9.9s %9.9s %9.9s",
"BioRLHits", "Misses", "BioD Hits", "Misses");
printf(" %9.9s %9.9s %9.9s %9.9s\n", "DirE Hits", "Misses", "Accs Hits", "Misses");
- if (run_v4 == 0) {
- printf("%9d %9d %9d %9d",
- nfsstats.biocache_readlinks -
- nfsstats.readlink_bios,
- nfsstats.readlink_bios,
- nfsstats.biocache_readdirs -
- nfsstats.readdir_bios,
- nfsstats.readdir_bios);
- printf(" %9d %9d %9d %9d\n",
- nfsstats.direofcache_hits,
- nfsstats.direofcache_misses,
- nfsstats.accesscache_hits,
- nfsstats.accesscache_misses);
- } else {
- printf("%9d %9d %9d %9d",
- ext_nfsstats.biocache_readlinks -
- ext_nfsstats.readlink_bios,
- ext_nfsstats.readlink_bios,
- ext_nfsstats.biocache_readdirs -
- ext_nfsstats.readdir_bios,
- ext_nfsstats.readdir_bios);
- printf(" %9d %9d %9d %9d\n",
- ext_nfsstats.direofcache_hits,
- ext_nfsstats.direofcache_misses,
- ext_nfsstats.accesscache_hits,
- ext_nfsstats.accesscache_misses);
- }
- }
- if (run_v4 == 0 && serverOnly && !nfsrvstatsp) {
- printf("Server not present!\n");
- serverOnly = 0;
+ printf("%9d %9d %9d %9d",
+ ext_nfsstats.biocache_readlinks -
+ ext_nfsstats.readlink_bios,
+ ext_nfsstats.readlink_bios,
+ ext_nfsstats.biocache_readdirs -
+ ext_nfsstats.readdir_bios,
+ ext_nfsstats.readdir_bios);
+ printf(" %9d %9d %9d %9d\n",
+ ext_nfsstats.direofcache_hits,
+ ext_nfsstats.direofcache_misses,
+ ext_nfsstats.accesscache_hits,
+ ext_nfsstats.accesscache_misses);
}
if (serverOnly) {
printf("\nServer Info:\n");
printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
"Getattr", "Setattr", "Lookup", "Readlink", "Read",
"Write", "Create", "Remove");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- nfsrvstats.srvrpccnt[NFSPROC_GETATTR],
- nfsrvstats.srvrpccnt[NFSPROC_SETATTR],
- nfsrvstats.srvrpccnt[NFSPROC_LOOKUP],
- nfsrvstats.srvrpccnt[NFSPROC_READLINK],
- nfsrvstats.srvrpccnt[NFSPROC_READ],
- nfsrvstats.srvrpccnt[NFSPROC_WRITE],
- nfsrvstats.srvrpccnt[NFSPROC_CREATE],
- nfsrvstats.srvrpccnt[NFSPROC_REMOVE]);
- else
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
- ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
- ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
- ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
- ext_nfsstats.srvrpccnt[NFSV4OP_READ],
- ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
- ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
- ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
+ printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+ ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
+ ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
+ ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
+ ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
+ ext_nfsstats.srvrpccnt[NFSV4OP_READ],
+ ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
+ ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
+ ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
"Rename", "Link", "Symlink", "Mkdir", "Rmdir",
"Readdir", "RdirPlus", "Access");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- nfsrvstats.srvrpccnt[NFSPROC_RENAME],
- nfsrvstats.srvrpccnt[NFSPROC_LINK],
- nfsrvstats.srvrpccnt[NFSPROC_SYMLINK],
- nfsrvstats.srvrpccnt[NFSPROC_MKDIR],
- nfsrvstats.srvrpccnt[NFSPROC_RMDIR],
- nfsrvstats.srvrpccnt[NFSPROC_READDIR],
- nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS],
- nfsrvstats.srvrpccnt[NFSPROC_ACCESS]);
- else
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
- ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
- ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
- ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
- ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
- ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
- ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
- ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
- ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
+ printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+ ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
+ ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
+ ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
+ ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
+ ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
+ ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
+ ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
+ ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
"Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d %9d\n",
- nfsrvstats.srvrpccnt[NFSPROC_MKNOD],
- nfsrvstats.srvrpccnt[NFSPROC_FSSTAT],
- nfsrvstats.srvrpccnt[NFSPROC_FSINFO],
- nfsrvstats.srvrpccnt[NFSPROC_PATHCONF],
- nfsrvstats.srvrpccnt[NFSPROC_COMMIT]);
- else
- printf("%9d %9d %9d %9d %9d\n",
- ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
- ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
- ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
- ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
- ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
+ printf("%9d %9d %9d %9d %9d\n",
+ ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
+ ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
+ ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
+ ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
+ ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
printf("Server Ret-Failed\n");
- if (run_v4 == 0)
- printf("%17d\n", nfsrvstats.srvrpc_errs);
- else
- printf("%17d\n", ext_nfsstats.srvrpc_errs);
+ printf("%17d\n", ext_nfsstats.srvrpc_errs);
printf("Server Faults\n");
- if (run_v4 == 0)
- printf("%13d\n", nfsrvstats.srv_errs);
- else
- printf("%13d\n", ext_nfsstats.srv_errs);
+ printf("%13d\n", ext_nfsstats.srv_errs);
printf("Server Cache Stats:\n");
printf("%9.9s %9.9s %9.9s %9.9s\n",
"Inprog", "Idem", "Non-idem", "Misses");
- if (run_v4 == 0)
- printf("%9d %9d %9d %9d\n",
- nfsrvstats.srvcache_inproghits,
- nfsrvstats.srvcache_idemdonehits,
- nfsrvstats.srvcache_nonidemdonehits,
- nfsrvstats.srvcache_misses);
- else
- printf("%9d %9d %9d %9d\n",
- ext_nfsstats.srvcache_inproghits,
- ext_nfsstats.srvcache_idemdonehits,
- ext_nfsstats.srvcache_nonidemdonehits,
- ext_nfsstats.srvcache_misses);
+ printf("%9d %9d %9d %9d\n",
+ ext_nfsstats.srvcache_inproghits,
+ ext_nfsstats.srvcache_idemdonehits,
+ ext_nfsstats.srvcache_nonidemdonehits,
+ ext_nfsstats.srvcache_misses);
printf("Server Write Gathering:\n");
printf("%9.9s %9.9s %9.9s\n",
"WriteOps", "WriteRPC", "Opsaved");
- if (run_v4 == 0)
- printf("%9d %9d %9d\n",
- nfsrvstats.srvvop_writes,
- nfsrvstats.srvrpccnt[NFSPROC_WRITE],
- nfsrvstats.srvrpccnt[NFSPROC_WRITE] -
- nfsrvstats.srvvop_writes);
- else
- /*
- * The new client doesn't do write gathering. It was
- * only useful for NFSv2.
- */
- printf("%9d %9d %9d\n",
- ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
- ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
- }
-}
-
-u_char signalled; /* set if alarm goes off "early" */
-
-/*
- * Print a running summary of nfs statistics.
- * Repeat display every interval seconds, showing statistics
- * collected over that interval. Assumes that interval is non-zero.
- * First line printed at top of screen is always cumulative.
- */
-void
-sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
-{
- struct nfsstats nfsstats, lastst, *nfsstatsp;
- struct nfsrvstats nfsrvstats, lastsrvst, *nfsrvstatsp;
- int hdrcnt = 1;
-
- nfsstatsp = &lastst;
- nfsrvstatsp = &lastsrvst;
- readstats(&nfsstatsp, &nfsrvstatsp, 0);
- if (clientOnly && !nfsstatsp) {
- printf("Client not present!\n");
- clientOnly = 0;
- }
- if (serverOnly && !nfsrvstatsp) {
- printf("Server not present!\n");
- serverOnly = 0;
- }
- sleep(interval);
-
- for (;;) {
- nfsstatsp = &nfsstats;
- nfsrvstatsp = &nfsrvstats;
- readstats(&nfsstatsp, &nfsrvstatsp, 0);
-
- if (--hdrcnt == 0) {
- printhdr(clientOnly, serverOnly);
- if (clientOnly && serverOnly)
- hdrcnt = 10;
- else
- hdrcnt = 20;
- }
- if (clientOnly) {
- printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
- ((clientOnly && serverOnly) ? "Client:" : ""),
- DELTA(rpccnt[NFSPROC_GETATTR]),
- DELTA(rpccnt[NFSPROC_LOOKUP]),
- DELTA(rpccnt[NFSPROC_READLINK]),
- DELTA(rpccnt[NFSPROC_READ]),
- DELTA(rpccnt[NFSPROC_WRITE]),
- DELTA(rpccnt[NFSPROC_RENAME]),
- DELTA(rpccnt[NFSPROC_ACCESS]),
- DELTA(rpccnt[NFSPROC_READDIR]) +
- DELTA(rpccnt[NFSPROC_READDIRPLUS])
- );
- if (widemode) {
- printf(" %s %s %s %s %s %s",
- sperc1(DELTA(attrcache_hits),
- DELTA(attrcache_misses)),
- sperc1(DELTA(lookupcache_hits),
- DELTA(lookupcache_misses)),
- sperc2(DELTA(biocache_reads),
- DELTA(read_bios)),
- sperc2(DELTA(biocache_writes),
- DELTA(write_bios)),
- sperc1(DELTA(accesscache_hits),
- DELTA(accesscache_misses)),
- sperc2(DELTA(biocache_readdirs),
- DELTA(readdir_bios))
- );
- }
- printf("\n");
- lastst = nfsstats;
- }
- if (serverOnly) {
- printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
- ((clientOnly && serverOnly) ? "Server:" : ""),
- nfsrvstats.srvrpccnt[NFSPROC_GETATTR]-lastsrvst.srvrpccnt[NFSPROC_GETATTR],
- nfsrvstats.srvrpccnt[NFSPROC_LOOKUP]-lastsrvst.srvrpccnt[NFSPROC_LOOKUP],
- nfsrvstats.srvrpccnt[NFSPROC_READLINK]-lastsrvst.srvrpccnt[NFSPROC_READLINK],
- nfsrvstats.srvrpccnt[NFSPROC_READ]-lastsrvst.srvrpccnt[NFSPROC_READ],
- nfsrvstats.srvrpccnt[NFSPROC_WRITE]-lastsrvst.srvrpccnt[NFSPROC_WRITE],
- nfsrvstats.srvrpccnt[NFSPROC_RENAME]-lastsrvst.srvrpccnt[NFSPROC_RENAME],
- nfsrvstats.srvrpccnt[NFSPROC_ACCESS]-lastsrvst.srvrpccnt[NFSPROC_ACCESS],
- (nfsrvstats.srvrpccnt[NFSPROC_READDIR]-lastsrvst.srvrpccnt[NFSPROC_READDIR])
- +(nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS]-lastsrvst.srvrpccnt[NFSPROC_READDIRPLUS]));
- printf("\n");
- lastsrvst = nfsrvstats;
- }
- fflush(stdout);
- sleep(interval);
+ /*
+ * The new client doesn't do write gathering. It was
+ * only useful for NFSv2.
+ */
+ printf("%9d %9d %9d\n",
+ ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
+ ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
}
- /*NOTREACHED*/
}
-void
+static void
printhdr(int clientOnly, int serverOnly)
{
printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
@@ -668,18 +352,18 @@ printhdr(int clientOnly, int serverOnly)
fflush(stdout);
}
-void
+static void
usage(void)
{
(void)fprintf(stderr,
- "usage: nfsstat [-cemoszW] [-M core] [-N system] [-w wait]\n");
+ "usage: nfsstat [-cemszW] [-M core] [-N system] [-w wait]\n");
exit(1);
}
static char SPBuf[64][8];
static int SPIndex;
-char *
+static char *
sperc1(int hits, int misses)
{
char *p = SPBuf[SPIndex];
@@ -694,7 +378,7 @@ sperc1(int hits, int misses)
return(p);
}
-char *
+static char *
sperc2(int ttl, int misses)
{
char *p = SPBuf[SPIndex];
@@ -712,7 +396,7 @@ sperc2(int ttl, int misses)
/*
* Print a description of the nfs stats for the experimental client/server.
*/
-void
+static void
exp_intpr(int clientOnly, int serverOnly)
{
int nfssvc_flag;
@@ -968,7 +652,7 @@ exp_intpr(int clientOnly, int serverOnly)
* collected over that interval. Assumes that interval is non-zero.
* First line printed at top of screen is always cumulative.
*/
-void
+static void
exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
{
struct ext_nfsstats nfsstats, lastst, *ext_nfsstatsp;
@@ -1042,4 +726,3 @@ exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
}
/*NOTREACHED*/
}
-
diff --git a/usr.bin/nm/Makefile b/usr.bin/nm/Makefile
new file mode 100644
index 0000000..5078e10
--- /dev/null
+++ b/usr.bin/nm/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+NMDIR= ${ELFTCDIR}/nm
+
+.PATH: ${NMDIR}
+
+PROG= nm
+
+LIBADD= dwarf elftc elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/opieinfo/Makefile b/usr.bin/opieinfo/Makefile
index b3ba166..f386be2 100644
--- a/usr.bin/opieinfo/Makefile
+++ b/usr.bin/opieinfo/Makefile
@@ -10,8 +10,7 @@ CFLAGS+=-DINSECURE_OVERRIDE
WARNS?= 0
-DPADD= ${LIBOPIE} ${LIBMD}
-LDADD= -lopie -lmd
+LIBADD= opie
BINOWN= root
BINMODE=4555
diff --git a/usr.bin/opiekey/Makefile b/usr.bin/opiekey/Makefile
index 0ee8570..95ae8b3 100644
--- a/usr.bin/opiekey/Makefile
+++ b/usr.bin/opiekey/Makefile
@@ -10,8 +10,7 @@ CFLAGS+=-DINSECURE_OVERRIDE
WARNS?= 0
-DPADD= ${LIBOPIE} ${LIBMD}
-LDADD= -lopie -lmd
+LIBADD= opie
LINKS= ${BINDIR}/opiekey ${BINDIR}/otp-md4
LINKS+= ${BINDIR}/opiekey ${BINDIR}/otp-md5
diff --git a/usr.bin/opiepasswd/Makefile b/usr.bin/opiepasswd/Makefile
index b05e3b2..7b3f1f2 100644
--- a/usr.bin/opiepasswd/Makefile
+++ b/usr.bin/opiepasswd/Makefile
@@ -10,8 +10,7 @@ CFLAGS+=-DINSECURE_OVERRIDE
WARNS?= 0
-DPADD= ${LIBOPIE} ${LIBMD}
-LDADD= -lopie -lmd
+LIBADD= opie
BINOWN= root
BINMODE=4555
diff --git a/usr.bin/pamtest/Makefile b/usr.bin/pamtest/Makefile
index 1968300..289beb6 100644
--- a/usr.bin/pamtest/Makefile
+++ b/usr.bin/pamtest/Makefile
@@ -5,7 +5,7 @@ OPENPAM= ${.CURDIR}/../../contrib/openpam
PROG= pamtest
SRCS= pamtest.c
-DPADD= ${LIBPAM}
-LDADD= ${MINUSLPAM}
+
+LIBADD= pam
.include <bsd.prog.mk>
diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile
index 3e6dc93..f1fff46 100644
--- a/usr.bin/passwd/Makefile
+++ b/usr.bin/passwd/Makefile
@@ -6,8 +6,7 @@
PROG = passwd
BINOWN = root
BINMODE = 4555
-DPADD = ${LIBPAM}
-LDADD = ${MINUSLPAM}
+LIBADD = pam
.if ${MK_NIS} != "no"
LINKS = ${BINDIR}/passwd ${BINDIR}/yppasswd
MLINKS = passwd.1 yppasswd.1
diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h
index a6da179..8963c83 100644
--- a/usr.bin/patch/common.h
+++ b/usr.bin/patch/common.h
@@ -40,6 +40,7 @@
#define INITHUNKMAX 125 /* initial dynamic allocation size */
#define INITLINELEN 4096
#define BUFFERSIZE 4096
+#define LINENUM_MAX LONG_MAX
#define SCCSPREFIX "s."
#define GET "get -e %s"
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 54b0bf2..826f85b 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -34,8 +34,8 @@
#include <ctype.h>
#include <libgen.h>
-#include <limits.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -57,8 +57,9 @@ static char empty_line[] = { '\0' };
static int tifd = -1; /* plan b virtual string array */
static char *tibuf[2]; /* plan b buffers */
static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */
-static LINENUM lines_per_buf; /* how many lines per buffer */
-static int tireclen; /* length of records in tmp file */
+static size_t lines_per_buf; /* how many lines per buffer */
+static size_t tibuflen; /* plan b buffer length */
+static size_t tireclen; /* length of records in tmp file */
static bool rev_in_string(const char *);
static bool reallocate_lines(size_t *);
@@ -319,7 +320,7 @@ plan_a(const char *filename)
/* now check for revision, if any */
if (revision != NULL) {
- if (!rev_in_string(i_womp)) {
+ if (i_womp == NULL || !rev_in_string(i_womp)) {
if (force) {
if (verbose)
say("Warning: this file doesn't appear "
@@ -349,8 +350,8 @@ static void
plan_b(const char *filename)
{
FILE *ifp;
- size_t i = 0, j, maxlen = 1;
- char *p;
+ size_t i = 0, j, len, maxlen = 1;
+ char *lbuf = NULL, *p;
bool found_revision = (revision == NULL);
using_plan_a = false;
@@ -359,15 +360,28 @@ plan_b(const char *filename)
unlink(TMPINNAME);
if ((tifd = open(TMPINNAME, O_EXCL | O_CREAT | O_WRONLY, 0666)) < 0)
pfatal("can't open file %s", TMPINNAME);
- while (fgets(buf, buf_size, ifp) != NULL) {
- if (revision != NULL && !found_revision && rev_in_string(buf))
+ while ((p = fgetln(ifp, &len)) != NULL) {
+ if (p[len - 1] == '\n')
+ p[len - 1] = '\0';
+ else {
+ /* EOF without EOL, copy and add the NUL */
+ if ((lbuf = malloc(len + 1)) == NULL)
+ fatal("out of memory\n");
+ memcpy(lbuf, p, len);
+ lbuf[len] = '\0';
+ p = lbuf;
+
+ last_line_missing_eol = true;
+ len++;
+ }
+ if (revision != NULL && !found_revision && rev_in_string(p))
found_revision = true;
- if ((i = strlen(buf)) > maxlen)
- maxlen = i; /* find longest line */
+ if (len > maxlen)
+ maxlen = len; /* find longest line */
}
- last_line_missing_eol = i > 0 && buf[i - 1] != '\n';
- if (last_line_missing_eol && maxlen == i)
- maxlen++;
+ free(lbuf);
+ if (ferror(ifp))
+ pfatal("can't read file %s", filename);
if (revision != NULL) {
if (!found_revision) {
@@ -392,23 +406,26 @@ plan_b(const char *filename)
revision);
}
fseek(ifp, 0L, SEEK_SET); /* rewind file */
- lines_per_buf = BUFFERSIZE / maxlen;
tireclen = maxlen;
- tibuf[0] = malloc(BUFFERSIZE + 1);
+ tibuflen = maxlen > BUFFERSIZE ? maxlen : BUFFERSIZE;
+ lines_per_buf = tibuflen / maxlen;
+ tibuf[0] = malloc(tibuflen + 1);
if (tibuf[0] == NULL)
fatal("out of memory\n");
- tibuf[1] = malloc(BUFFERSIZE + 1);
+ tibuf[1] = malloc(tibuflen + 1);
if (tibuf[1] == NULL)
fatal("out of memory\n");
for (i = 1;; i++) {
p = tibuf[0] + maxlen * (i % lines_per_buf);
if (i % lines_per_buf == 0) /* new block */
- if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
+ if (write(tifd, tibuf[0], tibuflen) !=
+ (ssize_t) tibuflen)
pfatal("can't write temp file");
if (fgets(p, maxlen + 1, ifp) == NULL) {
input_lines = i - 1;
if (i % lines_per_buf != 0)
- if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
+ if (write(tifd, tibuf[0], tibuflen) !=
+ (ssize_t) tibuflen)
pfatal("can't write temp file");
break;
}
@@ -450,10 +467,11 @@ ifetch(LINENUM line, int whichbuf)
tiline[whichbuf] = baseline;
if (lseek(tifd, (off_t) (baseline / lines_per_buf *
- BUFFERSIZE), SEEK_SET) < 0)
+ tibuflen), SEEK_SET) < 0)
pfatal("cannot seek in the temporary input file");
- if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
+ if (read(tifd, tibuf[whichbuf], tibuflen) !=
+ (ssize_t) tibuflen)
pfatal("error reading tmp file %s", TMPINNAME);
}
return tibuf[whichbuf] + (tireclen * offline);
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 85daf7f..22f3027 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -23,7 +23,7 @@
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
* behaviour
*
- * $OpenBSD: patch.c,v 1.50 2012/05/15 19:32:02 millert Exp $
+ * $OpenBSD: patch.c,v 1.54 2014/12/13 10:31:07 tobias Exp $
* $FreeBSD$
*
*/
@@ -150,8 +150,8 @@ main(int argc, char *argv[])
const char *tmpdir;
char *v;
- setlinebuf(stdout);
- setlinebuf(stderr);
+ setvbuf(stdout, NULL, _IOLBF, 0);
+ setvbuf(stderr, NULL, _IOLBF, 0);
for (i = 0; i < MAXFILEC; i++)
filearg[i] = NULL;
@@ -215,13 +215,13 @@ main(int argc, char *argv[])
for (open_patch_file(filearg[1]); there_is_another_patch();
reinitialize_almost_everything()) {
/* for each patch in patch file */
-
+
patch_seen = true;
warn_on_invalid_line = true;
if (outname == NULL)
- outname = savestr(filearg[0]);
+ outname = xstrdup(filearg[0]);
/* for ed script just up and do it and exit */
if (diff_type == ED_DIFF) {
@@ -416,7 +416,7 @@ main(int argc, char *argv[])
}
set_signals(1);
}
-
+
if (!patch_seen)
error = 2;
@@ -514,10 +514,10 @@ get_some_switches(void)
/* FALLTHROUGH */
case 'z':
/* must directly follow 'b' case for backwards compat */
- simple_backup_suffix = savestr(optarg);
+ simple_backup_suffix = xstrdup(optarg);
break;
case 'B':
- origprae = savestr(optarg);
+ origprae = xstrdup(optarg);
break;
case 'c':
diff_type = CONTEXT_DIFF;
@@ -555,7 +555,7 @@ get_some_switches(void)
case 'i':
if (++filec == MAXFILEC)
fatal("too many file arguments\n");
- filearg[filec] = savestr(optarg);
+ filearg[filec] = xstrdup(optarg);
break;
case 'l':
canonicalize = true;
@@ -567,7 +567,7 @@ get_some_switches(void)
noreverse = true;
break;
case 'o':
- outname = savestr(optarg);
+ outname = xstrdup(optarg);
break;
case 'p':
strippath = atoi(optarg);
@@ -611,12 +611,12 @@ get_some_switches(void)
Argv += optind;
if (Argc > 0) {
- filearg[0] = savestr(*Argv++);
+ filearg[0] = xstrdup(*Argv++);
Argc--;
while (Argc > 0) {
if (++filec == MAXFILEC)
fatal("too many file arguments\n");
- filearg[filec] = savestr(*Argv++);
+ filearg[filec] = xstrdup(*Argv++);
Argc--;
}
}
@@ -634,7 +634,7 @@ usage(void)
" [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
" [--posix] [origfile [patchfile]]\n"
" patch <patchfile\n");
- my_exit(EXIT_SUCCESS);
+ my_exit(EXIT_FAILURE);
}
/*
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index d9c4b3d..e731ca1 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -24,7 +24,7 @@
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
* behaviour
*
- * $OpenBSD: pch.c,v 1.39 2012/04/11 08:07:13 ajacoutot Exp $
+ * $OpenBSD: pch.c,v 1.43 2014/11/18 17:03:35 tobias Exp $
* $FreeBSD$
*/
@@ -34,6 +34,7 @@
#include <ctype.h>
#include <libgen.h>
#include <limits.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -46,7 +47,7 @@
/* Patch (diff listing) abstract type. */
-static long p_filesize; /* size of the patch file */
+static off_t p_filesize; /* size of the patch file */
static LINENUM p_first; /* 1st line number */
static LINENUM p_newfirst; /* 1st line number of replacement */
static LINENUM p_ptrn_lines; /* # lines in pattern */
@@ -60,9 +61,9 @@ static unsigned short *p_len = NULL; /* length of each line */
static char *p_char = NULL; /* +, -, and ! */
static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */
static int p_indent; /* indent to patch */
-static LINENUM p_base; /* where to intuit this time */
+static off_t p_base; /* where to intuit this time */
static LINENUM p_bline; /* line # of p_base */
-static LINENUM p_start; /* where intuit found a patch */
+static off_t p_start; /* where intuit found a patch */
static LINENUM p_sline; /* and the line number for it */
static LINENUM p_hunk_beg; /* line number of current hunk */
static LINENUM p_efake = -1; /* end of faked up lines--don't free */
@@ -72,12 +73,13 @@ static char *bestguess = NULL; /* guess at correct filename */
static void grow_hunkmax(void);
static int intuit_diff_type(void);
-static void next_intuit_at(LINENUM, LINENUM);
-static void skip_to(LINENUM, LINENUM);
+static void next_intuit_at(off_t, LINENUM);
+static void skip_to(off_t, LINENUM);
static size_t pgets(bool _do_indent);
static char *best_name(const struct file_name *, bool);
static char *posix_name(const struct file_name *, bool);
static size_t num_components(const char *);
+static LINENUM strtolinenum(char *, char **);
/*
* Prepare to look for the next patch in the patch file.
@@ -119,9 +121,10 @@ open_patch_file(const char *filename)
pfp = fopen(filename, "r");
if (pfp == NULL)
pfatal("patch file %s not found", filename);
- fstat(fileno(pfp), &filestat);
+ if (fstat(fileno(pfp), &filestat))
+ pfatal("can't stat %s", filename);
p_filesize = filestat.st_size;
- next_intuit_at(0L, 1L); /* start at the beginning */
+ next_intuit_at(0, 1L); /* start at the beginning */
set_hunkmax();
}
@@ -172,7 +175,7 @@ there_is_another_patch(void)
{
bool exists = false;
- if (p_base != 0L && p_base >= p_filesize) {
+ if (p_base != 0 && p_base >= p_filesize) {
if (verbose)
say("done\n");
return false;
@@ -181,7 +184,7 @@ there_is_another_patch(void)
say("Hmm...");
diff_type = intuit_diff_type();
if (!diff_type) {
- if (p_base != 0L) {
+ if (p_base != 0) {
if (verbose)
say(" Ignoring the trailing garbage.\ndone\n");
} else
@@ -190,7 +193,7 @@ there_is_another_patch(void)
}
if (verbose)
say(" %sooks like %s to me...\n",
- (p_base == 0L ? "L" : "The next patch l"),
+ (p_base == 0 ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
@@ -203,14 +206,14 @@ there_is_another_patch(void)
while (filearg[0] == NULL) {
if (force || batch) {
say("No file to patch. Skipping...\n");
- filearg[0] = savestr(bestguess);
+ filearg[0] = xstrdup(bestguess);
skip_rest_of_patch = true;
return true;
}
ask("File to patch: ");
if (*buf != '\n') {
free(bestguess);
- bestguess = savestr(buf);
+ bestguess = xstrdup(buf);
filearg[0] = fetchname(buf, &exists, 0);
}
if (!exists) {
@@ -252,8 +255,8 @@ p4_fetchname(struct file_name *name, char *str)
static int
intuit_diff_type(void)
{
- long this_line = 0, previous_line;
- long first_command_line = -1;
+ off_t this_line = 0, previous_line;
+ off_t first_command_line = -1;
LINENUM fcl_line = -1;
bool last_line_was_command = false, this_is_a_command = false;
bool stars_last_line = false, stars_this_line = false;
@@ -263,17 +266,17 @@ intuit_diff_type(void)
memset(names, 0, sizeof(names));
ok_to_create_file = false;
- fseek(pfp, p_base, SEEK_SET);
+ fseeko(pfp, p_base, SEEK_SET);
p_input_line = p_bline - 1;
for (;;) {
previous_line = this_line;
last_line_was_command = this_is_a_command;
stars_last_line = stars_this_line;
- this_line = ftell(pfp);
+ this_line = ftello(pfp);
indent = 0;
p_input_line++;
if (pgets(false) == 0) {
- if (first_command_line >= 0L) {
+ if (first_command_line >= 0) {
/* nothing but deletes!? */
p_start = first_command_line;
p_sline = fcl_line;
@@ -296,7 +299,7 @@ intuit_diff_type(void)
;
this_is_a_command = (isdigit((unsigned char)*s) &&
(*t == 'd' || *t == 'c' || *t == 'a'));
- if (first_command_line < 0L && this_is_a_command) {
+ if (first_command_line < 0 && this_is_a_command) {
first_command_line = this_line;
fcl_line = p_input_line;
p_indent = indent; /* assume this for now */
@@ -317,8 +320,9 @@ intuit_diff_type(void)
else if (strnEQ(s, "Prereq:", 7)) {
for (t = s + 7; isspace((unsigned char)*t); t++)
;
- revision = savestr(t);
- for (t = revision; *t && !isspace((unsigned char)*t); t++)
+ revision = xstrdup(t);
+ for (t = revision;
+ *t && !isspace((unsigned char)*t); t++)
;
*t = '\0';
if (*revision == '\0') {
@@ -332,7 +336,7 @@ intuit_diff_type(void)
p4_fetchname(&names[OLD_FILE], s + 5);
}
if ((!diff_type || diff_type == ED_DIFF) &&
- first_command_line >= 0L &&
+ first_command_line >= 0 &&
strEQ(s, ".\n")) {
p_indent = indent;
p_start = first_command_line;
@@ -352,13 +356,13 @@ intuit_diff_type(void)
stars_this_line = strnEQ(s, "********", 8);
if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
strnEQ(s, "*** ", 4)) {
- if (atol(s + 4) == 0)
+ if (strtolinenum(s + 4, &s) == 0)
ok_to_create_file = true;
/*
* If this is a new context diff the character just
- * before the newline is a '*'.
+ * at the end of the line is a '*'.
*/
- while (*s != '\n')
+ while (*s && *s != '\n')
s++;
p_indent = indent;
p_start = previous_line;
@@ -400,7 +404,7 @@ scan_exit:
free(bestguess);
bestguess = NULL;
if (filearg[0] != NULL)
- bestguess = savestr(filearg[0]);
+ bestguess = xstrdup(filearg[0]);
else if (!ok_to_create_file) {
/*
* We don't want to create a new file but we need a
@@ -422,26 +426,27 @@ scan_exit:
* Remember where this patch ends so we know where to start up again.
*/
static void
-next_intuit_at(LINENUM file_pos, LINENUM file_line)
+next_intuit_at(off_t file_pos, LINENUM file_line)
{
p_base = file_pos;
p_bline = file_line;
}
/*
- * Basically a verbose fseek() to the actual diff listing.
+ * Basically a verbose fseeko() to the actual diff listing.
*/
static void
-skip_to(LINENUM file_pos, LINENUM file_line)
+skip_to(off_t file_pos, LINENUM file_line)
{
size_t len;
if (p_base > file_pos)
- fatal("Internal error: seek %ld>%ld\n", p_base, file_pos);
+ fatal("Internal error: seek %lld>%lld\n",
+ (long long)p_base, (long long)file_pos);
if (verbose && p_base < file_pos) {
- fseek(pfp, p_base, SEEK_SET);
+ fseeko(pfp, p_base, SEEK_SET);
say("The text leading up to this was:\n--------------------------\n");
- while (ftell(pfp) < file_pos) {
+ while (ftello(pfp) < file_pos) {
len = pgets(false);
if (len == 0)
fatal("Unexpected end of file\n");
@@ -449,7 +454,7 @@ skip_to(LINENUM file_pos, LINENUM file_line)
}
say("--------------------------\n");
} else
- fseek(pfp, file_pos, SEEK_SET);
+ fseeko(pfp, file_pos, SEEK_SET);
p_input_line = file_line - 1;
}
@@ -479,7 +484,7 @@ remove_special_line(void)
return true;
}
if (c != EOF)
- fseek(pfp, -1L, SEEK_CUR);
+ fseeko(pfp, -1, SEEK_CUR);
return false;
}
@@ -490,7 +495,7 @@ remove_special_line(void)
bool
another_hunk(void)
{
- long line_beginning; /* file pos of the current line */
+ off_t line_beginning; /* file pos of the current line */
LINENUM repl_beginning; /* index of --- line */
LINENUM fillcnt; /* #lines of missing ptrn or repl */
LINENUM fillsrc; /* index of first line to copy */
@@ -498,7 +503,7 @@ another_hunk(void)
bool ptrn_spaces_eaten; /* ptrn was slightly misformed */
bool repl_could_be_missing; /* no + or ! lines in this hunk */
bool repl_missing; /* we are now backtracking */
- long repl_backtrack_position; /* file pos of first repl line */
+ off_t repl_backtrack_position; /* file pos of first repl line */
LINENUM repl_patch_line; /* input line number for same */
LINENUM ptrn_copiable; /* # of copiable lines in ptrn */
char *s;
@@ -516,7 +521,7 @@ another_hunk(void)
p_max = hunkmax; /* gets reduced when --- found */
if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) {
- line_beginning = ftell(pfp);
+ line_beginning = ftello(pfp);
repl_beginning = 0;
fillcnt = 0;
fillsrc = 0;
@@ -537,7 +542,7 @@ another_hunk(void)
p_context = 100;
p_hunk_beg = p_input_line + 1;
while (p_end < p_max) {
- line_beginning = ftell(pfp);
+ line_beginning = ftello(pfp);
len = pgets(true);
p_input_line++;
if (len == 0) {
@@ -583,27 +588,32 @@ another_hunk(void)
p_end--;
return false;
}
- for (s = buf; *s && !isdigit((unsigned char)*s); s++)
+ for (s = buf;
+ *s && !isdigit((unsigned char)*s); s++)
;
if (!*s)
malformed();
if (strnEQ(s, "0,0", 3))
memmove(s, s + 2, strlen(s + 2) + 1);
- p_first = (LINENUM) atol(s);
- while (isdigit((unsigned char)*s))
- s++;
+ p_first = strtolinenum(s, &s);
if (*s == ',') {
- for (; *s && !isdigit((unsigned char)*s); s++)
+ for (;
+ *s && !isdigit((unsigned char)*s); s++)
;
if (!*s)
malformed();
- p_ptrn_lines = ((LINENUM) atol(s)) - p_first + 1;
+ p_ptrn_lines = strtolinenum(s, &s) - p_first + 1;
+ if (p_ptrn_lines < 0)
+ malformed();
} else if (p_first)
p_ptrn_lines = 1;
else {
p_ptrn_lines = 0;
p_first = 1;
}
+ if (p_first >= LINENUM_MAX - p_ptrn_lines ||
+ p_ptrn_lines >= LINENUM_MAX - 6)
+ malformed();
/* we need this much at least */
p_max = p_ptrn_lines + 6;
@@ -644,7 +654,7 @@ another_hunk(void)
}
}
repl_beginning = p_end;
- repl_backtrack_position = ftell(pfp);
+ repl_backtrack_position = ftello(pfp);
repl_patch_line = p_input_line;
p_line[p_end] = savestr(buf);
if (out_of_mem) {
@@ -656,22 +666,25 @@ another_hunk(void)
;
if (!*s)
malformed();
- p_newfirst = (LINENUM) atol(s);
- while (isdigit((unsigned char)*s))
- s++;
+ p_newfirst = strtolinenum(s, &s);
if (*s == ',') {
for (; *s && !isdigit((unsigned char)*s); s++)
;
if (!*s)
malformed();
- p_repl_lines = ((LINENUM) atol(s)) -
+ p_repl_lines = strtolinenum(s, &s) -
p_newfirst + 1;
+ if (p_repl_lines < 0)
+ malformed();
} else if (p_newfirst)
p_repl_lines = 1;
else {
p_repl_lines = 0;
p_newfirst = 1;
}
+ if (p_newfirst >= LINENUM_MAX - p_repl_lines ||
+ p_repl_lines >= LINENUM_MAX - p_end)
+ malformed();
p_max = p_repl_lines + p_end;
if (p_max > MAXHUNKSIZE)
fatal("hunk too large (%ld lines) at line %ld: %s",
@@ -690,8 +703,8 @@ another_hunk(void)
change_line:
if (buf[1] == '\n' && canonicalize)
strlcpy(buf + 1, " \n", buf_size - 1);
- if (!isspace((unsigned char)buf[1]) && buf[1] != '>' &&
- buf[1] != '<' &&
+ if (!isspace((unsigned char)buf[1]) &&
+ buf[1] != '>' && buf[1] != '<' &&
repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
@@ -776,7 +789,7 @@ hunk_done:
p_input_line = repl_patch_line;
for (p_end--; p_end > repl_beginning; p_end--)
free(p_line[p_end]);
- fseek(pfp, repl_backtrack_position, SEEK_SET);
+ fseeko(pfp, repl_backtrack_position, SEEK_SET);
/* redundant 'new' context lines were omitted - set */
/* up to fill them in from the old file context */
@@ -854,7 +867,7 @@ hunk_done:
LINENUM fillnew; /* index of new lines */
char ch;
- line_beginning = ftell(pfp); /* file pos of the current line */
+ line_beginning = ftello(pfp); /* file pos of the current line */
len = pgets(true);
p_input_line++;
if (len == 0 || strnNE(buf, "@@ -", 4)) {
@@ -864,32 +877,28 @@ hunk_done:
s = buf + 4;
if (!*s)
malformed();
- p_first = (LINENUM) atol(s);
- while (isdigit((unsigned char)*s))
- s++;
+ p_first = strtolinenum(s, &s);
if (*s == ',') {
- p_ptrn_lines = (LINENUM) atol(++s);
- while (isdigit((unsigned char)*s))
- s++;
+ p_ptrn_lines = strtolinenum(s + 1, &s);
} else
p_ptrn_lines = 1;
if (*s == ' ')
s++;
if (*s != '+' || !*++s)
malformed();
- p_newfirst = (LINENUM) atol(s);
- while (isdigit((unsigned char)*s))
- s++;
+ p_newfirst = strtolinenum(s, &s);
if (*s == ',') {
- p_repl_lines = (LINENUM) atol(++s);
- while (isdigit((unsigned char)*s))
- s++;
+ p_repl_lines = strtolinenum(s + 1, &s);
} else
p_repl_lines = 1;
if (*s == ' ')
s++;
if (*s != '@')
malformed();
+ if (p_first >= LINENUM_MAX - p_ptrn_lines ||
+ p_newfirst > LINENUM_MAX - p_repl_lines ||
+ p_ptrn_lines >= LINENUM_MAX - p_repl_lines - 1)
+ malformed();
if (!p_ptrn_lines)
p_first++; /* do append rather than insert */
p_max = p_ptrn_lines + p_repl_lines + 1;
@@ -918,7 +927,7 @@ hunk_done:
context = 0;
p_hunk_beg = p_input_line + 1;
while (fillold <= p_ptrn_lines || fillnew <= p_end) {
- line_beginning = ftell(pfp);
+ line_beginning = ftello(pfp);
len = pgets(true);
p_input_line++;
if (len == 0) {
@@ -1021,7 +1030,7 @@ hunk_done:
int i;
LINENUM min, max;
- line_beginning = ftell(pfp);
+ line_beginning = ftello(pfp);
p_context = 0;
len = pgets(true);
p_input_line++;
@@ -1029,35 +1038,36 @@ hunk_done:
next_intuit_at(line_beginning, p_input_line);
return false;
}
- p_first = (LINENUM) atol(buf);
- for (s = buf; isdigit((unsigned char)*s); s++)
- ;
+ p_first = strtolinenum(buf, &s);
if (*s == ',') {
- p_ptrn_lines = (LINENUM) atol(++s) - p_first + 1;
- while (isdigit((unsigned char)*s))
- s++;
+ p_ptrn_lines = strtolinenum(s + 1, &s) - p_first + 1;
+ if (p_ptrn_lines < 0)
+ malformed();
} else
p_ptrn_lines = (*s != 'a');
hunk_type = *s;
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
- min = (LINENUM) atol(++s);
- for (; isdigit((unsigned char)*s); s++)
- ;
+ min = strtolinenum(s + 1, &s);
if (*s == ',')
- max = (LINENUM) atol(++s);
+ max = strtolinenum(s + 1, &s);
else
max = min;
+ if (min < 0 || min > max || max - min == LINENUM_MAX)
+ malformed();
if (hunk_type == 'd')
min++;
- p_end = p_ptrn_lines + 1 + max - min + 1;
+ p_newfirst = min;
+ p_repl_lines = max - min + 1;
+ if (p_newfirst > LINENUM_MAX - p_repl_lines ||
+ p_ptrn_lines >= LINENUM_MAX - p_repl_lines - 1)
+ malformed();
+ p_end = p_ptrn_lines + p_repl_lines + 1;
if (p_end > MAXHUNKSIZE)
fatal("hunk too large (%ld lines) at line %ld: %s",
p_end, p_input_line, buf);
while (p_end >= hunkmax)
grow_hunkmax();
- p_newfirst = min;
- p_repl_lines = max - min + 1;
snprintf(buf, buf_size, "*** %ld,%ld\n", p_first,
p_first + p_ptrn_lines - 1);
p_line[0] = savestr(buf);
@@ -1398,7 +1408,7 @@ void
do_ed_script(void)
{
char *t;
- long beginning_of_this_line;
+ off_t beginning_of_this_line;
FILE *pipefp = NULL;
if (!skip_rest_of_patch) {
@@ -1411,7 +1421,7 @@ do_ed_script(void)
pipefp = popen(buf, "w");
}
for (;;) {
- beginning_of_this_line = ftell(pfp);
+ beginning_of_this_line = ftello(pfp);
if (pgets(true) == 0) {
next_intuit_at(beginning_of_this_line, p_input_line);
break;
@@ -1420,8 +1430,8 @@ do_ed_script(void)
for (t = buf; isdigit((unsigned char)*t) || *t == ','; t++)
;
/* POSIX defines allowed commands as {a,c,d,i,s} */
- if (isdigit((unsigned char)*buf) && (*t == 'a' || *t == 'c' ||
- *t == 'd' || *t == 'i' || *t == 's')) {
+ if (isdigit((unsigned char)*buf) &&
+ (*t == 'a' || *t == 'c' || *t == 'd' || *t == 'i' || *t == 's')) {
if (pipefp != NULL)
fputs(buf, pipefp);
if (*t != 'd') {
@@ -1496,7 +1506,7 @@ posix_name(const struct file_name *names, bool assume_exists)
path = names[NEW_FILE].path;
}
- return path ? savestr(path) : NULL;
+ return path ? xstrdup(path) : NULL;
}
static char *
@@ -1562,7 +1572,7 @@ best_name(const struct file_name *names, bool assume_exists)
best = names[NEW_FILE].path;
}
- return best ? savestr(best) : NULL;
+ return best ? xstrdup(best) : NULL;
}
static size_t
@@ -1577,3 +1587,36 @@ num_components(const char *path)
}
return n;
}
+
+/*
+ * Convert number at NPTR into LINENUM and save address of first
+ * character that is not a digit in ENDPTR. If conversion is not
+ * possible, call fatal.
+ */
+static LINENUM
+strtolinenum(char *nptr, char **endptr)
+{
+ LINENUM rv;
+ char c;
+ char *p;
+ const char *errstr;
+
+ for (p = nptr; isdigit((unsigned char)*p); p++)
+ ;
+
+ if (p == nptr)
+ malformed();
+
+ c = *p;
+ *p = '\0';
+
+ rv = strtonum(nptr, 0, LINENUM_MAX, &errstr);
+ if (errstr != NULL)
+ fatal("invalid line number at line %ld: `%s' is %s\n",
+ p_input_line, nptr, errstr);
+
+ *p = c;
+ *endptr = p;
+
+ return rv;
+}
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index 6980676..1859e17 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -27,13 +27,13 @@
* $FreeBSD$
*/
-#include <sys/param.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
+#include <limits.h>
#include <paths.h>
#include <signal.h>
#include <stdarg.h>
@@ -96,7 +96,7 @@ int
backup_file(const char *orig)
{
struct stat filestat;
- char bakname[MAXPATHLEN], *s, *simplename;
+ char bakname[PATH_MAX], *s, *simplename;
dev_t orig_device;
ino_t orig_inode;
@@ -202,6 +202,22 @@ savestr(const char *s)
}
/*
+ * Allocate a unique area for a string. Call fatal if out of memory.
+ */
+char *
+xstrdup(const char *s)
+{
+ char *rv;
+
+ if (!s)
+ s = "Oops";
+ rv = strdup(s);
+ if (rv == NULL)
+ fatal("out of memory\n");
+ return rv;
+}
+
+/*
* Vanilla terminal output (buffered).
*/
void
@@ -390,7 +406,7 @@ fetchname(const char *at, bool *exists, int strip_leading)
char *
checked_in(char *file)
{
- char *filebase, *filedir, tmpbuf[MAXPATHLEN];
+ char *filebase, *filedir, tmpbuf[PATH_MAX];
struct stat filestat;
filebase = basename(file);
@@ -412,7 +428,7 @@ checked_in(char *file)
void
version(void)
{
- fprintf(stderr, "patch 2.0-12u10 FreeBSD\n");
+ printf("patch 2.0-12u10 FreeBSD\n");
my_exit(EXIT_SUCCESS);
}
diff --git a/usr.bin/patch/util.h b/usr.bin/patch/util.h
index 5759d68..ff2feab 100644
--- a/usr.bin/patch/util.h
+++ b/usr.bin/patch/util.h
@@ -23,7 +23,7 @@
* -C option added in 1998, original code by Marc Espie, based on FreeBSD
* behaviour
*
- * $OpenBSD: util.h,v 1.15 2005/06/20 07:14:06 otto Exp $
+ * $OpenBSD: util.h,v 1.16 2014/12/13 10:31:07 tobias Exp $
* $FreeBSD$
*/
@@ -41,6 +41,7 @@ void pfatal(const char *, ...)
void ask(const char *, ...)
__attribute__((__format__(__printf__, 1, 2)));
char *savestr(const char *);
+char *xstrdup(const char *);
void set_signals(int);
void ignore_signals(void);
void makedirs(const char *, bool);
diff --git a/usr.bin/perror/perror.1 b/usr.bin/perror/perror.1
index 0b724b1..6fa1664 100644
--- a/usr.bin/perror/perror.1
+++ b/usr.bin/perror/perror.1
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (c) 2009 Advanced Computing Technologies LLC
+.\" Copyright (c) 2009 Hudson River Trading LLC
.\" Written by: George V. Neville-Neil <gnn@FreeBSD.org>
.\" All rights reserved.
.\"
diff --git a/usr.bin/perror/perror.c b/usr.bin/perror/perror.c
index ef3db35..62af5df 100644
--- a/usr.bin/perror/perror.c
+++ b/usr.bin/perror/perror.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2009 Advanced Computing Technologies LLC
+ * Copyright (c) 2009 Hudson River Trading LLC
* Written by: George V. Neville-Neil <gnn@FreeBSD.org>
* All rights reserved.
*
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c
index 452711e..8636cc1 100644
--- a/usr.bin/printf/printf.c
+++ b/usr.bin/printf/printf.c
@@ -66,7 +66,6 @@ static const char rcsid[] =
#ifdef SHELL
#define main printfcmd
#include "bltin/bltin.h"
-#include "error.h"
#include "options.h"
#endif
diff --git a/usr.bin/procstat/Makefile b/usr.bin/procstat/Makefile
index 4def311..211ce1a 100644
--- a/usr.bin/procstat/Makefile
+++ b/usr.bin/procstat/Makefile
@@ -8,6 +8,7 @@ SRCS= procstat.c \
procstat_basic.c \
procstat_bin.c \
procstat_cred.c \
+ procstat_cs.c \
procstat_files.c \
procstat_kstack.c \
procstat_rlimit.c \
@@ -16,7 +17,6 @@ SRCS= procstat.c \
procstat_threads.c \
procstat_vm.c
-LDADD+= -lutil -lprocstat -lkvm
-DPADD+= ${LIBUTIL} ${LIBPROCSTAT} ${LIBKVM}
+LIBADD+= util procstat
.include <bsd.prog.mk>
diff --git a/usr.bin/procstat/procstat.1 b/usr.bin/procstat/procstat.1
index f33c746..0fd314f 100644
--- a/usr.bin/procstat/procstat.1
+++ b/usr.bin/procstat/procstat.1
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 16, 2014
+.Dd May 18, 2015
.Dt PROCSTAT 1
.Os
.Sh NAME
@@ -35,7 +35,7 @@
.Nm
.Op Fl CHhn
.Op Fl w Ar interval
-.Op Fl b | c | e | f | i | j | k | l | r | s | t | v | x
+.Op Fl b | c | e | f | i | j | k | l | r | s | S | t | v | x
.Op Fl a | Ar pid | Ar core ...
.Sh DESCRIPTION
The
@@ -75,6 +75,8 @@ Display resource limits for the process.
Display resource usage information for the process.
.It Fl s
Display security credential information for the process.
+.It Fl S
+Display the cpuset information for the thread.
.It Fl t
Display thread information for the process.
.It Fl v
@@ -108,9 +110,16 @@ flag may be used to request per-thread statistics rather than per-process
statistics for some options.
For those options, the second field in the table will list the thread ID
to which the row of information corresponds.
+The
+.Fl H
+flag is implied for the
+.Fl S
+mode.
.Pp
-Some information, such as VM and file descriptor information, is available
+Information for VM, file descriptor, and cpuset options is available
only to the owner of a process or the superuser.
+A cpuset value displayed as -1 means that the information is either invalid
+or not available.
.Ss Binary Information
Display the process ID, command, and path to the process binary:
.Pp
@@ -521,6 +530,7 @@ auxiliary vector value
.Xr sockstat 1 ,
.Xr cap_enter 2 ,
.Xr cap_rights_limit 2 ,
+.Xr libprocstat 3 ,
.Xr ddb 4 ,
.Xr stack 9
.Sh AUTHORS
diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
index de0237f..48a2135 100644
--- a/usr.bin/procstat/procstat.c
+++ b/usr.bin/procstat/procstat.c
@@ -40,7 +40,7 @@
#include "procstat.h"
static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, lflag, rflag;
-static int sflag, tflag, vflag, xflag;
+static int sflag, tflag, vflag, xflag, Sflag;
int hflag, nflag, Cflag, Hflag;
static void
@@ -50,7 +50,7 @@ usage(void)
fprintf(stderr, "usage: procstat [-CHhn] [-M core] [-N system] "
"[-w interval] \n");
fprintf(stderr, " [-b | -c | -e | -f | -i | -j | -k | "
- "-l | -r | -s | -t | -v | -x]\n");
+ "-l | -r | -s | -S | -t | -v | -x]\n");
fprintf(stderr, " [-a | pid | core ...]\n");
exit(EX_USAGE);
}
@@ -85,6 +85,8 @@ procstat(struct procstat *prstat, struct kinfo_proc *kipp)
procstat_vm(prstat, kipp);
else if (xflag)
procstat_auxv(prstat, kipp);
+ else if (Sflag)
+ procstat_cs(prstat, kipp);
else
procstat_basic(kipp);
}
@@ -128,7 +130,7 @@ main(int argc, char *argv[])
interval = 0;
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "CHN:M:abcefijklhrstvw:x")) != -1) {
+ while ((ch = getopt(argc, argv, "CHN:M:abcefijklhrsStvw:x")) != -1) {
switch (ch) {
case 'C':
Cflag++;
@@ -144,6 +146,9 @@ main(int argc, char *argv[])
case 'N':
nlistf = optarg;
break;
+ case 'S':
+ Sflag++;
+ break;
case 'a':
aflag++;
break;
@@ -228,7 +233,7 @@ main(int argc, char *argv[])
/* We require that either 0 or 1 mode flags be set. */
tmp = bflag + cflag + eflag + fflag + iflag + jflag + (kflag ? 1 : 0) +
- lflag + rflag + sflag + tflag + vflag + xflag;
+ lflag + rflag + sflag + tflag + vflag + xflag + Sflag;
if (!(tmp == 0 || tmp == 1))
usage();
diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
index 98282b3..5079521 100644
--- a/usr.bin/procstat/procstat.h
+++ b/usr.bin/procstat/procstat.h
@@ -39,6 +39,7 @@ void procstat_auxv(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_basic(struct kinfo_proc *kipp);
void procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_cred(struct procstat *prstat, struct kinfo_proc *kipp);
+void procstat_cs(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_env(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_kstack(struct procstat *prstat, struct kinfo_proc *kipp,
diff --git a/usr.bin/procstat/procstat_cs.c b/usr.bin/procstat/procstat_cs.c
new file mode 100644
index 0000000..8ccf1ea
--- /dev/null
+++ b/usr.bin/procstat/procstat_cs.c
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2007 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+#include <err.h>
+#include <errno.h>
+#include <libprocstat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "procstat.h"
+
+void
+procstat_cs(struct procstat *procstat, struct kinfo_proc *kipp)
+{
+ cpusetid_t cs;
+ cpuset_t mask;
+ struct kinfo_proc *kip;
+ unsigned int count, i;
+ int once, twice, lastcpu, cpu;
+
+ if (!hflag)
+ printf("%5s %6s %-16s %-16s %2s %4s %-7s\n", "PID",
+ "TID", "COMM", "TDNAME", "CPU", "CSID", "CPU MASK");
+
+ kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD,
+ kipp->ki_pid, &count);
+ if (kip == NULL)
+ return;
+ kinfo_proc_sort(kip, count);
+ for (i = 0; i < count; i++) {
+ kipp = &kip[i];
+ printf("%5d ", kipp->ki_pid);
+ printf("%6d ", kipp->ki_tid);
+ printf("%-16s ", strlen(kipp->ki_comm) ?
+ kipp->ki_comm : "-");
+ printf("%-16s ", (strlen(kipp->ki_tdname) &&
+ (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
+ kipp->ki_tdname : "-");
+ if (kipp->ki_oncpu != 255)
+ printf("%3d ", kipp->ki_oncpu);
+ else if (kipp->ki_lastcpu != 255)
+ printf("%3d ", kipp->ki_lastcpu);
+ else
+ printf("%3s ", "-");
+ if (cpuset_getid(CPU_LEVEL_CPUSET, CPU_WHICH_TID,
+ kipp->ki_tid, &cs) != 0) {
+ cs = CPUSET_INVALID;
+ }
+ printf("%4d ", cs);
+ if ((cs != CPUSET_INVALID) &&
+ (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
+ kipp->ki_tid, sizeof(mask), &mask) == 0)) {
+ lastcpu = -1;
+ once = 0;
+ twice = 0;
+ for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
+ if (CPU_ISSET(cpu, &mask)) {
+ if (once == 0) {
+ printf("%d", cpu);
+ once = 1;
+ } else if (cpu == lastcpu + 1) {
+ twice = 1;
+ } else if (twice == 1) {
+ printf("-%d,%d", lastcpu, cpu);
+ twice = 0;
+ } else
+ printf(",%d", cpu);
+ lastcpu = cpu;
+ }
+ }
+ if (once && twice)
+ printf("-%d", lastcpu);
+ }
+ printf("\n");
+ }
+ procstat_freeprocs(procstat, kip);
+}
diff --git a/usr.bin/procstat/procstat_rusage.c b/usr.bin/procstat/procstat_rusage.c
index b3c9d99..63e5ab8 100644
--- a/usr.bin/procstat/procstat_rusage.c
+++ b/usr.bin/procstat/procstat_rusage.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2012 Advanced Computing Technologies LLC
+ * Copyright (c) 2012 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
diff --git a/usr.bin/protect/protect.1 b/usr.bin/protect/protect.1
index 919714e..b9be4af 100644
--- a/usr.bin/protect/protect.1
+++ b/usr.bin/protect/protect.1
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2013 Advanced Computing Technologies LLC
+.\" Copyright (c) 2013 Hudson River Trading LLC
.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
.\" All rights reserved.
.\"
diff --git a/usr.bin/protect/protect.c b/usr.bin/protect/protect.c
index ba15aa6..16b0d29 100644
--- a/usr.bin/protect/protect.c
+++ b/usr.bin/protect/protect.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2013 Advanced Computing Technologies LLC
+ * Copyright (c) 2013 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
diff --git a/usr.bin/quota/Makefile b/usr.bin/quota/Makefile
index 26585ae..753972e 100644
--- a/usr.bin/quota/Makefile
+++ b/usr.bin/quota/Makefile
@@ -5,7 +5,6 @@ PROG= quota
BINOWN= root
BINMODE=4555
-DPADD= ${LIBRPCSVC} ${LIBUTIL}
-LDADD= -lrpcsvc -lutil
+LIBADD= rpcsvc util
.include <bsd.prog.mk>
diff --git a/usr.bin/rctl/Makefile b/usr.bin/rctl/Makefile
index c5c32eb..0191bdd 100644
--- a/usr.bin/rctl/Makefile
+++ b/usr.bin/rctl/Makefile
@@ -3,7 +3,6 @@
PROG= rctl
MAN= rctl.8
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD= util
.include <bsd.prog.mk>
diff --git a/usr.bin/rctl/rctl.8 b/usr.bin/rctl/rctl.8
index 3f72b91..fe14756 100644
--- a/usr.bin/rctl/rctl.8
+++ b/usr.bin/rctl/rctl.8
@@ -233,6 +233,18 @@ for a list of supported signals
Not all actions are supported for all resources.
Attempting to add a rule with an action not supported by a given resource will
result in error.
+.Sh LOADER TUNABLES
+Tunables can be set at the
+.Xr loader 8
+prompt, or
+.Xr loader.conf 5 .
+.Bl -tag -width indent
+.It Va kern.racct.enable: No 1
+Enable
+.Nm .
+This defaults to 1, unless
+.Cd "options RACCT_DEFAULT_TO_DISABLED"
+is set in the kernel configuration file.
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
diff --git a/usr.bin/rctl/rctl.c b/usr.bin/rctl/rctl.c
index 185788d..b534258 100644
--- a/usr.bin/rctl/rctl.c
+++ b/usr.bin/rctl/rctl.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/rctl.h>
+#include <sys/sysctl.h>
#include <assert.h>
#include <ctype.h>
#include <err.h>
@@ -305,13 +306,37 @@ print_rules(char *rules, int hflag, int nflag)
}
static void
+enosys(void)
+{
+ int error, racct_enable;
+ size_t racct_enable_len;
+
+ racct_enable_len = sizeof(racct_enable);
+ error = sysctlbyname("kern.racct.enable",
+ &racct_enable, &racct_enable_len, NULL, 0);
+
+ if (error != 0) {
+ if (errno == ENOENT)
+ errx(1, "RACCT/RCTL support not present in kernel; see rctl(8) for details");
+
+ err(1, "sysctlbyname");
+ }
+
+ if (racct_enable == 0)
+ errx(1, "RACCT/RCTL present, but disabled; enable using kern.racct.enable=1 tunable");
+}
+
+static void
add_rule(char *rule)
{
int error;
error = rctl_add_rule(rule, strlen(rule) + 1, NULL, 0);
- if (error != 0)
+ if (error != 0) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_add_rule");
+ }
free(rule);
}
@@ -330,8 +355,11 @@ show_limits(char *filter, int hflag, int nflag)
error = rctl_get_limits(filter, strlen(filter) + 1, outbuf,
outbuflen);
- if (error && errno != ERANGE)
+ if (error && errno != ERANGE) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_get_limits");
+ }
} while (error && errno == ERANGE);
print_rules(outbuf, hflag, nflag);
@@ -345,8 +373,11 @@ remove_rule(char *filter)
int error;
error = rctl_remove_rule(filter, strlen(filter) + 1, NULL, 0);
- if (error != 0)
+ if (error != 0) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_remove_rule");
+ }
free(filter);
}
@@ -399,8 +430,11 @@ show_usage(char *filter, int hflag)
error = rctl_get_racct(filter, strlen(filter) + 1, outbuf,
outbuflen);
- if (error && errno != ERANGE)
+ if (error && errno != ERANGE) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_get_racct");
+ }
} while (error && errno == ERANGE);
while ((tmp = strsep(&outbuf, ",")) != NULL) {
@@ -439,8 +473,11 @@ show_rules(char *filter, int hflag, int nflag)
err(1, "realloc");
error = rctl_get_rules(filter, filterlen, outbuf, outbuflen);
- if (error && errno != ERANGE)
+ if (error && errno != ERANGE) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_get_rules");
+ }
} while (error && errno == ERANGE);
print_rules(outbuf, hflag, nflag);
diff --git a/usr.bin/readelf/Makefile b/usr.bin/readelf/Makefile
new file mode 100644
index 0000000..e5d7401
--- /dev/null
+++ b/usr.bin/readelf/Makefile
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+READELFDIR= ${ELFTCDIR}/readelf
+
+.PATH: ${READELFDIR}
+
+PROG= readelf
+
+LIBADD= dwarf elftc elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/rlogin/Makefile b/usr.bin/rlogin/Makefile
index 195bffb..e41417d 100644
--- a/usr.bin/rlogin/Makefile
+++ b/usr.bin/rlogin/Makefile
@@ -5,6 +5,5 @@ PROG= rlogin
BINOWN= root
BINMODE=4555
-PRECIOUSPROG=
.include <bsd.prog.mk>
diff --git a/usr.bin/rlogin/rlogin.c b/usr.bin/rlogin/rlogin.c
index 646630b..2669255 100644
--- a/usr.bin/rlogin/rlogin.c
+++ b/usr.bin/rlogin/rlogin.c
@@ -131,7 +131,7 @@ main(int argc, char *argv[])
long omask;
int argoff, ch, dflag, Dflag, one;
uid_t uid;
- char *host, *localname, *p, *user, term[1024];
+ char *host, *localname, *p, *user, term[1024] = "network";
speed_t ospeed;
struct sockaddr_storage ss;
socklen_t sslen;
diff --git a/usr.bin/rpcgen/rpc_sample.c b/usr.bin/rpcgen/rpc_sample.c
index 6a2bef8..5d6c9a9 100644
--- a/usr.bin/rpcgen/rpc_sample.c
+++ b/usr.bin/rpcgen/rpc_sample.c
@@ -115,7 +115,7 @@ write_sample_client(const char *program_name, version_list *vp)
for (l = proc->args.decls; l != NULL; l = l->next) {
f_print(fout, "\t");
ptype(l->decl.prefix, l->decl.type, 1);
- if (strcmp(l->decl.type,"string") == 1)
+ if (strcmp(l->decl.type,"string") >= 1)
f_print(fout, " ");
pvname(proc->proc_name, vp->vers_num);
f_print(fout, "_%s;\n", l->decl.name);
diff --git a/usr.bin/rs/rs.1 b/usr.bin/rs/rs.1
index 6ff1842..23a37b8 100644
--- a/usr.bin/rs/rs.1
+++ b/usr.bin/rs/rs.1
@@ -28,7 +28,7 @@
.\" @(#)rs.1 8.2 (Berkeley) 12/30/93
.\" $FreeBSD$
.\"
-.Dd February 25, 2011
+.Dd April 7, 2015
.Dt RS 1
.Os
.Sh NAME
@@ -222,6 +222,8 @@ The
.Nm
utility first appeared in
.Bx 4.2 .
+.Sh AUTHORS
+.An John A. Kunze
.Sh BUGS
.Bl -item
.It
diff --git a/usr.bin/rsh/Makefile b/usr.bin/rsh/Makefile
index 5c6951c..d7c26a5 100644
--- a/usr.bin/rsh/Makefile
+++ b/usr.bin/rsh/Makefile
@@ -8,6 +8,5 @@ WARNS?= 2
BINOWN= root
BINMODE=4555
-PRECIOUSPROG=
.include <bsd.prog.mk>
diff --git a/usr.bin/rup/Makefile b/usr.bin/rup/Makefile
index e872201..4b5131e 100644
--- a/usr.bin/rup/Makefile
+++ b/usr.bin/rup/Makefile
@@ -4,7 +4,6 @@ PROG= rup
WARNS?= 1
-DPADD= ${LIBRPCSVC}
-LDADD= -lrpcsvc
+LIBADD= rpcsvc
.include <bsd.prog.mk>
diff --git a/usr.bin/rup/rup.1 b/usr.bin/rup/rup.1
index 8b16670..499d6ab 100644
--- a/usr.bin/rup/rup.1
+++ b/usr.bin/rup/rup.1
@@ -83,8 +83,8 @@ and cannot accommodate any RPC-based services.
The host may be down.
.El
.Sh SEE ALSO
-.Xr rpcbind 8 ,
-.Xr rpc.rstatd 8
+.Xr rpc.rstatd 8 ,
+.Xr rpcbind 8
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/rusers/Makefile b/usr.bin/rusers/Makefile
index 6cb39ac..f640350 100644
--- a/usr.bin/rusers/Makefile
+++ b/usr.bin/rusers/Makefile
@@ -2,7 +2,6 @@
PROG = rusers
-DPADD= ${LIBRPCSVC}
-LDADD= -lrpcsvc
+LIBADD= rpcsvc
.include <bsd.prog.mk>
diff --git a/usr.bin/rusers/rusers.1 b/usr.bin/rusers/rusers.1
index b96933f..8980d21 100644
--- a/usr.bin/rusers/rusers.1
+++ b/usr.bin/rusers/rusers.1
@@ -92,8 +92,8 @@ The host may be down.
.Xr rwho 1 ,
.Xr users 1 ,
.Xr who 1 ,
-.Xr rpcbind 8 ,
-.Xr rpc.rusersd 8
+.Xr rpc.rusersd 8 ,
+.Xr rpcbind 8
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/rwall/rwall.1 b/usr.bin/rwall/rwall.1
index 7e54603..bb545e8 100644
--- a/usr.bin/rwall/rwall.1
+++ b/usr.bin/rwall/rwall.1
@@ -67,8 +67,8 @@ The host may be down.
.El
.Sh SEE ALSO
.Xr who 1 ,
-.Xr rpcbind 8 ,
-.Xr rpc.rwalld 8
+.Xr rpc.rwalld 8 ,
+.Xr rpcbind 8
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/script/Makefile b/usr.bin/script/Makefile
index 50ba12e..f75106f 100644
--- a/usr.bin/script/Makefile
+++ b/usr.bin/script/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
PROG= script
-LDADD= -lutil
-DPADD= ${LIBUTIL}
+
+LIBADD= util
.include <bsd.prog.mk>
diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1
index de8e7ff..239508f 100644
--- a/usr.bin/script/script.1
+++ b/usr.bin/script/script.1
@@ -164,7 +164,7 @@ is assumed.
.Pq Most shells set this variable automatically .
.El
.Sh SEE ALSO
-.Xr csh 1
+.Xr csh 1 ,
.Xr filemon 4
.Po
for the
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index e146668..c7fbe21 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -558,7 +558,7 @@ compile_flags(char *p, struct s_subst *s)
{
int gn; /* True if we have seen g or n */
unsigned long nval;
- char wfile[_POSIX2_LINE_MAX + 1], *q;
+ char wfile[_POSIX2_LINE_MAX + 1], *q, *eq;
s->n = 1; /* Default */
s->p = 0;
@@ -611,9 +611,12 @@ compile_flags(char *p, struct s_subst *s)
#endif
EATSPACE();
q = wfile;
+ eq = wfile + sizeof(wfile) - 1;
while (*p) {
if (*p == '\n')
break;
+ if (q >= eq)
+ err(1, "wfile too long");
*q++ = *p++;
}
*q = '\0';
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 76e186f..36a3299 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -400,15 +400,17 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
sizeof(oldfname));
len = strlcat(oldfname, inplace,
sizeof(oldfname));
- if (len > sizeof(oldfname))
+ if (len > (ssize_t)sizeof(oldfname))
errx(1, "%s: name too long", fname);
}
len = snprintf(tmpfname, sizeof(tmpfname),
"%s/.!%ld!%s", dirname(fname), (long)getpid(),
basename(fname));
- if (len >= sizeof(tmpfname))
+ if (len >= (ssize_t)sizeof(tmpfname))
errx(1, "%s: name too long", fname);
unlink(tmpfname);
+ if (outfile != NULL && outfile != stdout)
+ fclose(outfile);
if ((outfile = fopen(tmpfname, "w")) == NULL)
err(1, "%s", fname);
fchown(fileno(outfile), sb.st_uid, sb.st_gid);
@@ -488,7 +490,7 @@ add_file(char *s)
}
static int
-next_files_have_lines()
+next_files_have_lines(void)
{
struct s_flist *file;
FILE *file_fd;
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index 9cd2c2e..daabfd8 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -67,11 +67,11 @@ static SPACE HS, PS, SS, YS;
#define hs HS.space
#define hsl HS.len
-static __inline int applies(struct s_command *);
+static inline int applies(struct s_command *);
static void do_tr(struct s_tr *);
static void flush_appends(void);
static void lputs(char *, size_t);
-static __inline int regexec_e(regex_t *, const char *, int, int, size_t);
+static int regexec_e(regex_t *, const char *, int, int, size_t);
static void regsub(SPACE *, char *, char *);
static int substitute(struct s_command *);
@@ -288,7 +288,7 @@ new: if (!nflag && !pd)
* Return TRUE if the command applies to the current line. Sets the start
* line for process ranges. Interprets the non-select (``!'') flag.
*/
-static __inline int
+static inline int
applies(struct s_command *cp)
{
int r;
@@ -324,7 +324,7 @@ applies(struct s_command *cp)
} else
r = 1;
}
- } else if (MATCH(cp->a1)) {
+ } else if (cp->a1 && MATCH(cp->a1)) {
/*
* If the second address is a number less than or
* equal to the line number first selected, only
@@ -656,7 +656,7 @@ lputs(char *s, size_t len)
errx(1, "%s: %s", outfname, strerror(errno ? errno : EIO));
}
-static __inline int
+static int
regexec_e(regex_t *preg, const char *string, int eflags, int nomatch,
size_t slen)
{
diff --git a/usr.bin/sed/tests/multi_test.sh b/usr.bin/sed/tests/multi_test.sh
index d821832..66207a6 100644
--- a/usr.bin/sed/tests/multi_test.sh
+++ b/usr.bin/sed/tests/multi_test.sh
@@ -51,7 +51,7 @@ main()
awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
- echo "1..129"
+ echo "1..130"
exec 4>&1 5>&2
tests
@@ -181,6 +181,8 @@ hello' /dev/null
mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
mark '2.21' ; $SED -n '13,+4p' lines1 lines2
mark '2.22' ; $SED -n '/l1_6/,+2p' lines1 lines2
+ # For PR bin/192108
+ mark '2.23'; $SED -n '12,+1p' lines1
}
test_group()
diff --git a/usr.bin/sed/tests/regress.multitest.out/2.23 b/usr.bin/sed/tests/regress.multitest.out/2.23
new file mode 100644
index 0000000..543c057
--- /dev/null
+++ b/usr.bin/sed/tests/regress.multitest.out/2.23
@@ -0,0 +1,2 @@
+l1_12
+l1_13
diff --git a/usr.bin/seq/Makefile b/usr.bin/seq/Makefile
index 58b16ae..bb3c295 100644
--- a/usr.bin/seq/Makefile
+++ b/usr.bin/seq/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
PROG= seq
-DPADD= ${LIBM}
-LDADD= -lm
+
+LIBADD= m
.include <bsd.prog.mk>
diff --git a/usr.bin/seq/seq.1 b/usr.bin/seq/seq.1
index 1ac977e..12dd184 100644
--- a/usr.bin/seq/seq.1
+++ b/usr.bin/seq/seq.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: seq.1,v 1.6 2008/11/26 15:03:47 ginsbach Exp $
+.\" $NetBSD: seq.1,v 1.8 2013/04/07 17:37:45 jdf Exp $
.\"
.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 19, 2010
+.Dd September 10, 2013
.Dt SEQ 1
.Os
.Sh NAME
@@ -59,7 +59,7 @@ as possible, in increments of
When
.Ar first
is larger than
-.Ar last
+.Ar last ,
the default
.Ar incr
is -1.
@@ -79,8 +79,11 @@ style
.Ar format
to print each number.
Only the
+.Cm A ,
+.Cm a ,
.Cm E ,
.Cm e ,
+.Cm F ,
.Cm f ,
.Cm G ,
.Cm g ,
diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c
index e077743..6d715e1 100644
--- a/usr.bin/seq/seq.c
+++ b/usr.bin/seq/seq.c
@@ -1,4 +1,4 @@
-/* $NetBSD: seq.c,v 1.5 2008/07/21 14:19:26 lukem Exp $ */
+/* $NetBSD: seq.c,v 1.7 2010/05/27 08:40:19 dholland Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -158,6 +158,8 @@ main(int argc, char *argv[])
if (!valid_format(fmt))
errx(1, "invalid format string: `%s'", fmt);
fmt = unescape(fmt);
+ if (!valid_format(fmt))
+ errx(1, "invalid format string");
/*
* XXX to be bug for bug compatible with Plan 9 add a
* newline if none found at the end of the format string.
@@ -225,39 +227,56 @@ numeric(const char *s)
static int
valid_format(const char *fmt)
{
- int conversions = 0;
+ unsigned conversions = 0;
while (*fmt != '\0') {
/* scan for conversions */
- if (*fmt != '\0' && *fmt != '%') {
- do {
- fmt++;
- } while (*fmt != '\0' && *fmt != '%');
+ if (*fmt != '%') {
+ fmt++;
+ continue;
}
- /* scan a conversion */
- if (*fmt != '\0') {
- do {
- fmt++;
+ fmt++;
- /* ok %% */
- if (*fmt == '%') {
- fmt++;
- break;
- }
- /* valid conversions */
- if (strchr("eEfgG", *fmt) &&
- conversions++ < 1) {
- fmt++;
- break;
- }
- /* flags, width and precision */
- if (isdigit((unsigned char)*fmt) ||
- strchr("+- 0#.", *fmt))
- continue;
+ /* allow %% but not things like %10% */
+ if (*fmt == '%') {
+ fmt++;
+ continue;
+ }
- /* oops! bad conversion format! */
- return (0);
- } while (*fmt != '\0');
+ /* flags */
+ while (*fmt != '\0' && strchr("#0- +'", *fmt)) {
+ fmt++;
+ }
+
+ /* field width */
+ while (*fmt != '\0' && strchr("0123456789", *fmt)) {
+ fmt++;
+ }
+
+ /* precision */
+ if (*fmt == '.') {
+ fmt++;
+ while (*fmt != '\0' && strchr("0123456789", *fmt)) {
+ fmt++;
+ }
+ }
+
+ /* conversion */
+ switch (*fmt) {
+ case 'A':
+ case 'a':
+ case 'E':
+ case 'e':
+ case 'F':
+ case 'f':
+ case 'G':
+ case 'g':
+ /* floating point formats are accepted */
+ conversions++;
+ break;
+ default:
+ /* anything else is not */
+ return 0;
}
}
diff --git a/usr.bin/setchannel/setchannel.1 b/usr.bin/setchannel/setchannel.1
index 5b2d4ab..d0c865e 100644
--- a/usr.bin/setchannel/setchannel.1
+++ b/usr.bin/setchannel/setchannel.1
@@ -85,8 +85,8 @@ Channel number to set.
Frequency in MHz (must include decimal point).
.El
.Sh SEE ALSO
-.Xr cxm 4 ,
.Xr bktr 4 ,
+.Xr cxm 4 ,
.Xr meteor 4
.Sh HISTORY
The
diff --git a/usr.bin/showmount/showmount.8 b/usr.bin/showmount/showmount.8
index 106b1a1..2831593 100644
--- a/usr.bin/showmount/showmount.8
+++ b/usr.bin/showmount/showmount.8
@@ -84,8 +84,8 @@ Ignored for backwards compatibility.
.El
.Sh SEE ALSO
.Xr mount 8 ,
-.Xr mountd 8 ,
-.Xr mount_nfs 8
+.Xr mount_nfs 8 ,
+.Xr mountd 8
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/size/Makefile b/usr.bin/size/Makefile
new file mode 100644
index 0000000..6aba73d
--- /dev/null
+++ b/usr.bin/size/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+SIZEDIR= ${ELFTCDIR}/size
+
+.PATH: ${SIZEDIR}
+
+PROG= size
+
+LIBADD= elftc elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/smbutil/Makefile b/usr.bin/smbutil/Makefile
index 19ac5fd..2012124 100644
--- a/usr.bin/smbutil/Makefile
+++ b/usr.bin/smbutil/Makefile
@@ -3,8 +3,7 @@
PROG= smbutil
SRCS= smbutil.c dumptree.c login.c lookup.c view.c print.c
-DPADD= ${LIBSMB} ${LIBKICONV}
-LDADD= -lsmb -lkiconv
+LIBADD= smb
CONTRIBDIR= ${.CURDIR}/../../contrib/smbfs
CFLAGS+= -I${CONTRIBDIR}/include
diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1
index b27a784..5076ae8 100644
--- a/usr.bin/sockstat/sockstat.1
+++ b/usr.bin/sockstat/sockstat.1
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 16, 2012
+.Dd April 7, 2015
.Dt SOCKSTAT 1
.Os
.Sh NAME
@@ -69,7 +69,7 @@ or do not contain the IPv6 loopback address
.It Fl l
Show listening sockets.
.It Fl p Ar ports
-Only show Internet sockets if either the local or foreign port number
+Only show Internet sockets if the local or foreign port number
is on the specified list.
The
.Ar ports
diff --git a/usr.bin/soelim/Makefile b/usr.bin/soelim/Makefile
new file mode 100644
index 0000000..21eaaff
--- /dev/null
+++ b/usr.bin/soelim/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+PROG= soelim
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/soelim/soelim.1 b/usr.bin/soelim/soelim.1
new file mode 100644
index 0000000..57e8614
--- /dev/null
+++ b/usr.bin/soelim/soelim.1
@@ -0,0 +1,86 @@
+.\" Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd May 1, 2015
+.Dt SOELIM 1
+.Os
+.Sh NAME
+.Nm soelim
+.Nd interpret .so requests in manpages
+.Sh SYNOPSIS
+.Nm
+.Op Fl Crtv
+.Op Fl I Ar dir
+.Op Ar files ...
+.Sh DESCRIPTION
+.Nm
+reads
+.Ar files
+lines by lines.
+.Pp
+If a line starts by:
+.Dq .so anotherfile
+it replace the line by processing
+.Dq anotherfile .
+Otherwise the line is printed to stdout.
+.Bl -tag -width "-I dir"
+.It Fl C
+Recognise
+.Em .so
+when not followed by a space character.
+.It Fl r
+Compatibility with GNU groff's
+.Xr soelim 1
+(does nothing).
+.It Fl t
+Compatibility with GNU groff's
+.Xr soelim 1
+(does nothing).
+.It Fl v
+Compatibility with GNU groff's
+.Xr soelim 1
+(does nothing).
+.It Fl I Ar dir
+This option specify directories where
+.Nm
+searches for files (both those on the command line and those named in
+.Dq .so
+directive.)
+This options may be specified multiple times. The directories will be searched
+in the order specified.
+.El
+.Pp
+The files are always searched first in the current directory.
+.Pp
+A file specified with an absolute path will be opened directly without
+performing a search.
+.Sh SEE ALSO
+.Xr mandoc 1
+.Sh AUTHORS
+This version of the
+.Nm
+utility was written by
+.An Baptiste Daroussin Aq Mt bapt@freebsd.org .
diff --git a/usr.bin/soelim/soelim.c b/usr.bin/soelim/soelim.c
new file mode 100644
index 0000000..4d747ee
--- /dev/null
+++ b/usr.bin/soelim/soelim.c
@@ -0,0 +1,178 @@
+/*-
+ * Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <limits.h>
+#define _WITH_GETLINE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#define C_OPTION 0x1
+
+static StringList *includes;
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: soelim [-Crtv] [-I dir] [files]\n");
+
+ exit(EXIT_FAILURE);
+}
+
+static FILE *
+soelim_fopen(const char *name)
+{
+ FILE *f;
+ char path[PATH_MAX];
+ size_t i;
+
+ if (strcmp(name, "-") == 0)
+ return (stdin);
+
+ if ((f = fopen(name, "r")) != NULL)
+ return (f);
+
+ if (*name == '/') {
+ warn("can't open '%s'", name);
+ return (NULL);
+ }
+
+ for (i = 0; i < includes->sl_cur; i++) {
+ snprintf(path, sizeof(path), "%s/%s", includes->sl_str[i],
+ name);
+ if ((f = fopen(path, "r")) != NULL)
+ return (f);
+ }
+
+ warn("can't open '%s'", name);
+
+ return (f);
+}
+
+static int
+soelim_file(FILE *f, int flag)
+{
+ char *line = NULL;
+ char *walk, *cp;
+ size_t linecap = 0;
+ ssize_t linelen;
+
+ if (f == NULL)
+ return (1);
+
+ while ((linelen = getline(&line, &linecap, f)) > 0) {
+ if (strncmp(line, ".so", 3) != 0) {
+ printf("%s", line);
+ continue;
+ }
+
+ walk = line + 3;
+ if (!isspace(*walk) && ((flag & C_OPTION) == 0)) {
+ printf("%s", line);
+ continue;
+ }
+
+ while (isspace(*walk))
+ walk++;
+
+ cp = walk;
+ while (*cp != '\0' && !isspace(*cp))
+ cp++;
+ *cp = 0;
+ if (cp < line + linelen)
+ cp++;
+
+ if (*walk == '\0') {
+ printf("%s", line);
+ continue;
+ }
+ if (soelim_file(soelim_fopen(walk), flag) == 1) {
+ free(line);
+ return (1);
+ }
+ if (*cp != '\0')
+ printf("%s", cp);
+ }
+
+ free(line);
+ fclose(f);
+
+ return (0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int ch, i;
+ int ret = 0;
+ int flags = 0;
+
+ includes = sl_init();
+ if (includes == NULL)
+ err(EXIT_FAILURE, "sl_init()");
+
+ while ((ch = getopt(argc, argv, "CrtvI:")) != -1) {
+ switch (ch) {
+ case 'C':
+ flags |= C_OPTION;
+ break;
+ case 'r':
+ case 'v':
+ case 't':
+ /* stub compatibility with groff's soelim */
+ break;
+ case 'I':
+ sl_add(includes, optarg);
+ break;
+ default:
+ sl_free(includes, 0);
+ usage();
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0)
+ ret = soelim_file(stdin, flags);
+
+ for (i = 0; i < argc; i++)
+ ret = soelim_file(soelim_fopen(argv[i]), flags);
+
+ sl_free(includes, 0);
+
+ return (ret);
+}
diff --git a/usr.bin/soelim/tests/Makefile b/usr.bin/soelim/tests/Makefile
new file mode 100644
index 0000000..4d787cf
--- /dev/null
+++ b/usr.bin/soelim/tests/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/usr.bin/soelim
+
+ATF_TESTS_SH= soelim
+
+FILES= nonexisting.in \
+ basic.in \
+ basic \
+ basic.out \
+ basic-with-space.in \
+ basic-with-space.out
+FILESDIR= ${TESTSDIR}
+
+.include <bsd.test.mk>
diff --git a/usr.bin/soelim/tests/basic b/usr.bin/soelim/tests/basic
new file mode 100644
index 0000000..c4fe1dd
--- /dev/null
+++ b/usr.bin/soelim/tests/basic
@@ -0,0 +1 @@
+basic has been included
diff --git a/usr.bin/soelim/tests/basic-with-space.in b/usr.bin/soelim/tests/basic-with-space.in
new file mode 100644
index 0000000..971d681
--- /dev/null
+++ b/usr.bin/soelim/tests/basic-with-space.in
@@ -0,0 +1,3 @@
+This is a test
+.so basic something
+end
diff --git a/usr.bin/soelim/tests/basic-with-space.out b/usr.bin/soelim/tests/basic-with-space.out
new file mode 100644
index 0000000..290b2c6
--- /dev/null
+++ b/usr.bin/soelim/tests/basic-with-space.out
@@ -0,0 +1,4 @@
+This is a test
+basic has been included
+something
+end
diff --git a/usr.bin/soelim/tests/basic.in b/usr.bin/soelim/tests/basic.in
new file mode 100644
index 0000000..cd32eb1
--- /dev/null
+++ b/usr.bin/soelim/tests/basic.in
@@ -0,0 +1,3 @@
+This is a test
+.so basic
+end
diff --git a/usr.bin/soelim/tests/basic.out b/usr.bin/soelim/tests/basic.out
new file mode 100644
index 0000000..db59fbb
--- /dev/null
+++ b/usr.bin/soelim/tests/basic.out
@@ -0,0 +1,3 @@
+This is a test
+basic has been included
+end
diff --git a/usr.bin/soelim/tests/nonexisting.in b/usr.bin/soelim/tests/nonexisting.in
new file mode 100644
index 0000000..e07599d
--- /dev/null
+++ b/usr.bin/soelim/tests/nonexisting.in
@@ -0,0 +1,3 @@
+This is a test
+.so nonexistingfile
+This is next
diff --git a/usr.bin/soelim/tests/soelim.sh b/usr.bin/soelim/tests/soelim.sh
new file mode 100755
index 0000000..69c92e4
--- /dev/null
+++ b/usr.bin/soelim/tests/soelim.sh
@@ -0,0 +1,103 @@
+# $FreeBSD$
+
+atf_test_case stdin
+stdin_head()
+{
+ atf_set "descr" "stdin functionality"
+}
+
+stdin_body()
+{
+ # no file after .so
+ atf_check \
+ -o inline:".so\n" \
+ -e empty \
+ -s exit:0 \
+ soelim <<-EOF
+.so
+EOF
+
+ # only space after .so
+ atf_check \
+ -o inline:".so \n" \
+ -e empty \
+ -s exit:0 \
+ soelim <<-EOF
+.so
+EOF
+
+ # explicit stdin
+ atf_check \
+ -o inline:".so\n" \
+ -e empty \
+ -s exit:0 \
+ soelim - <<-EOF
+.so
+EOF
+
+ atf_check \
+ -o empty \
+ -e inline:"soelim: can't open 'afile': No such file or directory\n" \
+ -s exit:1 \
+ soelim <<-EOF
+.so afile
+EOF
+
+ atf_check \
+ -o inline:".soafile\n" \
+ -e empty \
+ -s exit:0 \
+ soelim <<-EOF
+.soafile
+EOF
+
+ atf_check \
+ -o empty \
+ -e inline:"soelim: can't open 'afile': No such file or directory\n" \
+ -s exit:1 \
+ soelim -C <<-EOF
+.soafile
+EOF
+}
+
+atf_test_case files
+files_head()
+{
+ atf_set "descr" "testing files"
+}
+
+files_body()
+{
+ atf_check \
+ -o inline:"This is a test\n" \
+ -e inline:"soelim: can't open 'nonexistingfile': No such file or directory\n" \
+ -s exit:1 \
+ soelim $(atf_get_srcdir)/nonexisting.in
+
+ cp $(atf_get_srcdir)/basic .
+ atf_check \
+ -o file:$(atf_get_srcdir)/basic.out \
+ -e empty \
+ -s exit:0 \
+ soelim $(atf_get_srcdir)/basic.in
+
+ rm -f basic
+ atf_check \
+ -o file:$(atf_get_srcdir)/basic.out \
+ -e empty \
+ -s exit:0 \
+ soelim -I$(atf_get_srcdir) $(atf_get_srcdir)/basic.in
+
+ atf_check \
+ -o file:$(atf_get_srcdir)/basic-with-space.out \
+ -e empty \
+ -s exit:0 \
+ soelim -I$(atf_get_srcdir) $(atf_get_srcdir)/basic-with-space.in
+
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case stdin
+ atf_add_test_case files
+}
diff --git a/usr.bin/sort/Makefile b/usr.bin/sort/Makefile
index 532e930..d097beb 100644
--- a/usr.bin/sort/Makefile
+++ b/usr.bin/sort/Makefile
@@ -13,12 +13,10 @@ CLEANFILES+= sort.1
.if ${MK_SORT_THREADS} != "no"
CFLAGS+= -DSORT_THREADS
-LDADD= -lpthread -lmd
-DPADD= ${LIBPTHREAD} ${LIBMD}
+LIBADD= pthread md
MAN_SUB+= -e 's|%%THREADS%%||g'
.else
-LDADD= -lmd
-DPADD= ${LIBMD}
+LIBADD= md
MAN_SUB+= -e 's|%%THREADS%%|\.\\"|g'
.endif
diff --git a/usr.bin/sort/bwstring.c b/usr.bin/sort/bwstring.c
index 3def9d0..fc30b56 100644
--- a/usr.bin/sort/bwstring.c
+++ b/usr.bin/sort/bwstring.c
@@ -65,18 +65,12 @@ initialise_months(void)
for (int i = 0; i < 12; i++) {
cmonths[i] = NULL;
tmp = (unsigned char *) nl_langinfo(item[i]);
- if (tmp == NULL)
- continue;
if (debug_sort)
printf("month[%d]=%s\n", i, tmp);
- len = strlen((char*)tmp);
- if (len < 1)
+ if (*tmp == '\0')
continue;
- while (isblank(*tmp))
- ++tmp;
- m = sort_malloc(len + 1);
- memcpy(m, tmp, len + 1);
- m[len] = '\0';
+ m = sort_strdup(tmp);
+ len = strlen(tmp);
for (unsigned int j = 0; j < len; j++)
m[j] = toupper(m[j]);
cmonths[i] = m;
@@ -91,18 +85,17 @@ initialise_months(void)
for (int i = 0; i < 12; i++) {
wmonths[i] = NULL;
tmp = (unsigned char *) nl_langinfo(item[i]);
- if (tmp == NULL)
- continue;
if (debug_sort)
printf("month[%d]=%s\n", i, tmp);
- len = strlen((char*)tmp);
- if (len < 1)
+ if (*tmp == '\0')
continue;
- while (isblank(*tmp))
- ++tmp;
+ len = strlen(tmp);
m = sort_malloc(SIZEOF_WCHAR_STRING(len + 1));
- if (mbstowcs(m, (char*)tmp, len) == ((size_t) -1))
+ if (mbstowcs(m, (char*)tmp, len) ==
+ ((size_t) - 1)) {
+ sort_free(m);
continue;
+ }
m[len] = L'\0';
for (unsigned int j = 0; j < len; j++)
m[j] = towupper(m[j]);
@@ -234,7 +227,7 @@ bwsdup(const struct bwstring *s)
}
/*
- * Create a new binary string from a raw binary buffer.
+ * Create a new binary string from a wide character buffer.
*/
struct bwstring *
bwssbdup(const wchar_t *str, size_t len)
diff --git a/usr.bin/sort/coll.c b/usr.bin/sort/coll.c
index b3c80f6..0b7eb57 100644
--- a/usr.bin/sort/coll.c
+++ b/usr.bin/sort/coll.c
@@ -78,7 +78,7 @@ keys_array_alloc(void)
}
/*
- * Calculate whether we need key hint space
+ * Calculate whether we need key hint space
*/
static size_t
key_hint_size(void)
@@ -595,12 +595,12 @@ list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2)
return (list_coll_offset(ss1, ss2, 0));
}
-#define LSCDEF(N) \
-static int \
-list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \
-{ \
- \
- return (list_coll_offset(ss1, ss2, N)); \
+#define LSCDEF(N) \
+static int \
+list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \
+{ \
+ \
+ return (list_coll_offset(ss1, ss2, N)); \
}
LSCDEF(1)
diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c
index d989008..0a00889 100644
--- a/usr.bin/sort/file.c
+++ b/usr.bin/sort/file.c
@@ -188,42 +188,6 @@ file_is_tmp(const char* fn)
}
/*
- * Read zero-terminated line from a file
- */
-char *
-read_file0_line(struct file0_reader *f0r)
-{
- size_t pos = 0;
- int c;
-
- if ((f0r->f == NULL) || feof(f0r->f))
- return (NULL);
-
- if (f0r->current_line && f0r->current_sz > 0)
- f0r->current_line[0] = 0;
-
- while (!feof(f0r->f)) {
- c = fgetc(f0r->f);
- if (feof(f0r->f) || (c == -1))
- break;
- if ((pos + 1) >= f0r->current_sz) {
- size_t newsz = (f0r->current_sz + 2) * 2;
- f0r->current_line = sort_realloc(f0r->current_line,
- newsz);
- f0r->current_sz = newsz;
- }
- f0r->current_line[pos] = (char)c;
- if (c == 0)
- break;
- else
- f0r->current_line[pos + 1] = 0;
- ++pos;
- }
-
- return f0r->current_line;
-}
-
-/*
* Generate new temporary file name
*/
char *
@@ -1127,7 +1091,7 @@ file_headers_merge(size_t fnum, struct file_header **fh, FILE *f_out)
memset(&lp, 0, sizeof(lp));
/*
- * construct the initial sort structure
+ * construct the initial sort structure
*/
for (i = 0; i < fnum; i++)
file_header_list_push(fh[i], fh, i);
diff --git a/usr.bin/sort/file.h b/usr.bin/sort/file.h
index 7037d87..e87fafd 100644
--- a/usr.bin/sort/file.h
+++ b/usr.bin/sort/file.h
@@ -55,7 +55,7 @@ struct sort_list
};
/*
- * File reader object
+ * File reader object
*/
struct file_reader;
@@ -70,16 +70,6 @@ struct file_list
bool tmp;
};
-/*
- * Structure for zero-separated file reading (for input files list)
- */
-struct file0_reader
-{
- char *current_line;
- FILE *f;
- size_t current_sz;
-};
-
/* memory */
/**/
@@ -110,8 +100,6 @@ struct file_reader *file_reader_init(const char *fsrc);
struct bwstring *file_reader_readline(struct file_reader *fr);
void file_reader_free(struct file_reader *fr);
-char *read_file0_line(struct file0_reader *f0r);
-
void init_tmp_files(void);
void clear_tmp_files(void);
char *new_tmp_file_name(void);
diff --git a/usr.bin/sort/mem.c b/usr.bin/sort/mem.c
index 93cb019..c6e9a53 100644
--- a/usr.bin/sort/mem.c
+++ b/usr.bin/sort/mem.c
@@ -29,7 +29,6 @@
__FBSDID("$FreeBSD$");
#include <err.h>
-#include <stdint.h>
#include <stdlib.h>
#include <string.h>
diff --git a/usr.bin/sort/radixsort.c b/usr.bin/sort/radixsort.c
index f6cf6ac..1fa260b 100644
--- a/usr.bin/sort/radixsort.c
+++ b/usr.bin/sort/radixsort.c
@@ -129,7 +129,7 @@ have_sort_left(void)
* Push sort level to the stack
*/
static inline void
-push_ls(struct sort_level* sl)
+push_ls(struct sort_level *sl)
{
struct level_stack *new_ls;
@@ -308,7 +308,7 @@ run_sort_level_next(struct sort_level *sl)
sl->sublevels = NULL;
}
- switch (sl->tosort_num){
+ switch (sl->tosort_num) {
case 0:
goto end;
case (1):
diff --git a/usr.bin/sort/sort.1.in b/usr.bin/sort/sort.1.in
index 1a836a8..7559306 100644
--- a/usr.bin/sort/sort.1.in
+++ b/usr.bin/sort/sort.1.in
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sort.1,v 1.31 2007/08/21 21:22:37 millert Exp $
+.\" $OpenBSD: sort.1,v 1.45 2015/03/19 13:51:10 jmc Exp $
.\" $FreeBSD$
.\"
.\" Copyright (c) 1991, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)sort.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd July 3, 2012
+.Dd March 19 2015
.Dt SORT 1
.Os
.Sh NAME
@@ -160,9 +160,10 @@ before comparison, that is, perform case-independent sorting.
Sort by general numerical value.
As opposed to
.Fl n ,
-this option handles general floating points, which have a much
-permissive format than those allowed by
-. Fl n ,
+this option handles general floating points.
+It has a more
+permissive format than that allowed by
+.Fl n
but it has a significant performance drawback.
.It Fl h, Fl Fl human-numeric-sort, Fl Fl sort=human-numeric
Sort by numerical value, but take into account the SI suffix,
@@ -247,9 +248,8 @@ can be attached independently to each
argument of the key specifications.
.Fl b .
.It Xo
-.Sm off
-.Fl k\ \& Ar field1 Op , Ar field2 , Fl Fl key Ns = Ns Ar field1 Op , Ar field2
-.Sm on
+.Fl k Ar field1 Ns Op , Ns Ar field2 ,
+.Fl Fl key Ns = Ns Ar field1 Ns Op , Ns Ar field2
.Xc
Define a restricted sort key that has the starting position
.Ar field1 ,
@@ -334,7 +334,7 @@ standard output.
%%THREADS%%Default number equals to the number of CPUs.
.It Fl Fl files0-from Ns = Ns Ar filename
Take the input file list from the file
-.Ar filename.
+.Ar filename .
The file names must be separated by NUL
(like the output produced by the command "find ... -print0").
.It Fl Fl radixsort
@@ -610,9 +610,9 @@ A
command first appeared in
.At v3 .
.Sh AUTHORS
-Gabor Kovesdan <gabor@FreeBSD.org>,
+.An Gabor Kovesdan Aq Mt gabor@FreeBSD.org ,
.Pp
-Oleg Moskalenko <mom040267@gmail.com>
+.An Oleg Moskalenko Aq Mt mom040267@gmail.com
.Sh NOTES
This implementation of
.Nm
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index 372c661..43ae43c 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -229,34 +229,38 @@ usage(bool opt_err)
static void
read_fns_from_file0(const char *fn)
{
- if (fn) {
- struct file0_reader f0r;
- FILE *f;
+ FILE *f;
+ char *line = NULL;
+ size_t linesize = 0;
+ ssize_t linelen;
- f = fopen(fn, "r");
- if (f == NULL)
- err(2, NULL);
-
- memset(&f0r, 0, sizeof(f0r));
- f0r.f = f;
-
- while (!feof(f)) {
- char *line = read_file0_line(&f0r);
+ if (fn == NULL)
+ return;
- if (line && *line) {
- if (argc_from_file0 == (size_t)-1)
- argc_from_file0 = 0;
- ++argc_from_file0;
- argv_from_file0 = sort_realloc(argv_from_file0,
- argc_from_file0 * sizeof(char *));
- if (argv_from_file0 == NULL)
- err(2, NULL);
- argv_from_file0[argc_from_file0 - 1] =
- sort_strdup(line);
- }
+ f = fopen(fn, "r");
+ if (f == NULL)
+ err(2, "%s", fn);
+
+ while ((linelen = getdelim(&line, &linesize, '\0', f)) != -1) {
+ if (*line != '\0') {
+ if (argc_from_file0 == (size_t) - 1)
+ argc_from_file0 = 0;
+ ++argc_from_file0;
+ argv_from_file0 = sort_realloc(argv_from_file0,
+ argc_from_file0 * sizeof(char *));
+ if (argv_from_file0 == NULL)
+ err(2, NULL);
+ argv_from_file0[argc_from_file0 - 1] = line;
+ } else {
+ free(line);
}
- closefile(f, fn);
+ line = NULL;
+ linesize = 0;
}
+ if (ferror(f))
+ err(2, "%s: getdelim", fn);
+
+ closefile(f, fn);
}
/*
@@ -523,7 +527,7 @@ check_mutually_exclusive_flags(char c, bool *mef_flags)
int fo_index, mec;
bool found_others, found_this;
- found_others = found_this =false;
+ found_others = found_this = false;
fo_index = 0;
for (int i = 0; i < NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS; i++) {
diff --git a/usr.bin/split/Makefile b/usr.bin/split/Makefile
index 097932c..6891f8b 100644
--- a/usr.bin/split/Makefile
+++ b/usr.bin/split/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
PROG= split
-LDADD= -lutil
-DPADD= ${LIBUTIL}
+
+LIBADD= util
.include <bsd.prog.mk>
diff --git a/usr.bin/ssh-copy-id/ssh-copy-id.sh b/usr.bin/ssh-copy-id/ssh-copy-id.sh
index 09fb3cc..f03d5c0 100755
--- a/usr.bin/ssh-copy-id/ssh-copy-id.sh
+++ b/usr.bin/ssh-copy-id/ssh-copy-id.sh
@@ -48,7 +48,7 @@ sendkey() {
done ; \
if [ -x /sbin/restorecon ]; then \
/sbin/restorecon -F "$HOME/.ssh/" "$keyfile" >/dev/null 2>&1 || true ; \
- fi
+ fi \
'\'
}
diff --git a/usr.bin/strings/Makefile b/usr.bin/strings/Makefile
new file mode 100644
index 0000000..8543dcf
--- /dev/null
+++ b/usr.bin/strings/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+
+.PATH: ${ELFTCDIR}/strings
+
+PROG= strings
+
+LIBADD= elftc elf
+
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/su/Makefile b/usr.bin/su/Makefile
index d5eb805..178e670 100644
--- a/usr.bin/su/Makefile
+++ b/usr.bin/su/Makefile
@@ -7,13 +7,11 @@ PROG= su
WARNS?= 5
-DPADD= ${LIBUTIL} ${LIBPAM}
-LDADD= -lutil ${MINUSLPAM}
+LIBADD= util pam
.if ${MK_AUDIT} != "no"
CFLAGS+= -DUSE_BSM_AUDIT
-DPADD+= ${LIBBSM}
-LDADD+= -lbsm
+LIBADD+= bsm
.endif
BINOWN= root
diff --git a/usr.bin/svn/Makefile.inc b/usr.bin/svn/Makefile.inc
index 203b817..5fe6464 100644
--- a/usr.bin/svn/Makefile.inc
+++ b/usr.bin/svn/Makefile.inc
@@ -13,7 +13,6 @@ SVNLITE?= lite
SVNDIR= ${.CURDIR}/../../../contrib/subversion/subversion
APRU= ${.CURDIR}/../../../contrib/apr-util
APR= ${.CURDIR}/../../../contrib/apr
-SQLITE= ${.CURDIR}/../../../contrib/sqlite3
WARNS?= 0 # defintely not warns friendly
.if exists(${.CURDIR}/../../Makefile.inc)
@@ -22,7 +21,6 @@ WARNS?= 0 # defintely not warns friendly
LIBAPRDIR= ${.OBJDIR}/../lib/libapr
LIBAPR_UTILDIR= ${.OBJDIR}/../lib/libapr_util
-LIBSQLITEDIR= ${.OBJDIR}/../lib/libsqlite3
LIBSERFDIR= ${.OBJDIR}/../lib/libserf
LIBSVN_CLIENTDIR= ${.OBJDIR}/../lib/libsvn_client
@@ -41,7 +39,6 @@ LIBSVN_WCDIR= ${.OBJDIR}/../lib/libsvn_wc
LIBAPR= ${LIBAPRDIR}/libapr.a
LIBAPR_UTIL= ${LIBAPR_UTILDIR}/libapr-util.a
-LIBSQLITE= ${LIBSQLITEDIR}/libsqlite3.a
LIBSERF= ${LIBSERFDIR}/libserf.a
LIBSVN_CLIENT= ${LIBSVN_CLIENTDIR}/libsvn_client.a
diff --git a/usr.bin/svn/lib/Makefile b/usr.bin/svn/lib/Makefile
index 3200625..5f4cf28 100644
--- a/usr.bin/svn/lib/Makefile
+++ b/usr.bin/svn/lib/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
-SUBDIR= libapr libapr_util libserf libsqlite3 \
+SUBDIR= libapr libapr_util libserf \
libsvn_client libsvn_delta libsvn_diff libsvn_fs libsvn_fs_fs \
libsvn_fs_util libsvn_ra libsvn_ra_local libsvn_ra_serf \
libsvn_ra_svn libsvn_repos libsvn_subr libsvn_wc
diff --git a/usr.bin/svn/lib/libsqlite3/Makefile b/usr.bin/svn/lib/libsqlite3/Makefile
deleted file mode 100644
index 15a2d00..0000000
--- a/usr.bin/svn/lib/libsqlite3/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# $FreeBSD$
-
-.include "${.CURDIR}/../Makefile.inc"
-
-INTERNALLIB= yes
-LIB= sqlite3
-
-SRCS= sqlite3.c
-
-.PATH: ${SQLITE}
-
-CFLAGS+= -DHAVE_CONFIG_H -I${.CURDIR} \
- -I${APR}/include/arch/unix -I${APR}/include
-
-CFLAGS+= -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 \
- -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 \
- -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 \
- -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DHAVE_USLEEP=1 \
- -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 \
- -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 \
- -DHAVE_READLINE=1 -DHAVE_POSIX_FALLOCATE=1 \
- -I${SQLITE} -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 \
- -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE
-
-.include <bsd.lib.mk>
diff --git a/usr.bin/svn/svn/Makefile b/usr.bin/svn/svn/Makefile
index 76d923a..b4f76f5 100644
--- a/usr.bin/svn/svn/Makefile
+++ b/usr.bin/svn/svn/Makefile
@@ -39,17 +39,14 @@ LDADD= -L${LIBSVN_CLIENTDIR} -lsvn_client \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBSERFDIR} -lserf \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt -lmagic -lcrypto -lssl -lpthread
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z magic crypto ssl pthread
DPADD= ${LIBSVN_CLIENT} ${LIBSVN_WC} ${LIBSVN_RA} ${LIBSVN_RA_LOCAL} \
${LIBSVN_RA_SVN} ${LIBSVN_RA_SERF} ${LIBSVN_REPOS} \
${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} ${LIBSVN_DELTA} \
${LIBSVN_DIFF} ${LIBSVN_SUBR} ${LIBSERF} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT} ${LIBMAGIC} \
- ${LIBCRYPTO} ${LIBSSL} ${LIBPTHREAD}
+ ${LIBAPR}
CLEANFILES+= svnlite.1
.if(defined(ORGANIZATION) && !empty(ORGANIZATION))
@@ -57,7 +54,7 @@ DPSRCS+= freebsd-organization.h
CLEANFILES+= freebsd-organization.h
CFLAGS+= -I. -DHAS_ORGANIZATION_NAME
freebsd-organization.h:
- @echo '#define ORGANIZATION_NAME ${ORGANIZATION}' \
+ @echo "#define ORGANIZATION_NAME \"$$(eval echo ${ORGANIZATION})\"" \
> freebsd-organization.h
.endif
diff --git a/usr.bin/svn/svnadmin/Makefile b/usr.bin/svn/svnadmin/Makefile
index 3220cde..00a9e2f 100644
--- a/usr.bin/svn/svnadmin/Makefile
+++ b/usr.bin/svn/svnadmin/Makefile
@@ -25,13 +25,11 @@ LDADD= -L${LIBSVN_REPOSDIR} -lsvn_repos \
-L${LIBSVN_DELTADIR} -lsvn_delta \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z pthread
DPADD= ${LIBSVN_REPOS} ${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} \
${LIBSVN_DELTA} ${LIBSVN_SUBR} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT}
+ ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svndumpfilter/Makefile b/usr.bin/svn/svndumpfilter/Makefile
index 864f376..44b4f07 100644
--- a/usr.bin/svn/svndumpfilter/Makefile
+++ b/usr.bin/svn/svndumpfilter/Makefile
@@ -25,13 +25,11 @@ LDADD= -L${LIBSVN_REPOSDIR} -lsvn_repos \
-L${LIBSVN_DELTADIR} -lsvn_delta \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z crypt pthread
DPADD= ${LIBSVN_REPOS} ${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} \
${LIBSVN_DELTA} ${LIBSVN_SUBR} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT}
+ ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svnlook/Makefile b/usr.bin/svn/svnlook/Makefile
index 3d8b1a0..6e9f2fa 100644
--- a/usr.bin/svn/svnlook/Makefile
+++ b/usr.bin/svn/svnlook/Makefile
@@ -26,13 +26,11 @@ LDADD= -L${LIBSVN_REPOSDIR} -lsvn_repos \
-L${LIBSVN_DIFFDIR} -lsvn_diff \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z pthread
DPADD= ${LIBSVN_REPOS} ${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} \
${LIBSVN_DELTA} ${LIBSVN_DIFF} ${LIBSVN_SUBR} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT}
+ ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svnmucc/Makefile b/usr.bin/svn/svnmucc/Makefile
index 23a98e3..0b45ed6 100644
--- a/usr.bin/svn/svnmucc/Makefile
+++ b/usr.bin/svn/svnmucc/Makefile
@@ -31,15 +31,12 @@ LDADD= -L${LIBSVN_CLIENTDIR} -lsvn_client \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBSERFDIR} -lserf \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt -lmagic -lcrypto -lssl -lpthread
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z crypto ssl pthread
DPADD= ${LIBSVN_CLIENT} ${LIBSVN_RA} ${LIBSVN_RA_LOCAL} ${LIBSVN_RA_SVN} \
${LIBSVN_RA_SERF} ${LIBSVN_REPOS} ${LIBSVN_FS} ${LIBSVN_FS_FS} \
${LIBSVN_FS_UTIL} ${LIBSVN_DELTA} ${LIBSVN_SUBR} ${LIBSERF} \
- ${LIBAPR_UTIL} ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} \
- ${LIBCRYPT} ${LIBMAGIC} ${LIBCRYPTO} ${LIBSSL} ${LIBPTHREAD}
+ ${LIBAPR_UTIL} ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svnrdump/Makefile b/usr.bin/svn/svnrdump/Makefile
index afeae00..ca9022c 100644
--- a/usr.bin/svn/svnrdump/Makefile
+++ b/usr.bin/svn/svnrdump/Makefile
@@ -33,16 +33,13 @@ LDADD= -L${LIBSVN_CLIENTDIR} -lsvn_client \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBSERFDIR} -lserf \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt -lmagic -lcrypto -lssl -lpthread
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z crypto ssl pthread
DPADD= ${LIBSVN_CLIENT} ${LIBSVN_WC} ${LIBSVN_RA} ${LIBSVN_RA_LOCAL} \
${LIBSVN_RA_SVN} ${LIBSVN_RA_SERF} ${LIBSVN_REPOS} \
${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} ${LIBSVN_DELTA} \
${LIBSVN_DIFF} ${LIBSVN_SUBR} ${LIBSERF} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT} ${LIBMAGIC} \
- ${LIBCRYPTO} ${LIBSSL} ${LIBPTHREAD}
+ ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svnserve/Makefile b/usr.bin/svn/svnserve/Makefile
index f1fa314..0622740 100644
--- a/usr.bin/svn/svnserve/Makefile
+++ b/usr.bin/svn/svnserve/Makefile
@@ -30,15 +30,12 @@ LDADD= -L${LIBSVN_RADIR} -lsvn_ra \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBSERFDIR} -lserf \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt -lmagic -lcrypto -lssl -lpthread
+ -L${LIBAPRDIR} -lapr
+LIBADD= bsdxml sqlite3 z pthread
DPADD= ${LIBSVN_RA} ${LIBSVN_RA_LOCAL} ${LIBSVN_RA_SVN} ${LIBSVN_RA_SERF} \
${LIBSVN_REPOS} ${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} \
${LIBSVN_DELTA} ${LIBSVN_SUBR} ${LIBSERF} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT} ${LIBMAGIC} \
- ${LIBCRYPTO} ${LIBSSL} ${LIBPTHREAD}
+ ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svnsync/Makefile b/usr.bin/svn/svnsync/Makefile
index a8cd380..4417760 100644
--- a/usr.bin/svn/svnsync/Makefile
+++ b/usr.bin/svn/svnsync/Makefile
@@ -30,15 +30,12 @@ LDADD= -L${LIBSVN_RADIR} -lsvn_ra \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBSERFDIR} -lserf \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt -lmagic -lcrypto -lssl -lpthread
+ -L${LIBAPRDIR} -lapr
+LIBADD= bsdxml sqlite3 z crypto ssl pthread
DPADD= ${LIBSVN_RA} ${LIBSVN_RA_LOCAL} ${LIBSVN_RA_SVN} ${LIBSVN_RA_SERF} \
${LIBSVN_REPOS} ${LIBSVN_FS} ${LIBSVN_FS_FS} ${LIBSVN_FS_UTIL} \
${LIBSVN_DELTA} ${LIBSVN_SUBR} ${LIBSERF} ${LIBAPR_UTIL} \
- ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} ${LIBZ} ${LIBCRYPT} ${LIBMAGIC} \
- ${LIBCRYPTO} ${LIBSSL} ${LIBPTHREAD}
+ ${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/svnversion/Makefile b/usr.bin/svn/svnversion/Makefile
index ca28ec3..594ba34 100644
--- a/usr.bin/svn/svnversion/Makefile
+++ b/usr.bin/svn/svnversion/Makefile
@@ -23,13 +23,10 @@ LDADD= -L${LIBSVN_WCDIR} -lsvn_wc \
-L${LIBSVN_DIFFDIR} -lsvn_diff \
-L${LIBSVN_SUBRDIR} -lsvn_subr \
-L${LIBAPR_UTILDIR} -lapr-util \
- -lbsdxml \
- -L${LIBAPRDIR} -lapr \
- -L${LIBSQLITEDIR} -lsqlite3 \
- -lz -lcrypt
+ -L${LIBAPRDIR} -lapr
+LIBADD+= bsdxml sqlite3 z pthread
DPADD= ${LIBSVN_WC} ${LIBSVN_DELTA} ${LIBSVN_DIFF} ${LIBSVN_SUBR} \
- ${LIBSERF} ${LIBAPR_UTIL} ${LIBBSDXML} ${LIBAPR} ${LIBSQLITE} \
- ${LIBZ} ${LIBCRYPT}
+ ${LIBSERF} ${LIBAPR_UTIL}${LIBAPR}
.include <bsd.prog.mk>
diff --git a/usr.bin/systat/Makefile b/usr.bin/systat/Makefile
index 1bb2da0..672aadc 100644
--- a/usr.bin/systat/Makefile
+++ b/usr.bin/systat/Makefile
@@ -16,7 +16,6 @@ CFLAGS+= -DINET6
WARNS?= 0
-DPADD= ${LIBNCURSESW} ${LIBM} ${LIBDEVSTAT} ${LIBKVM}
-LDADD= -lncursesw -lm -ldevstat -lkvm
+LIBADD= ncursesw m devstat kvm
.include <bsd.prog.mk>
diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c
index bb1318d..b5938eb 100644
--- a/usr.bin/systat/netstat.c
+++ b/usr.bin/systat/netstat.c
@@ -333,8 +333,8 @@ enter_kvm(struct inpcb *inp, struct socket *so, int state, const char *proto)
struct netinfo *p;
if ((p = enter(inp, state, proto)) != NULL) {
- p->ni_rcvcc = so->so_rcv.sb_cc;
- p->ni_sndcc = so->so_snd.sb_cc;
+ p->ni_rcvcc = so->so_rcv.sb_ccc;
+ p->ni_sndcc = so->so_snd.sb_ccc;
}
}
diff --git a/usr.bin/tabs/Makefile b/usr.bin/tabs/Makefile
index 2c5f729..f8c085b 100644
--- a/usr.bin/tabs/Makefile
+++ b/usr.bin/tabs/Makefile
@@ -1,7 +1,7 @@
# $FreeBSD$
PROG= tabs
-DPADD= ${LIBTERMCAPW}
-LDADD= -ltermcapw
+
+LIBADD= ncursesw
.include <bsd.prog.mk>
diff --git a/usr.bin/talk/Makefile b/usr.bin/talk/Makefile
index eb14d22..f595be8 100644
--- a/usr.bin/talk/Makefile
+++ b/usr.bin/talk/Makefile
@@ -4,7 +4,7 @@
PROG= talk
SRCS= ctl.c ctl_transact.c display.c get_addrs.c get_iface.c get_names.c \
init_disp.c invite.c io.c look_up.c msgs.c talk.c
-DPADD= ${LIBNCURSESW}
-LDADD= -lncursesw
+
+LIBADD= ncursesw
.include <bsd.prog.mk>
diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile
index a289ea4..e8a9ad4 100644
--- a/usr.bin/tar/Makefile
+++ b/usr.bin/tar/Makefile
@@ -19,15 +19,7 @@ SRCS= bsdtar.c \
SRCS+= err.c \
line_reader.c
-DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ} ${LIBLZMA} ${LIBBSDXML}
-LDADD= -larchive -lbz2 -lz -llzma -lbsdxml
-.if ${MK_OPENSSL} != "no"
-DPADD+= ${LIBCRYPTO}
-LDADD+= -lcrypto
-.else
-DPADD+= ${LIBMD}
-LDADD+= -lmd
-.endif
+LIBADD= archive
.if ${MK_ICONV} != "no"
CFLAGS+= -DHAVE_ICONV=1 -DHAVE_ICONV_H=1 -DICONV_CONST=const
@@ -39,7 +31,6 @@ CFLAGS+= -I${LIBARCHIVEDIR}/tar -I${LIBARCHIVEDIR}/libarchive
CFLAGS+= -I${LIBARCHIVEDIR}/libarchive_fe
SYMLINKS= bsdtar ${BINDIR}/tar
MLINKS= bsdtar.1 tar.1
-DEBUG_FLAGS=-g
.PHONY: check test clean-test
check test: $(PROG) bsdtar.1.gz
diff --git a/usr.bin/tar/Makefile.depend b/usr.bin/tar/Makefile.depend
index 7f1d531..52fc11f 100644
--- a/usr.bin/tar/Makefile.depend
+++ b/usr.bin/tar/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/libcompiler_rt \
lib/libexpat \
lib/liblzma \
+ lib/libthr \
lib/libz \
secure/lib/libcrypto \
diff --git a/usr.bin/telnet/Makefile b/usr.bin/telnet/Makefile
index b88f8e1..a24a966 100644
--- a/usr.bin/telnet/Makefile
+++ b/usr.bin/telnet/Makefile
@@ -19,15 +19,11 @@ CFLAGS+= -DINET6
WARNS?= 2
-LIBTELNET= ${.OBJDIR}/../../lib/libtelnet/libtelnet.a
-
-DPADD= ${LIBTERMCAPW} ${LIBTELNET}
-LDADD= -ltermcapw ${LIBTELNET}
+LIBADD= telnet ncursesw
.if !defined(RELEASE_CRUNCH)
CFLAGS+= -DIPSEC
-DPADD+= ${LIBIPSEC}
-LDADD+= -lipsec
+LIBADD+= ipsec
.else
.PATH: ${TELNETDIR}/libtelnet
SRCS+= genget.c getent.c misc.c
@@ -35,16 +31,14 @@ CFLAGS+= -DHAS_CGETENT
.endif
.if ${MK_OPENSSL} != "no"
-SRCS+= authenc.c
+SRCS+= authenc.c
CFLAGS+= -DENCRYPTION -DAUTHENTICATION -DIPSEC
-DPADD+= ${LIBMP} ${LIBCRYPTO} ${LIBCRYPT} ${LIBIPSEC} ${LIBPAM}
-LDADD+= -lmp -lcrypto -lcrypt -lipsec ${MINUSLPAM}
+LIBADD+= mp crypto ipsec pam
.endif
.if ${MK_KERBEROS_SUPPORT} != "no"
CFLAGS+= -DKRB5 -DFORWARD -Dnet_write=telnet_net_write
-DPADD+= ${LIBKRB5} ${LIBHX509} ${LIBASN1} ${LIBCOM_ERR} ${LIBROKEN}
-LDADD+= -lkrb5 -lhx509 -lasn1 -lcom_err -lroken
+LIBADD+= krb5 roken
.endif
.include <bsd.prog.mk>
diff --git a/usr.bin/tftp/Makefile b/usr.bin/tftp/Makefile
index 88f8c37..0f96d23 100644
--- a/usr.bin/tftp/Makefile
+++ b/usr.bin/tftp/Makefile
@@ -7,7 +7,7 @@ PROG= tftp
SRCS= main.c tftp-file.c tftp-io.c tftp-options.c tftp-transfer.c
SRCS+= tftp-utils.c tftp.c
CFLAGS+=-I${.CURDIR}/../../libexec/tftpd
-DPADD= ${LIBEDIT} ${LIBTERMCAPW}
-LDADD= -ledit -ltermcapw
+
+LIBADD= edit
.include <bsd.prog.mk>
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c
index c2ea522..678a2af 100644
--- a/usr.bin/time/time.c
+++ b/usr.bin/time/time.c
@@ -65,6 +65,7 @@ static void showtime(FILE *, struct timeval *, struct timeval *,
static void siginfo(int);
static void usage(void);
+static sig_atomic_t siginfo_recvd;
static char decimal_point;
static struct timeval before_tv;
static int hflag, pflag;
@@ -130,8 +131,17 @@ main(int argc, char **argv)
/* parent */
(void)signal(SIGINT, SIG_IGN);
(void)signal(SIGQUIT, SIG_IGN);
+ siginfo_recvd = 0;
(void)signal(SIGINFO, siginfo);
- while (wait4(pid, &status, 0, &ru) != pid);
+ (void)siginterrupt(SIGINFO, 1);
+ while (wait4(pid, &status, 0, &ru) != pid) {
+ if (siginfo_recvd) {
+ siginfo_recvd = 0;
+ (void)gettimeofday(&after, NULL);
+ getrusage(RUSAGE_CHILDREN, &ru);
+ showtime(stdout, &before_tv, &after, &ru);
+ }
+ }
(void)gettimeofday(&after, NULL);
if ( ! WIFEXITED(status))
warnx("command terminated abnormally");
@@ -292,10 +302,6 @@ showtime(FILE *out, struct timeval *before, struct timeval *after,
static void
siginfo(int sig __unused)
{
- struct timeval after;
- struct rusage ru;
- (void)gettimeofday(&after, NULL);
- getrusage(RUSAGE_CHILDREN, &ru);
- showtime(stdout, &before_tv, &after, &ru);
+ siginfo_recvd = 1;
}
diff --git a/usr.bin/timeout/timeout.c b/usr.bin/timeout/timeout.c
index 214ab13..a682dde 100644
--- a/usr.bin/timeout/timeout.c
+++ b/usr.bin/timeout/timeout.c
@@ -28,6 +28,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/procctl.h>
#include <sys/time.h>
#include <sys/wait.h>
@@ -166,12 +167,15 @@ main(int argc, char **argv)
int foreground, preserve;
int error, pstat, status;
int killsig = SIGTERM;
- pid_t pgid, pid, cpid;
+ pid_t pid, cpid;
double first_kill;
double second_kill;
bool timedout = false;
bool do_second_kill = false;
+ bool child_done = false;
struct sigaction signals;
+ struct procctl_reaper_status info;
+ struct procctl_reaper_kill killemall;
int signums[] = {
-1,
SIGTERM,
@@ -184,8 +188,6 @@ main(int argc, char **argv)
foreground = preserve = 0;
second_kill = 0;
- cpid = -1;
- pgid = -1;
const struct option longopts[] = {
{ "preserve-status", no_argument, &preserve, 1 },
@@ -225,10 +227,9 @@ main(int argc, char **argv)
argv++;
if (!foreground) {
- pgid = setpgid(0,0);
-
- if (pgid == -1)
- err(EX_OSERR, "setpgid()");
+ /* Aquire a reaper */
+ if (procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL) == -1)
+ err(EX_OSERR, "Fail to acquire the reaper");
}
memset(&signals, 0, sizeof(signals));
@@ -280,20 +281,38 @@ main(int argc, char **argv)
if (sig_chld) {
sig_chld = 0;
- while (((cpid = wait(&status)) < 0) && errno == EINTR)
- continue;
- if (cpid == pid) {
- pstat = status;
- break;
+ while ((cpid = waitpid(-1, &status, WNOHANG)) != 0) {
+ if (cpid < 0) {
+ if (errno == EINTR)
+ continue;
+ else
+ break;
+ } else if (cpid == pid) {
+ pstat = status;
+ child_done = true;
+ }
+ }
+ if (child_done) {
+ if (foreground) {
+ break;
+ } else {
+ procctl(P_PID, getpid(),
+ PROC_REAP_STATUS, &info);
+ if (info.rs_children == 0)
+ break;
+ }
}
} else if (sig_alrm) {
sig_alrm = 0;
timedout = true;
- if (!foreground)
- killpg(pgid, killsig);
- else
+ if (!foreground) {
+ killemall.rk_sig = killsig;
+ killemall.rk_flags = 0;
+ procctl(P_PID, getpid(), PROC_REAP_KILL,
+ &killemall);
+ } else
kill(pid, killsig);
if (do_second_kill) {
@@ -305,9 +324,12 @@ main(int argc, char **argv)
break;
} else if (sig_term) {
- if (!foreground)
- killpg(pgid, killsig);
- else
+ if (!foreground) {
+ killemall.rk_sig = sig_term;
+ killemall.rk_flags = 0;
+ procctl(P_PID, getpid(), PROC_REAP_KILL,
+ &killemall);
+ } else
kill(pid, sig_term);
if (do_second_kill) {
@@ -320,11 +342,14 @@ main(int argc, char **argv)
}
}
- while (cpid != pid && wait(&pstat) == -1) {
+ while (!child_done && wait(&pstat) == -1) {
if (errno != EINTR)
err(EX_OSERR, "waitpid()");
}
+ if (!foreground)
+ procctl(P_PID, getpid(), PROC_REAP_RELEASE, NULL);
+
if (WEXITSTATUS(pstat))
pstat = WEXITSTATUS(pstat);
else if(WIFSIGNALED(pstat))
diff --git a/usr.bin/top/Makefile b/usr.bin/top/Makefile
index 0f8d980..edeb47f 100644
--- a/usr.bin/top/Makefile
+++ b/usr.bin/top/Makefile
@@ -21,8 +21,7 @@ WARNS?= 0
CFLAGS+= -D"Table_size=${TOP_TABLE_SIZE}"
.endif
-DPADD= ${LIBTERMCAP} ${LIBM} ${LIBKVM} ${LIBJAIL}
-LDADD= -ltermcap -lm -lkvm -ljail
+LIBADD= ncursesw m kvm jail
CLEANFILES= sigdesc.h
SIGCONV_AWK= ${.CURDIR}/../../contrib/top/sigconv.awk
diff --git a/usr.bin/top/Makefile.depend b/usr.bin/top/Makefile.depend
index e5ee6d3..fd276ae 100644
--- a/usr.bin/top/Makefile.depend
+++ b/usr.bin/top/Makefile.depend
@@ -14,7 +14,7 @@ DIRDEPS = \
lib/libjail \
lib/libkvm \
lib/msun \
- lib/ncurses/ncurses \
+ lib/ncurses/ncursesw \
.include <dirdeps.mk>
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 0a74521..20be935 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -373,7 +373,7 @@ machine_init(struct statics *statics, char do_unames)
size = sizeof(long) * maxcpu * CPUSTATES;
times = malloc(size);
if (times == NULL)
- err(1, "malloc %zd bytes", size);
+ err(1, "malloc %zu bytes", size);
if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1)
err(1, "sysctlbyname kern.cp_times");
pcpu_cp_time = calloc(1, size);
@@ -1004,7 +1004,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags)
argbuflen = cmdlen * 4;
argbuf = (char *)malloc(argbuflen + 1);
if (argbuf == NULL) {
- warn("malloc(%zd)", argbuflen + 1);
+ warn("malloc(%zu)", argbuflen + 1);
free(cmdbuf);
return NULL;
}
diff --git a/usr.bin/touch/touch.1 b/usr.bin/touch/touch.1
index 6201b28..a3cc2a7 100644
--- a/usr.bin/touch/touch.1
+++ b/usr.bin/touch/touch.1
@@ -31,7 +31,7 @@
.\" @(#)touch.1 8.3 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
-.Dd June 10, 2012
+.Dd March 8, 2015
.Dt TOUCH 1
.Os
.Sh NAME
@@ -238,7 +238,7 @@ If the
letter pair is in the range 39 to 99, the year is set to 1939 to 1999,
otherwise, the year is set in the 21st century.
.Sh SEE ALSO
-.Xr utimes 2
+.Xr utimensat 2
.Sh STANDARDS
The
.Nm
diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c
index 4439c07..804af7e 100644
--- a/usr.bin/touch/touch.c
+++ b/usr.bin/touch/touch.c
@@ -56,10 +56,10 @@ static const char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93";
#include <time.h>
#include <unistd.h>
-static void stime_arg1(const char *, struct timeval *);
-static void stime_arg2(const char *, int, struct timeval *);
-static void stime_darg(const char *, struct timeval *);
-static void stime_file(const char *, struct timeval *);
+static void stime_arg1(const char *, struct timespec *);
+static void stime_arg2(const char *, int, struct timespec *);
+static void stime_darg(const char *, struct timespec *);
+static void stime_file(const char *, struct timespec *);
static int timeoffset(const char *);
static void usage(const char *);
@@ -67,19 +67,17 @@ int
main(int argc, char *argv[])
{
struct stat sb;
- struct timeval tv[2];
- int (*stat_f)(const char *, struct stat *);
- int (*utimes_f)(const char *, const struct timeval *);
+ struct timespec ts[2];
+ int atflag;
int Aflag, aflag, cflag, mflag, ch, fd, len, rval, timeset;
char *p;
char *myname;
myname = basename(argv[0]);
Aflag = aflag = cflag = mflag = timeset = 0;
- stat_f = stat;
- utimes_f = utimes;
- if (gettimeofday(&tv[0], NULL) == -1)
- err(1, "gettimeofday");
+ atflag = 0;
+ ts[0].tv_sec = ts[1].tv_sec = 0;
+ ts[0].tv_nsec = ts[1].tv_nsec = UTIME_NOW;
while ((ch = getopt(argc, argv, "A:acd:fhmr:t:")) != -1)
switch(ch) {
@@ -94,26 +92,25 @@ main(int argc, char *argv[])
break;
case 'd':
timeset = 1;
- stime_darg(optarg, tv);
+ stime_darg(optarg, ts);
break;
case 'f':
/* No-op for compatibility. */
break;
case 'h':
cflag = 1;
- stat_f = lstat;
- utimes_f = lutimes;
+ atflag = AT_SYMLINK_NOFOLLOW;
break;
case 'm':
mflag = 1;
break;
case 'r':
timeset = 1;
- stime_file(optarg, tv);
+ stime_file(optarg, ts);
break;
case 't':
timeset = 1;
- stime_arg1(optarg, tv);
+ stime_arg1(optarg, ts);
break;
default:
usage(myname);
@@ -132,9 +129,9 @@ main(int argc, char *argv[])
* that time once and for all here.
*/
if (aflag)
- tv[0].tv_sec += Aflag;
+ ts[0].tv_sec += Aflag;
if (mflag)
- tv[1].tv_sec += Aflag;
+ ts[1].tv_sec += Aflag;
Aflag = 0; /* done our job */
}
} else {
@@ -148,13 +145,18 @@ main(int argc, char *argv[])
len = p - argv[0];
if (*p == '\0' && (len == 8 || len == 10)) {
timeset = 1;
- stime_arg2(*argv++, len == 10, tv);
+ stime_arg2(*argv++, len == 10, ts);
}
}
/* Both times default to the same. */
- tv[1] = tv[0];
+ ts[1] = ts[0];
}
+ if (!aflag)
+ ts[0].tv_nsec = UTIME_OMIT;
+ if (!mflag)
+ ts[1].tv_nsec = UTIME_OMIT;
+
if (*argv == NULL)
usage(myname);
@@ -163,7 +165,7 @@ main(int argc, char *argv[])
for (rval = 0; *argv; ++argv) {
/* See if the file exists. */
- if (stat_f(*argv, &sb) != 0) {
+ if (fstatat(AT_FDCWD, *argv, &sb, atflag) != 0) {
if (errno != ENOENT) {
rval = 1;
warn("%s", *argv);
@@ -186,44 +188,22 @@ main(int argc, char *argv[])
continue;
}
- if (!aflag)
- TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atim);
- if (!mflag)
- TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtim);
-
/*
* We're adjusting the times based on the file times, not a
* specified time (that gets handled above).
*/
if (Aflag) {
if (aflag) {
- TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atim);
- tv[0].tv_sec += Aflag;
+ ts[0] = sb.st_atim;
+ ts[0].tv_sec += Aflag;
}
if (mflag) {
- TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtim);
- tv[1].tv_sec += Aflag;
+ ts[1] = sb.st_mtim;
+ ts[1].tv_sec += Aflag;
}
}
- /* Try utimes(2). */
- if (!utimes_f(*argv, tv))
- continue;
-
- /* If the user specified a time, nothing else we can do. */
- if (timeset || Aflag) {
- rval = 1;
- warn("%s", *argv);
- continue;
- }
-
- /*
- * System V and POSIX 1003.1 require that a NULL argument
- * set the access/modification times to the current time.
- * The permission checks are different, too, in that the
- * ability to write the file is sufficient. Take a shot.
- */
- if (!utimes_f(*argv, NULL))
+ if (!utimensat(AT_FDCWD, *argv, ts, atflag))
continue;
rval = 1;
@@ -235,14 +215,14 @@ main(int argc, char *argv[])
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
static void
-stime_arg1(const char *arg, struct timeval *tvp)
+stime_arg1(const char *arg, struct timespec *tvp)
{
time_t now;
struct tm *t;
int yearset;
char *p;
- /* Start with the current time. */
- now = tvp[0].tv_sec;
+
+ now = time(NULL);
if ((t = localtime(&now)) == NULL)
err(1, "localtime");
/* [[CC]YY]MMDDhhmm[.SS] */
@@ -291,7 +271,7 @@ stime_arg1(const char *arg, struct timeval *tvp)
if (tvp[0].tv_sec == -1)
goto terr;
- tvp[0].tv_usec = tvp[1].tv_usec = 0;
+ tvp[0].tv_nsec = tvp[1].tv_nsec = 0;
return;
terr:
@@ -299,12 +279,12 @@ terr:
}
static void
-stime_arg2(const char *arg, int year, struct timeval *tvp)
+stime_arg2(const char *arg, int year, struct timespec *tvp)
{
time_t now;
struct tm *t;
- /* Start with the current time. */
- now = tvp[0].tv_sec;
+
+ now = time(NULL);
if ((t = localtime(&now)) == NULL)
err(1, "localtime");
@@ -325,18 +305,18 @@ stime_arg2(const char *arg, int year, struct timeval *tvp)
errx(1,
"out of range or illegal time specification: MMDDhhmm[yy]");
- tvp[0].tv_usec = tvp[1].tv_usec = 0;
+ tvp[0].tv_nsec = tvp[1].tv_nsec = 0;
}
static void
-stime_darg(const char *arg, struct timeval *tvp)
+stime_darg(const char *arg, struct timespec *tvp)
{
struct tm t = { .tm_sec = 0 };
const char *fmt, *colon;
char *p;
int val, isutc = 0;
- tvp[0].tv_usec = 0;
+ tvp[0].tv_nsec = 0;
t.tm_isdst = -1;
colon = strchr(arg, ':');
if (colon == NULL || strchr(colon + 1, ':') == NULL)
@@ -349,9 +329,9 @@ stime_darg(const char *arg, struct timeval *tvp)
/* POSIX: must have at least one digit after dot */
if ((*p == '.' || *p == ',') && isdigit((unsigned char)p[1])) {
p++;
- val = 100000;
+ val = 100000000;
while (isdigit((unsigned char)*p)) {
- tvp[0].tv_usec += val * (*p - '0');
+ tvp[0].tv_nsec += val * (*p - '0');
p++;
val /= 10;
}
@@ -403,14 +383,14 @@ timeoffset(const char *arg)
}
static void
-stime_file(const char *fname, struct timeval *tvp)
+stime_file(const char *fname, struct timespec *tsp)
{
struct stat sb;
if (stat(fname, &sb))
err(1, "%s", fname);
- TIMESPEC_TO_TIMEVAL(tvp, &sb.st_atim);
- TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtim);
+ tsp[0] = sb.st_atim;
+ tsp[1] = sb.st_mtim;
}
static void
diff --git a/usr.bin/tput/Makefile b/usr.bin/tput/Makefile
index c42ef79..d3171da 100644
--- a/usr.bin/tput/Makefile
+++ b/usr.bin/tput/Makefile
@@ -2,8 +2,7 @@
# $FreeBSD$
PROG= tput
-DPADD= ${LIBTERMCAPW}
-LDADD= -ltermcapw
+LIBADD= ncursesw
SCRIPTS=clear.sh
MLINKS= tput.1 clear.1
diff --git a/usr.bin/truncate/Makefile b/usr.bin/truncate/Makefile
index b51c9b0..a6de5c6 100644
--- a/usr.bin/truncate/Makefile
+++ b/usr.bin/truncate/Makefile
@@ -2,9 +2,8 @@
.include <src.opts.mk>
-PROG= truncate
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+PROG= truncate
+LIBADD= util
.if ${MK_TESTS} != "no"
SUBDIR+= tests
diff --git a/usr.bin/tset/Makefile b/usr.bin/tset/Makefile
index c486bf8..acf8334 100644
--- a/usr.bin/tset/Makefile
+++ b/usr.bin/tset/Makefile
@@ -4,8 +4,7 @@
PROG= tset
SRCS= map.c misc.c set.c term.c tset.c wrterm.c
-DPADD= ${LIBTERMCAPW}
-LDADD= -ltermcapw
+LIBADD= ncursesw
LINKS= ${BINDIR}/tset ${BINDIR}/reset
MLINKS= tset.1 reset.1
diff --git a/usr.bin/ul/Makefile b/usr.bin/ul/Makefile
index 685e4a4..817f07b 100644
--- a/usr.bin/ul/Makefile
+++ b/usr.bin/ul/Makefile
@@ -3,7 +3,6 @@
PROG= ul
-DPADD= ${LIBTERMCAPW}
-LDADD= -ltermcapw
+LIBADD= ncursesw
.include <bsd.prog.mk>
diff --git a/usr.bin/unifdef/unifdef.1 b/usr.bin/unifdef/unifdef.1
index f09a244..24a9205 100644
--- a/usr.bin/unifdef/unifdef.1
+++ b/usr.bin/unifdef/unifdef.1
@@ -31,7 +31,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 21, 2012
+.Dd January 7, 2014
.Dt UNIFDEF 1 PRM
.Os " "
.Sh NAME
@@ -44,6 +44,7 @@
.Op Fl [i]D Ns Ar sym Ns Op = Ns Ar val
.Op Fl [i]U Ns Ar sym
.Ar ...
+.Op Fl f Ar defile
.Op Fl x Bro Ar 012 Brc
.Op Fl M Ar backext
.Op Fl o Ar outfile
@@ -70,11 +71,17 @@ utility acts on
.Ic #elif , #else ,
and
.Ic #endif
-lines.
-A directive is only processed
-if the symbols specified on the command line are sufficient to allow
-.Nm
-to get a definite value for its control expression.
+lines,
+using macros specified in
+.Fl D
+and
+.Fl U
+command line options or in
+.Fl f
+definitions files.
+A directive is processed
+if the macro specifications are sufficient to provide
+a definite value for its control expression.
If the result is false,
the directive and the following lines under its control are removed.
If the result is true,
@@ -84,7 +91,7 @@ An
or
.Ic #ifndef
directive is passed through unchanged
-if its controlling symbol is not specified on the command line.
+if its controlling macro is not specified.
Any
.Ic #if
or
@@ -110,7 +117,7 @@ and
.Ic #elif
lines:
integer constants,
-integer values of symbols defined on the command line,
+integer values of macros defined on the command line,
the
.Fn defined
operator,
@@ -131,16 +138,42 @@ if either operand of
.Ic ||
is definitely true then the result is true.
.Pp
-In most cases, the
+When evaluating an expression,
.Nm
-utility does not distinguish between object-like macros
-(without arguments) and function-like arguments (with arguments).
-If a macro is not explicitly defined, or is defined with the
+does not expand macros first.
+The value of a macro must be a simple number,
+not an expression.
+A limited form of indirection is allowed,
+where one macro's value is the name of another.
+.Pp
+In most cases,
+.Nm
+does not distinguish between object-like macros
+(without arguments) and function-like macros (with arguments).
+A function-like macro invocation can appear in
+.Ic #if
+and
+.Ic #elif
+control expressions.
+If the macro is not explicitly defined,
+or is defined with the
.Fl D
-flag on the command-line, its arguments are ignored.
+flag on the command-line,
+or with
+.Ic #define
+in a
+.Fl f
+definitions file,
+its arguments are ignored.
If a macro is explicitly undefined on the command line with the
.Fl U
-flag, it may not have any arguments since this leads to a syntax error.
+flag,
+or with
+.Ic #undef
+in a
+.Fl f
+definitions file,
+it may not have any arguments since this leads to a syntax error.
.Pp
The
.Nm
@@ -161,7 +194,7 @@ It uses
.Nm Fl s
and
.Nm cpp Fl dM
-to get lists of all the controlling symbols
+to get lists of all the controlling macros
and their definitions (or lack thereof),
then invokes
.Nm
@@ -169,19 +202,15 @@ with appropriate arguments to process the file.
.Sh OPTIONS
.Bl -tag -width indent -compact
.It Fl D Ns Ar sym Ns = Ns Ar val
-Specify that a symbol is defined to a given value
-which is used when evaluating
-.Ic #if
-and
-.Ic #elif
-control expressions.
+Specify that a macro is defined to a given value.
.Pp
.It Fl D Ns Ar sym
-Specify that a symbol is defined to the value 1.
+Specify that a macro is defined to the value 1.
.Pp
.It Fl U Ns Ar sym
-Specify that a symbol is undefined.
-If the same symbol appears in more than one argument,
+Specify that a macro is undefined.
+.Pp
+If the same macro appears in more than one argument,
the last occurrence dominates.
.Pp
.It Fl iD Ns Ar sym Ns Op = Ns Ar val
@@ -193,9 +222,37 @@ are ignored within
and
.Ic #ifndef
blocks
-controlled by symbols
+controlled by macros
specified with these options.
.Pp
+.It Fl f Ar defile
+The file
+.Ar defile
+contains
+.Ic #define
+and
+.Ic #undef
+preprocessor directives,
+which have the same effect as the corresponding
+.Fl D
+and
+.Fl U
+command-line arguments.
+You can have multiple
+.Fl f
+arguments and mix them with
+.Fl D
+and
+.Fl U
+arguments;
+later options override earlier ones.
+.Pp
+Each directive must be on a single line.
+Object-like macro definitions (without arguments)
+are set to the given value.
+Function-like macro definitions (with arguments)
+are treated as if they are set to 1.
+.Pp
.It Fl b
Replace removed lines with blank lines
instead of deleting them.
@@ -291,24 +348,15 @@ instead of the standard output when processing a single file.
Instead of processing an input file as usual,
this option causes
.Nm
-to produce a list of symbols that appear in expressions
-that
-.Nm
-understands.
-It is useful in conjunction with the
-.Fl dM
-option of
-.Xr cpp 1
-for creating
-.Nm
-command lines.
+to produce a list of macros that are used in
+preprocessor directive controlling expressions.
.Pp
.It Fl S
Like the
.Fl s
-option, but the nesting depth of each symbol is also printed.
+option, but the nesting depth of each macro is also printed.
This is useful for working out the number of possible combinations
-of interdependent defined/undefined symbols.
+of interdependent defined/undefined macros.
.Pp
.It Fl t
Disables parsing for C strings, comments,
@@ -406,6 +454,9 @@ in comment.
.Sh SEE ALSO
.Xr cpp 1 ,
.Xr diff 1
+.Pp
+The unifdef home page is
+.Pa http://dotat.at/prog/unifdef
.Sh HISTORY
The
.Nm
@@ -431,7 +482,7 @@ cannot be handled in every situation.
.Pp
Trigraphs are not recognized.
.Pp
-There is no support for symbols with different definitions at
+There is no support for macros with different definitions at
different points in the source file.
.Pp
The text-mode and ignore functionality does not correspond to modern
diff --git a/usr.bin/unifdef/unifdef.c b/usr.bin/unifdef/unifdef.c
index 22f81ef..fd378a1 100644
--- a/usr.bin/unifdef/unifdef.c
+++ b/usr.bin/unifdef/unifdef.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002 - 2013 Tony Finch <dot@dotat.at>
+ * Copyright (c) 2002 - 2014 Tony Finch <dot@dotat.at>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -46,7 +46,7 @@
#include "unifdef.h"
static const char copyright[] =
- "@(#) $Version: unifdef-2.7 $\n"
+ "@(#) $Version: unifdef-2.10 $\n"
"@(#) $FreeBSD$\n"
"@(#) $Author: Tony Finch (dot@dotat.at) $\n"
"@(#) $URL: http://dotat.at/prog/unifdef $\n"
@@ -138,7 +138,7 @@ static char const * const linestate_name[] = {
*/
#define MAXDEPTH 64 /* maximum #if nesting */
#define MAXLINE 4096 /* maximum length of line */
-#define MAXSYMS 4096 /* maximum number of symbols */
+#define MAXSYMS 16384 /* maximum number of symbols */
/*
* Sometimes when editing a keyword the replacement text is longer, so
@@ -180,6 +180,15 @@ static char *tempname; /* avoid splatting input */
static char tline[MAXLINE+EDITSLOP];/* input buffer plus space */
static char *keyword; /* used for editing #elif's */
+/*
+ * When processing a file, the output's newline style will match the
+ * input's, and unifdef correctly handles CRLF or LF endings whatever
+ * the platform's native style. The stdio streams are opened in binary
+ * mode to accommodate platforms whose native newline style is CRLF.
+ * When the output isn't a processed input file (when it is error /
+ * debug / diagnostic messages) then unifdef uses native line endings.
+ */
+
static const char *newline; /* input file format */
static const char newline_unix[] = "\n";
static const char newline_crlf[] = "\r\n";
@@ -200,33 +209,41 @@ static bool firstsym; /* ditto */
static int exitmode; /* exit status mode */
static int exitstat; /* program exit status */
-static void addsym(bool, bool, char *);
+static void addsym1(bool, bool, char *);
+static void addsym2(bool, const char *, const char *);
static char *astrcat(const char *, const char *);
static void cleantemp(void);
-static void closeout(void);
+static void closeio(void);
static void debug(const char *, ...);
+static void debugsym(const char *, int);
+static bool defundef(void);
+static void defundefile(const char *);
static void done(void);
static void error(const char *);
-static int findsym(const char *);
+static int findsym(const char **);
static void flushline(bool);
static void hashline(void);
static void help(void);
static Linetype ifeval(const char **);
static void ignoreoff(void);
static void ignoreon(void);
+static void indirectsym(void);
static void keywordedit(const char *);
+static const char *matchsym(const char *, const char *);
static void nest(void);
static Linetype parseline(void);
static void process(void);
static void processinout(const char *, const char *);
static const char *skipargs(const char *);
static const char *skipcomment(const char *);
+static const char *skiphash(void);
+static const char *skipline(const char *);
static const char *skipsym(const char *);
static void state(Ifstate);
-static int strlcmp(const char *, const char *, size_t);
static void unnest(void);
static void usage(void);
static void version(void);
+static const char *xstrdup(const char *, const char *);
#define endsym(c) (!isalnum((unsigned char)c) && c != '_')
@@ -238,7 +255,7 @@ main(int argc, char *argv[])
{
int opt;
- while ((opt = getopt(argc, argv, "i:D:U:I:M:o:x:bBcdehKklmnsStV")) != -1)
+ while ((opt = getopt(argc, argv, "i:D:U:f:I:M:o:x:bBcdehKklmnsStV")) != -1)
switch (opt) {
case 'i': /* treat stuff controlled by these symbols as text */
/*
@@ -248,17 +265,17 @@ main(int argc, char *argv[])
*/
opt = *optarg++;
if (opt == 'D')
- addsym(true, true, optarg);
+ addsym1(true, true, optarg);
else if (opt == 'U')
- addsym(true, false, optarg);
+ addsym1(true, false, optarg);
else
usage();
break;
case 'D': /* define a symbol */
- addsym(false, true, optarg);
+ addsym1(false, true, optarg);
break;
case 'U': /* undef a symbol */
- addsym(false, false, optarg);
+ addsym1(false, false, optarg);
break;
case 'I': /* no-op for compatibility with cpp */
break;
@@ -278,6 +295,9 @@ main(int argc, char *argv[])
case 'e': /* fewer errors from dodgy lines */
iocccok = true;
break;
+ case 'f': /* definitions file */
+ defundefile(optarg);
+ break;
case 'h':
help();
break;
@@ -334,6 +354,7 @@ main(int argc, char *argv[])
argc = 1;
if (argc == 1 && !inplace && ofilename == NULL)
ofilename = "-";
+ indirectsym();
atexit(cleantemp);
if (ofilename != NULL)
@@ -392,10 +413,10 @@ processinout(const char *ifn, const char *ofn)
if (backext != NULL) {
char *backname = astrcat(ofn, backext);
if (rename(ofn, backname) < 0)
- err(2, "can't rename \"%s\" to \"%s%s\"", ofn, ofn, backext);
+ err(2, "can't rename \"%s\" to \"%s\"", ofn, backname);
free(backname);
}
- if (rename(tempname, ofn) < 0)
+ if (replace(tempname, ofn) < 0)
err(2, "can't rename \"%s\" to \"%s\"", tempname, ofn);
free(tempname);
tempname = NULL;
@@ -434,7 +455,7 @@ synopsis(FILE *fp)
{
fprintf(fp,
"usage: unifdef [-bBcdehKkmnsStV] [-x{012}] [-Mext] [-opath] \\\n"
- " [-[i]Dsym[=val]] [-[i]Usym] ... [file] ...\n");
+ " [-[i]Dsym[=val]] [-[i]Usym] [-fpath] ... [file] ...\n");
}
static void
@@ -455,6 +476,7 @@ help(void)
" -iDsym=val \\ ignore C strings and comments\n"
" -iDsym ) in sections controlled by these\n"
" -iUsym / preprocessor symbols\n"
+ " -fpath file containing #define and #undef directives\n"
" -b blank lines instead of deleting them\n"
" -B compress blank lines around deleted section\n"
" -c complement (invert) keep vs. delete\n"
@@ -650,12 +672,12 @@ done(void)
{
if (incomment)
error("EOF in comment");
- closeout();
+ closeio();
}
/*
* Write a line to the output or not, according to command line options.
- * If writing fails, closeout() will print the error and exit.
+ * If writing fails, closeio() will print the error and exit.
*/
static void
flushline(bool keep)
@@ -671,19 +693,19 @@ flushline(bool keep)
if (lnnum && delcount > 0)
hashline();
if (fputs(tline, output) == EOF)
- closeout();
+ closeio();
delcount = 0;
blankmax = blankcount = blankline ? blankcount + 1 : 0;
}
} else {
if (lnblank && fputs(newline, output) == EOF)
- closeout();
+ closeio();
exitstat = 1;
delcount += 1;
blankcount = 0;
}
if (debugging && fflush(output) == EOF)
- closeout();
+ closeio();
}
/*
@@ -700,20 +722,21 @@ hashline(void)
e = fprintf(output, "#line %d \"%s\"%s",
linenum, linefile, newline);
if (e < 0)
- closeout();
+ closeio();
}
/*
* Flush the output and handle errors.
*/
static void
-closeout(void)
+closeio(void)
{
/* Tidy up after findsym(). */
if (symdepth && !zerosyms)
printf("\n");
- if (ferror(output) || fclose(output) == EOF)
- err(2, "%s: can't write to output", filename);
+ if (output != NULL && (ferror(output) || fclose(output) == EOF))
+ err(2, "%s: can't write to output", filename);
+ fclose(input);
}
/*
@@ -727,6 +750,8 @@ process(void)
is preceded by a large number of blank lines. */
blankmax = blankcount = 1000;
zerosyms = true;
+ newline = NULL;
+ linenum = 0;
while (lineval != LT_EOF) {
lineval = parseline();
trans_table[ifstate[depth]][lineval]();
@@ -746,105 +771,86 @@ parseline(void)
{
const char *cp;
int cursym;
- int kwlen;
Linetype retval;
Comment_state wascomment;
- linenum++;
- if (fgets(tline, MAXLINE, input) == NULL) {
- if (ferror(input))
- err(2, "can't read %s", filename);
- else
- return (LT_EOF);
- }
+ wascomment = incomment;
+ cp = skiphash();
+ if (cp == NULL)
+ return (LT_EOF);
if (newline == NULL) {
if (strrchr(tline, '\n') == strrchr(tline, '\r') + 1)
newline = newline_crlf;
else
newline = newline_unix;
}
- retval = LT_PLAIN;
- wascomment = incomment;
- cp = skipcomment(tline);
- if (linestate == LS_START) {
- if (*cp == '#') {
- linestate = LS_HASH;
- firstsym = true;
- cp = skipcomment(cp + 1);
- } else if (*cp != '\0')
- linestate = LS_DIRTY;
+ if (*cp == '\0') {
+ retval = LT_PLAIN;
+ goto done;
}
- if (!incomment && linestate == LS_HASH) {
- keyword = tline + (cp - tline);
- cp = skipsym(cp);
- kwlen = cp - keyword;
+ keyword = tline + (cp - tline);
+ if ((cp = matchsym("ifdef", keyword)) != NULL ||
+ (cp = matchsym("ifndef", keyword)) != NULL) {
+ cp = skipcomment(cp);
+ if ((cursym = findsym(&cp)) < 0)
+ retval = LT_IF;
+ else {
+ retval = (keyword[2] == 'n')
+ ? LT_FALSE : LT_TRUE;
+ if (value[cursym] == NULL)
+ retval = (retval == LT_TRUE)
+ ? LT_FALSE : LT_TRUE;
+ if (ignore[cursym])
+ retval = (retval == LT_TRUE)
+ ? LT_TRUEI : LT_FALSEI;
+ }
+ } else if ((cp = matchsym("if", keyword)) != NULL)
+ retval = ifeval(&cp);
+ else if ((cp = matchsym("elif", keyword)) != NULL)
+ retval = linetype_if2elif(ifeval(&cp));
+ else if ((cp = matchsym("else", keyword)) != NULL)
+ retval = LT_ELSE;
+ else if ((cp = matchsym("endif", keyword)) != NULL)
+ retval = LT_ENDIF;
+ else {
+ cp = skipsym(keyword);
/* no way can we deal with a continuation inside a keyword */
if (strncmp(cp, "\\\r\n", 3) == 0 ||
strncmp(cp, "\\\n", 2) == 0)
Eioccc();
- if (strlcmp("ifdef", keyword, kwlen) == 0 ||
- strlcmp("ifndef", keyword, kwlen) == 0) {
- cp = skipcomment(cp);
- if ((cursym = findsym(cp)) < 0)
- retval = LT_IF;
- else {
- retval = (keyword[2] == 'n')
- ? LT_FALSE : LT_TRUE;
- if (value[cursym] == NULL)
- retval = (retval == LT_TRUE)
- ? LT_FALSE : LT_TRUE;
- if (ignore[cursym])
- retval = (retval == LT_TRUE)
- ? LT_TRUEI : LT_FALSEI;
- }
- cp = skipsym(cp);
- } else if (strlcmp("if", keyword, kwlen) == 0)
- retval = ifeval(&cp);
- else if (strlcmp("elif", keyword, kwlen) == 0)
- retval = linetype_if2elif(ifeval(&cp));
- else if (strlcmp("else", keyword, kwlen) == 0)
- retval = LT_ELSE;
- else if (strlcmp("endif", keyword, kwlen) == 0)
- retval = LT_ENDIF;
- else {
- linestate = LS_DIRTY;
- retval = LT_PLAIN;
- }
- cp = skipcomment(cp);
- if (*cp != '\0') {
+ cp = skipline(cp);
+ retval = LT_PLAIN;
+ goto done;
+ }
+ cp = skipcomment(cp);
+ if (*cp != '\0') {
+ cp = skipline(cp);
+ if (retval == LT_TRUE || retval == LT_FALSE ||
+ retval == LT_TRUEI || retval == LT_FALSEI)
+ retval = LT_IF;
+ if (retval == LT_ELTRUE || retval == LT_ELFALSE)
+ retval = LT_ELIF;
+ }
+ /* the following can happen if the last line of the file lacks a
+ newline or if there is too much whitespace in a directive */
+ if (linestate == LS_HASH) {
+ long len = cp - tline;
+ if (fgets(tline + len, MAXLINE - len, input) == NULL) {
+ if (ferror(input))
+ err(2, "can't read %s", filename);
+ /* append the missing newline at eof */
+ strcpy(tline + len, newline);
+ cp += strlen(newline);
+ linestate = LS_START;
+ } else {
linestate = LS_DIRTY;
- if (retval == LT_TRUE || retval == LT_FALSE ||
- retval == LT_TRUEI || retval == LT_FALSEI)
- retval = LT_IF;
- if (retval == LT_ELTRUE || retval == LT_ELFALSE)
- retval = LT_ELIF;
- }
- if (retval != LT_PLAIN && (wascomment || incomment)) {
- retval = linetype_2dodgy(retval);
- if (incomment)
- linestate = LS_DIRTY;
- }
- /* skipcomment normally changes the state, except
- if the last line of the file lacks a newline, or
- if there is too much whitespace in a directive */
- if (linestate == LS_HASH) {
- size_t len = cp - tline;
- if (fgets(tline + len, MAXLINE - len, input) == NULL) {
- if (ferror(input))
- err(2, "can't read %s", filename);
- /* append the missing newline at eof */
- strcpy(tline + len, newline);
- cp += strlen(newline);
- linestate = LS_START;
- } else {
- linestate = LS_DIRTY;
- }
}
}
- if (linestate == LS_DIRTY) {
- while (*cp != '\0')
- cp = skipcomment(cp + 1);
+ if (retval != LT_PLAIN && (wascomment || linestate != LS_START)) {
+ retval = linetype_2dodgy(retval);
+ linestate = LS_DIRTY;
}
+done:
debug("parser line %d state %s comment %s line", linenum,
comment_name[incomment], linestate_name[linestate]);
return (retval);
@@ -854,34 +860,34 @@ parseline(void)
* These are the binary operators that are supported by the expression
* evaluator.
*/
-static Linetype op_strict(int *p, int v, Linetype at, Linetype bt) {
+static Linetype op_strict(long *p, long v, Linetype at, Linetype bt) {
if(at == LT_IF || bt == LT_IF) return (LT_IF);
return (*p = v, v ? LT_TRUE : LT_FALSE);
}
-static Linetype op_lt(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_lt(long *p, Linetype at, long a, Linetype bt, long b) {
return op_strict(p, a < b, at, bt);
}
-static Linetype op_gt(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_gt(long *p, Linetype at, long a, Linetype bt, long b) {
return op_strict(p, a > b, at, bt);
}
-static Linetype op_le(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_le(long *p, Linetype at, long a, Linetype bt, long b) {
return op_strict(p, a <= b, at, bt);
}
-static Linetype op_ge(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_ge(long *p, Linetype at, long a, Linetype bt, long b) {
return op_strict(p, a >= b, at, bt);
}
-static Linetype op_eq(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_eq(long *p, Linetype at, long a, Linetype bt, long b) {
return op_strict(p, a == b, at, bt);
}
-static Linetype op_ne(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_ne(long *p, Linetype at, long a, Linetype bt, long b) {
return op_strict(p, a != b, at, bt);
}
-static Linetype op_or(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_or(long *p, Linetype at, long a, Linetype bt, long b) {
if (!strictlogic && (at == LT_TRUE || bt == LT_TRUE))
return (*p = 1, LT_TRUE);
return op_strict(p, a || b, at, bt);
}
-static Linetype op_and(int *p, Linetype at, int a, Linetype bt, int b) {
+static Linetype op_and(long *p, Linetype at, long a, Linetype bt, long b) {
if (!strictlogic && (at == LT_FALSE || bt == LT_FALSE))
return (*p = 0, LT_FALSE);
return op_strict(p, a && b, at, bt);
@@ -899,7 +905,7 @@ static Linetype op_and(int *p, Linetype at, int a, Linetype bt, int b) {
*/
struct ops;
-typedef Linetype eval_fn(const struct ops *, int *, const char **);
+typedef Linetype eval_fn(const struct ops *, long *, const char **);
static eval_fn eval_table, eval_unary;
@@ -912,7 +918,7 @@ static eval_fn eval_table, eval_unary;
*/
struct op {
const char *str;
- Linetype (*fn)(int *, Linetype, int, Linetype, int);
+ Linetype (*fn)(long *, Linetype, long, Linetype, long);
};
struct ops {
eval_fn *inner;
@@ -930,7 +936,7 @@ static const struct ops eval_ops[] = {
};
/* Current operator precedence level */
-static int prec(const struct ops *ops)
+static long prec(const struct ops *ops)
{
return (ops - eval_ops);
}
@@ -941,7 +947,7 @@ static int prec(const struct ops *ops)
* We reset the constexpr flag in the last two cases.
*/
static Linetype
-eval_unary(const struct ops *ops, int *valp, const char **cpp)
+eval_unary(const struct ops *ops, long *valp, const char **cpp)
{
const char *cp;
char *ep;
@@ -975,32 +981,33 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
if (ep == cp)
return (LT_ERROR);
lt = *valp ? LT_TRUE : LT_FALSE;
- cp = skipsym(cp);
- } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) {
+ cp = ep;
+ } else if (matchsym("defined", cp) != NULL) {
cp = skipcomment(cp+7);
- debug("eval%d defined", prec(ops));
if (*cp == '(') {
cp = skipcomment(cp+1);
defparen = true;
} else {
defparen = false;
}
- sym = findsym(cp);
+ sym = findsym(&cp);
+ cp = skipcomment(cp);
+ if (defparen && *cp++ != ')') {
+ debug("eval%d defined missing ')'", prec(ops));
+ return (LT_ERROR);
+ }
if (sym < 0) {
+ debug("eval%d defined unknown", prec(ops));
lt = LT_IF;
} else {
+ debug("eval%d defined %s", prec(ops), symname[sym]);
*valp = (value[sym] != NULL);
lt = *valp ? LT_TRUE : LT_FALSE;
}
- cp = skipsym(cp);
- cp = skipcomment(cp);
- if (defparen && *cp++ != ')')
- return (LT_ERROR);
constexpr = false;
} else if (!endsym(*cp)) {
debug("eval%d symbol", prec(ops));
- sym = findsym(cp);
- cp = skipsym(cp);
+ sym = findsym(&cp);
if (sym < 0) {
lt = LT_IF;
cp = skipargs(cp);
@@ -1029,11 +1036,11 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
* Table-driven evaluation of binary operators.
*/
static Linetype
-eval_table(const struct ops *ops, int *valp, const char **cpp)
+eval_table(const struct ops *ops, long *valp, const char **cpp)
{
const struct op *op;
const char *cp;
- int val;
+ long val;
Linetype lt, rt;
debug("eval%d", prec(ops));
@@ -1071,7 +1078,7 @@ static Linetype
ifeval(const char **cpp)
{
Linetype ret;
- int val = 0;
+ long val = 0;
debug("eval %s", *cpp);
constexpr = killconsts ? false : true;
@@ -1081,6 +1088,49 @@ ifeval(const char **cpp)
}
/*
+ * Read a line and examine its initial part to determine if it is a
+ * preprocessor directive. Returns NULL on EOF, or a pointer to a
+ * preprocessor directive name, or a pointer to the zero byte at the
+ * end of the line.
+ */
+static const char *
+skiphash(void)
+{
+ const char *cp;
+
+ linenum++;
+ if (fgets(tline, MAXLINE, input) == NULL) {
+ if (ferror(input))
+ err(2, "can't read %s", filename);
+ else
+ return (NULL);
+ }
+ cp = skipcomment(tline);
+ if (linestate == LS_START && *cp == '#') {
+ linestate = LS_HASH;
+ return (skipcomment(cp + 1));
+ } else if (*cp == '\0') {
+ return (cp);
+ } else {
+ return (skipline(cp));
+ }
+}
+
+/*
+ * Mark a line dirty and consume the rest of it, keeping track of the
+ * lexical state.
+ */
+static const char *
+skipline(const char *cp)
+{
+ if (*cp != '\0')
+ linestate = LS_DIRTY;
+ while (*cp != '\0')
+ cp = skipcomment(cp + 1);
+ return (cp);
+}
+
+/*
* Skip over comments, strings, and character literals and stop at the
* next character position that is not whitespace. Between calls we keep
* the comment state in the global variable incomment, and we also adjust
@@ -1233,33 +1283,69 @@ skipsym(const char *cp)
}
/*
+ * Skip whitespace and take a copy of any following identifier.
+ */
+static const char *
+getsym(const char **cpp)
+{
+ const char *cp = *cpp, *sym;
+
+ cp = skipcomment(cp);
+ cp = skipsym(sym = cp);
+ if (cp == sym)
+ return NULL;
+ *cpp = cp;
+ return (xstrdup(sym, cp));
+}
+
+/*
+ * Check that s (a symbol) matches the start of t, and that the
+ * following character in t is not a symbol character. Returns a
+ * pointer to the following character in t if there is a match,
+ * otherwise NULL.
+ */
+static const char *
+matchsym(const char *s, const char *t)
+{
+ while (*s != '\0' && *t != '\0')
+ if (*s != *t)
+ return (NULL);
+ else
+ ++s, ++t;
+ if (*s == '\0' && endsym(*t))
+ return(t);
+ else
+ return(NULL);
+}
+
+/*
* Look for the symbol in the symbol table. If it is found, we return
* the symbol table index, else we return -1.
*/
static int
-findsym(const char *str)
+findsym(const char **strp)
{
- const char *cp;
+ const char *str;
int symind;
- cp = skipsym(str);
- if (cp == str)
- return (-1);
+ str = *strp;
+ *strp = skipsym(str);
if (symlist) {
+ if (*strp == str)
+ return (-1);
if (symdepth && firstsym)
printf("%s%3d", zerosyms ? "" : "\n", depth);
firstsym = zerosyms = false;
printf("%s%.*s%s",
- symdepth ? " " : "",
- (int)(cp-str), str,
- symdepth ? "" : "\n");
+ symdepth ? " " : "",
+ (int)(*strp-str), str,
+ symdepth ? "" : "\n");
/* we don't care about the value of the symbol */
return (0);
}
for (symind = 0; symind < nsyms; ++symind) {
- if (strlcmp(symname[symind], str, cp-str) == 0) {
- debug("findsym %s %s", symname[symind],
- value[symind] ? value[symind] : "");
+ if (matchsym(symname[symind], str) != NULL) {
+ debugsym("findsym", symind);
return (symind);
}
}
@@ -1267,53 +1353,155 @@ findsym(const char *str)
}
/*
+ * Resolve indirect symbol values to their final definitions.
+ */
+static void
+indirectsym(void)
+{
+ const char *cp;
+ int changed, sym, ind;
+
+ do {
+ changed = 0;
+ for (sym = 0; sym < nsyms; ++sym) {
+ if (value[sym] == NULL)
+ continue;
+ cp = value[sym];
+ ind = findsym(&cp);
+ if (ind == -1 || ind == sym ||
+ *cp != '\0' ||
+ value[ind] == NULL ||
+ value[ind] == value[sym])
+ continue;
+ debugsym("indir...", sym);
+ value[sym] = value[ind];
+ debugsym("...ectsym", sym);
+ changed++;
+ }
+ } while (changed);
+}
+
+/*
+ * Add a symbol to the symbol table, specified with the format sym=val
+ */
+static void
+addsym1(bool ignorethis, bool definethis, char *symval)
+{
+ const char *sym, *val;
+
+ sym = symval;
+ val = skipsym(sym);
+ if (definethis && *val == '=') {
+ symval[val - sym] = '\0';
+ val = val + 1;
+ } else if (*val == '\0') {
+ val = definethis ? "1" : NULL;
+ } else {
+ usage();
+ }
+ addsym2(ignorethis, sym, val);
+}
+
+/*
* Add a symbol to the symbol table.
*/
static void
-addsym(bool ignorethis, bool definethis, char *sym)
+addsym2(bool ignorethis, const char *sym, const char *val)
{
+ const char *cp = sym;
int symind;
- char *val;
- symind = findsym(sym);
+ symind = findsym(&cp);
if (symind < 0) {
if (nsyms >= MAXSYMS)
errx(2, "too many symbols");
symind = nsyms++;
}
- symname[symind] = sym;
ignore[symind] = ignorethis;
- val = sym + (skipsym(sym) - sym);
- if (definethis) {
- if (*val == '=') {
- value[symind] = val+1;
- *val = '\0';
- } else if (*val == '\0')
- value[symind] = "1";
- else
- usage();
- } else {
- if (*val != '\0')
- usage();
- value[symind] = NULL;
- }
- debug("addsym %s=%s", symname[symind],
+ symname[symind] = sym;
+ value[symind] = val;
+ debugsym("addsym", symind);
+}
+
+static void
+debugsym(const char *why, int symind)
+{
+ debug("%s %s%c%s", why, symname[symind],
+ value[symind] ? '=' : ' ',
value[symind] ? value[symind] : "undef");
}
/*
- * Compare s with n characters of t.
- * The same as strncmp() except that it checks that s[n] == '\0'.
+ * Add symbols to the symbol table from a file containing
+ * #define and #undef preprocessor directives.
*/
-static int
-strlcmp(const char *s, const char *t, size_t n)
+static void
+defundefile(const char *fn)
{
- while (n-- && *t != '\0')
- if (*s != *t)
- return ((unsigned char)*s - (unsigned char)*t);
- else
- ++s, ++t;
- return ((unsigned char)*s);
+ filename = fn;
+ input = fopen(fn, "rb");
+ if (input == NULL)
+ err(2, "can't open %s", fn);
+ linenum = 0;
+ while (defundef())
+ ;
+ if (ferror(input))
+ err(2, "can't read %s", filename);
+ else
+ fclose(input);
+ if (incomment)
+ error("EOF in comment");
+}
+
+/*
+ * Read and process one #define or #undef directive
+ */
+static bool
+defundef(void)
+{
+ const char *cp, *kw, *sym, *val, *end;
+
+ cp = skiphash();
+ if (cp == NULL)
+ return (false);
+ if (*cp == '\0')
+ goto done;
+ /* strip trailing whitespace, and do a fairly rough check to
+ avoid unsupported multi-line preprocessor directives */
+ end = cp + strlen(cp);
+ while (end > tline && strchr(" \t\n\r", end[-1]) != NULL)
+ --end;
+ if (end > tline && end[-1] == '\\')
+ Eioccc();
+
+ kw = cp;
+ if ((cp = matchsym("define", kw)) != NULL) {
+ sym = getsym(&cp);
+ if (sym == NULL)
+ error("missing macro name in #define");
+ if (*cp == '(') {
+ val = "1";
+ } else {
+ cp = skipcomment(cp);
+ val = (cp < end) ? xstrdup(cp, end) : "";
+ }
+ debug("#define");
+ addsym2(false, sym, val);
+ } else if ((cp = matchsym("undef", kw)) != NULL) {
+ sym = getsym(&cp);
+ if (sym == NULL)
+ error("missing macro name in #undef");
+ cp = skipcomment(cp);
+ debug("#undef");
+ addsym2(false, sym, NULL);
+ } else {
+ error("unrecognized preprocessor directive");
+ }
+ skipline(cp);
+done:
+ debug("parser line %d state %s comment %s line", linenum,
+ comment_name[incomment], linestate_name[linestate]);
+ return (true);
}
/*
@@ -1324,12 +1512,34 @@ astrcat(const char *s1, const char *s2)
{
char *s;
int len;
+ size_t size;
+
+ len = snprintf(NULL, 0, "%s%s", s1, s2);
+ if (len < 0)
+ err(2, "snprintf");
+ size = (size_t)len + 1;
+ s = (char *)malloc(size);
+ if (s == NULL)
+ err(2, "malloc");
+ snprintf(s, size, "%s%s", s1, s2);
+ return (s);
+}
+
+/*
+ * Duplicate a segment of a string, checking for failure.
+ */
+static const char *
+xstrdup(const char *start, const char *end)
+{
+ size_t n;
+ char *s;
- len = 1 + snprintf(NULL, 0, "%s%s", s1, s2);
- s = (char *)malloc(len);
+ if (end < start) abort(); /* bug */
+ n = (size_t)(end - start) + 1;
+ s = malloc(n);
if (s == NULL)
err(2, "malloc");
- snprintf(s, len, "%s%s", s1, s2);
+ snprintf(s, n, "%s", start);
return (s);
}
@@ -1356,6 +1566,6 @@ error(const char *msg)
else
warnx("%s: %d: %s (#if line %d depth %d)",
filename, linenum, msg, stifline[depth], depth);
- closeout();
+ closeio();
errx(2, "output may be truncated");
}
diff --git a/usr.bin/unifdef/unifdef.h b/usr.bin/unifdef/unifdef.h
index 8837b68..e2e0bd8 100644
--- a/usr.bin/unifdef/unifdef.h
+++ b/usr.bin/unifdef/unifdef.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012 Tony Finch <dot@dotat.at>
+ * Copyright (c) 2012 - 2013 Tony Finch <dot@dotat.at>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,6 +40,8 @@
#define fbinmode(fp) (fp)
+#define replace(old,new) rename(old,new)
+
static FILE *
mktempmode(char *tmp, int mode)
{
diff --git a/usr.bin/unifdef/unifdefall.sh b/usr.bin/unifdef/unifdefall.sh
index 6c8614b..6abf60b 100644
--- a/usr.bin/unifdef/unifdefall.sh
+++ b/usr.bin/unifdef/unifdefall.sh
@@ -47,32 +47,14 @@ trap 'rm -r "$tmp" || exit 2' EXIT
export LC_ALL=C
-# list of all controlling macros
-"$unifdef" $debug -s "$@" | sort | uniq >"$tmp/ctrl"
+# list of all controlling macros; assume these are undefined
+"$unifdef" $debug -s "$@" | sort -u | sed 's/^/#undef /' >"$tmp/undefs"
# list of all macro definitions
-cpp -dM "$@" | sort | sed 's/^#define //' >"$tmp/hashdefs"
-# list of defined macro names
-sed 's/[^A-Za-z0-9_].*$//' <"$tmp/hashdefs" >"$tmp/alldef"
-# list of undefined and defined controlling macros
-comm -23 "$tmp/ctrl" "$tmp/alldef" >"$tmp/undef"
-comm -12 "$tmp/ctrl" "$tmp/alldef" >"$tmp/def"
-# create a sed script that extracts the controlling macro definitions
-# and converts them to unifdef command-line arguments
-sed 's|.*|s/^&\\(([^)]*)\\)\\{0,1\\} /-D&=/p|' <"$tmp/def" >"$tmp/script"
-# create the final unifdef command
-{ echo "$unifdef" $debug -k '\'
- # convert the controlling undefined macros to -U arguments
- sed 's/.*/-U& \\/' <"$tmp/undef"
- # convert the controlling defined macros to quoted -D arguments
- sed -nf "$tmp/script" <"$tmp/hashdefs" |
- sed "s/'/'\\\\''/g;s/.*/'&' \\\\/"
- echo '"$@"'
-} >"$tmp/cmd"
+cc -E -dM "$@" | sort >"$tmp/defs"
+
case $debug in
--d) for i in ctrl hashdefs alldef undef def script cmd
- do echo ==== $i
- cat "$tmp/$i"
- done 1>&2
+-d) cat "$tmp/undefs" "$tmp/defs" 1>&2
esac
-# run the command we just created
-sh "$tmp/cmd" "$@"
+
+# order of -f arguments means definitions override undefs
+"$unifdef" $debug -k -f "$tmp/undefs" -f "$tmp/defs" "$@"
diff --git a/usr.bin/units/Makefile b/usr.bin/units/Makefile
index 3757c85..9018866 100644
--- a/usr.bin/units/Makefile
+++ b/usr.bin/units/Makefile
@@ -6,8 +6,7 @@ PROG= units
FILES= units.lib
FILESDIR= ${SHAREDIR}/misc
-LDADD+=-ledit -ltermcapw
-DPADD+=${LIBEDIT} ${LIBTERMCAPW}
+LIBADD= edit
.if ${MK_TESTS} != "no"
SUBDIR+= tests
diff --git a/usr.bin/unzip/Makefile b/usr.bin/unzip/Makefile
index ef8a690..9ed1a95 100644
--- a/usr.bin/unzip/Makefile
+++ b/usr.bin/unzip/Makefile
@@ -2,7 +2,6 @@
PROG = unzip
CSTD = c99
-DPADD = ${LIBARCHIVE} ${LIBZ}
-LDADD = -larchive -lz
+LIBADD= archive
.include <bsd.prog.mk>
diff --git a/usr.bin/unzip/Makefile.depend b/usr.bin/unzip/Makefile.depend
index 7f1d531..52fc11f 100644
--- a/usr.bin/unzip/Makefile.depend
+++ b/usr.bin/unzip/Makefile.depend
@@ -14,6 +14,7 @@ DIRDEPS = \
lib/libcompiler_rt \
lib/libexpat \
lib/liblzma \
+ lib/libthr \
lib/libz \
secure/lib/libcrypto \
diff --git a/usr.bin/unzip/unzip.c b/usr.bin/unzip/unzip.c
index 89677a2..841c9fb 100644
--- a/usr.bin/unzip/unzip.c
+++ b/usr.bin/unzip/unzip.c
@@ -67,9 +67,6 @@ static int u_opt; /* update */
static int v_opt; /* verbose/list */
static int Z1_opt; /* zipinfo mode list files only */
-/* time when unzip started */
-static time_t now;
-
/* debug flag */
static int unzip_debug;
@@ -470,9 +467,9 @@ static void
extract_file(struct archive *a, struct archive_entry *e, char **path)
{
int mode;
- time_t mtime;
+ struct timespec mtime;
struct stat sb;
- struct timeval tv[2];
+ struct timespec ts[2];
int cr, fd, text, warn, check;
ssize_t len;
unsigned char *p, *q, *end;
@@ -480,14 +477,18 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
mode = archive_entry_mode(e) & 0777;
if (mode == 0)
mode = 0644;
- mtime = archive_entry_mtime(e);
+ mtime.tv_sec = archive_entry_mtime(e);
+ mtime.tv_nsec = archive_entry_mtime_nsec(e);
/* look for existing file of same name */
recheck:
if (lstat(*path, &sb) == 0) {
if (u_opt || f_opt) {
/* check if up-to-date */
- if (S_ISREG(sb.st_mode) && sb.st_mtime >= mtime)
+ if (S_ISREG(sb.st_mode) &&
+ (sb.st_mtim.tv_sec > mtime.tv_sec ||
+ (sb.st_mtim.tv_sec == mtime.tv_sec &&
+ sb.st_mtim.tv_nsec >= mtime.tv_nsec)))
return;
(void)unlink(*path);
} else if (o_opt) {
@@ -593,12 +594,11 @@ recheck:
info("\n");
/* set access and modification time */
- tv[0].tv_sec = now;
- tv[0].tv_usec = 0;
- tv[1].tv_sec = mtime;
- tv[1].tv_usec = 0;
- if (futimes(fd, tv) != 0)
- error("utimes('%s')", *path);
+ ts[0].tv_sec = 0;
+ ts[0].tv_nsec = UTIME_NOW;
+ ts[1] = mtime;
+ if (futimens(fd, ts) != 0)
+ error("futimens('%s')", *path);
if (close(fd) != 0)
error("close('%s')", *path);
}
@@ -1065,8 +1065,6 @@ main(int argc, char *argv[])
if (n_opt + o_opt + u_opt > 1)
errorx("-n, -o and -u are contradictory");
- time(&now);
-
unzip(zipfile);
exit(0);
diff --git a/usr.bin/usbhidaction/Makefile b/usr.bin/usbhidaction/Makefile
index 6c2f7a6..7aadd6c 100644
--- a/usr.bin/usbhidaction/Makefile
+++ b/usr.bin/usbhidaction/Makefile
@@ -3,7 +3,6 @@
PROG= usbhidaction
-LDADD= -lusbhid
-DPADD= ${LIBUSBHID}
+LIBADD= usbhid
.include <bsd.prog.mk>
diff --git a/usr.bin/usbhidctl/Makefile b/usr.bin/usbhidctl/Makefile
index 3738b50..f0b5758 100644
--- a/usr.bin/usbhidctl/Makefile
+++ b/usr.bin/usbhidctl/Makefile
@@ -3,7 +3,7 @@
PROG= usbhidctl
SRCS= usbhid.c
-DPADD= ${LIBUSBHID}
-LDADD= -lusbhid
+
+LIBADD= usbhid
.include <bsd.prog.mk>
diff --git a/usr.bin/vacation/Makefile b/usr.bin/vacation/Makefile
index 056f576..f32e0c4 100644
--- a/usr.bin/vacation/Makefile
+++ b/usr.bin/vacation/Makefile
@@ -11,17 +11,7 @@ CFLAGS+=-D_FFR_LISTDB -D_FFR_DEBUG
WARNS?= 2
-LIBSMDIR= ${.OBJDIR}/../../lib/libsm
-LIBSM= ${LIBSMDIR}/libsm.a
-
-LIBSMDBDIR= ${.OBJDIR}/../../lib/libsmdb
-LIBSMDB= ${LIBSMDBDIR}/libsmdb.a
-
-LIBSMUTILDIR= ${.OBJDIR}/../../lib/libsmutil
-LIBSMUTIL= ${LIBSMUTILDIR}/libsmutil.a
-
-DPADD= ${LIBSMDB} ${LIBSMUTIL} ${LIBSM}
-LDADD= ${LIBSMDB} ${LIBSMUTIL} ${LIBSM}
+LIBADD= smdb smutil sm
SRCS+= sm_os.h
CLEANFILES+=sm_os.h
diff --git a/usr.bin/vgrind/Makefile b/usr.bin/vgrind/Makefile
index 612e504..06d9052 100644
--- a/usr.bin/vgrind/Makefile
+++ b/usr.bin/vgrind/Makefile
@@ -11,7 +11,7 @@ FILESDIR= ${SHAREDIR}/misc
FILESDIR_tmac.vgrind= ${SHAREDIR}/tmac
MAN= vgrind.1 vgrindefs.5
-WARNS?= 2
+WARNS?= 3
BINDIR= /usr/libexec
SCRIPTSDIR=/usr/bin
diff --git a/usr.bin/vgrind/extern.h b/usr.bin/vgrind/extern.h
index 6616ca9..812592f 100644
--- a/usr.bin/vgrind/extern.h
+++ b/usr.bin/vgrind/extern.h
@@ -31,9 +31,7 @@
* $FreeBSD$
*/
-typedef int boolean;
-
-extern boolean _escaped; /* if last character was an escape */
+extern bool _escaped; /* if last character was an escape */
extern char *s_start; /* start of the current string */
extern char *l_acmbeg; /* string introducing a comment */
extern char *l_acmend; /* string ending a comment */
@@ -45,11 +43,11 @@ extern char *l_combeg; /* string introducing a comment */
extern char *l_comend; /* string ending a comment */
extern char l_escape; /* character used to escape characters */
extern char *l_keywds[]; /* keyword table address */
-extern boolean l_onecase; /* upper and lower case are equivalent */
+extern bool l_onecase; /* upper and lower case are equivalent */
extern char *l_prcbeg; /* regular expr for procedure begin */
extern char *l_strbeg; /* delimiter for string constant */
extern char *l_strend; /* delimiter for string constant */
-extern boolean l_toplex; /* procedures only defined at top lex level */
+extern bool l_toplex; /* procedures only defined at top lex level */
extern const char *language; /* the language indicator */
#include <sys/cdefs.h>
diff --git a/usr.bin/vgrind/regexp.c b/usr.bin/vgrind/regexp.c
index 2da447d..cd57835 100644
--- a/usr.bin/vgrind/regexp.c
+++ b/usr.bin/vgrind/regexp.c
@@ -44,19 +44,16 @@ static const char sccsid[] = "@(#)regexp.c 8.1 (Berkeley) 6/6/93";
#include <ctype.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include "extern.h"
-#define FALSE 0
-#define TRUE !(FALSE)
-#define NIL 0
-
static void expconv(void);
-boolean _escaped; /* true if we are currently _escaped */
+bool _escaped; /* true if we are currently x_escaped */
char *s_start; /* start of string */
-boolean l_onecase; /* true if upper and lower equivalent */
+bool l_onecase; /* true if upper and lower equivalent */
#define makelower(c) (isupper((c)) ? tolower((c)) : (c))
@@ -66,9 +63,7 @@ boolean l_onecase; /* true if upper and lower equivalent */
*/
int
-STRNCMP(s1, s2, len)
- register char *s1,*s2;
- register int len;
+STRNCMP(register char *s1, register char *s2, register int len)
{
if (l_onecase) {
do
@@ -147,18 +142,18 @@ STRNCMP(s1, s2, len)
static char *ccre; /* pointer to current position in converted exp*/
static char *ure; /* pointer current position in unconverted exp */
+/* re: unconverted irregular expression */
char *
-convexp(re)
- char *re; /* unconverted irregular expression */
+convexp(char *re)
{
register char *cre; /* pointer to converted regular expression */
/* allocate room for the converted expression */
- if (re == NIL)
- return (NIL);
+ if (re == NULL)
+ return (NULL);
if (*re == '\0')
- return (NIL);
- cre = malloc (4 * strlen(re) + 3);
+ return (NULL);
+ cre = malloc(4 * strlen(re) + 3);
ccre = cre;
ure = re;
@@ -182,9 +177,9 @@ expconv()
register int temp;
/* let the conversion begin */
- acs = NIL;
- cs = NIL;
- while (*ure != NIL) {
+ acs = NULL;
+ cs = NULL;
+ while (*ure) {
switch (c = *ure++) {
case '\\':
@@ -192,7 +187,7 @@ expconv()
/* escaped characters are just characters */
default:
- if (cs == NIL || (*cs & STR) == 0) {
+ if (cs == NULL || (*cs & STR) == 0) {
cs = ccre;
*cs = STR;
SCNT(cs) = 1;
@@ -207,13 +202,13 @@ expconv()
case 'd':
case 'e':
case 'p':
- if (acs != NIL && acs != cs) {
+ if (acs != NULL && acs != cs) {
do {
temp = OCNT(acs);
OCNT(acs) = ccre - acs;
acs -= temp;
} while (temp != 0);
- acs = NIL;
+ acs = NULL;
}
cs = ccre;
*cs = META;
@@ -226,13 +221,13 @@ expconv()
/* just put the symbol in */
case '^':
case '$':
- if (acs != NIL && acs != cs) {
+ if (acs != NULL && acs != cs) {
do {
temp = OCNT(acs);
OCNT(acs) = ccre - acs;
acs -= temp;
} while (temp != 0);
- acs = NIL;
+ acs = NULL;
}
cs = ccre;
*cs = META;
@@ -248,31 +243,31 @@ expconv()
/* recurse and define a subexpression */
case '(':
- if (acs != NIL && acs != cs) {
+ if (acs != NULL && acs != cs) {
do {
temp = OCNT(acs);
OCNT(acs) = ccre - acs;
acs -= temp;
} while (temp != 0);
- acs = NIL;
+ acs = NULL;
}
cs = ccre;
*cs = OPER;
OSYM(cs) = '(';
ccre = ONEXT(cs);
- expconv ();
+ expconv();
OCNT(cs) = ccre - cs; /* offset to next symbol */
break;
/* return from a recursion */
case ')':
- if (acs != NIL) {
+ if (acs != NULL) {
do {
temp = OCNT(acs);
OCNT(acs) = ccre - acs;
acs -= temp;
} while (temp != 0);
- acs = NIL;
+ acs = NULL;
}
cs = ccre;
*cs = META;
@@ -284,7 +279,7 @@ expconv()
/* the third byte will contain an offset to jump over the */
/* alternate match in case the first did not fail */
case '|':
- if (acs != NIL && acs != cs)
+ if (acs != NULL && acs != cs)
OCNT(ccre) = ccre - acs; /* make a back pointer */
else
OCNT(ccre) = 0;
@@ -298,7 +293,7 @@ expconv()
/* if its not a metasymbol just build a scharacter string */
default:
- if (cs == NIL || (*cs & STR) == 0) {
+ if (cs == NULL || (*cs & STR) == 0) {
cs = ccre;
*cs = STR;
SCNT(cs) = 1;
@@ -309,13 +304,13 @@ expconv()
break;
}
}
- if (acs != NIL) {
+ if (acs != NULL) {
do {
temp = OCNT(acs);
OCNT(acs) = ccre - acs;
acs -= temp;
} while (temp != 0);
- acs = NIL;
+ acs = NULL;
}
return;
}
@@ -344,21 +339,23 @@ expconv()
* character matched.
*/
+/*
+ * s: string to check for a match in
+ * re: a converted irregular expression
+ * mstring: where to put whatever matches a \p
+ */
char *
-expmatch (s, re, mstring)
- register char *s; /* string to check for a match in */
- register char *re; /* a converted irregular expression */
- register char *mstring; /* where to put whatever matches a \p */
+expmatch (register char *s, register char *re, register char *mstring)
{
register char *cs; /* the current symbol */
register char *ptr,*s1; /* temporary pointer */
- boolean matched; /* a temporary boolean */
+ bool matched; /* a temporary bool */
/* initial conditions */
- if (re == NIL)
- return (NIL);
+ if (re == NULL)
+ return (NULL);
cs = re;
- matched = FALSE;
+ matched = false;
/* loop till expression string is exhausted (or at least pretty tired) */
while (*cs) {
@@ -384,7 +381,7 @@ expmatch (s, re, mstring)
} else {
/* no match, error return */
- return (NIL);
+ return (NULL);
}
break;
@@ -406,8 +403,8 @@ expmatch (s, re, mstring)
/* this is a grouping, recurse */
case '(':
- ptr = expmatch (s, ONEXT(cs), mstring);
- if (ptr != NIL) {
+ ptr = expmatch(s, ONEXT(cs), mstring);
+ if (ptr != NULL) {
/* the subexpression matched */
matched = 1;
@@ -423,7 +420,7 @@ expmatch (s, re, mstring)
} else {
/* no match, error return */
- return (NIL);
+ return (NULL);
}
cs = OPTR(cs);
break;
@@ -443,35 +440,35 @@ expmatch (s, re, mstring)
*/
s1 = s;
do {
- ptr = expmatch (s1, MNEXT(cs), mstring);
- if (ptr != NIL && s1 != s) {
+ ptr = expmatch(s1, MNEXT(cs), mstring);
+ if (ptr != NULL && s1 != s) {
/* we have a match, remember the match */
strncpy (mstring, s, s1 - s);
mstring[s1 - s] = '\0';
return (ptr);
- } else if (ptr != NIL && (*cs & OPT)) {
+ } else if (ptr != NULL && (*cs & OPT)) {
/* it was aoptional so no match is ok */
return (ptr);
- } else if (ptr != NIL) {
+ } else if (ptr != NULL) {
/* not optional and we still matched */
- return (NIL);
+ return (NULL);
}
if (!(isalnum(*s1) || *s1 == '_' ||
/* C++ destructor */
*s1 == '~' ||
/* C++ scope operator */
(strlen(s1) > 1 && *s1 == ':' && s1[1] == ':' &&
- (s1++, TRUE))))
- return (NIL);
+ (s1++, true))))
+ return (NULL);
if (*s1 == '\\')
- _escaped = _escaped ? FALSE : TRUE;
+ _escaped = _escaped ? false : true;
else
- _escaped = FALSE;
+ _escaped = false;
} while (*s1++);
- return (NIL);
+ return (NULL);
/* try to match anything */
case 'a':
@@ -482,31 +479,31 @@ expmatch (s, re, mstring)
*/
s1 = s;
do {
- ptr = expmatch (s1, MNEXT(cs), mstring);
- if (ptr != NIL && s1 != s) {
+ ptr = expmatch(s1, MNEXT(cs), mstring);
+ if (ptr != NULL && s1 != s) {
/* we have a match */
return (ptr);
- } else if (ptr != NIL && (*cs & OPT)) {
+ } else if (ptr != NULL && (*cs & OPT)) {
/* it was aoptional so no match is ok */
return (ptr);
- } else if (ptr != NIL) {
+ } else if (ptr != NULL) {
/* not optional and we still matched */
- return (NIL);
+ return (NULL);
}
if (*s1 == '\\')
- _escaped = _escaped ? FALSE : TRUE;
+ _escaped = _escaped ? false : true;
else
- _escaped = FALSE;
+ _escaped = false;
} while (*s1++);
- return (NIL);
+ return (NULL);
/* fail if we are currently _escaped */
case 'e':
if (_escaped)
- return(NIL);
+ return(NULL);
cs = MNEXT(cs);
break;
@@ -538,7 +535,7 @@ expmatch (s, re, mstring)
} else
/* no match, error return */
- return (NIL);
+ return (NULL);
break;
/* check for end of line */
@@ -562,7 +559,7 @@ expmatch (s, re, mstring)
} else
/* no match, error return */
- return (NIL);
+ return (NULL);
break;
/* check for start of line */
@@ -585,7 +582,7 @@ expmatch (s, re, mstring)
} else
/* no match, error return */
- return (NIL);
+ return (NULL);
break;
/* end of a subexpression, return success */
diff --git a/usr.bin/vgrind/vfontedpr.c b/usr.bin/vgrind/vfontedpr.c
index 5baaec0..ec0b4e0 100644
--- a/usr.bin/vgrind/vfontedpr.c
+++ b/usr.bin/vgrind/vfontedpr.c
@@ -47,14 +47,12 @@ static const char sccsid[] = "@(#)vfontedpr.c 8.1 (Berkeley) 6/6/93";
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <time.h>
#include "pathnames.h"
#include "extern.h"
-#define FALSE 0
-#define TRUE !(FALSE)
-#define NIL 0
#define STANDARD 0
#define ALTERNATE 1
@@ -70,8 +68,8 @@ static const char sccsid[] = "@(#)vfontedpr.c 8.1 (Berkeley) 6/6/93";
#define PSMAX 20 /* size of procedure name stacking */
static int iskw(char *);
-static boolean isproc(char *);
-static void putKcp(char *, char *, boolean);
+static bool isproc(char *);
+static void putKcp(char *, char *, bool);
static void putScp(char *);
static void putcp(int);
static int tabs(char *, char *);
@@ -81,13 +79,13 @@ static int width(char *, char *);
* The state variables
*/
-static boolean filter = FALSE; /* act as a filter (like eqn) */
-static boolean inchr; /* in a string constant */
-static boolean incomm; /* in a comment of the primary type */
-static boolean idx = FALSE; /* form an index */
-static boolean instr; /* in a string constant */
-static boolean nokeyw = FALSE; /* no keywords being flagged */
-static boolean pass = FALSE; /*
+static bool filter = false; /* act as a filter (like eqn) */
+static bool inchr; /* in a string constant */
+static bool incomm; /* in a comment of the primary type */
+static bool idx = false; /* form an index */
+static bool instr; /* in a string constant */
+static bool nokeyw = false; /* no keywords being flagged */
+static bool pass = false; /*
* when acting as a filter, pass indicates
* whether we are currently processing
* input.
@@ -100,7 +98,7 @@ static char * defsfile[2] = { _PATH_VGRINDEFS, 0 };
static int margin;
static int plstack[PSMAX]; /* the procedure nesting level stack */
static char pname[BUFSIZ+1];
-static boolean prccont; /* continue last procedure */
+static bool prccont; /* continue last procedure */
static int psptr; /* the stack index of the current procedure */
static char pstack[PSMAX][PNAMELEN+1]; /* the procedure name stack */
@@ -122,15 +120,15 @@ char *l_nocom; /* regexp for non-comments */
char *l_prcbeg; /* regular expr for procedure begin */
char *l_strbeg; /* delimiter for string constant */
char *l_strend; /* delimiter for string constant */
-boolean l_toplex; /* procedures only defined at top lex level */
+bool l_toplex; /* procedures only defined at top lex level */
const char *language = "c"; /* the language indicator */
#define ps(x) printf("%s", x)
+static char minus[] = "-";
+static char minusn[] = "-n";
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char **argv)
{
const char *fname = "";
struct stat stbuf;
@@ -160,9 +158,9 @@ main(argc, argv)
/* act as a filter like eqn */
if (!strcmp(argv[0], "-f")) {
- filter++;
+ filter = true;
argv[0] = argv[argc-1];
- argv[argc-1] = strdup("-");
+ argv[argc-1] = minus;
continue;
}
@@ -174,13 +172,13 @@ main(argc, argv)
/* build an index */
if (!strcmp(argv[0], "-x")) {
- idx++;
- argv[0] = strdup("-n");
+ idx = true;
+ argv[0] = minusn;
}
/* indicate no keywords */
if (!strcmp(argv[0], "-n")) {
- nokeyw++;
+ nokeyw = true;
argc--, argv++;
continue;
}
@@ -227,17 +225,17 @@ main(argc, argv)
i = cgetent(&defs, defsfile, language);
if (i == -1) {
fprintf (stderr, "no entry for language %s\n", language);
- exit (0);
+ exit(0);
} else if (i == -2) { fprintf(stderr,
"cannot find vgrindefs file %s\n", defsfile[0]);
- exit (0);
+ exit(0);
} else if (i == -3) { fprintf(stderr,
"potential reference loop detected in vgrindefs file %s\n",
defsfile[0]);
exit(0);
}
if (cgetustr(defs, "kw", &cp) == -1)
- nokeyw = TRUE;
+ nokeyw = true;
else {
char **cpp;
@@ -250,7 +248,7 @@ main(argc, argv)
while (*cp != ' ' && *cp != '\t' && *cp)
cp++;
}
- *cpp = NIL;
+ *cpp = NULL;
}
cgetustr(defs, "pb", &cp);
l_prcbeg = convexp(cp);
@@ -282,10 +280,10 @@ main(argc, argv)
/* initialize the program */
- incomm = FALSE;
- instr = FALSE;
- inchr = FALSE;
- _escaped = FALSE;
+ incomm = false;
+ instr = false;
+ inchr = false;
+ _escaped = false;
blklevel = 0;
for (psptr=0; psptr<PSMAX; psptr++) {
pstack[psptr][0] = '\0';
@@ -321,12 +319,12 @@ main(argc, argv)
if (buf[0] == '.') {
printf("%s", buf);
if (!strncmp (buf+1, "vS", 2))
- pass = TRUE;
+ pass = true;
if (!strncmp (buf+1, "vE", 2))
- pass = FALSE;
+ pass = false;
continue;
}
- prccont = FALSE;
+ prccont = false;
if (!filter || pass)
putScp(buf);
else
@@ -349,8 +347,7 @@ main(argc, argv)
#define isidchr(c) (isalnum(c) || (c) == '_')
static void
-putScp(os)
- char *os;
+putScp(char *os)
{
register char *s = os; /* pointer to unmatched string */
char dummy[BUFSIZ]; /* dummy to be used by expmatch */
@@ -363,7 +360,7 @@ putScp(os)
char *nocomptr; /* end of a non-comment delimiter */
s_start = os; /* remember the start for expmatch */
- _escaped = FALSE;
+ _escaped = false;
if (nokeyw || incomm || instr)
goto skip;
if (isproc(s)) {
@@ -382,82 +379,82 @@ skip:
/* check for string, comment, blockstart, etc */
if (!incomm && !instr && !inchr) {
- blkeptr = expmatch (s, l_blkend, dummy);
- blksptr = expmatch (s, l_blkbeg, dummy);
- comptr = expmatch (s, l_combeg, dummy);
- acmptr = expmatch (s, l_acmbeg, dummy);
- strptr = expmatch (s, l_strbeg, dummy);
- chrptr = expmatch (s, l_chrbeg, dummy);
+ blkeptr = expmatch(s, l_blkend, dummy);
+ blksptr = expmatch(s, l_blkbeg, dummy);
+ comptr = expmatch(s, l_combeg, dummy);
+ acmptr = expmatch(s, l_acmbeg, dummy);
+ strptr = expmatch(s, l_strbeg, dummy);
+ chrptr = expmatch(s, l_chrbeg, dummy);
nocomptr = expmatch (s, l_nocom, dummy);
/* start of non-comment? */
- if (nocomptr != NIL)
- if ((nocomptr <= comptr || comptr == NIL)
- && (nocomptr <= acmptr || acmptr == NIL)) {
+ if (nocomptr != NULL)
+ if ((nocomptr <= comptr || comptr == NULL)
+ && (nocomptr <= acmptr || acmptr == NULL)) {
/* continue after non-comment */
- putKcp (s, nocomptr-1, FALSE);
+ putKcp (s, nocomptr-1, false);
s = nocomptr;
continue;
}
/* start of a comment? */
- if (comptr != NIL)
- if ((comptr < strptr || strptr == NIL)
- && (comptr < acmptr || acmptr == NIL)
- && (comptr < chrptr || chrptr == NIL)
- && (comptr < blksptr || blksptr == NIL)
- && (comptr < blkeptr || blkeptr == NIL)) {
- putKcp (s, comptr-1, FALSE);
+ if (comptr != NULL)
+ if ((comptr < strptr || strptr == NULL)
+ && (comptr < acmptr || acmptr == NULL)
+ && (comptr < chrptr || chrptr == NULL)
+ && (comptr < blksptr || blksptr == NULL)
+ && (comptr < blkeptr || blkeptr == NULL)) {
+ putKcp(s, comptr-1, false);
s = comptr;
- incomm = TRUE;
+ incomm = true;
comtype = STANDARD;
if (s != os)
- ps ("\\c");
- ps ("\\c\n'+C\n");
+ ps("\\c");
+ ps("\\c\n'+C\n");
continue;
}
/* start of a comment? */
- if (acmptr != NIL)
- if ((acmptr < strptr || strptr == NIL)
- && (acmptr < chrptr || chrptr == NIL)
- && (acmptr < blksptr || blksptr == NIL)
- && (acmptr < blkeptr || blkeptr == NIL)) {
- putKcp (s, acmptr-1, FALSE);
+ if (acmptr != NULL)
+ if ((acmptr < strptr || strptr == NULL)
+ && (acmptr < chrptr || chrptr == NULL)
+ && (acmptr < blksptr || blksptr == NULL)
+ && (acmptr < blkeptr || blkeptr == NULL)) {
+ putKcp(s, acmptr-1, false);
s = acmptr;
- incomm = TRUE;
+ incomm = true;
comtype = ALTERNATE;
if (s != os)
- ps ("\\c");
- ps ("\\c\n'+C\n");
+ ps("\\c");
+ ps("\\c\n'+C\n");
continue;
}
/* start of a string? */
- if (strptr != NIL)
- if ((strptr < chrptr || chrptr == NIL)
- && (strptr < blksptr || blksptr == NIL)
- && (strptr < blkeptr || blkeptr == NIL)) {
- putKcp (s, strptr-1, FALSE);
+ if (strptr != NULL)
+ if ((strptr < chrptr || chrptr == NULL)
+ && (strptr < blksptr || blksptr == NULL)
+ && (strptr < blkeptr || blkeptr == NULL)) {
+ putKcp(s, strptr-1, false);
s = strptr;
- instr = TRUE;
+ instr = true;
continue;
}
/* start of a character string? */
- if (chrptr != NIL)
- if ((chrptr < blksptr || blksptr == NIL)
- && (chrptr < blkeptr || blkeptr == NIL)) {
- putKcp (s, chrptr-1, FALSE);
+ if (chrptr != NULL)
+ if ((chrptr < blksptr || blksptr == NULL)
+ && (chrptr < blkeptr || blkeptr == NULL)) {
+ putKcp(s, chrptr-1, false);
s = chrptr;
- inchr = TRUE;
+ inchr = true;
continue;
}
/* end of a lexical block */
- if (blkeptr != NIL) {
- if (blkeptr < blksptr || blksptr == NIL) {
- putKcp (s, blkeptr - 1, FALSE);
+ if (blkeptr != NULL) {
+ if (blkeptr < blksptr || blksptr == NULL) {
+ putKcp(s, blkeptr - 1, false);
s = blkeptr;
if (blklevel > 0 /* sanity */)
blklevel--;
@@ -465,13 +462,13 @@ skip:
/* end of current procedure */
if (s != os)
- ps ("\\c");
- ps ("\\c\n'-F\n");
+ ps("\\c");
+ ps("\\c\n'-F\n");
blklevel = plstack[psptr];
/* see if we should print the last proc name */
if (--psptr >= 0)
- prccont = TRUE;
+ prccont = true;
else
psptr = -1;
}
@@ -480,8 +477,8 @@ skip:
}
/* start of a lexical block */
- if (blksptr != NIL) {
- putKcp (s, blksptr - 1, FALSE);
+ if (blksptr != NULL) {
+ putKcp(s, blksptr - 1, false);
s = blksptr;
blklevel++;
continue;
@@ -489,64 +486,66 @@ skip:
/* check for end of comment */
} else if (incomm) {
- comptr = expmatch (s, l_comend, dummy);
- acmptr = expmatch (s, l_acmend, dummy);
- if (((comtype == STANDARD) && (comptr != NIL)) ||
- ((comtype == ALTERNATE) && (acmptr != NIL))) {
+ comptr = expmatch(s, l_comend, dummy);
+ acmptr = expmatch(s, l_acmend, dummy);
+ if (((comtype == STANDARD) && (comptr != NULL)) ||
+ ((comtype == ALTERNATE) && (acmptr != NULL))) {
if (comtype == STANDARD) {
- putKcp (s, comptr-1, TRUE);
+ putKcp(s, comptr-1, true);
s = comptr;
} else {
- putKcp (s, acmptr-1, TRUE);
+ putKcp(s, acmptr-1, true);
s = acmptr;
}
- incomm = FALSE;
+ incomm = false;
ps("\\c\n'-C\n");
continue;
} else {
- putKcp (s, s + strlen(s) -1, TRUE);
+ putKcp(s, s + strlen(s) -1, true);
s = s + strlen(s);
continue;
}
/* check for end of string */
} else if (instr) {
- if ((strptr = expmatch (s, l_strend, dummy)) != NIL) {
- putKcp (s, strptr-1, TRUE);
+ if ((strptr = expmatch(s, l_strend, dummy)) != NULL) {
+ putKcp(s, strptr-1, true);
s = strptr;
- instr = FALSE;
+ instr = false;
continue;
} else {
- putKcp (s, s+strlen(s)-1, TRUE);
+ putKcp(s, s+strlen(s)-1, true);
s = s + strlen(s);
continue;
}
/* check for end of character string */
} else if (inchr) {
- if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) {
- putKcp (s, chrptr-1, TRUE);
+ if ((chrptr = expmatch(s, l_chrend, dummy)) != NULL) {
+ putKcp(s, chrptr-1, true);
s = chrptr;
- inchr = FALSE;
+ inchr = false;
continue;
} else {
- putKcp (s, s+strlen(s)-1, TRUE);
+ putKcp(s, s+strlen(s)-1, true);
s = s + strlen(s);
continue;
}
}
/* print out the line */
- putKcp (s, s + strlen(s) -1, FALSE);
+ putKcp(s, s + strlen(s) -1, false);
s = s + strlen(s);
} while (*s);
}
+/*
+ * start: start of string to write
+ * end: end of string to write
+ * force: true if we should force nokeyw
+ */
static void
-putKcp (start, end, force)
- char *start; /* start of string to write */
- char *end; /* end of string to write */
- boolean force; /* true if we should force nokeyw */
+putKcp(char *start, char *end, bool force)
{
int i;
int xfld = 0;
@@ -587,22 +586,20 @@ putKcp (start, end, force)
}
}
- putcp ((unsigned char)*start++);
+ putcp((unsigned char)*start++);
}
}
static int
-tabs(s, os)
- char *s, *os;
+tabs(char *s, char *os)
{
return (width(s, os) / 8);
}
static int
-width(s, os)
- register char *s, *os;
+width(register char *s, register char *os)
{
register int i = 0;
@@ -622,8 +619,7 @@ width(s, os)
}
static void
-putcp(c)
- register int c;
+putcp(register int c)
{
switch(c) {
@@ -689,16 +685,15 @@ putcp(c)
/*
* look for a process beginning on this line
*/
-static boolean
-isproc(s)
- char *s;
+static bool
+isproc(char *s)
{
pname[0] = '\0';
if (!l_toplex || blklevel == 0)
- if (expmatch (s, l_prcbeg, pname) != NIL) {
- return (TRUE);
+ if (expmatch(s, l_prcbeg, pname) != NULL) {
+ return (true);
}
- return (FALSE);
+ return (false);
}
@@ -706,8 +701,7 @@ isproc(s)
*/
static int
-iskw(s)
- register char *s;
+iskw(register char *s)
{
register char **ss = l_keywds;
register int i = 1;
@@ -720,4 +714,3 @@ iskw(s)
return (i);
return (0);
}
-
diff --git a/usr.bin/vgrind/vgrindefs.c b/usr.bin/vgrind/vgrindefs.c
index b811c2c..c48a048 100644
--- a/usr.bin/vgrind/vgrindefs.c
+++ b/usr.bin/vgrind/vgrindefs.c
@@ -55,30 +55,30 @@ __FBSDID("$FreeBSD$");
static char *tbuf;
static char *filename;
static int hopcount; /* detect infinite loops in termcap, init 0 */
-char *tskip();
-char *tgetstr();
-char *tdecode();
-char *getenv();
+
+static int tnchktc(void);
+static int tnamatch(char *);
+static char *tskip(register char *);
+static char *tdecode(register char *, char **);
/*
* Get an entry for terminal name in buffer bp,
* from the termcap file. Parse is very rudimentary;
* we just notice escaped newlines.
*/
-tgetent(bp, name, file)
- char *bp, *name, *file;
+int
+tgetent(char *bp, char *name, char *file)
{
register char *cp;
register int c;
register int i = 0, cnt = 0;
char ibuf[BUFSIZ];
- char *cp2;
int tf;
tbuf = bp;
tf = 0;
filename = file;
- tf = open(filename, 0);
+ tf = open(filename, O_RDONLY);
if (tf < 0)
return (-1);
for (;;) {
@@ -125,7 +125,8 @@ tgetent(bp, name, file)
* entries to say "like an HP2621 but doesn't turn on the labels".
* Note that this works because of the left to right scan.
*/
-tnchktc()
+static int
+tnchktc(void)
{
register char *p, *q;
char tcname[16]; /* name of similar terminal */
@@ -143,7 +144,7 @@ tnchktc()
/* p now points to beginning of last field */
if (p[0] != 't' || p[1] != 'c')
return(1);
- strcpy(tcname,p+3);
+ strlcpy(tcname, p+3, 16);
q = tcname;
while (q && *q != ':')
q++;
@@ -161,7 +162,7 @@ tnchktc()
write(STDERR_FILENO, "Vgrind entry too long\n", 23);
q[BUFSIZ - (p-tbuf)] = 0;
}
- strcpy(p, q+1);
+ strlcpy(p, q+1, BUFSIZ - (p - holdtbuf));
tbuf = holdtbuf;
return(1);
}
@@ -172,8 +173,8 @@ tnchktc()
* against each such name. The normal : terminator after the last
* name (before the first field) stops us.
*/
-tnamatch(np)
- char *np;
+static int
+tnamatch(char *np)
{
register char *Np, *Bp;
@@ -199,8 +200,7 @@ tnamatch(np)
* into the termcap file in octal.
*/
static char *
-tskip(bp)
- register char *bp;
+tskip(register char *bp)
{
while (*bp && *bp != ':')
@@ -218,8 +218,8 @@ tskip(bp)
* a # character. If the option is not found we return -1.
* Note that we handle octal numbers beginning with 0.
*/
-tgetnum(id)
- char *id;
+int
+tgetnum(char *id)
{
register int i, base;
register char *bp = tbuf;
@@ -251,8 +251,8 @@ tgetnum(id)
* of the buffer. Return 1 if we find the option, or 0 if it is
* not given.
*/
-tgetflag(id)
- char *id;
+int
+tgetflag(char *id)
{
register char *bp = tbuf;
@@ -278,8 +278,7 @@ tgetflag(id)
* No checking on area overflow.
*/
char *
-tgetstr(id, area)
- char *id, **area;
+tgetstr(char *id, char **area)
{
register char *bp = tbuf;
@@ -303,13 +302,10 @@ tgetstr(id, area)
* string capability escapes.
*/
static char *
-tdecode(str, area)
- register char *str;
- char **area;
+tdecode(register char *str, char **area)
{
register char *cp;
register int c;
- int i;
cp = *area;
while (c = *str++) {
diff --git a/usr.bin/vi/Makefile b/usr.bin/vi/Makefile
index 6ed95ee..3a0fd47 100644
--- a/usr.bin/vi/Makefile
+++ b/usr.bin/vi/Makefile
@@ -21,7 +21,7 @@ LINKS= ${BINDIR}/${VI} ${BINDIR}/${EX} ${BINDIR}/${VI} ${BINDIR}/${VIEW}
LINKS+= ${BINDIR}/${VI} ${BINDIR}/vi ${BINDIR}/${EX} ${BINDIR}/ex
LINKS+= ${BINDIR}/${VI} ${BINDIR}/view
-MAN= ${SRCDIR}/docs/USD.doc/vi.man/vi.1
+MAN= ${SRCDIR}/docs/man/vi.1
MLINKS+=vi.1 ex.1 vi.1 view.1
MLINKS+=vi.1 nex.1 vi.1 nview.1 vi.1 nvi.1
@@ -33,12 +33,8 @@ MLINKS+=vi.1 nex.1 vi.1 nview.1 vi.1 nvi.1
CFLAGS+=-I${.CURDIR} -I${SRCDIR} -I${SRCDIR}/regex
-DPADD= ${LIBUTIL}
-LDADD= -lutil
-
+LIBADD= util ncursesw
CFLAGS+= -DUSE_WIDECHAR
-DPADD+= ${LIBNCURSESW}
-LDADD+= -lncursesw
.if ${MK_ICONV} == "yes" && !defined(RESCUE) && !defined(RELEASE_CRUNCH)
CFLAGS+= -DUSE_ICONV
diff --git a/usr.bin/vi/catalog/Makefile b/usr.bin/vi/catalog/Makefile
index bd9db9f..4e21298 100644
--- a/usr.bin/vi/catalog/Makefile
+++ b/usr.bin/vi/catalog/Makefile
@@ -101,7 +101,7 @@ english.base: dump ${SCAN} #Makefile
dump: dump.c
- ${CC} -o dump ${.ALLSRC}
+ ${CC} -o ${.TARGET} ${.ALLSRC}
CLEANFILES+= dump ${CAT} english.base *.check __ck1 __ck2
diff --git a/usr.bin/vmstat/Makefile b/usr.bin/vmstat/Makefile
index d413d25..8945b3d 100644
--- a/usr.bin/vmstat/Makefile
+++ b/usr.bin/vmstat/Makefile
@@ -3,8 +3,7 @@
PROG= vmstat
MAN= vmstat.8
-DPADD= ${LIBDEVSTAT} ${LIBKVM} ${LIBMEMSTAT} ${LIBUTIL}
-LDADD= -ldevstat -lkvm -lmemstat -lutil
+LIBADD= devstat kvm memstat util
WARNS?= 1
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 760dce8..9049e44 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -148,7 +148,7 @@ static void cpustats(void);
static void pcpustats(int, u_long, int);
static void devstats(void);
static void doforkst(void);
-static void dointr(void);
+static void dointr(unsigned int, int);
static void dosum(void);
static void dovmstat(unsigned int, int);
static void domemstat_malloc(void);
@@ -163,7 +163,7 @@ static void printhdr(int, u_long);
static void usage(void);
static long pct(long, long);
-static long getuptime(void);
+static long long getuptime(void);
static char **getdrivedata(char **);
@@ -325,7 +325,7 @@ retry_nlist:
dotimes();
#endif
if (todo & INTRSTAT)
- dointr();
+ dointr(interval, reps);
if (todo & VMSTAT)
dovmstat(interval, reps);
exit(0);
@@ -406,14 +406,15 @@ getdrivedata(char **argv)
return(argv);
}
-static long
+/* Return system uptime in nanoseconds */
+static long long
getuptime(void)
{
struct timespec sp;
- (void)clock_gettime(CLOCK_MONOTONIC, &sp);
+ (void)clock_gettime(CLOCK_UPTIME, &sp);
- return(sp.tv_sec);
+ return((long long)sp.tv_sec * 1000000000LL + sp.tv_nsec);
}
static void
@@ -654,7 +655,7 @@ dovmstat(unsigned int interval, int reps)
u_long cpumask;
int rate_adj;
- uptime = getuptime();
+ uptime = getuptime() / 1000000000LL;
halfuptime = uptime / 2;
rate_adj = 1;
ncpus = 1;
@@ -1165,61 +1166,133 @@ pcpustats(int ncpus, u_long cpumask, int maxid)
}
}
-static void
-dointr(void)
+static unsigned int
+read_intrcnts(unsigned long **intrcnts)
{
- unsigned long *intrcnt, uptime;
- uint64_t inttotal;
- size_t clen, inamlen, intrcntlen, istrnamlen;
- unsigned int i, nintr;
- char *intrname, *tintrname;
+ size_t intrcntlen;
- uptime = getuptime();
if (kd != NULL) {
kread(X_SINTRCNT, &intrcntlen, sizeof(intrcntlen));
- kread(X_SINTRNAMES, &inamlen, sizeof(inamlen));
- if ((intrcnt = malloc(intrcntlen)) == NULL ||
- (intrname = malloc(inamlen)) == NULL)
+ if ((*intrcnts = malloc(intrcntlen)) == NULL)
err(1, "malloc()");
- kread(X_INTRCNT, intrcnt, intrcntlen);
- kread(X_INTRNAMES, intrname, inamlen);
+ kread(X_INTRCNT, *intrcnts, intrcntlen);
} else {
- for (intrcnt = NULL, intrcntlen = 1024; ; intrcntlen *= 2) {
- if ((intrcnt = reallocf(intrcnt, intrcntlen)) == NULL)
+ for (*intrcnts = NULL, intrcntlen = 1024; ; intrcntlen *= 2) {
+ *intrcnts = reallocf(*intrcnts, intrcntlen);
+ if (*intrcnts == NULL)
err(1, "reallocf()");
if (mysysctl("hw.intrcnt",
- intrcnt, &intrcntlen, NULL, 0) == 0)
+ *intrcnts, &intrcntlen, NULL, 0) == 0)
break;
}
- for (intrname = NULL, inamlen = 1024; ; inamlen *= 2) {
- if ((intrname = reallocf(intrname, inamlen)) == NULL)
+ }
+
+ return (intrcntlen / sizeof(unsigned long));
+}
+
+static void
+print_intrcnts(unsigned long *intrcnts, unsigned long *old_intrcnts,
+ char *intrnames, unsigned int nintr,
+ size_t istrnamlen, long long period_ms)
+{
+ unsigned long *intrcnt, *old_intrcnt;
+ uint64_t inttotal, old_inttotal, total_count, total_rate;
+ char* intrname;
+ unsigned int i;
+
+ inttotal = 0;
+ old_inttotal = 0;
+ intrname = intrnames;
+ for (i = 0, intrcnt=intrcnts, old_intrcnt=old_intrcnts; i < nintr; i++) {
+ if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) {
+ unsigned long count, rate;
+
+ count = *intrcnt - *old_intrcnt;
+ rate = (count * 1000 + period_ms / 2) / period_ms;
+ (void)printf("%-*s %20lu %10lu\n", (int)istrnamlen,
+ intrname, count, rate);
+ }
+ intrname += strlen(intrname) + 1;
+ inttotal += *intrcnt++;
+ old_inttotal += *old_intrcnt++;
+ }
+ total_count = inttotal - old_inttotal;
+ total_rate = (total_count * 1000 + period_ms / 2) / period_ms;
+ (void)printf("%-*s %20" PRIu64 " %10" PRIu64 "\n", (int)istrnamlen,
+ "Total", total_count, total_rate);
+}
+
+static void
+dointr(unsigned int interval, int reps)
+{
+ unsigned long *intrcnts;
+ long long uptime, period_ms;
+ unsigned long *old_intrcnts = NULL;
+ size_t clen, inamlen, istrnamlen;
+ char *intrnames, *intrname;
+
+ uptime = getuptime();
+
+ /* Get the names of each interrupt source */
+ if (kd != NULL) {
+ kread(X_SINTRNAMES, &inamlen, sizeof(inamlen));
+ if ((intrnames = malloc(inamlen)) == NULL)
+ err(1, "malloc()");
+ kread(X_INTRNAMES, intrnames, inamlen);
+ } else {
+ for (intrnames = NULL, inamlen = 1024; ; inamlen *= 2) {
+ if ((intrnames = reallocf(intrnames, inamlen)) == NULL)
err(1, "reallocf()");
if (mysysctl("hw.intrnames",
- intrname, &inamlen, NULL, 0) == 0)
+ intrnames, &inamlen, NULL, 0) == 0)
break;
}
}
- nintr = intrcntlen / sizeof(unsigned long);
- tintrname = intrname;
+
+ /* Determine the length of the longest interrupt name */
+ intrname = intrnames;
istrnamlen = strlen("interrupt");
- for (i = 0; i < nintr; i++) {
- clen = strlen(tintrname);
+ while(*intrname != '\0') {
+ clen = strlen(intrname);
if (clen > istrnamlen)
istrnamlen = clen;
- tintrname += clen + 1;
+ intrname += strlen(intrname) + 1;
}
(void)printf("%-*s %20s %10s\n", (int)istrnamlen, "interrupt", "total",
"rate");
- inttotal = 0;
- for (i = 0; i < nintr; i++) {
- if (intrname[0] != '\0' && (*intrcnt != 0 || aflag))
- (void)printf("%-*s %20lu %10lu\n", (int)istrnamlen,
- intrname, *intrcnt, *intrcnt / uptime);
- intrname += strlen(intrname) + 1;
- inttotal += *intrcnt++;
+
+ /*
+ * Loop reps times printing differential interrupt counts. If reps is
+ * zero, then run just once, printing total counts
+ */
+ period_ms = uptime / 1000000;
+ while(1) {
+ unsigned int nintr;
+ long long old_uptime;
+
+ nintr = read_intrcnts(&intrcnts);
+ /*
+ * Initialize old_intrcnts to 0 for the first pass, so
+ * print_intrcnts will print total interrupts since boot
+ */
+ if (old_intrcnts == NULL) {
+ old_intrcnts = calloc(nintr, sizeof(unsigned long));
+ if (old_intrcnts == NULL)
+ err(1, "calloc()");
+ }
+
+ print_intrcnts(intrcnts, old_intrcnts, intrnames, nintr,
+ istrnamlen, period_ms);
+
+ free(old_intrcnts);
+ old_intrcnts = intrcnts;
+ if (reps >= 0 && --reps <= 0)
+ break;
+ usleep(interval * 1000);
+ old_uptime = uptime;
+ uptime = getuptime();
+ period_ms = (uptime - old_uptime) / 1000000;
}
- (void)printf("%-*s %20" PRIu64 " %10" PRIu64 "\n", (int)istrnamlen,
- "Total", inttotal, inttotal / uptime);
}
static void
diff --git a/usr.bin/vtfontcvt/vtfontcvt.c b/usr.bin/vtfontcvt/vtfontcvt.c
index 21c519b..07c3547 100644
--- a/usr.bin/vtfontcvt/vtfontcvt.c
+++ b/usr.bin/vtfontcvt/vtfontcvt.c
@@ -473,24 +473,24 @@ print_font_info(void)
{
printf(
"Statistics:\n"
-"- glyph_total: %5u\n"
-"- glyph_normal: %5u\n"
-"- glyph_normal_right: %5u\n"
-"- glyph_bold: %5u\n"
-"- glyph_bold_right: %5u\n"
-"- glyph_unique: %5u\n"
-"- glyph_dupe: %5u\n"
-"- mapping_total: %5u\n"
-"- mapping_normal: %5u\n"
-"- mapping_normal_folded: %5u\n"
-"- mapping_normal_right: %5u\n"
-"- mapping_normal_right_folded: %5u\n"
-"- mapping_bold: %5u\n"
-"- mapping_bold_folded: %5u\n"
-"- mapping_bold_right: %5u\n"
-"- mapping_bold_right_folded: %5u\n"
-"- mapping_unique: %5u\n"
-"- mapping_dupe: %5u\n",
+"- glyph_total: %6u\n"
+"- glyph_normal: %6u\n"
+"- glyph_normal_right: %6u\n"
+"- glyph_bold: %6u\n"
+"- glyph_bold_right: %6u\n"
+"- glyph_unique: %6u\n"
+"- glyph_dupe: %6u\n"
+"- mapping_total: %6u\n"
+"- mapping_normal: %6u\n"
+"- mapping_normal_folded: %6u\n"
+"- mapping_normal_right: %6u\n"
+"- mapping_normal_right_folded: %6u\n"
+"- mapping_bold: %6u\n"
+"- mapping_bold_folded: %6u\n"
+"- mapping_bold_right: %6u\n"
+"- mapping_bold_right_folded: %6u\n"
+"- mapping_unique: %6u\n"
+"- mapping_dupe: %6u\n",
glyph_total,
glyph_count[0],
glyph_count[1],
diff --git a/usr.bin/w/Makefile b/usr.bin/w/Makefile
index 6a5bbe5..0c51463 100644
--- a/usr.bin/w/Makefile
+++ b/usr.bin/w/Makefile
@@ -4,8 +4,7 @@
PROG= w
SRCS= fmt.c pr_time.c proc_compare.c w.c
MAN= w.1 uptime.1
-DPADD= ${LIBKVM} ${LIBUTIL} ${LIBXO}
-LDADD= -lkvm -lutil -lxo
+LIBADD= kvm sbuf util xo
#BINGRP= kmem
#BINMODE=2555
LINKS= ${BINDIR}/w ${BINDIR}/uptime
diff --git a/usr.bin/w/Makefile.depend b/usr.bin/w/Makefile.depend
index d371bbe..d17ba05 100644
--- a/usr.bin/w/Makefile.depend
+++ b/usr.bin/w/Makefile.depend
@@ -12,6 +12,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libkvm \
+ lib/libsbuf \
lib/libutil \
lib/libxo \
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index effd0e3..f94d8a6 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -54,8 +54,10 @@ static const char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94";
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/ioctl.h>
+#include <sys/sbuf.h>
#include <sys/socket.h>
#include <sys/tty.h>
+#include <sys/types.h>
#include <machine/cpu.h>
#include <netinet/in.h>
@@ -264,7 +266,9 @@ main(int argc, char *argv[])
if (header || wcmd == 0) {
pr_header(&now, nusers);
if (wcmd == 0) {
- xo_close_container("uptime-information");
+ xo_close_container("uptime-information");
+ xo_finish();
+
(void)kvm_close(kd);
exit(0);
}
@@ -470,7 +474,9 @@ pr_header(time_t *nowp, int nusers)
struct timespec tp;
int days, hrs, i, mins, secs;
char buf[256];
+ struct sbuf *upbuf;
+ upbuf = sbuf_new_auto();
/*
* Print time of day.
*/
@@ -491,21 +497,27 @@ pr_header(time_t *nowp, int nusers)
mins = uptime / 60;
secs = uptime % 60;
xo_emit(" up");
- xo_attr("seconds", "%lu", (unsigned long) tp.tv_sec);
+ xo_emit("{e:uptime/%lu}", (unsigned long) tp.tv_sec);
+ xo_emit("{e:days/%d}{e:hours/%d}{e:minutes/%d}{e:seconds/%d}", days, hrs, mins, secs);
+
if (days > 0)
- xo_emit(" {:uptime/%d day%s},",
+ sbuf_printf(upbuf, " %d day%s,",
days, days > 1 ? "s" : "");
if (hrs > 0 && mins > 0)
- xo_emit(" {:uptime/%2d:%02d},", hrs, mins);
+ sbuf_printf(upbuf, " %2d:%02d,", hrs, mins);
else if (hrs > 0)
- xo_emit(" {:uptime/%d hr%s},",
+ sbuf_printf(upbuf, " %d hr%s,",
hrs, hrs > 1 ? "s" : "");
else if (mins > 0)
- xo_emit(" {:uptime/%d min%s},",
+ sbuf_printf(upbuf, " %d min%s,",
mins, mins > 1 ? "s" : "");
- else
- xo_emit(" {:uptime/%d sec%s},",
+ else
+ sbuf_printf(upbuf, " %d sec%s,",
secs, secs > 1 ? "s" : "");
+ if (sbuf_finish(upbuf) != 0)
+ xo_err(1, "Could not generate output");
+ xo_emit("{:uptime-human/%s}", sbuf_data(upbuf));
+ sbuf_delete(upbuf);
}
/* Print number of users logged in to system */
@@ -552,5 +564,6 @@ usage(int wcmd)
xo_error("usage: w [-dhin] [-M core] [-N system] [user ...]\n");
else
xo_error("usage: uptime\n");
+ xo_finish();
exit(1);
}
diff --git a/usr.bin/wc/Makefile b/usr.bin/wc/Makefile
index 6c67135..540e33d 100644
--- a/usr.bin/wc/Makefile
+++ b/usr.bin/wc/Makefile
@@ -2,7 +2,6 @@
# $FreeBSD$
PROG= wc
-DPADD= ${LIBXO}
-LDADD= -lxo
+LIBADD= xo
.include <bsd.prog.mk>
diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c
index 79ac4a0..a6ca137 100644
--- a/usr.bin/wc/wc.c
+++ b/usr.bin/wc/wc.c
@@ -76,6 +76,14 @@ siginfo_handler(int sig __unused)
siginfo = 1;
}
+static void
+reset_siginfo(void)
+{
+
+ signal(SIGINFO, SIG_DFL);
+ siginfo = 0;
+}
+
int
main(int argc, char *argv[])
{
@@ -140,12 +148,14 @@ main(int argc, char *argv[])
} while(*++argv);
}
+ xo_close_list("file");
+
if (total > 1) {
xo_open_container("total");
show_cnt("total", tlinect, twordct, tcharct, tlongline);
xo_close_container("total");
}
- xo_close_list("file");
+
xo_close_container("wc");
xo_finish();
exit(errors == 0 ? 0 : 1);
@@ -227,6 +237,7 @@ cnt(const char *file)
} else
tmpll++;
}
+ reset_siginfo();
tlinect += linect;
if (dochar)
tcharct += charct;
@@ -249,6 +260,7 @@ cnt(const char *file)
return (1);
}
if (S_ISREG(sb.st_mode)) {
+ reset_siginfo();
charct = sb.st_size;
show_cnt(file, linect, wordct, charct, llct);
tcharct += charct;
@@ -309,6 +321,7 @@ word: gotsp = 1;
}
}
}
+ reset_siginfo();
if (domulti && MB_CUR_MAX > 1)
if (mbrtowc(NULL, NULL, 0, &mbs) == (size_t)-1 && !warned)
xo_warn("%s", file != NULL ? file : "stdin");
diff --git a/usr.bin/whereis/pathnames.h b/usr.bin/whereis/pathnames.h
index 1668d90..f5d27d1 100644
--- a/usr.bin/whereis/pathnames.h
+++ b/usr.bin/whereis/pathnames.h
@@ -25,9 +25,8 @@
* $FreeBSD$
*/
-/* Where to look for libexec and games */
+/* Where to look for libexec */
#define PATH_LIBEXEC "/usr/libexec"
-#define PATH_GAMES "/usr/games"
/* Where to look for sources. */
#define PATH_SOURCES \
diff --git a/usr.bin/whereis/whereis.1 b/usr.bin/whereis/whereis.1
index a5b2899..e72911c 100644
--- a/usr.bin/whereis/whereis.1
+++ b/usr.bin/whereis/whereis.1
@@ -65,8 +65,7 @@ The default path searched is the string returned by the
utility for the
.Dq user.cs_path
string, with
-.Pa /usr/libexec ,
-.Pa /usr/games
+.Pa /usr/libexec
and the current user's
.Ev $PATH
appended.
diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c
index 401461f..ed8d93a 100644
--- a/usr.bin/whereis/whereis.c
+++ b/usr.bin/whereis/whereis.c
@@ -265,7 +265,7 @@ defaults(void)
opt_b = opt_m = opt_s = 1;
/* -b defaults to default path + /usr/libexec +
- * /usr/games + user's path */
+ * user's path */
if (!bindirs) {
if (sysctlbyname("user.cs_path", (void *)NULL, &s,
(void *)NULL, 0) == -1)
@@ -276,11 +276,10 @@ defaults(void)
err(EX_OSERR, "sysctlbyname(\"user.cs_path\")");
nele = 0;
decolonify(b, &bindirs, &nele);
- bindirs = realloc(bindirs, (nele + 3) * sizeof(char *));
+ bindirs = realloc(bindirs, (nele + 2) * sizeof(char *));
if (bindirs == NULL)
abort();
bindirs[nele++] = PATH_LIBEXEC;
- bindirs[nele++] = PATH_GAMES;
bindirs[nele] = NULL;
if ((cp = getenv("PATH")) != NULL) {
/* don't destroy the original environment... */
diff --git a/usr.bin/whois/whois.1 b/usr.bin/whois/whois.1
index 0f0f177..a9ed50a 100644
--- a/usr.bin/whois/whois.1
+++ b/usr.bin/whois/whois.1
@@ -28,7 +28,7 @@
.\" From: @(#)whois.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd October 2, 2009
+.Dd May 14, 2015
.Dt WHOIS 1
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Nd "Internet domain name and network number directory service"
.Sh SYNOPSIS
.Nm
-.Op Fl aAbfgiIklmQrR
+.Op Fl aAbfgiIklmPQr
.Op Fl c Ar country-code | Fl h Ar host
.Op Fl p Ar port
.Ar name ...
@@ -47,6 +47,42 @@ utility looks up records in the databases maintained by several
Network Information Centers
.Pq Tn NICs .
.Pp
+By default
+.Nm
+automatically discovers the name of a whois server to use
+from the top-level domain
+.Pq Tn TLD
+of the supplied (single) argument.
+It tries
+.Qq Va TLD Ns Li .whois-servers.net
+and
+.Qq Li whois.nic. Ns Va TLD
+and if neither host exists it falls back to its default server.
+.Pp
+If an IP address is specified, the whois server will default to
+the American Registry for Internet Numbers
+.Pq Tn ARIN .
+If a query to
+.Tn ARIN
+references
+.Tn APNIC , AfriNIC , LACNIC ,
+or
+.Tn RIPE ,
+that server will be queried also, provided that the
+.Fl Q
+option is not specified.
+.Pp
+If
+.Nm
+cannot automatically discover a server,
+it will fall back to
+the host specified in the
+.Ev WHOIS_SERVER
+or
+.Ev RA_SERVER
+environment variables, or if those are not set, it will use
+.Pa whois.crsnic.net .
+.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl a
@@ -88,66 +124,12 @@ Use the US non-military federal government database, which contains points of
contact for subdomains of
.Pa .GOV .
.It Fl h Ar host
-Use the specified host instead of the default variant.
+Use the specified host instead of the default.
Either a host name or an IP address may be specified.
-.Pp
-By default
-.Nm
-constructs the name of a whois server to use from the top-level domain
-.Pq Tn TLD
-of the supplied (single) argument, and appending
-.Qq Li .whois-servers.net .
-This effectively allows a suitable whois server to be selected
-automatically for a large number of
-.Tn TLDs .
-.Pp
-In the event that an IP
-address is specified, the whois server will default to the American
-Registry for Internet Numbers
-.Pq Tn ARIN .
-If a query to
-.Tn ARIN
-references
-.Tn APNIC , AfriNIC , LACNIC ,
-or
-.Tn RIPE ,
-that server will be queried also, provided that the
-.Fl Q
-option is not specified.
-.Pp
-If the query is not a domain name or IP address,
-.Nm
-will fall back to
-.Pa whois.crsnic.net .
.It Fl i
-Use the Network Solutions Registry for Internet Numbers
+Use the obsolete Network Solutions Registry for Internet Numbers
.Pq Pa whois.networksolutions.com
database.
-It contains network numbers and domain contact information for most of
-.Pa .COM , .NET , .ORG
-and
-.Pa .EDU
-domains.
-.Pp
-.Sy NOTE !
-The registration of these domains is now done by a number of
-independent and competing registrars and this database holds no information
-on the domains registered by organizations other than Network Solutions, Inc.
-Also, note that the
-.Tn InterNIC
-database
-.Pq Pa whois.internic.net
-is no longer handled by Network Solutions, Inc.
-For details, see
-.Pa http://www.internic.net/ .
-.Pp
-(Hint: Contact information, identified by the term
-.Em handle ,
-can be looked up by prefixing
-.Qq Li "handle "
-to the
-.Tn NIC
-handle in the query.)
.It Fl I
Use the Internet Assigned Numbers Authority
.Pq Tn IANA
@@ -177,6 +159,10 @@ Connect to the whois server on
If this option is not specified,
.Nm
defaults to port 43.
+.It Fl P
+Use the PeeringDB database of AS numbers.
+It contains details about presence at internet peering points
+for many network operators.
.It Fl Q
Do a quick lookup.
This means that
@@ -190,24 +176,28 @@ Use the R\(aaeseaux IP Europ\(aaeens
database.
It contains network numbers and domain contact information
for Europe.
-.It Fl R
-Use the Russia Network Information Center
-.Pq Tn RIPN
-database.
-It contains network numbers and domain contact information
-for subdomains of
-.Pa .RU .
-This option is deprecated; use the
-.Fl c
-option with an argument of
-.Qq Li RU
-instead.
.El
.Pp
The operands specified to
.Nm
are treated independently and may be used
as queries on different whois servers.
+.Sh ENVIRONMENT
+.Bl -tag
+.It Ev WHOIS_SERVER
+The primary default whois server.
+If this is unset,
+.Nm
+uses the
+.Ev RA_SERVER
+environment variable.
+.It Ev RA_SERVER
+The secondary default whois server.
+If this is unset,
+.Nm
+will use
+.Pa whois.crsnic.net .
+.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index 3f6f93a..6ad8826 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -1,4 +1,4 @@
-/*
+/*-
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/poll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
@@ -55,24 +56,29 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
#define ABUSEHOST "whois.abuse.net"
-#define NICHOST "whois.crsnic.net"
-#define INICHOST "whois.networksolutions.com"
-#define GNICHOST "whois.nic.gov"
#define ANICHOST "whois.arin.net"
-#define LNICHOST "whois.lacnic.net"
+#define BNICHOST "whois.registro.br"
+#define FNICHOST "whois.afrinic.net"
+#define GERMNICHOST "de.whois-servers.net"
+#define GNICHOST "whois.nic.gov"
+#define IANAHOST "whois.iana.org"
+#define INICHOST "whois.networksolutions.com"
#define KNICHOST "whois.krnic.net"
-#define RNICHOST "whois.ripe.net"
-#define PNICHOST "whois.apnic.net"
+#define LNICHOST "whois.lacnic.net"
#define MNICHOST "whois.ra.net"
+#define NICHOST "whois.crsnic.net"
+#define PDBHOST "whois.peeringdb.com"
+#define PNICHOST "whois.apnic.net"
+#define QNICHOST_HEAD "whois.nic."
#define QNICHOST_TAIL ".whois-servers.net"
-#define BNICHOST "whois.registro.br"
-#define NORIDHOST "whois.norid.no"
-#define IANAHOST "whois.iana.org"
-#define GERMNICHOST "de.whois-servers.net"
-#define FNICHOST "whois.afrinic.net"
+#define RNICHOST "whois.ripe.net"
+
#define DEFAULT_PORT "whois"
+
#define WHOIS_SERVER_ID "Whois Server: "
#define WHOIS_ORG_SERVER_ID "Registrant Street1:Whois Server:"
@@ -81,12 +87,25 @@ __FBSDID("$FreeBSD$");
#define ishost(h) (isalnum((unsigned char)h) || h == '.' || h == '-')
+static struct {
+ const char *suffix, *server;
+} whoiswhere[] = {
+ /* Various handles */
+ { "-ARIN", ANICHOST },
+ { "-NICAT", "at" QNICHOST_TAIL },
+ { "-NORID", "no" QNICHOST_TAIL },
+ { "-RIPE", RNICHOST },
+ /* Nominet's whois server doesn't return referrals to JANET */
+ { ".ac.uk", "ac.uk" QNICHOST_TAIL },
+ { NULL, NULL }
+};
+
static const char *ip_whois[] = { LNICHOST, RNICHOST, PNICHOST, BNICHOST,
FNICHOST, NULL };
static const char *port = DEFAULT_PORT;
static char *choose_server(char *);
-static struct addrinfo *gethostinfo(char const *host, int exit_on_error);
+static struct addrinfo *gethostinfo(char const *host, int exitnoname);
static void s_asprintf(char **ret, const char *format, ...) __printflike(2, 3);
static void usage(void);
static void whois(const char *, const char *, int);
@@ -104,7 +123,7 @@ main(int argc, char *argv[])
country = host = qnichost = NULL;
flags = use_qnichost = 0;
- while ((ch = getopt(argc, argv, "aAbc:fgh:iIklmp:QrR6")) != -1) {
+ while ((ch = getopt(argc, argv, "aAbc:fgh:iIklmp:PQr")) != -1) {
switch (ch) {
case 'a':
host = ANICHOST;
@@ -145,21 +164,15 @@ main(int argc, char *argv[])
case 'p':
port = optarg;
break;
+ case 'P':
+ host = PDBHOST;
+ break;
case 'Q':
flags |= WHOIS_QUICK;
break;
case 'r':
host = RNICHOST;
break;
- case 'R':
- warnx("-R is deprecated; use '-c ru' instead");
- country = "ru";
- break;
- /* Remove in FreeBSD 10 */
- case '6':
- errx(EX_USAGE,
- "-6 is deprecated; use -[aAflr] instead");
- break;
case '?':
default:
usage();
@@ -173,13 +186,12 @@ main(int argc, char *argv[])
usage();
/*
- * If no host or country is specified determine the top level domain
- * from the query. If the TLD is a number, query ARIN. Otherwise, use
- * TLD.whois-server.net. If the domain does not contain '.', fall
- * back to NICHOST.
+ * If no host or country is specified, try to determine the top
+ * level domain from the query, or fall back to NICHOST.
*/
if (host == NULL && country == NULL) {
- if ((host = getenv("RA_SERVER")) == NULL) {
+ if ((host = getenv("WHOIS_SERVER")) == NULL &&
+ (host = getenv("RA_SERVER")) == NULL) {
use_qnichost = 1;
host = NICHOST;
if (!(flags & WHOIS_QUICK))
@@ -207,39 +219,67 @@ main(int argc, char *argv[])
* returns a pointer to newly allocated memory containing the whois server to
* be queried, or a NULL if the correct server couldn't be determined. The
* caller must remember to free(3) the allocated memory.
+ *
+ * If the domain is an IPv6 address or has a known suffix, that determines
+ * the server, else if the TLD is a number, query ARIN, else try a couple of
+ * formulaic server names. Fail if the domain does not contain '.'.
*/
static char *
choose_server(char *domain)
{
char *pos, *retval;
+ int i;
+ struct addrinfo *res;
if (strchr(domain, ':')) {
s_asprintf(&retval, "%s", ANICHOST);
return (retval);
}
- for (pos = strchr(domain, '\0'); pos > domain && *--pos == '.';)
- *pos = '\0';
+ for (pos = strchr(domain, '\0'); pos > domain && pos[-1] == '.';)
+ *--pos = '\0';
if (*domain == '\0')
errx(EX_USAGE, "can't search for a null string");
- if (strlen(domain) > sizeof("-NORID")-1 &&
- strcasecmp(domain + strlen(domain) - sizeof("-NORID") + 1,
- "-NORID") == 0) {
- s_asprintf(&retval, "%s", NORIDHOST);
- return (retval);
+ for (i = 0; whoiswhere[i].suffix != NULL; i++) {
+ size_t suffix_len = strlen(whoiswhere[i].suffix);
+ if (domain + suffix_len < pos &&
+ strcasecmp(pos - suffix_len, whoiswhere[i].suffix) == 0) {
+ s_asprintf(&retval, "%s", whoiswhere[i].server);
+ return (retval);
+ }
}
while (pos > domain && *pos != '.')
--pos;
if (pos <= domain)
return (NULL);
- if (isdigit((unsigned char)*++pos))
+ if (isdigit((unsigned char)*++pos)) {
s_asprintf(&retval, "%s", ANICHOST);
- else
- s_asprintf(&retval, "%s%s", pos, QNICHOST_TAIL);
- return (retval);
+ return (retval);
+ }
+ /* Try possible alternative whois server name formulae. */
+ for (i = 0; ; ++i) {
+ switch (i) {
+ case 0:
+ s_asprintf(&retval, "%s%s", pos, QNICHOST_TAIL);
+ break;
+ case 1:
+ s_asprintf(&retval, "%s%s", QNICHOST_HEAD, pos);
+ break;
+ default:
+ return (NULL);
+ }
+ res = gethostinfo(retval, 0);
+ if (res) {
+ freeaddrinfo(res);
+ return (retval);
+ } else {
+ free(retval);
+ continue;
+ }
+ }
}
static struct addrinfo *
-gethostinfo(char const *host, int exit_on_error)
+gethostinfo(char const *host, int exit_on_noname)
{
struct addrinfo hints, *res;
int error;
@@ -248,13 +288,10 @@ gethostinfo(char const *host, int exit_on_error)
hints.ai_flags = 0;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
+ res = NULL;
error = getaddrinfo(host, port, &hints, &res);
- if (error) {
- warnx("%s: %s", host, gai_strerror(error));
- if (exit_on_error)
- exit(EX_NOHOST);
- return (NULL);
- }
+ if (error && (exit_on_noname || error != EAI_NONAME))
+ err(EX_NOHOST, "%s: %s", host, gai_strerror(error));
return (res);
}
@@ -280,21 +317,137 @@ whois(const char *query, const char *hostname, int flags)
FILE *fp;
struct addrinfo *hostres, *res;
char *buf, *host, *nhost, *p;
- int i, s;
- size_t c, len;
+ int s = -1, f;
+ nfds_t i, j;
+ size_t c, len, count;
+ struct pollfd *fds;
+ int timeout = 180;
- s = -1;
hostres = gethostinfo(hostname, 1);
- for (res = hostres; res; res = res->ai_next) {
- s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ for (res = hostres, count = 0; res; res = res->ai_next)
+ count++;
+
+ fds = calloc(count, sizeof(*fds));
+ if (fds == NULL)
+ err(EX_OSERR, "calloc()");
+
+ /*
+ * Traverse the result list elements and make non-block
+ * connection attempts.
+ */
+ count = i = 0;
+ for (res = hostres; res != NULL; res = res->ai_next) {
+ s = socket(res->ai_family, res->ai_socktype | SOCK_NONBLOCK,
+ res->ai_protocol);
if (s < 0)
continue;
- if (connect(s, res->ai_addr, res->ai_addrlen) == 0)
- break;
- close(s);
+ if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
+ if (errno == EINPROGRESS) {
+ /* Add the socket to poll list */
+ fds[i].fd = s;
+ fds[i].events = POLLERR | POLLHUP |
+ POLLIN | POLLOUT;
+ count++;
+ i++;
+ } else {
+ close(s);
+ s = -1;
+
+ /*
+ * Poll only if we have something to poll,
+ * otherwise just go ahead and try next
+ * address
+ */
+ if (count == 0)
+ continue;
+ }
+ } else
+ goto done;
+
+ /*
+ * If we are at the last address, poll until a connection is
+ * established or we failed all connection attempts.
+ */
+ if (res->ai_next == NULL)
+ timeout = INFTIM;
+
+ /*
+ * Poll the watched descriptors for successful connections:
+ * if we still have more untried resolved addresses, poll only
+ * once; otherwise, poll until all descriptors have errors,
+ * which will be considered as ETIMEDOUT later.
+ */
+ do {
+ int n;
+
+ n = poll(fds, i, timeout);
+ if (n == 0) {
+ /*
+ * No event reported in time. Try with a
+ * smaller timeout (but cap at 2-3ms)
+ * after a new host have been added.
+ */
+ if (timeout >= 3)
+ timeout <<= 1;
+
+ break;
+ } else if (n < 0) {
+ /*
+ * errno here can only be EINTR which we would want
+ * to clean up and bail out.
+ */
+ s = -1;
+ goto done;
+ }
+
+ /*
+ * Check for the event(s) we have seen.
+ */
+ for (j = 0; j < i; j++) {
+ if (fds[j].fd == -1 || fds[j].events == 0 ||
+ fds[j].revents == 0)
+ continue;
+ if (fds[j].revents & ~(POLLIN | POLLOUT)) {
+ close(s);
+ fds[j].fd = -1;
+ fds[j].events = 0;
+ count--;
+ continue;
+ } else if (fds[j].revents & (POLLIN | POLLOUT)) {
+ /* Connect succeeded. */
+ s = fds[j].fd;
+
+ goto done;
+ }
+
+ }
+ } while (timeout == INFTIM && count != 0);
}
+
+ /* All attempts were failed */
+ s = -1;
+ if (count == 0)
+ errno = ETIMEDOUT;
+
+done:
+ /* Close all watched fds except the succeeded one */
+ for (j = 0; j < i; j++)
+ if (fds[j].fd != s && fds[j].fd != -1)
+ close(fds[j].fd);
+
+ if (s != -1) {
+ /* Restore default blocking behavior. */
+ if ((f = fcntl(s, F_GETFL)) != -1) {
+ f &= ~O_NONBLOCK;
+ if (fcntl(s, F_SETFL, f) == -1)
+ err(EX_OSERR, "fcntl()");
+ } else
+ err(EX_OSERR, "fcntl()");
+ }
+
+ free(fds);
freeaddrinfo(hostres);
- if (res == NULL)
+ if (s == -1)
err(EX_OSERR, "connect()");
fp = fdopen(s, "r+");
@@ -362,7 +515,7 @@ static void
usage(void)
{
fprintf(stderr,
- "usage: whois [-aAbfgiIklmQrR6] [-c country-code | -h hostname] "
+ "usage: whois [-aAbfgiIklmPQr] [-c country-code | -h hostname] "
"[-p port] name ...\n");
exit(EX_USAGE);
}
diff --git a/usr.bin/xinstall/Makefile b/usr.bin/xinstall/Makefile
index 773dd4e..1d39273 100644
--- a/usr.bin/xinstall/Makefile
+++ b/usr.bin/xinstall/Makefile
@@ -12,7 +12,6 @@ CFLAGS+= -I${.CURDIR}/../../contrib/mtree
CFLAGS+= -I${.CURDIR}/../../lib/libnetbsd
CFLAGS+= -I${.CURDIR}/../../lib/libmd
-DPADD+= ${LIBMD}
-LDADD+= -lmd
+LIBADD= md
.include <bsd.prog.mk>
diff --git a/usr.bin/svn/lib/libsqlite3/Makefile.depend b/usr.bin/xinstall/Makefile.depend.host
index 639d45d..bc49a51 100644
--- a/usr.bin/svn/lib/libsqlite3/Makefile.depend
+++ b/usr.bin/xinstall/Makefile.depend.host
@@ -3,8 +3,8 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- include \
- include/xlocale \
+ gnu/usr.bin/binutils/ld \
+ lib/libmd \
.include <dirdeps.mk>
diff --git a/usr.bin/xlint/Makefile.inc b/usr.bin/xlint/Makefile.inc
index a59b16c..2bd511c 100644
--- a/usr.bin/xlint/Makefile.inc
+++ b/usr.bin/xlint/Makefile.inc
@@ -5,18 +5,10 @@ WARNS?= 0
.PATH: ${.CURDIR}/../common
-# These assignments duplicate much of the functionality of
-# MACHINE_CPUARCH, but there's no easy way to export make functions...
-.if defined(TARGET_ARCH)
-TARGET_CPUARCH= ${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/}
+.if exists(${.CURDIR}/../arch/${MACHINE_ARCH})
+CFLAGS+= -I${.CURDIR}/../arch/${MACHINE_ARCH}
.else
-TARGET_CPUARCH= ${MACHINE_CPUARCH}
-TARGET_ARCH= ${MACHINE_ARCH}
-.endif
-.if exists(${.CURDIR}/../arch/${TARGET_ARCH})
-CFLAGS+= -I${.CURDIR}/../arch/${TARGET_ARCH}
-.else
-CFLAGS+= -I${.CURDIR}/../arch/${TARGET_CPUARCH}
+CFLAGS+= -I${.CURDIR}/../arch/${MACHINE_CPUARCH}
.endif
CFLAGS+= -I${.CURDIR}/../common
diff --git a/usr.bin/xlint/arch/aarch64/targparam.h b/usr.bin/xlint/arch/aarch64/targparam.h
new file mode 100644
index 0000000..fa03450
--- /dev/null
+++ b/usr.bin/xlint/arch/aarch64/targparam.h
@@ -0,0 +1,50 @@
+/* $NetBSD: targparam.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Machine-dependent target parameters for lint1.
+ */
+#include "lp64.h"
+
+/*
+ * Should be set to 1 if the difference of two pointers is of type long
+ * or the value of sizeof is of type unsigned long. Note this MUST be
+ * kept in sync with the compiler!
+ */
+
+#define PTRDIFF_IS_LONG 1
+#define SIZEOF_IS_ULONG 1
+
+#define FLOAT_SIZE (4 * CHAR_BIT)
+#define DOUBLE_SIZE (8 * CHAR_BIT)
+#define LDOUBLE_SIZE (16 * CHAR_BIT)
+
+#define ENUM_SIZE (4 * CHAR_BIT)
diff --git a/usr.bin/xlint/arch/sparc64/targparam.h b/usr.bin/xlint/arch/sparc64/targparam.h
index 8d57fbd..df151f2 100644
--- a/usr.bin/xlint/arch/sparc64/targparam.h
+++ b/usr.bin/xlint/arch/sparc64/targparam.h
@@ -1,4 +1,4 @@
-/* $NetBSD: targparam.h,v 1.2 2002/01/30 06:55:00 thorpej Exp $ */
+/* $NetBSD: targparam.h,v 1.3 2002/01/31 23:31:34 he Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -29,6 +29,8 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
/*
diff --git a/usr.bin/xlint/common/lint.h b/usr.bin/xlint/common/lint.h
index c50d28d..231d2d6 100644
--- a/usr.bin/xlint/common/lint.h
+++ b/usr.bin/xlint/common/lint.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lint.h,v 1.5 2002/03/07 18:29:56 tv Exp $ */
+/* $NetBSD: lint.h,v 1.7 2003/10/27 00:12:44 lukem Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -29,6 +29,8 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
#if HAVE_CONFIG_H
@@ -90,7 +92,7 @@ typedef struct {
u_int tt_isftyp : 1; /* 1 if floating point type */
u_int tt_isatyp : 1; /* 1 if arithmetic type */
u_int tt_issclt : 1; /* 1 if scalar type */
- char *tt_name; /* Bezeichnung des Typs */
+ const char *tt_name; /* Bezeichnung des Typs */
} ttab_t;
#define size(t) (ttab[t].tt_sz)
diff --git a/usr.bin/xlint/common/mem.c b/usr.bin/xlint/common/mem.c
index 2621081..8802da1 100644
--- a/usr.bin/xlint/common/mem.c
+++ b/usr.bin/xlint/common/mem.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mem.c,v 1.2 2002/01/21 19:49:51 tv Exp $ */
+/* $NetBSD: mem.c,v 1.4 2003/10/16 06:35:26 itojun Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,8 +33,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem.c,v 1.2 2002/01/21 19:49:51 tv Exp $");
+__RCSID("$NetBSD: mem.c,v 1.4 2003/10/16 06:35:26 itojun Exp $");
#endif
+__FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
@@ -64,9 +65,13 @@ xcalloc(size_t n, size_t s)
void *
xrealloc(void *p, size_t s)
{
+ void *n;
- if ((p = realloc(p, s)) == NULL)
+ if ((n = realloc(p, s)) == NULL) {
+ free(p);
nomem();
+ }
+ p = n;
return (p);
}
diff --git a/usr.bin/xlint/lint1/Makefile b/usr.bin/xlint/lint1/Makefile
index b7f78c5..2d6539e 100644
--- a/usr.bin/xlint/lint1/Makefile
+++ b/usr.bin/xlint/lint1/Makefile
@@ -7,8 +7,7 @@ SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \
MAN= lint.7
CLEANFILES= lint.7
-LDADD= -ll -lm
-DPADD= ${LIBL} ${LIBM}
+LIBADD= l m
CFLAGS+= -I. -I${.CURDIR}
LINTFLAGS=-aehpz
diff --git a/usr.bin/xlint/lint1/Makefile.depend b/usr.bin/xlint/lint1/Makefile.depend
index d097f49..0886bd5 100644
--- a/usr.bin/xlint/lint1/Makefile.depend
+++ b/usr.bin/xlint/lint1/Makefile.depend
@@ -13,6 +13,7 @@ DIRDEPS = \
lib/libcompiler_rt \
lib/msun \
usr.bin/lex/lib \
+ usr.bin/yacc.host \
.include <dirdeps.mk>
diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y
index 8791a2d..71d38f4 100644
--- a/usr.bin/xlint/lint1/cgram.y
+++ b/usr.bin/xlint/lint1/cgram.y
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $ */
+/* $NetBSD: cgram.y,v 1.40 2008/04/25 17:18:24 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.40 2008/04/25 17:18:24 christos Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -65,13 +65,13 @@ int mblklev;
*/
static int onowarn = -1;
-static int toicon(tnode_t *);
+static int toicon(tnode_t *, int);
static void idecl(sym_t *, int, sbuf_t *);
static void ignuptorp(void);
#ifdef DEBUG
-static __inline void CLRWFLGS(void);
-static __inline void CLRWFLGS(void)
+static inline void CLRWFLGS(void);
+static inline void CLRWFLGS(void)
{
printf("%s, %d: clear flags %s %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__);
@@ -79,8 +79,8 @@ static __inline void CLRWFLGS(void)
onowarn = -1;
}
-static __inline void SAVE(void);
-static __inline void SAVE(void)
+static inline void SAVE(void);
+static inline void SAVE(void)
{
if (onowarn != -1)
abort();
@@ -89,8 +89,8 @@ static __inline void SAVE(void)
onowarn = nowarn;
}
-static __inline void RESTORE(void);
-static __inline void RESTORE(void)
+static inline void RESTORE(void);
+static inline void RESTORE(void)
{
if (onowarn != -1) {
nowarn = onowarn;
@@ -107,6 +107,8 @@ static __inline void RESTORE(void)
#endif
%}
+%expect 1
+
%union {
int y_int;
val_t *y_val;
@@ -118,6 +120,7 @@ static __inline void RESTORE(void)
tqual_t y_tqual;
type_t *y_type;
tnode_t *y_tnode;
+ range_t y_range;
strg_t *y_strg;
pqinf_t *y_pqinf;
};
@@ -243,6 +246,8 @@ static __inline void RESTORE(void)
%type <y_sym> parameter_type_list
%type <y_sym> parameter_declaration
%type <y_tnode> expr
+%type <y_tnode> expr_stmnt_val
+%type <y_tnode> expr_stmnt_list
%type <y_tnode> term
%type <y_tnode> func_arg_list
%type <y_op> point_or_arrow
@@ -253,6 +258,8 @@ static __inline void RESTORE(void)
%type <y_strg> string
%type <y_strg> string2
%type <y_sb> opt_asm_or_symbolrename
+%type <y_range> range
+%type <y_range> lorange
%%
@@ -682,12 +689,12 @@ notype_member_decl:
$$ = $1;
}
| notype_decl T_COLON constant {
- $$ = bitfield($1, toicon($3));
+ $$ = bitfield($1, toicon($3, 1));
}
| {
symtyp = FVFT;
} T_COLON constant {
- $$ = bitfield(NULL, toicon($3));
+ $$ = bitfield(NULL, toicon($3, 1));
}
;
@@ -696,12 +703,12 @@ type_member_decl:
$$ = $1;
}
| type_decl T_COLON constant {
- $$ = bitfield($1, toicon($3));
+ $$ = bitfield($1, toicon($3, 1));
}
| {
symtyp = FVFT;
} T_COLON constant {
- $$ = bitfield(NULL, toicon($3));
+ $$ = bitfield(NULL, toicon($3, 1));
}
;
@@ -784,7 +791,7 @@ enumerator:
$$ = ename($1, enumval, 1);
}
| ename T_ASSIGN constant {
- $$ = ename($1, toicon($3), 0);
+ $$ = ename($1, toicon($3, 1), 0);
}
;
@@ -849,7 +856,7 @@ notype_direct_decl:
$$ = addarray($1, 0, 0);
}
| notype_direct_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| notype_direct_decl param_list {
$$ = addfunc($1, $2);
@@ -878,7 +885,7 @@ type_direct_decl:
$$ = addarray($1, 0, 0);
}
| type_direct_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| type_direct_decl param_list {
$$ = addfunc($1, $2);
@@ -914,7 +921,7 @@ direct_param_decl:
$$ = addarray($1, 0, 0);
}
| direct_param_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| direct_param_decl param_list {
$$ = addfunc($1, $2);
@@ -943,7 +950,7 @@ direct_notype_param_decl:
$$ = addarray($1, 0, 0);
}
| direct_notype_param_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| direct_notype_param_decl param_list {
$$ = addfunc($1, $2);
@@ -1121,6 +1128,7 @@ init_expr:
expr %prec T_COMMA {
mkinit($1);
}
+ | init_by_name init_expr %prec T_COMMA
| init_lbrace init_expr_list init_rbrace
| init_lbrace init_expr_list T_COMMA init_rbrace
| error
@@ -1131,6 +1139,38 @@ init_expr_list:
| init_expr_list T_COMMA init_expr
;
+lorange:
+ constant T_ELLIPSE {
+ $$.lo = toicon($1, 1);
+ }
+ ;
+range:
+ constant {
+ $$.lo = toicon($1, 1);
+ $$.hi = $$.lo + 1;
+ }
+ | lorange constant {
+ $$.lo = $1.lo;
+ $$.hi = toicon($2, 1);
+ }
+ ;
+
+init_by_name:
+ T_LBRACK range T_RBRACK T_ASSIGN {
+ if (!Sflag)
+ warning(321);
+ }
+ | point identifier T_ASSIGN {
+ if (!Sflag)
+ warning(313);
+ memberpush($2);
+ }
+ | identifier T_COLON {
+ gnuism(315);
+ memberpush($1);
+ }
+ ;
+
init_lbrace:
T_LBRACE {
initlbr();
@@ -1187,13 +1227,13 @@ direct_abs_decl:
$$ = addarray(aname(), 0, 0);
}
| T_LBRACK constant T_RBRACK {
- $$ = addarray(aname(), 1, toicon($2));
+ $$ = addarray(aname(), 1, toicon($2, 0));
}
| direct_abs_decl T_LBRACK T_RBRACK {
$$ = addarray($1, 0, 0);
}
| direct_abs_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| abs_decl_param_list {
$$ = addfunc(aname(), $1);
@@ -1207,9 +1247,8 @@ direct_abs_decl:
}
;
-stmnt:
+non_expr_stmnt:
labeled_stmnt
- | expr_stmnt
| comp_stmnt
| selection_stmnt
| iteration_stmnt
@@ -1217,6 +1256,10 @@ stmnt:
ftflg = 0;
}
| asm_stmnt
+
+stmnt:
+ expr_stmnt
+ | non_expr_stmnt
;
labeled_stmnt:
@@ -1231,7 +1274,12 @@ label:
| T_CASE constant T_COLON {
label(T_CASE, NULL, $2);
ftflg = 1;
- }
+ }
+ | T_CASE constant T_ELLIPSE constant T_COLON {
+ /* XXX: We don't fill all cases */
+ label(T_CASE, NULL, $2);
+ ftflg = 1;
+ }
| T_DEFAULT T_COLON {
label(T_DEFAULT, NULL, NULL);
ftflg = 1;
@@ -1239,11 +1287,11 @@ label:
;
comp_stmnt:
- compstmnt_lbrace declaration_list opt_stmnt_list compstmnt_rbrace
- | compstmnt_lbrace opt_stmnt_list compstmnt_rbrace
+ comp_stmnt_lbrace declaration_list opt_stmnt_list comp_stmnt_rbrace
+ | comp_stmnt_lbrace opt_stmnt_list comp_stmnt_rbrace
;
-compstmnt_lbrace:
+comp_stmnt_lbrace:
T_LBRACE {
blklev++;
mblklev++;
@@ -1251,7 +1299,7 @@ compstmnt_lbrace:
}
;
-compstmnt_rbrace:
+comp_stmnt_rbrace:
T_RBRACE {
popdecl();
freeblk();
@@ -1276,7 +1324,7 @@ stmnt_list:
expr_stmnt:
expr T_SEMI {
- expr($1, 0, 0);
+ expr($1, 0, 0, 1);
ftflg = 0;
}
| T_SEMI {
@@ -1284,6 +1332,34 @@ expr_stmnt:
}
;
+/*
+ * The following two productions are used to implement
+ * ({ [[decl-list] stmt-list] }).
+ * XXX: This is not well tested.
+ */
+expr_stmnt_val:
+ expr T_SEMI {
+ /* XXX: We should really do that only on the last name */
+ if ($1->tn_op == NAME)
+ $1->tn_sym->s_used = 1;
+ $$ = $1;
+ expr($1, 0, 0, 0);
+ ftflg = 0;
+ }
+ | non_expr_stmnt {
+ $$ = getnode();
+ $$->tn_type = gettyp(VOID);
+ }
+ ;
+
+expr_stmnt_list:
+ expr_stmnt_val
+ | expr_stmnt_list expr_stmnt_val {
+ $$ = $2;
+ }
+ | expr_stmnt_list expr_stmnt_val
+ ;
+
selection_stmnt:
if_without_else {
SAVE();
@@ -1525,6 +1601,26 @@ term:
$2->tn_parn = 1;
$$ = $2;
}
+ | T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list {
+ blklev--;
+ mblklev--;
+ initsym = mktempsym(duptyp($4->tn_type));
+ mblklev++;
+ blklev++;
+ gnuism(320);
+ } comp_stmnt_rbrace T_RPARN {
+ $$ = getnnode(initsym, 0);
+ }
+ | T_LPARN comp_stmnt_lbrace expr_stmnt_list {
+ blklev--;
+ mblklev--;
+ initsym = mktempsym($3->tn_type);
+ mblklev++;
+ blklev++;
+ gnuism(320);
+ } comp_stmnt_rbrace T_RPARN {
+ $$ = getnnode(initsym, 0);
+ }
| term T_INCDEC {
$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
}
@@ -1580,6 +1676,14 @@ term:
| T_LPARN type_name T_RPARN term %prec T_UNOP {
$$ = cast($4, $2);
}
+ | T_LPARN type_name T_RPARN %prec T_UNOP {
+ sym_t *tmp = mktempsym($2);
+ idecl(tmp, 1, NULL);
+ } init_lbrace init_expr_list init_rbrace {
+ if (!Sflag)
+ gnuism(319);
+ $$ = getnnode(initsym, 0);
+ }
;
string:
@@ -1620,6 +1724,13 @@ point_or_arrow:
}
;
+point:
+ T_STROP {
+ if ($1 != POINT)
+ error(249);
+ }
+ ;
+
identifier:
T_NAME {
$$ = $1;
@@ -1635,7 +1746,6 @@ identifier:
int
yyerror(char *msg)
{
-
error(249);
if (++sytxerr >= 5)
norecover();
@@ -1670,13 +1780,13 @@ q_gt(int64_t a, int64_t b)
* expressions, it frees the memory used for the expression.
*/
static int
-toicon(tnode_t *tn)
+toicon(tnode_t *tn, int required)
{
int i;
tspec_t t;
val_t *v;
- v = constant(tn);
+ v = constant(tn, required);
/*
* Abstract declarations are used inside expression. To free
@@ -1721,7 +1831,7 @@ idecl(sym_t *decl, int initflg, sbuf_t *rename)
case EXTERN:
if (rename != NULL) {
if (decl->s_rename != NULL)
- lerror("idecl() 1");
+ LERROR("idecl()");
s = getlblk(1, rename->sb_len + 1);
(void)memcpy(s, rename->sb_name, rename->sb_len + 1);
@@ -1749,7 +1859,7 @@ idecl(sym_t *decl, int initflg, sbuf_t *rename)
decl1loc(decl, initflg);
break;
default:
- lerror("idecl() 2");
+ LERROR("idecl()");
}
if (initflg && !initerr)
diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c
index e62882f..ace50b6 100644
--- a/usr.bin/xlint/lint1/decl.c
+++ b/usr.bin/xlint/lint1/decl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $ */
+/* $NetBSD: decl.c,v 1.33 2004/06/20 22:20:16 jmc Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $");
+__RCSID("$NetBSD: decl.c,v 1.33 2004/06/20 22:20:16 jmc Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -197,7 +197,7 @@ setcompl(type_t *tp, int ic)
tp->t_str->sincompl = ic;
} else {
if (t != ENUM)
- lerror("setcompl() 1");
+ LERROR("setcompl()");
tp->t_enum->eincompl = ic;
}
}
@@ -256,7 +256,7 @@ addtype(type_t *tp)
* something like "typedef int a; int a b;"
* This should not happen with current grammar.
*/
- lerror("addtype()");
+ LERROR("addtype()");
}
dcs->d_type = tp;
return;
@@ -297,7 +297,7 @@ addtype(type_t *tp)
dcs->d_lmod = NOTSPEC;
if (!quadflg)
/* %s C does not support 'long long' */
- (void)gnuism(265, tflag ? "traditional" : "ANSI");
+ (void)c99ism(265, tflag ? "traditional" : "c89");
}
if (dcs->d_type != NULL && dcs->d_type->t_typedef) {
@@ -466,7 +466,7 @@ addqual(tqual_t q)
dcs->d_const = 1;
} else {
if (q != VOLATILE)
- lerror("addqual() 1");
+ LERROR("addqual()");
if (dcs->d_volatile) {
/* duplicate "%s" */
warning(10, "volatile");
@@ -508,13 +508,13 @@ popdecl(void)
(void)printf("popdecl(%d)\n", (int)dcs->d_ctx);
if (dcs->d_nxt == NULL)
- lerror("popdecl() 1");
+ LERROR("popdecl()");
di = dcs;
dcs = di->d_nxt;
switch (di->d_ctx) {
case EXTERN:
/* there is nothing after external declarations */
- lerror("popdecl() 2");
+ LERROR("popdecl()");
/* NOTREACHED */
case MOS:
case MOU:
@@ -562,7 +562,7 @@ popdecl(void)
rmsyms(di->d_dlsyms);
break;
default:
- lerror("popdecl() 3");
+ LERROR("popdecl()");
}
free(di);
}
@@ -635,7 +635,7 @@ deftyp(void)
if (tp != NULL && (t != NOTSPEC || s != NOTSPEC || l != NOTSPEC)) {
/* should never happen */
- lerror("deftyp() 1");
+ LERROR("deftyp()");
}
if (tp == NULL) {
@@ -674,7 +674,7 @@ deftyp(void)
case VOID:
break;
default:
- lerror("deftyp() 2");
+ LERROR("deftyp()");
}
if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) {
dcs->d_terr = 1;
@@ -712,13 +712,13 @@ deftyp(void)
if (dcs->d_const && dcs->d_type->t_const) {
if (!dcs->d_type->t_typedef)
- lerror("deftyp() 3");
+ LERROR("deftyp()");
/* typedef already qualified with "%s" */
warning(68, "const");
}
if (dcs->d_volatile && dcs->d_type->t_volatile) {
if (!dcs->d_type->t_typedef)
- lerror("deftyp() 4");
+ LERROR("deftyp()");
/* typedef already qualified with "%s" */
warning(68, "volatile");
}
@@ -777,7 +777,7 @@ length(type_t *tp, const char *name)
switch (tp->t_tspec) {
case FUNC:
/* compiler takes size of function */
- lerror("%s", msgs[12]);
+ LERROR("%s", msgs[12]);
/* NOTREACHED */
case STRUCT:
case UNION:
@@ -796,7 +796,7 @@ length(type_t *tp, const char *name)
default:
elsz = size(tp->t_tspec);
if (elsz <= 0)
- lerror("length()");
+ LERROR("length()");
break;
}
return (elem * elsz);
@@ -831,7 +831,7 @@ getbound(type_t *tp)
}
}
if (a < CHAR_BIT || a > LINT_ALIGN(1) * CHAR_BIT)
- lerror("getbound() 1");
+ LERROR("getbound()");
return (a);
}
@@ -925,7 +925,7 @@ chktyp(sym_t *sym)
if (dcs->d_ctx == PARG) {
if (sym->s_scl != ABSTRACT) {
if (sym->s_name == unnamed)
- lerror("chktyp()");
+ LERROR("chktyp()");
/* void param cannot have name: %s */
error(61, sym->s_name);
*tpp = gettyp(INT);
@@ -963,12 +963,12 @@ decl1str(sym_t *dsym)
scl_t sc;
if ((sc = dsym->s_scl) != MOS && sc != MOU)
- lerror("decl1str() 1");
+ LERROR("decl1str()");
if (dcs->d_rdcsym != NULL) {
if ((sc = dcs->d_rdcsym->s_scl) != MOS && sc != MOU)
/* should be ensured by storesym() */
- lerror("decl1str() 2");
+ LERROR("decl1str()");
if (dsym->s_styp == dcs->d_rdcsym->s_styp) {
/* duplicate member name: %s */
error(33, dsym->s_name);
@@ -991,11 +991,13 @@ decl1str(sym_t *dsym)
t == SHORT || t == USHORT || t == ENUM) {
if (bitfieldtype_ok == 0) {
if (sflag) {
+ char buf[64];
/*
* bit-field type '%s' invalid in
* ANSI C
*/
- warning(273, tyname(tp));
+ warning(273,
+ tyname(buf, sizeof(buf), tp));
} else if (pflag) {
/* nonportable bit-field type */
warning(34);
@@ -1051,7 +1053,7 @@ decl1str(sym_t *dsym)
if ((sz = length(dsym->s_type, dsym->s_name)) == 0) {
if (t == ARRAY && dsym->s_type->t_dim == 0) {
/* illegal zero sized structure member: %s */
- warning(39, dsym->s_name);
+ c99ism(39, dsym->s_name);
}
}
@@ -1221,12 +1223,12 @@ addarray(sym_t *decl, int dim, int n)
tp->t_dim = n;
if (n < 0) {
- /* zero or negative array dimension */
- error(20);
+ /* negative array dimension */
+ error(20, n);
n = 0;
} else if (n == 0 && dim) {
- /* zero or negative array dimension */
- warning(20);
+ /* zero array dimension */
+ c99ism(322, dim);
} else if (n == 0 && !dim) {
/* is incomplete type */
setcompl(tp, 1);
@@ -1417,7 +1419,7 @@ dname(sym_t *sym)
} else if (sc == EXTERN) {
sym->s_def = DECL;
} else {
- lerror("dname() 1");
+ LERROR("dname()");
}
break;
case PARG:
@@ -1430,7 +1432,7 @@ dname(sym_t *sym)
sym->s_reg = 1;
sc = AUTO;
} else {
- lerror("dname() 2");
+ LERROR("dname()");
}
sym->s_def = DEF;
break;
@@ -1453,11 +1455,11 @@ dname(sym_t *sym)
} else if (sc == EXTERN) {
sym->s_def = DECL;
} else {
- lerror("dname() 3");
+ LERROR("dname()");
}
break;
default:
- lerror("dname() 4");
+ LERROR("dname()");
}
sym->s_scl = sc;
@@ -1481,7 +1483,7 @@ iname(sym_t *sym)
/* redeclaration of formal parameter %s */
error(21, sym->s_name);
if (!sym->s_defarg)
- lerror("iname()");
+ LERROR("iname()");
}
sym = pushdown(sym);
}
@@ -1514,7 +1516,7 @@ mktag(sym_t *tag, tspec_t kind, int decl, int semi)
} else if (kind == ENUM) {
scl = ENUMTAG;
} else {
- lerror("mktag()");
+ LERROR("mktag()");
}
if (tag != NULL) {
@@ -1636,7 +1638,7 @@ scltoa(scl_t sc)
case STRTAG: s = "struct"; break;
case UNIONTAG: s = "union"; break;
case ENUMTAG: s = "enum"; break;
- default: lerror("tagttoa()");
+ default: LERROR("tagttoa()");
}
return (s);
}
@@ -1664,7 +1666,7 @@ compltag(type_t *tp, sym_t *fmem)
sp->memb = fmem;
if (sp->size == 0) {
/* zero sized %s */
- (void)gnuism(47, ttab[t].tt_name);
+ (void)c99ism(47, ttab[t].tt_name);
} else {
n = 0;
for (mem = fmem; mem != NULL; mem = mem->s_nxt) {
@@ -2143,7 +2145,7 @@ compltyp(sym_t *dsym, sym_t *ssym)
while ((dst = *dstp) != NULL) {
if (src == NULL || dst->t_tspec != src->t_tspec)
- lerror("compltyp() 1");
+ LERROR("compltyp()");
if (dst->t_tspec == ARRAY) {
if (dst->t_dim == 0 && src->t_dim != 0) {
*dstp = dst = duptyp(dst);
@@ -2472,7 +2474,7 @@ decl1loc(sym_t *dsym, int initflg)
*/
break;
default:
- lerror("decl1loc() 1");
+ LERROR("decl1loc()");
}
} else if (dcs->d_rdcsym->s_blklev == blklev) {
@@ -2621,7 +2623,7 @@ aname(void)
sym_t *sym;
if (dcs->d_ctx != ABSTRACT && dcs->d_ctx != PARG)
- lerror("aname()");
+ LERROR("aname()");
sym = getblk(sizeof (sym_t));
@@ -2791,7 +2793,7 @@ chkausg(int novar, sym_t *arg)
{
if (!arg->s_set)
- lerror("chkausg() 1");
+ LERROR("chkausg()");
if (novar)
return;
@@ -2810,7 +2812,7 @@ chkvusg(int novar, sym_t *sym)
sym_t *xsym;
if (blklev == 0 || sym->s_blklev == 0)
- lerror("chkvusg() 1");
+ LERROR("chkvusg()");
/* errors in expressions easily cause lots of these warnings */
if (nerr != 0)
@@ -2875,7 +2877,7 @@ chklusg(sym_t *lab)
{
if (blklev != 1 || lab->s_blklev != 1)
- lerror("chklusg() 1");
+ LERROR("chklusg()");
if (lab->s_set && !lab->s_used) {
STRUCT_ASSIGN(curr_pos, lab->s_spos);
@@ -2914,7 +2916,7 @@ chktusg(sym_t *sym)
warning(235, sym->s_name);
break;
default:
- lerror("chktusg() 1");
+ LERROR("chktusg()");
}
}
@@ -2946,7 +2948,7 @@ chkglsyms(void)
chktusg(sym);
} else {
if (sym->s_kind != FMOS)
- lerror("chkglsyms() 1");
+ LERROR("chkglsyms()");
}
}
@@ -2961,7 +2963,7 @@ chkglvar(sym_t *sym)
return;
if (sym->s_scl != EXTERN && sym->s_scl != STATIC)
- lerror("chkglvar() 1");
+ LERROR("chkglvar()");
glchksz(sym);
diff --git a/usr.bin/xlint/lint1/emit1.c b/usr.bin/xlint/lint1/emit1.c
index 762945f..4d198d6 100644
--- a/usr.bin/xlint/lint1/emit1.c
+++ b/usr.bin/xlint/lint1/emit1.c
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $ */
+/* $NetBSD: emit1.c,v 1.14 2004/06/20 22:20:16 jmc Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.14 2004/06/20 22:20:16 jmc Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -117,7 +117,7 @@ outtype(type_t *tp)
case STRUCT: t = 'T'; s = 's'; break;
case UNION: t = 'T'; s = 'u'; break;
default:
- lerror("outtyp() 1");
+ LERROR("outtyp()");
}
if (tp->t_const)
outchar('c');
@@ -257,7 +257,7 @@ outsym(sym_t *sym, scl_t sc, def_t def)
outchar('e');
break;
default:
- lerror("outsym() 2");
+ LERROR("outsym()");
}
if (llibflg && def != DECL) {
/*
@@ -485,7 +485,7 @@ outfstrg(strg_t *strg)
u_char *cp;
if (strg->st_tspec != CHAR)
- lerror("outfstrg() 1");
+ LERROR("outfstrg()");
cp = strg->st_cp;
diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c
index 5c56638..e05305e 100644
--- a/usr.bin/xlint/lint1/err.c
+++ b/usr.bin/xlint/lint1/err.c
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.17 2002/01/31 19:36:54 tv Exp $ */
+/* $NetBSD: err.c,v 1.40 2009/04/15 01:20:57 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.17 2002/01/31 19:36:54 tv Exp $");
+__RCSID("$NetBSD: err.c,v 1.40 2009/04/15 01:20:57 christos Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -76,7 +76,7 @@ const char *msgs[] = {
"null dimension", /* 17 */
"illegal use of 'void'", /* 18 */
"void type for %s", /* 19 */
- "zero or negative array dimension", /* 20 */
+ "negative array dimension (%d)", /* 20 */
"redeclaration of formal parameter %s", /* 21 */
"incomplete or misplaced function definition", /* 22 */
"undefined label %s", /* 23 */
@@ -95,7 +95,7 @@ const char *msgs[] = {
"illegal bit-field size", /* 36 */
"zero size bit-field", /* 37 */
"function illegal in structure or union", /* 38 */
- "illegal zero sized structure member: %s", /* 39 */
+ "zero sized array in struct is a C99 extension: %s", /* 39 */
"unknown size: %s", /* 40 */
"illegal use of bit-field", /* 41 */
"forward reference to enum type", /* 42 */
@@ -103,7 +103,7 @@ const char *msgs[] = {
"declaration introduces new type in ANSI C: %s %s", /* 44 */
"base type is really '%s %s'", /* 45 */
"(%s) tag redeclared", /* 46 */
- "zero sized %s", /* 47 */
+ "zero sized %s is a C9X feature", /* 47 */
"overflow in enumeration values: %s", /* 48 */
"struct or union member must be named", /* 49 */
"a function is declared as an argument: %s", /* 50 */
@@ -188,7 +188,7 @@ const char *msgs[] = {
"expression has null effect", /* 129 */
"enum type mismatch, op %s", /* 130 */
"conversion to '%s' may sign-extend incorrectly", /* 131 */
- "conversion from '%s' may lose accuracy", /* 132 */
+ "conversion from '%s' to '%s' may lose accuracy", /* 132 */
"conversion of pointer to '%s' loses bits", /* 133 */
"conversion of pointer to '%s' may lose bits", /* 134 */
"possible pointer alignment problem", /* 135 */
@@ -232,7 +232,7 @@ const char *msgs[] = {
"too many array initializers", /* 173 */
"too many initializers", /* 174 */
"initialisation of an incomplete type", /* 175 */
- "invalid initializer", /* 176 */
+ "invalid initializer type %s", /* 176 */
"non-constant initializer", /* 177 */
"initializer does not fit", /* 178 */
"cannot initialize struct/union with no named member", /* 179 */
@@ -354,7 +354,7 @@ const char *msgs[] = {
"conversion of '%s' to '%s' is out of range, arg #%d", /* 295 */
"conversion of negative constant to unsigned type, arg #%d", /* 296 */
"conversion to '%s' may sign-extend incorrectly, arg #%d", /* 297 */
- "conversion from '%s' may lose accuracy, arg #%d", /* 298 */
+ "conversion from '%s' to '%s' may lose accuracy, arg #%d", /* 298 */
"prototype does not match old style definition, arg #%d", /* 299 */
"old style definition", /* 300 */
"array of incomplete type", /* 301 */
@@ -369,6 +369,16 @@ const char *msgs[] = {
"symbol renaming can't be used on function arguments", /* 310 */
"symbol renaming can't be used on automatic variables", /* 311 */
"%s C does not support // comments", /* 312 */
+ "struct or union member name in initializer is a C9X feature",/* 313 */
+ "%s is not a structure or a union", /* 314 */
+ "GCC style struct or union member name in initializer", /* 315 */
+ "__FUNCTION__ is a GCC extension", /* 316 */
+ "__func__ is a C9X feature", /* 317 */
+ "variable array dimension is a C99/GCC extension", /* 318 */
+ "compound literals are a C9X/GCC extension", /* 319 */
+ "({ }) is a GCC extension", /* 320 */
+ "array initializer with designators is a C9X feature", /* 321 */
+ "zero sized array is a C99 extension", /* 322 */
};
/*
@@ -377,10 +387,10 @@ const char *msgs[] = {
void
msglist(void)
{
- int i;
+ size_t i;
for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
- printf("%d\t%s\n", i, msgs[i]);
+ printf("%zu\t%s\n", i, msgs[i]);
}
/*
@@ -451,14 +461,15 @@ error(int n, ...)
}
void
-lerror(const char *msg, ...)
+lerror(const char *file, int line, const char *msg, ...)
{
va_list ap;
const char *fn;
va_start(ap, msg);
fn = lbasename(curr_pos.p_file);
- (void)fprintf(stderr, "%s(%d): lint error: ", fn, curr_pos.p_line);
+ (void)fprintf(stderr, "%s(%d): lint error: %s, %d", fn, curr_pos.p_line,
+ file, line);
(void)vfprintf(stderr, msg, ap);
(void)fprintf(stderr, "\n");
va_end(ap);
@@ -492,6 +503,33 @@ message(int n, ...)
va_end(ap);
}
+/*
+ * XXX I think the logic is possibly somewhat screwed up here. The
+ * question is, how do we want to interpret the -s and -S flags going
+ * forward? We need to answer that and then we can fix this to be
+ * "right"... [perry, 2 Nov 2002]
+*/
+int
+c99ism(int n, ...)
+{
+ va_list ap;
+ int msg;
+
+ va_start(ap, n);
+ if (sflag && !(Sflag || gflag)) {
+ verror(n, ap);
+ msg = 1;
+ } else if (!sflag && (Sflag || gflag)) {
+ msg = 0;
+ } else {
+ vwarning(n, ap);
+ msg = 1;
+ }
+ va_end(ap);
+
+ return (msg);
+}
+
int
gnuism(int n, ...)
{
diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h
index 765c1ef..cf40a5d 100644
--- a/usr.bin/xlint/lint1/externs1.h
+++ b/usr.bin/xlint/lint1/externs1.h
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.13 2002/01/18 21:01:39 thorpej Exp $ */
+/* $NetBSD: externs1.h,v 1.20 2002/11/02 20:09:27 perry Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -29,6 +29,8 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
/*
@@ -50,6 +52,7 @@ extern int vflag;
extern int yflag;
extern int wflag;
extern int zflag;
+extern int Sflag;
extern void norecover(void);
@@ -80,6 +83,7 @@ extern void clrwflgs(void);
extern sym_t *getsym(sbuf_t *);
extern void cleanup(void);
extern sym_t *pushdown(sym_t *);
+extern sym_t *mktempsym(type_t *);
extern void rmsym(sym_t *);
extern void rmsyms(sym_t *);
extern void inssym(int, sym_t *);
@@ -118,8 +122,9 @@ extern void error(int, ...);
extern void warning(int, ...);
extern void message(int, ...);
extern int gnuism(int, ...);
-extern void lerror(const char *, ...)
- __attribute__((__noreturn__,__format__(__printf__, 1, 2)));
+extern int c99ism(int, ...);
+extern void lerror(const char *, int, const char *, ...)
+ __attribute__((__noreturn__,__format__(__printf__, 3, 4)));
/*
* decl.c
@@ -194,13 +199,14 @@ extern int typeok(op_t, int, tnode_t *, tnode_t *);
extern tnode_t *promote(op_t, int, tnode_t *);
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
-extern const char *tyname(type_t *);
+extern const char *tyname(char *, size_t, type_t *);
+extern const char *basictyname(tspec_t);
extern tnode_t *bldszof(type_t *);
extern tnode_t *cast(tnode_t *, type_t *);
extern tnode_t *funcarg(tnode_t *, tnode_t *);
extern tnode_t *funccall(tnode_t *, tnode_t *);
-extern val_t *constant(tnode_t *);
-extern void expr(tnode_t *, int, int);
+extern val_t *constant(tnode_t *, int);
+extern void expr(tnode_t *, int, int, int);
extern void chkmisc(tnode_t *, int, int, int, int, int, int);
extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *);
extern strg_t *catstrg(strg_t *, strg_t *);
@@ -273,6 +279,7 @@ extern void prepinit(void);
extern void initrbr(void);
extern void initlbr(void);
extern void mkinit(tnode_t *);
+extern void memberpush(sbuf_t *);
/*
* emit.c
diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c
index f34baa1..118aa68 100644
--- a/usr.bin/xlint/lint1/func.c
+++ b/usr.bin/xlint/lint1/func.c
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $ */
+/* $NetBSD: func.c,v 1.22 2005/09/24 15:30:35 perry Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -167,7 +167,7 @@ popctrl(int env)
clst_t *cl;
if (cstk == NULL || cstk->c_env != env)
- lerror("popctrl() 1");
+ LERROR("popctrl()");
cstk = (ci = cstk)->c_nxt;
@@ -220,7 +220,7 @@ funcdef(sym_t *fsym)
for (sym = dcs->d_fpsyms; sym != NULL; sym = sym->s_dlnxt) {
if (sym->s_blklev != -1) {
if (sym->s_blklev != 1)
- lerror("funcdef() 1");
+ LERROR("funcdef()");
inssym(1, sym);
}
}
@@ -264,12 +264,12 @@ funcdef(sym_t *fsym)
for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_nxt) {
if (arg->s_scl == ABSTRACT) {
if (arg->s_name != unnamed)
- lerror("funcdef() 2");
+ LERROR("funcdef()");
/* formal parameter lacks name: param #%d */
error(59, n);
} else {
if (arg->s_name == unnamed)
- lerror("funcdef() 3");
+ LERROR("funcdef()");
}
n++;
}
@@ -389,7 +389,7 @@ funcend(void)
* the symbol table
*/
if (dcs->d_nxt != NULL || dcs->d_ctx != EXTERN)
- lerror("funcend() 1");
+ LERROR("funcend()");
rmsyms(dcs->d_fpsyms);
/* must be set on level 0 */
@@ -446,7 +446,7 @@ label(int typ, sym_t *sym, tnode_t *tn)
if (tn != NULL) {
if (ci->c_swtype == NULL)
- lerror("label() 1");
+ LERROR("label()");
if (reached && !ftflg) {
if (hflag)
@@ -466,7 +466,7 @@ label(int typ, sym_t *sym, tnode_t *tn)
* get the value of the expression and convert it
* to the type of the switch expression
*/
- v = constant(tn);
+ v = constant(tn, 1);
(void) memset(&nv, 0, sizeof nv);
cvtcon(CASE, 0, ci->c_swtype, &nv, v);
free(v);
@@ -532,7 +532,7 @@ if1(tnode_t *tn)
tn = cconv(tn);
if (tn != NULL)
tn = promote(NOOP, 0, tn);
- expr(tn, 0, 1);
+ expr(tn, 0, 1, 1);
pushctrl(T_IF);
}
@@ -606,7 +606,7 @@ switch1(tnode_t *tn)
tp->t_tspec = INT;
}
- expr(tn, 1, 0);
+ expr(tn, 1, 0, 1);
pushctrl(T_SWITCH);
cstk->c_switch = 1;
@@ -627,7 +627,7 @@ switch2(void)
clst_t *cl;
if (cstk->c_swtype == NULL)
- lerror("switch2() 1");
+ LERROR("switch2()");
/*
* If the switch expression was of type enumeration, count the case
@@ -637,7 +637,7 @@ switch2(void)
if (cstk->c_swtype->t_isenum) {
nenum = nclab = 0;
if (cstk->c_swtype->t_enum == NULL)
- lerror("switch2() 2");
+ LERROR("switch2()");
for (esym = cstk->c_swtype->t_enum->elem;
esym != NULL; esym = esym->s_nxt) {
nenum++;
@@ -704,7 +704,7 @@ while1(tnode_t *tn)
}
}
- expr(tn, 0, 1);
+ expr(tn, 0, 1, 1);
}
/*
@@ -775,7 +775,7 @@ do2(tnode_t *tn)
}
}
- expr(tn, 0, 1);
+ expr(tn, 0, 1, 1);
/*
* The end of the loop is only reached if it is no endless loop
@@ -818,7 +818,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
STRUCT_ASSIGN(cstk->c_cfpos, csrc_pos);
if (tn1 != NULL)
- expr(tn1, 0, 0);
+ expr(tn1, 0, 0, 1);
if (tn2 != NULL)
tn2 = cconv(tn2);
@@ -830,7 +830,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
tn2 = NULL;
}
if (tn2 != NULL)
- expr(tn2, 0, 1);
+ expr(tn2, 0, 1, 1);
if (tn2 == NULL) {
cstk->c_infinite = 1;
@@ -877,7 +877,7 @@ for2(void)
}
if (tn3 != NULL) {
- expr(tn3, 0, 0);
+ expr(tn3, 0, 0, 1);
} else {
tfreeblk();
}
@@ -1014,7 +1014,7 @@ doreturn(tnode_t *tn)
}
}
- expr(tn, 1, 0);
+ expr(tn, 1, 0, 1);
} else {
diff --git a/usr.bin/xlint/lint1/init.c b/usr.bin/xlint/lint1/init.c
index cf4cbdd..9a10b33 100644
--- a/usr.bin/xlint/lint1/init.c
+++ b/usr.bin/xlint/lint1/init.c
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $ */
+/* $NetBSD: init.c,v 1.10 2002/01/31 19:36:54 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,11 +33,13 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $");
+__RCSID("$NetBSD: init.c,v 1.10 2002/01/31 19:36:54 tv Exp $");
#endif
__FBSDID("$FreeBSD$");
+#include <ctype.h>
#include <stdlib.h>
+#include <string.h>
#include "lint1.h"
@@ -54,6 +56,15 @@ sym_t *initsym;
/* Points to the top element of the initialisation stack. */
istk_t *initstk;
+typedef struct namlist {
+ const char *n_name;
+ struct namlist *n_prev;
+ struct namlist *n_next;
+} namlist_t;
+
+/* Points to a c9x named member; */
+namlist_t *namedmem = NULL;
+
static void popi2(void);
static void popinit(int);
@@ -61,6 +72,53 @@ static void pushinit(void);
static void testinit(void);
static void nextinit(int);
static int strginit(tnode_t *);
+static void memberpop(void);
+
+#ifndef DEBUG
+#define DPRINTF(a)
+#else
+#define DPRINTF(a) printf a
+#endif
+
+void
+memberpush(sb)
+ sbuf_t *sb;
+{
+ namlist_t *nam = xcalloc(1, sizeof (namlist_t));
+ nam->n_name = sb->sb_name;
+ DPRINTF(("memberpush = %s\n", nam->n_name));
+ if (namedmem == NULL) {
+ nam->n_prev = nam->n_next = nam;
+ namedmem = nam;
+ } else {
+ namedmem->n_prev->n_next = nam;
+ nam->n_prev = namedmem->n_prev;
+ nam->n_next = namedmem;
+ namedmem->n_prev = nam;
+ }
+#if 0
+ nam->n_next = namedmem;
+ namedmem = nam;
+#endif
+}
+
+static void
+memberpop()
+{
+ DPRINTF(("memberpop = %s\n", namedmem->n_name));
+ if (namedmem->n_next == namedmem) {
+ free(namedmem);
+ namedmem = NULL;
+ } else {
+ namlist_t *nam = namedmem;
+ namedmem = namedmem->n_next;
+ free(nam);
+ }
+#if 0
+ namedmem = namedmem->n_next;
+ free(nam);
+#endif
+}
/*
@@ -97,29 +155,53 @@ prepinit(void)
static void
popi2(void)
{
+#ifdef DEBUG
+ char buf[64];
+#endif
istk_t *istk;
sym_t *m;
initstk = (istk = initstk)->i_nxt;
if (initstk == NULL)
- lerror("popi2() 1");
+ LERROR("popi2()");
free(istk);
istk = initstk;
istk->i_cnt--;
if (istk->i_cnt < 0)
- lerror("popi2() 3");
+ LERROR("popi2()");
+ DPRINTF(("popi2(): %d %s\n", istk->i_cnt,
+ namedmem ? namedmem->n_name : "*null*"));
+ if (istk->i_cnt >= 0 && namedmem != NULL) {
+ DPRINTF(("popi2(): %d %s %s\n", istk->i_cnt,
+ tyname(buf, sizeof(buf), istk->i_type), namedmem->n_name));
+ for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_nxt) {
+ if (m->s_field && m->s_name == unnamed)
+ continue;
+ if (strcmp(m->s_name, namedmem->n_name) == 0) {
+ istk->i_subt = m->s_type;
+ istk->i_cnt++;
+ memberpop();
+ return;
+ }
+ }
+ error(101, namedmem->n_name);
+ memberpop();
+ istk->i_namedmem = 1;
+ return;
+ }
/*
* If the removed element was a structure member, we must go
* to the next structure member.
*/
- if (istk->i_cnt > 0 && istk->i_type->t_tspec == STRUCT) {
+ if (istk->i_cnt > 0 && istk->i_type->t_tspec == STRUCT &&
+ !istk->i_namedmem) {
do {
m = istk->i_mem = istk->i_mem->s_nxt;
if (m == NULL)
- lerror("popi2() 2");
+ LERROR("popi2()");
} while (m->s_field && m->s_name == unnamed);
istk->i_subt = m->s_type;
}
@@ -128,6 +210,7 @@ popi2(void)
static void
popinit(int brace)
{
+ DPRINTF(("popinit(%d)\n", brace));
if (brace) {
/*
@@ -154,6 +237,9 @@ popinit(int brace)
static void
pushinit(void)
{
+#ifdef DEBUG
+ char buf[64];
+#endif
istk_t *istk;
int cnt;
sym_t *m;
@@ -162,35 +248,45 @@ pushinit(void)
/* Extend an incomplete array type by one element */
if (istk->i_cnt == 0) {
+ DPRINTF(("pushinit(extend) %s\n", tyname(buf, sizeof(buf),
+ istk->i_type)));
/*
* Inside of other aggregate types must not be an incomplete
* type.
*/
if (istk->i_nxt->i_nxt != NULL)
- lerror("pushinit() 1");
+ LERROR("pushinit()");
istk->i_cnt = 1;
if (istk->i_type->t_tspec != ARRAY)
- lerror("pushinit() 2");
+ LERROR("pushinit()");
istk->i_type->t_dim++;
/* from now its a complete type */
setcompl(istk->i_type, 0);
}
if (istk->i_cnt <= 0)
- lerror("pushinit() 3");
+ LERROR("pushinit()");
if (istk->i_type != NULL && issclt(istk->i_type->t_tspec))
- lerror("pushinit() 4");
+ LERROR("pushinit() 4");
initstk = xcalloc(1, sizeof (istk_t));
initstk->i_nxt = istk;
initstk->i_type = istk->i_subt;
if (initstk->i_type->t_tspec == FUNC)
- lerror("pushinit() 5");
+ LERROR("pushinit()");
+again:
istk = initstk;
+ DPRINTF(("pushinit(%s)\n", tyname(buf, sizeof(buf), istk->i_type)));
switch (istk->i_type->t_tspec) {
case ARRAY:
+ if (namedmem) {
+ DPRINTF(("pushinit ARRAY %s\n", namedmem->n_name));
+ free(istk);
+ initstk = initstk->i_nxt;
+ goto again;
+ }
if (incompl(istk->i_type) && istk->i_nxt->i_nxt != NULL) {
/* initialisation of an incomplete type */
error(175);
@@ -200,6 +296,9 @@ pushinit(void)
istk->i_subt = istk->i_type->t_subt;
istk->i_nolimit = incompl(istk->i_type);
istk->i_cnt = istk->i_type->t_dim;
+ DPRINTF(("elements array %s[%d] %s\n",
+ tyname(buf, sizeof(buf), istk->i_subt), istk->i_cnt,
+ namedmem ? namedmem->n_name : "*none*"));
break;
case UNION:
if (tflag)
@@ -214,14 +313,38 @@ pushinit(void)
return;
}
cnt = 0;
+ DPRINTF(("2. member lookup %s %s\n",
+ tyname(buf, sizeof(buf), istk->i_type),
+ namedmem ? namedmem->n_name : "*none*"));
for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_nxt) {
if (m->s_field && m->s_name == unnamed)
continue;
+ if (namedmem != NULL) {
+ DPRINTF(("pushinit():[member:%s, looking:%s]\n",
+ m->s_name, namedmem->n_name));
+ if (strcmp(m->s_name, namedmem->n_name) == 0) {
+ cnt++;
+ break;
+ } else
+ continue;
+ }
if (++cnt == 1) {
istk->i_mem = m;
istk->i_subt = m->s_type;
}
}
+ if (namedmem != NULL) {
+ istk->i_namedmem = 1;
+ if (m == NULL) {
+ error(101, namedmem->n_name);
+ initerr = 1;
+ } else {
+ istk->i_mem = m;
+ istk->i_subt = m->s_type;
+ }
+ memberpop();
+ cnt = istk->i_type->t_tspec == STRUCT ? 2 : 1;
+ }
if (cnt == 0) {
/* cannot init. struct/union with no named member */
error(179);
@@ -231,6 +354,12 @@ pushinit(void)
istk->i_cnt = istk->i_type->t_tspec == STRUCT ? cnt : 1;
break;
default:
+ if (namedmem) {
+ DPRINTF(("pushinit(): pop\n"));
+ free(istk);
+ initstk = initstk->i_nxt;
+ goto again;
+ }
istk->i_cnt = 1;
break;
}
@@ -247,7 +376,7 @@ testinit(void)
* If a closing brace is expected we have at least one initializer
* too much.
*/
- if (istk->i_cnt == 0 && !istk->i_nolimit) {
+ if (istk->i_cnt == 0 && !istk->i_nolimit && !istk->i_namedmem) {
switch (istk->i_type->t_tspec) {
case ARRAY:
/* too many array initializers */
@@ -270,7 +399,9 @@ testinit(void)
static void
nextinit(int brace)
{
+ char buf[64];
+ DPRINTF(("nextinit(%d)\n", brace));
if (!brace) {
if (initstk->i_type == NULL &&
!issclt(initstk->i_subt->t_tspec)) {
@@ -346,14 +477,18 @@ mkinit(tnode_t *tn)
tnode_t *ln;
struct mbl *tmem;
scl_t sc;
+#ifdef DEBUG
+ char buf[64];
+#endif
+ DPRINTF(("mkinit(%s)\n", tyname(buf, sizeof(buf), tn->tn_type)));
if (initerr || tn == NULL)
goto end;
sc = initsym->s_scl;
/*
- * Do not test for automatic aggregat initialisation. If the
+ * Do not test for automatic aggregate initialisation. If the
* initializer starts with a brace we have the warning already.
* If not, an error will be printed that the initializer must
* be enclosed by braces.
@@ -369,7 +504,7 @@ mkinit(tnode_t *tn)
ln->tn_type = tduptyp(ln->tn_type);
ln->tn_type->t_const = 0;
tn = build(ASSIGN, ln, tn);
- expr(tn, 0, 0);
+ expr(tn, 0, 0, 1);
goto end;
}
@@ -388,7 +523,7 @@ mkinit(tnode_t *tn)
goto end;
initstk->i_cnt--;
-
+ DPRINTF(("mkinit() cnt=%d tn=%p\n", initstk->i_cnt, tn));
/* Create a temporary node for the left side. */
ln = tgetblk(sizeof (tnode_t));
ln->tn_op = NAME;
@@ -403,7 +538,7 @@ mkinit(tnode_t *tn)
rt = tn->tn_type->t_tspec;
if (!issclt(lt))
- lerror("mkinit() 1");
+ LERROR("mkinit()");
if (!typeok(INIT, 0, ln, tn))
goto end;
@@ -413,7 +548,7 @@ mkinit(tnode_t *tn)
* expr() would free it.
*/
tmem = tsave();
- expr(tn, 1, 0);
+ expr(tn, 1, 0, 1);
trestor(tmem);
if (isityp(lt) && ln->tn_type->t_isfield && !isityp(rt)) {
@@ -444,7 +579,13 @@ mkinit(tnode_t *tn)
}
end:
- tfreeblk();
+ /*
+ * We only free the block, if we are not a compound declaration
+ * We know that the only symbols that start with a digit are the
+ * ones we allocate with mktempsym() for compound declarations
+ */
+ if (!isdigit((unsigned char)initsym->s_name[0]))
+ tfreeblk();
}
@@ -466,7 +607,7 @@ strginit(tnode_t *tn)
* Check if we have an array type which can be initialized by
* the string.
*/
- if (istk->i_subt->t_tspec == ARRAY) {
+ if (istk->i_subt != NULL && istk->i_subt->t_tspec == ARRAY) {
t = istk->i_subt->t_subt->t_tspec;
if (!((strg->st_tspec == CHAR &&
(t == CHAR || t == UCHAR || t == SCHAR)) ||
diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h
index 6cfcbb7..1eb1cc2 100644
--- a/usr.bin/xlint/lint1/lint1.h
+++ b/usr.bin/xlint/lint1/lint1.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.12 2002/01/31 19:33:27 tv Exp $ */
+/* $NetBSD: lint1.h,v 1.16 2002/10/21 22:44:08 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -106,7 +106,7 @@ typedef struct {
* Structures of type str_t uniqely identify structures. This can't
* be done in structures of type type_t, because these are copied
* if they must be modified. So it would not be possible to check
- * if to structures are identical by comparing the pointers to
+ * if two structures are identical by comparing the pointers to
* the type structures.
*
* The typename is used if the structure is unnamed to identify
@@ -141,7 +141,7 @@ typedef struct type {
u_int t_const : 1; /* const modifier */
u_int t_volatile : 1; /* volatile modifier */
u_int t_proto : 1; /* function prototype (t_args valid) */
- u_int t_vararg : 1; /* protoype with ... */
+ u_int t_vararg : 1; /* prototype with ... */
u_int t_typedef : 1; /* type defined with typedef */
u_int t_isfield : 1; /* type is bitfield */
u_int t_isenum : 1; /* type is (or was) enum (t_enum valid) */
@@ -221,7 +221,7 @@ typedef struct sym {
u_int s_reg : 1; /* symbol is register variable */
u_int s_defarg : 1; /* undefined symbol in old style function
definition */
- u_int s_rimpl : 1; /* return value of function implizit decl. */
+ u_int s_rimpl : 1; /* return value of function implicit decl. */
u_int s_osdef : 1; /* symbol stems from old style function def. */
u_int s_inline : 1; /* true if this is an inline function */
struct sym *s_xsym; /* for local declared external symbols pointer
@@ -347,6 +347,7 @@ typedef struct istk {
type_t *i_subt; /* type of next level */
u_int i_brace : 1; /* need } for pop */
u_int i_nolimit : 1; /* incomplete array type */
+ u_int i_namedmem : 1; /* has c9x named members */
sym_t *i_mem; /* next structure member */
int i_cnt; /* # of remaining elements */
struct istk *i_nxt; /* previous level */
@@ -396,6 +397,11 @@ typedef struct cstk {
struct cstk *c_nxt; /* outer control statement */
} cstk_t;
+typedef struct {
+ size_t lo;
+ size_t hi;
+} range_t;
+
#include "externs1.h"
#define ERR_SETSIZE 1024
@@ -413,4 +419,6 @@ typedef struct err_set {
((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS)))
#define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
+#define LERROR(fmt, args...) lerror(__FILE__, __LINE__, fmt, ##args)
+
extern err_set msgset;
diff --git a/usr.bin/xlint/lint1/main1.c b/usr.bin/xlint/lint1/main1.c
index 29c872f..59f6c7f 100644
--- a/usr.bin/xlint/lint1/main1.c
+++ b/usr.bin/xlint/lint1/main1.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $ */
+/* $NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $");
+__RCSID("$NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -53,7 +53,7 @@ int yflag;
/*
* Print warnings if an assignment of an integertype to another integertype
- * causes an implizit narrowing conversion. If aflag is 1, these warnings
+ * causes an implicit narrowing conversion. If aflag is 1, these warnings
* are printed only if the source type is at least as wide as long. If aflag
* is greater than 1, they are always printed.
*/
@@ -101,6 +101,8 @@ int sflag;
/* Traditional C mode. */
int tflag;
+/* Enable C9X extensions */
+int Sflag;
/*
* Complain about functions and external variables used and not defined,
* or defined and not used.
@@ -126,7 +128,7 @@ main(int argc, char *argv[])
char *ptr;
ERR_ZERO(&msgset);
- while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) {
+ while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFSX:")) != -1) {
switch (c) {
case 'a': aflag++; break;
case 'b': bflag = 1; break;
@@ -139,6 +141,7 @@ main(int argc, char *argv[])
case 'p': pflag = 1; break;
case 'r': rflag = 1; break;
case 's': sflag = 1; break;
+ case 'S': Sflag = 1; break;
case 't': tflag = 1; break;
case 'u': uflag = 0; break;
case 'w': wflag = 1; break;
@@ -154,7 +157,10 @@ main(int argc, char *argv[])
for (ptr = strtok(optarg, ","); ptr;
ptr = strtok(NULL, ",")) {
char *eptr;
- long msg = strtol(ptr, &eptr, 0);
+ long msg;
+
+ errno = 0;
+ msg = strtol(ptr, &eptr, 0);
if ((msg == LONG_MIN || msg == LONG_MAX) &&
errno == ERANGE)
err(1, "invalid error message id '%s'",
@@ -197,7 +203,9 @@ main(int argc, char *argv[])
/* Following warnings cannot be suppressed by LINTED */
nowarn = 0;
-
+#ifdef DEBUG
+ printf("%s, %d: nowarn = 0\n", curr_pos.p_file, curr_pos.p_line);
+#endif
chkglsyms();
outclose();
@@ -209,7 +217,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "usage: lint1 [-abcdeghmprstuvwyzF] [-X <id>[,<id>]... src dest\n");
+ "usage: lint1 [-abcdeghmprstuvwyzFS] [-X <id>[,<id>]... src dest\n");
exit(1);
}
diff --git a/usr.bin/xlint/lint1/makeman b/usr.bin/xlint/lint1/makeman
index 7aa060c..922fe5a 100644
--- a/usr.bin/xlint/lint1/makeman
+++ b/usr.bin/xlint/lint1/makeman
@@ -74,7 +74,7 @@ It is intended to be used with
.Fl X
flag of
.Xr lint 1 .
-.Bl -column -offset indent "Id#" "Message"
+.Bl -column -offset indent "XXXX"
__EOF
"$@" | sed -e 's/\\/\\e/g' -e "s/'/\\'/"
echo ".El"
diff --git a/usr.bin/xlint/lint1/param.h b/usr.bin/xlint/lint1/param.h
index 94d8947..7d31373 100644
--- a/usr.bin/xlint/lint1/param.h
+++ b/usr.bin/xlint/lint1/param.h
@@ -95,6 +95,9 @@
#elif __mips__
#define PTRDIFF_IS_LONG 0
#define SIZEOF_IS_ULONG 0
+#elif __aarch64__
+#define PTRDIFF_IS_LONG 1
+#define SIZEOF_IS_ULONG 1
#else
#error unknown machine type
#endif
diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l
index 013a795..5b71517 100644
--- a/usr.bin/xlint/lint1/scan.l
+++ b/usr.bin/xlint/lint1/scan.l
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $ */
+/* $NetBSD: scan.l,v 1.37 2007/02/06 00:08:31 he Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $");
+__RCSID("$NetBSD: scan.l,v 1.37 2007/02/06 00:08:31 he Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -96,12 +96,13 @@ EX ([eE][+-]?[0-9]+)
%%
-{L}({L}|{D})* return (name());
+{L}({L}|{D})* return (name());
0{OD}*[lLuU]* return (icon(8));
{NZD}{D}*[lLuU]* return (icon(10));
0[xX]{HD}+[lLuU]* return (icon(16));
{D}+\.{D}*{EX}?[fFlL]? |
{D}+{EX}[fFlL]? |
+0[xX]{HD}+p{HD}+[fFlL]? |
\.{D}+{EX}?[fFlL]? return (fcon());
"=" return (operator(T_ASSIGN, ASSIGN));
"*=" return (operator(T_OPASS, MULASS));
@@ -191,55 +192,56 @@ static struct kwtab {
scl_t kw_scl; /* storage class if kw_token T_SCLASS */
tspec_t kw_tspec; /* type spec. if kw_token T_TYPE or T_SOU */
tqual_t kw_tqual; /* type qual. fi kw_token T_QUAL */
- u_int kw_stdc : 1; /* STDC keyword */
- u_int kw_gcc : 1; /* GCC keyword */
+ u_int kw_c89; /* c89 keyword */
+ u_int kw_c99; /* c99 keyword */
+ u_int kw_gcc; /* GCC keyword */
} kwtab[] = {
- { "asm", T_ASM, 0, 0, 0, 0, 1 },
- { "__asm", T_ASM, 0, 0, 0, 0, 0 },
- { "__asm__", T_ASM, 0, 0, 0, 0, 0 },
- { "auto", T_SCLASS, AUTO, 0, 0, 0, 0 },
- { "break", T_BREAK, 0, 0, 0, 0, 0 },
- { "case", T_CASE, 0, 0, 0, 0, 0 },
- { "char", T_TYPE, 0, CHAR, 0, 0, 0 },
- { "const", T_QUAL, 0, 0, CONST, 1, 0 },
- { "__const__", T_QUAL, 0, 0, CONST, 0, 0 },
- { "__const", T_QUAL, 0, 0, CONST, 0, 0 },
- { "continue", T_CONTINUE, 0, 0, 0, 0, 0 },
- { "default", T_DEFAULT, 0, 0, 0, 0, 0 },
- { "do", T_DO, 0, 0, 0, 0, 0 },
- { "double", T_TYPE, 0, DOUBLE, 0, 0, 0 },
- { "else", T_ELSE, 0, 0, 0, 0, 0 },
- { "enum", T_ENUM, 0, 0, 0, 0, 0 },
- { "extern", T_SCLASS, EXTERN, 0, 0, 0, 0 },
- { "float", T_TYPE, 0, FLOAT, 0, 0, 0 },
- { "for", T_FOR, 0, 0, 0, 0, 0 },
- { "goto", T_GOTO, 0, 0, 0, 0, 0 },
- { "if", T_IF, 0, 0, 0, 0, 0 },
- { "inline", T_SCLASS, INLINE, 0, 0, 0, 1 },
- { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 },
- { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 },
- { "int", T_TYPE, 0, INT, 0, 0, 0 },
- { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0 },
- { "long", T_TYPE, 0, LONG, 0, 0, 0 },
- { "register", T_SCLASS, REG, 0, 0, 0, 0 },
- { "return", T_RETURN, 0, 0, 0, 0, 0 },
- { "short", T_TYPE, 0, SHORT, 0, 0, 0 },
- { "signed", T_TYPE, 0, SIGNED, 0, 1, 0 },
- { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0 },
- { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0 },
- { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0 },
- { "static", T_SCLASS, STATIC, 0, 0, 0, 0 },
- { "struct", T_SOU, 0, STRUCT, 0, 0, 0 },
- { "switch", T_SWITCH, 0, 0, 0, 0, 0 },
- { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0 },
- { "union", T_SOU, 0, UNION, 0, 0, 0 },
- { "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0 },
- { "void", T_TYPE, 0, VOID, 0, 0, 0 },
- { "volatile", T_QUAL, 0, 0, VOLATILE, 1, 0 },
- { "__volatile__", T_QUAL, 0, 0, VOLATILE, 0, 0 },
- { "__volatile", T_QUAL, 0, 0, VOLATILE, 0, 0 },
- { "while", T_WHILE, 0, 0, 0, 0, 0 },
- { NULL, 0, 0, 0, 0, 0, 0 }
+ { "asm", T_ASM, 0, 0, 0, 0, 0, 1 },
+ { "__asm", T_ASM, 0, 0, 0, 0, 0, 0 },
+ { "__asm__", T_ASM, 0, 0, 0, 0, 0, 0 },
+ { "auto", T_SCLASS, AUTO, 0, 0, 0, 0, 0 },
+ { "break", T_BREAK, 0, 0, 0, 0, 0, 0 },
+ { "case", T_CASE, 0, 0, 0, 0, 0, 0 },
+ { "char", T_TYPE, 0, CHAR, 0, 0, 0, 0 },
+ { "const", T_QUAL, 0, 0, CONST, 1, 0, 0 },
+ { "__const__", T_QUAL, 0, 0, CONST, 0, 0, 0 },
+ { "__const", T_QUAL, 0, 0, CONST, 0, 0, 0 },
+ { "continue", T_CONTINUE, 0, 0, 0, 0, 0, 0 },
+ { "default", T_DEFAULT, 0, 0, 0, 0, 0, 0 },
+ { "do", T_DO, 0, 0, 0, 0, 0, 0 },
+ { "double", T_TYPE, 0, DOUBLE, 0, 0, 0, 0 },
+ { "else", T_ELSE, 0, 0, 0, 0, 0, 0 },
+ { "enum", T_ENUM, 0, 0, 0, 0, 0, 0 },
+ { "extern", T_SCLASS, EXTERN, 0, 0, 0, 0, 0 },
+ { "float", T_TYPE, 0, FLOAT, 0, 0, 0, 0 },
+ { "for", T_FOR, 0, 0, 0, 0, 0, 0 },
+ { "goto", T_GOTO, 0, 0, 0, 0, 0, 0 },
+ { "if", T_IF, 0, 0, 0, 0, 0, 0 },
+ { "inline", T_SCLASS, INLINE, 0, 0, 0, 1, 0 },
+ { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0, 0 },
+ { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0, 0 },
+ { "int", T_TYPE, 0, INT, 0, 0, 0, 0 },
+ { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0, 0 },
+ { "long", T_TYPE, 0, LONG, 0, 0, 0, 0 },
+ { "register", T_SCLASS, REG, 0, 0, 0, 0, 0 },
+ { "return", T_RETURN, 0, 0, 0, 0, 0, 0 },
+ { "short", T_TYPE, 0, SHORT, 0, 0, 0, 0 },
+ { "signed", T_TYPE, 0, SIGNED, 0, 1, 0, 0 },
+ { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0, 0 },
+ { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0, 0 },
+ { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0, 0 },
+ { "static", T_SCLASS, STATIC, 0, 0, 0, 0, 0 },
+ { "struct", T_SOU, 0, STRUCT, 0, 0, 0, 0 },
+ { "switch", T_SWITCH, 0, 0, 0, 0, 0, 0 },
+ { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0, 0 },
+ { "union", T_SOU, 0, UNION, 0, 0, 0, 0 },
+ { "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0, 0 },
+ { "void", T_TYPE, 0, VOID, 0, 0, 0, 0 },
+ { "volatile", T_QUAL, 0, 0, VOLATILE, 1, 0, 0 },
+ { "__volatile__", T_QUAL, 0, 0, VOLATILE, 0, 0, 0 },
+ { "__volatile", T_QUAL, 0, 0, VOLATILE, 0, 0, 0 },
+ { "while", T_WHILE, 0, 0, 0, 0, 0, 0 },
+ { NULL, 0, 0, 0, 0, 0, 0, 0 }
};
/* Symbol table */
@@ -274,7 +276,9 @@ initscan(void)
uint64_t uq;
for (kw = kwtab; kw->kw_name != NULL; kw++) {
- if (kw->kw_stdc && tflag)
+ if ((kw->kw_c89 || kw->kw_c99) && tflag)
+ continue;
+ if (kw->kw_c99 && !(Sflag || gflag))
continue;
if (kw->kw_gcc && !gflag)
continue;
@@ -400,7 +404,7 @@ name(void)
if (sym != NULL) {
if (blklev < sym->s_blklev)
- lerror("name() 1");
+ LERROR("name()");
sb->sb_name = sym->s_name;
sb->sb_len = strlen(sym->s_name);
tok = sym->s_scl == TYPEDEF ? T_TYPENAME : T_NAME;
@@ -508,7 +512,7 @@ icon(int base)
uq = strtouq(cp, &eptr, base);
}
if (eptr != cp + len)
- lerror("icon() 1");
+ LERROR("icon()");
if (errno != 0)
/* integer constant out of range */
warning(252);
@@ -524,8 +528,10 @@ icon(int base)
/* ok */
} else if (ul <= (unsigned)UINT_MAX && base != 10) {
typ = UINT;
+#if INT_MAX != LONG_MAX
} else if (ul <= LONG_MAX) {
typ = LONG;
+#endif
} else {
typ = ULONG;
}
@@ -681,8 +687,24 @@ fcon(void)
errno = 0;
d = strtod(cp, &eptr);
- if (eptr != cp + len)
- lerror("fcon() 1");
+ if (eptr != cp + len) {
+ switch (*eptr) {
+ /*
+ * XXX: non-native non-current strtod() may not handle hex
+ * floats, ignore the rest if we find traces of hex float
+ * syntax...
+ */
+ case 'p':
+ case 'P':
+ case 'x':
+ case 'X':
+ d = 0;
+ errno = 0;
+ break;
+ default:
+ LERROR("fcon()");
+ }
+ }
if (errno != 0)
/* floating-point constant out of range */
warning(248);
@@ -1140,7 +1162,7 @@ slashslashcomment(void)
{
int c;
- if (sflag < 2 && !gflag)
+ if (!Sflag && !gflag)
/* // comments only supported in C99 */
(void)gnuism(312, tflag ? "traditional" : "ANSI");
@@ -1299,7 +1321,7 @@ getsym(sbuf_t *sb)
if (sym != NULL) {
if (sym->s_kind != symtyp)
- lerror("storesym() 1");
+ LERROR("storesym()");
symtyp = FVFT;
freesb(sb);
return (sym);
@@ -1318,7 +1340,7 @@ getsym(sbuf_t *sb)
while (di->d_nxt != NULL && di->d_nxt->d_nxt != NULL)
di = di->d_nxt;
if (di->d_ctx != AUTO)
- lerror("storesym() 2");
+ LERROR("storesym()");
} else {
sym = getblk(sizeof (sym_t));
sym->s_name = sb->sb_name;
@@ -1344,6 +1366,39 @@ getsym(sbuf_t *sb)
}
/*
+ * Construct a temporary symbol. The symbol starts with a digit, so that
+ * it is illegal.
+ */
+sym_t *
+mktempsym(type_t *t)
+{
+ static int n = 0;
+ int h;
+ char *s = getlblk(blklev, 64);
+ sym_t *sym = getblk(sizeof (sym_t));
+
+ (void)snprintf(s, 64, "%.8d_tmp", n++);
+ h = hash(s);
+
+ sym->s_name = s;
+ sym->s_type = t;
+ sym->s_blklev = blklev;
+ sym->s_scl = AUTO;
+ sym->s_kind = FVFT;
+ sym->s_used = 1;
+ sym->s_set = 1;
+
+ if ((sym->s_link = symtab[h]) != NULL)
+ symtab[h]->s_rlink = &sym->s_link;
+ (symtab[h] = sym)->s_rlink = &symtab[h];
+
+ *dcs->d_ldlsym = sym;
+ dcs->d_ldlsym = &sym->s_dlnxt;
+
+ return sym;
+}
+
+/*
* Remove a symbol forever from the symbol table. s_blklev
* is set to -1 to avoid that the symbol will later be put
* back to the symbol table.
@@ -1391,7 +1446,7 @@ inssym(int bl, sym_t *sym)
(symtab[h] = sym)->s_rlink = &symtab[h];
sym->s_blklev = bl;
if (sym->s_link != NULL && sym->s_blklev < sym->s_link->s_blklev)
- lerror("inssym()");
+ LERROR("inssym()");
}
/*
@@ -1432,7 +1487,7 @@ pushdown(sym_t *sym)
h = hash(sym->s_name);
nsym = getblk(sizeof (sym_t));
if (sym->s_blklev > blklev)
- lerror("pushdown()");
+ LERROR("pushdown()");
nsym->s_name = sym->s_name;
UNIQUE_CURR_POS(nsym->s_dpos);
nsym->s_kind = sym->s_kind;
@@ -1469,7 +1524,7 @@ freeyyv(void *sp, int tok)
} else if (strg->st_tspec == WCHAR) {
free(strg->st_wcp);
} else {
- lerror("fryylv() 1");
+ LERROR("fryylv()");
}
free(strg);
}
diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index 12417ba..4989322 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $ */
+/* $NetBSD: tree.c,v 1.45 2008/03/04 02:41:46 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $");
+__RCSID("$NetBSD: tree.c,v 1.45 2008/03/04 02:41:46 christos Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -302,13 +302,32 @@ getnnode(sym_t *sym, int ntok)
*/
sym->s_type = incref(sym->s_type, FUNC);
} else {
- /* %s undefined */
- error(99, sym->s_name);
+ if (!blklev) {
+ /* %s undefined */
+ error(99, sym->s_name);
+ } else {
+ int fixtype;
+ if (strcmp(sym->s_name, "__FUNCTION__") == 0) {
+ gnuism(316);
+ fixtype = 1;
+ } else if (strcmp(sym->s_name, "__func__") == 0) {
+ if (!Sflag)
+ warning(317);
+ fixtype = 1;
+ } else {
+ error(99, sym->s_name);
+ fixtype = 0;
+ }
+ if (fixtype) {
+ sym->s_type = incref(gettyp(CHAR), PTR);
+ sym->s_type->t_const = 1;
+ }
+ }
}
}
if (sym->s_kind != FVFT && sym->s_kind != FMOS)
- lerror("getnnode() 1");
+ LERROR("getnnode()");
n = getnode();
n->tn_type = sym->s_type;
@@ -382,6 +401,7 @@ strmemb(tnode_t *tn, op_t op, sym_t *msym)
*/
if (msym->s_scl == NOSCL) {
/* undefined struct/union member: %s */
+ fprintf(stderr, "3. %s\n", msym->s_name);
error(101, msym->s_name);
rmsym(msym);
msym->s_kind = FMOS;
@@ -651,7 +671,7 @@ build(op_t op, tnode_t *ln, tnode_t *rn)
default:
rtp = mp->m_logop ? gettyp(INT) : ln->tn_type;
if (!mp->m_binary && rn != NULL)
- lerror("build() 1");
+ LERROR("build()");
ntn = mktnode(op, rtp, ln, rn);
break;
}
@@ -757,10 +777,15 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
mp = &modtab[op];
- if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR)
+ if ((ltp = ln->tn_type) == NULL)
+ LERROR("typeok()");
+
+ if ((lt = ltp->t_tspec) == PTR)
lst = (lstp = ltp->t_subt)->t_tspec;
if (mp->m_binary) {
- if ((rt = (rtp = rn->tn_type)->t_tspec) == PTR)
+ if ((rtp = rn->tn_type) == NULL)
+ LERROR("typeok()");
+ if ((rt = rtp->t_tspec) == PTR)
rst = (rstp = rtp->t_subt)->t_tspec;
}
@@ -1009,8 +1034,10 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
error(170);
return (0);
}
+ while (rn->tn_op == CVT)
+ rn = rn->tn_left;
if (rn->tn_op != COLON)
- lerror("typeok() 2");
+ LERROR("typeok()");
break;
case COLON:
@@ -1149,9 +1176,9 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
if (mp->m_badeop &&
(ltp->t_isenum || (mp->m_binary && rtp->t_isenum))) {
chkbeop(op, ln, rn);
- } else if (mp->m_enumop && (ltp->t_isenum && rtp->t_isenum)) {
+ } else if (mp->m_enumop && (ltp->t_isenum && rtp && rtp->t_isenum)) {
chkeop2(op, arg, ln, rn);
- } else if (mp->m_enumop && (ltp->t_isenum || rtp->t_isenum)) {
+ } else if (mp->m_enumop && (ltp->t_isenum || (rtp &&rtp->t_isenum))) {
chkeop1(op, arg, ln, rn);
}
@@ -1409,6 +1436,7 @@ chkeop2(op_t op, int arg, tnode_t *ln, tnode_t *rn)
static void
chkeop1(op_t op, int arg, tnode_t *ln, tnode_t *rn)
{
+ char lbuf[64], rbuf[64];
if (!eflag)
return;
@@ -1425,20 +1453,24 @@ chkeop1(op_t op, int arg, tnode_t *ln, tnode_t *rn)
return;
}
/* initialisation of '%s' with '%s' */
- warning(277, tyname(ln->tn_type), tyname(rn->tn_type));
+ warning(277, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type));
break;
case FARG:
/* combination of '%s' and '%s', arg #%d */
- warning(278, tyname(ln->tn_type), tyname(rn->tn_type), arg);
+ warning(278, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type), arg);
break;
case RETURN:
/* combination of '%s' and '%s' in return */
- warning(279, tyname(ln->tn_type), tyname(rn->tn_type));
+ warning(279, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type));
break;
default:
/* combination of '%s' and %s, op %s */
- warning(242, tyname(ln->tn_type), tyname(rn->tn_type),
- modtab[op].m_name);
+ warning(242, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type),
+ modtab[op].m_name);
break;
}
}
@@ -1465,7 +1497,7 @@ mktnode(op_t op, type_t *type, tnode_t *ln, tnode_t *rn)
if (t != FUNC && t != VOID)
ntn->tn_lvalue = 1;
} else {
- lerror("mktnode() 2");
+ LERROR("mktnode()");
}
}
@@ -1503,7 +1535,7 @@ promote(op_t op, int farg, tnode_t *tn)
t = INT;
} else {
if (size(INT) != len)
- lerror("promote() 1");
+ LERROR("promote()");
if (isutyp(t)) {
t = UINT;
} else {
@@ -1636,7 +1668,7 @@ convert(op_t op, int arg, type_t *tp, tnode_t *tn)
tspec_t nt, ot, ost = NOTSPEC;
if (tn->tn_lvalue)
- lerror("convert() 1");
+ LERROR("convert()");
nt = tp->t_tspec;
if ((ot = tn->tn_type->t_tspec) == PTR)
@@ -1682,6 +1714,7 @@ static void
ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
{
tnode_t *ptn;
+ char buf[64];
if (!isatyp(nt) || !isatyp(ot))
return;
@@ -1704,9 +1737,10 @@ ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
if (isftyp(nt) != isftyp(ot) || psize(nt) != psize(ot)) {
/* representation and/or width change */
- if (styp(nt) != SHORT || !isityp(ot) || psize(ot) > psize(INT))
+ if (!isityp(ot) || psize(ot) > psize(INT)) {
/* conversion to '%s' due to prototype, arg #%d */
- warning(259, tyname(tp), arg);
+ warning(259, tyname(buf, sizeof(buf), tp), arg);
+ }
} else if (hflag) {
/*
* they differ in sign or base type (char, short, int,
@@ -1720,7 +1754,7 @@ ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
/* ok */
} else {
/* conversion to '%s' due to prototype, arg #%d */
- warning(259, tyname(tp), arg);
+ warning(259, tyname(buf, sizeof(buf), tp), arg);
}
}
}
@@ -1733,6 +1767,7 @@ ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
static void
iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
{
+ char lbuf[64], rbuf[64];
if (tn->tn_op == CON)
return;
@@ -1744,9 +1779,10 @@ iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
/* conversion to %s may sign-extend incorrectly (, arg #%d) */
if (aflag && pflag) {
if (op == FARG) {
- warning(297, tyname(tp), arg);
+ warning(297, tyname(lbuf, sizeof(lbuf), tp),
+ arg);
} else {
- warning(131, tyname(tp));
+ warning(131, tyname(lbuf, sizeof(lbuf), tp));
}
}
}
@@ -1758,9 +1794,14 @@ iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
/* conversion from '%s' may lose accuracy */
if (aflag) {
if (op == FARG) {
- warning(298, tyname(tn->tn_type), arg);
+ warning(298,
+ tyname(rbuf, sizeof(rbuf), tn->tn_type),
+ tyname(lbuf, sizeof(lbuf), tp),
+ arg);
} else {
- warning(132, tyname(tn->tn_type));
+ warning(132,
+ tyname(rbuf, sizeof(rbuf), tn->tn_type),
+ tyname(lbuf, sizeof(lbuf), tp));
}
}
}
@@ -1772,6 +1813,7 @@ iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
static void
piconv(op_t op, tspec_t nt, type_t *tp, tnode_t *tn)
{
+ char buf[64];
if (tn->tn_op == CON)
return;
@@ -1784,10 +1826,10 @@ piconv(op_t op, tspec_t nt, type_t *tp, tnode_t *tn)
if (psize(nt) < psize(PTR)) {
if (pflag && size(nt) >= size(PTR)) {
/* conv. of pointer to %s may lose bits */
- warning(134, tyname(tp));
+ warning(134, tyname(buf, sizeof(buf), tp));
} else {
/* conv. of pointer to %s loses bits */
- warning(133, tyname(tp));
+ warning(133, tyname(buf, sizeof(buf), tp));
}
}
}
@@ -1855,6 +1897,7 @@ ppconv(op_t op, tnode_t *tn, type_t *tp)
void
cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v)
{
+ char lbuf[64], rbuf[64];
tspec_t ot, nt;
ldbl_t max = 0.0, min = 0.0;
int sz, rchk;
@@ -1899,18 +1942,21 @@ cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v)
case LDOUBLE:
max = LDBL_MAX; min = -LDBL_MAX; break;
default:
- lerror("cvtcon() 1");
+ LERROR("cvtcon()");
}
if (v->v_ldbl > max || v->v_ldbl < min) {
if (nt == LDOUBLE)
- lerror("cvtcon() 2");
+ LERROR("cvtcon()");
if (op == FARG) {
/* conv. of %s to %s is out of rng., arg #%d */
- warning(295, tyname(gettyp(ot)), tyname(tp),
- arg);
+ warning(295, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ arg);
} else {
/* conversion of %s to %s is out of range */
- warning(119, tyname(gettyp(ot)), tyname(tp));
+ warning(119, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)),
+ tyname(rbuf, sizeof(rbuf), tp));
}
v->v_ldbl = v->v_ldbl > 0 ? max : min;
}
@@ -1988,8 +2034,9 @@ cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v)
* extra bits set to 0 in conversion
* of '%s' to '%s', op %s
*/
- warning(309, tyname(gettyp(ot)),
- tyname(tp), modtab[op].m_name);
+ warning(309, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ modtab[op].m_name);
} else if (nsz < osz &&
(v->v_quad & xmask) != xmask &&
(v->v_quad & xmask) != 0) {
@@ -2049,11 +2096,14 @@ cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v)
warning(196);
} else if (op == FARG) {
/* conv. of %s to %s is out of rng., arg #%d */
- warning(295, tyname(gettyp(ot)), tyname(tp),
- arg);
+ warning(295, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ arg);
} else {
/* conversion of %s to %s is out of range */
- warning(119, tyname(gettyp(ot)), tyname(tp));
+ warning(119, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)),
+ tyname(rbuf, sizeof(rbuf), tp));
}
} else if (nv->v_quad != v->v_quad) {
if (op == ASSIGN && tp->t_isfield) {
@@ -2067,11 +2117,14 @@ cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v)
warning(196);
} else if (op == FARG) {
/* conv. of %s to %s is out of rng., arg #%d */
- warning(295, tyname(gettyp(ot)), tyname(tp),
- arg);
+ warning(295, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ arg);
} else {
/* conversion of %s to %s is out of range */
- warning(119, tyname(gettyp(ot)), tyname(tp));
+ warning(119, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)),
+ tyname(rbuf, sizeof(rbuf), tp));
}
}
}
@@ -2119,7 +2172,7 @@ illptrc(mod_t *mp, type_t *ltp, type_t *rtp)
tspec_t lt, rt;
if (ltp->t_tspec != PTR || rtp->t_tspec != PTR)
- lerror("illptrc() 1");
+ LERROR("illptrc()");
lt = ltp->t_subt->t_tspec;
rt = rtp->t_subt->t_tspec;
@@ -2153,7 +2206,7 @@ mrgqual(type_t **tpp, type_t *tp1, type_t *tp2)
if ((*tpp)->t_tspec != PTR ||
tp1->t_tspec != PTR || tp2->t_tspec != PTR) {
- lerror("mrgqual()");
+ LERROR("mrgqual()");
}
if ((*tpp)->t_subt->t_const ==
@@ -2182,7 +2235,7 @@ conmemb(type_t *tp)
tspec_t t;
if ((t = tp->t_tspec) != STRUCT && t != UNION)
- lerror("conmemb()");
+ LERROR("conmemb()");
for (m = tp->t_str->memb; m != NULL; m = m->s_nxt) {
tp = m->s_type;
if (tp->t_const)
@@ -2196,39 +2249,87 @@ conmemb(type_t *tp)
}
const char *
-tyname(type_t *tp)
+basictyname(tspec_t t)
+{
+ switch (t) {
+ case CHAR: return "char";
+ case UCHAR: return "unsigned char";
+ case SCHAR: return "signed char";
+ case SHORT: return "short";
+ case USHORT: return "unsigned short";
+ case INT: return "int";
+ case UINT: return "unsigned int";
+ case LONG: return "long";
+ case ULONG: return "unsigned long";
+ case QUAD: return "long long";
+ case UQUAD: return "unsigned long long";
+ case FLOAT: return "float";
+ case DOUBLE: return "double";
+ case LDOUBLE: return "long double";
+ case PTR: return "pointer";
+ case ENUM: return "enum";
+ case STRUCT: return "struct";
+ case UNION: return "union";
+ case FUNC: return "function";
+ case ARRAY: return "array";
+ default:
+ LERROR("basictyname()");
+ return NULL;
+ }
+}
+
+const char *
+tyname(char *buf, size_t bufsiz, type_t *tp)
{
tspec_t t;
const char *s;
+ char lbuf[64];
if ((t = tp->t_tspec) == INT && tp->t_isenum)
t = ENUM;
+ s = basictyname(t);
+
+
switch (t) {
- case CHAR: s = "char"; break;
- case UCHAR: s = "unsigned char"; break;
- case SCHAR: s = "signed char"; break;
- case SHORT: s = "short"; break;
- case USHORT: s = "unsigned short"; break;
- case INT: s = "int"; break;
- case UINT: s = "unsigned int"; break;
- case LONG: s = "long"; break;
- case ULONG: s = "unsigned long"; break;
- case QUAD: s = "long long"; break;
- case UQUAD: s = "unsigned long long"; break;
- case FLOAT: s = "float"; break;
- case DOUBLE: s = "double"; break;
- case LDOUBLE: s = "long double"; break;
- case PTR: s = "pointer"; break;
- case ENUM: s = "enum"; break;
- case STRUCT: s = "struct"; break;
- case UNION: s = "union"; break;
- case FUNC: s = "function"; break;
- case ARRAY: s = "array"; break;
+ case CHAR:
+ case UCHAR:
+ case SCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case LONG:
+ case ULONG:
+ case QUAD:
+ case UQUAD:
+ case FLOAT:
+ case DOUBLE:
+ case LDOUBLE:
+ case FUNC:
+ (void)snprintf(buf, bufsiz, "%s", s);
+ break;
+ case PTR:
+ (void)snprintf(buf, bufsiz, "%s to %s", s,
+ tyname(lbuf, sizeof(lbuf), tp->t_subt));
+ break;
+ case ENUM:
+ (void)snprintf(buf, bufsiz, "%s %s", s,
+ tp->t_enum->etag->s_name);
+ break;
+ case STRUCT:
+ case UNION:
+ (void)snprintf(buf, bufsiz, "%s %s", s,
+ tp->t_str->stag->s_name);
+ break;
+ case ARRAY:
+ (void)snprintf(buf, bufsiz, "%s of %s[%d]", s,
+ tyname(lbuf, sizeof(lbuf), tp->t_subt), tp->t_dim);
+ break;
default:
- lerror("tyname()");
+ LERROR("tyname()");
}
- return (s);
+ return (buf);
}
/*
@@ -2241,11 +2342,11 @@ bldstr(op_t op, tnode_t *ln, tnode_t *rn)
int nolval;
if (rn->tn_op != NAME)
- lerror("bldstr() 1");
+ LERROR("bldstr()");
if (rn->tn_sym->s_value.v_tspec != INT)
- lerror("bldstr() 2");
+ LERROR("bldstr()");
if (rn->tn_sym->s_scl != MOS && rn->tn_sym->s_scl != MOU)
- lerror("bldstr() 3");
+ LERROR("bldstr()");
/*
* Remember if the left operand is an lvalue (structure members
@@ -2257,7 +2358,7 @@ bldstr(op_t op, tnode_t *ln, tnode_t *rn)
ln = bldamper(ln, 1);
} else if (ln->tn_type->t_tspec != PTR) {
if (!tflag || !isityp(ln->tn_type->t_tspec))
- lerror("bldstr() 4");
+ LERROR("bldstr()");
ln = convert(NOOP, 0, tincref(gettyp(VOID), PTR), ln);
}
@@ -2292,7 +2393,7 @@ bldincdec(op_t op, tnode_t *ln)
tnode_t *cn, *ntn;
if (ln == NULL)
- lerror("bldincdec() 1");
+ LERROR("bldincdec()");
if (ln->tn_type->t_tspec == PTR) {
cn = plength(ln->tn_type);
@@ -2351,7 +2452,7 @@ bldplmi(op_t op, tnode_t *ln, tnode_t *rn)
if (ln->tn_type->t_tspec == PTR && rn->tn_type->t_tspec != PTR) {
if (!isityp(rn->tn_type->t_tspec))
- lerror("bldplmi() 1");
+ LERROR("bldplmi()");
ctn = plength(ln->tn_type);
if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
@@ -2364,7 +2465,7 @@ bldplmi(op_t op, tnode_t *ln, tnode_t *rn)
} else if (rn->tn_type->t_tspec == PTR) {
if (ln->tn_type->t_tspec != PTR || op != MINUS)
- lerror("bldplmi() 2");
+ LERROR("bldplmi()");
#if PTRDIFF_IS_LONG
tp = gettyp(LONG);
#else
@@ -2429,9 +2530,9 @@ bldcol(tnode_t *ln, tnode_t *rn)
} else if (lt == STRUCT || lt == UNION) {
/* Both types must be identical. */
if (rt != STRUCT && rt != UNION)
- lerror("bldcol() 1");
+ LERROR("bldcol()");
if (ln->tn_type->t_str != rn->tn_type->t_str)
- lerror("bldcol() 2");
+ LERROR("bldcol()");
if (incompl(ln->tn_type)) {
/* unknown operand size, op %s */
error(138, modtab[COLON].m_name);
@@ -2452,17 +2553,17 @@ bldcol(tnode_t *ln, tnode_t *rn)
rtp = rn->tn_type;
} else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) {
if (rt != PTR)
- lerror("bldcol() 4");
+ LERROR("bldcol()");
rtp = ln->tn_type;
mrgqual(&rtp, ln->tn_type, rn->tn_type);
} else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) {
if (lt != PTR)
- lerror("bldcol() 5");
+ LERROR("bldcol()");
rtp = rn->tn_type;
mrgqual(&rtp, ln->tn_type, rn->tn_type);
} else {
if (lt != PTR || rt != PTR)
- lerror("bldcol() 6");
+ LERROR("bldcol()");
/*
* XXX For now we simply take the left type. This is
* probably wrong, if one type contains a functionprototype
@@ -2488,14 +2589,14 @@ bldasgn(op_t op, tnode_t *ln, tnode_t *rn)
tnode_t *ntn, *ctn;
if (ln == NULL || rn == NULL)
- lerror("bldasgn() 1");
+ LERROR("bldasgn()");
lt = ln->tn_type->t_tspec;
rt = rn->tn_type->t_tspec;
if ((op == ADDASS || op == SUBASS) && lt == PTR) {
if (!isityp(rt))
- lerror("bldasgn() 2");
+ LERROR("bldasgn()");
ctn = plength(ln->tn_type);
if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
rn = convert(NOOP, 0, ctn->tn_type, rn);
@@ -2506,7 +2607,7 @@ bldasgn(op_t op, tnode_t *ln, tnode_t *rn)
if ((op == ASSIGN || op == RETURN) && (lt == STRUCT || rt == STRUCT)) {
if (rt != lt || ln->tn_type->t_str != rn->tn_type->t_str)
- lerror("bldasgn() 3");
+ LERROR("bldasgn()");
if (incompl(ln->tn_type)) {
if (op == RETURN) {
/* cannot return incomplete type */
@@ -2519,12 +2620,13 @@ bldasgn(op_t op, tnode_t *ln, tnode_t *rn)
}
}
- if (op == SHLASS || op == SHRASS) {
- if (rt != INT) {
- rn = convert(NOOP, 0, gettyp(INT), rn);
- rt = INT;
+ if (op == SHLASS) {
+ if (psize(lt) < psize(rt)) {
+ if (hflag)
+ /* semantics of %s change in ANSI C; use ... */
+ warning(118, "<<=");
}
- } else {
+ } else if (op != SHRASS) {
if (op == ASSIGN || lt != PTR) {
if (lt != rt ||
(ln->tn_type->t_isfield && rn->tn_op == CON)) {
@@ -2549,7 +2651,7 @@ plength(type_t *tp)
tspec_t st;
if (tp->t_tspec != PTR)
- lerror("plength() 1");
+ LERROR("plength()");
tp = tp->t_subt;
elem = 1;
@@ -2586,7 +2688,7 @@ plength(type_t *tp)
/* cannot do pointer arithmetic on operand of ... */
error(136);
} else if (elsz == -1) {
- lerror("plength() 2");
+ LERROR("plength()");
}
break;
}
@@ -2743,7 +2845,7 @@ fold(tnode_t *tn)
q = utyp ? ul | ur : sl | sr;
break;
default:
- lerror("fold() 5");
+ LERROR("fold()");
}
/* XXX does not work for quads. */
@@ -2773,7 +2875,7 @@ foldtst(tnode_t *tn)
nomem();
v->v_tspec = tn->tn_type->t_tspec;
if (tn->tn_type->t_tspec != INT)
- lerror("foldtst() 1");
+ LERROR("foldtst()");
if (isftyp(tn->tn_left->tn_type->t_tspec)) {
l = tn->tn_left->tn_val->v_ldbl != 0.0;
@@ -2803,7 +2905,7 @@ foldtst(tnode_t *tn)
v->v_quad = l || r;
break;
default:
- lerror("foldtst() 1");
+ LERROR("foldtst()");
}
return (getcnode(tn->tn_type, v));
@@ -2824,12 +2926,12 @@ foldflt(tnode_t *tn)
v->v_tspec = t = tn->tn_type->t_tspec;
if (!isftyp(t))
- lerror("foldflt() 1");
+ LERROR("foldflt()");
if (t != tn->tn_left->tn_type->t_tspec)
- lerror("foldflt() 2");
+ LERROR("foldflt()");
if (modtab[tn->tn_op].m_binary && t != tn->tn_right->tn_type->t_tspec)
- lerror("foldflt() 3");
+ LERROR("foldflt()");
l = tn->tn_left->tn_val->v_ldbl;
if (modtab[tn->tn_op].m_binary)
@@ -2885,11 +2987,11 @@ foldflt(tnode_t *tn)
v->v_quad = l != r;
break;
default:
- lerror("foldflt() 4");
+ LERROR("foldflt()");
}
if (isnan((double)v->v_ldbl))
- lerror("foldflt() 5");
+ LERROR("foldflt()");
if (!finite((double)v->v_ldbl) ||
(t == FLOAT &&
(v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) ||
@@ -2962,7 +3064,7 @@ bldszof(type_t *tp)
} else {
elsz = size(tp->t_tspec);
if (elsz <= 0)
- lerror("bldszof() 1");
+ LERROR("bldszof()");
}
break;
}
@@ -3199,7 +3301,7 @@ parg( int n, /* pos of arg */
* type, an error message is printed.
*/
val_t *
-constant(tnode_t *tn)
+constant(tnode_t *tn, int required)
{
val_t *v;
@@ -3213,7 +3315,7 @@ constant(tnode_t *tn)
if (tn == NULL) {
if (nerr == 0)
- lerror("constant() 1");
+ LERROR("constant()");
v->v_tspec = INT;
v->v_quad = 1;
return (v);
@@ -3223,7 +3325,7 @@ constant(tnode_t *tn)
if (tn->tn_op == CON) {
if (tn->tn_type->t_tspec != tn->tn_val->v_tspec)
- lerror("constant() 2");
+ LERROR("constant()");
if (isityp(tn->tn_val->v_tspec)) {
v->v_ansiu = tn->tn_val->v_ansiu;
v->v_quad = tn->tn_val->v_quad;
@@ -3235,7 +3337,10 @@ constant(tnode_t *tn)
}
/* integral constant expression expected */
- error(55);
+ if (required)
+ error(55);
+ else
+ c99ism(318);
if (!isityp(v->v_tspec))
v->v_tspec = INT;
@@ -3252,11 +3357,11 @@ constant(tnode_t *tn)
* for the expression.
*/
void
-expr(tnode_t *tn, int vctx, int tctx)
+expr(tnode_t *tn, int vctx, int tctx, int freeblk)
{
if (tn == NULL && nerr == 0)
- lerror("expr() 1");
+ LERROR("expr()");
if (tn == NULL) {
tfreeblk();
@@ -3289,7 +3394,8 @@ expr(tnode_t *tn, int vctx, int tctx)
displexpr(tn, 0);
/* free the tree memory */
- tfreeblk();
+ if (freeblk)
+ tfreeblk();
}
static void
@@ -3361,7 +3467,7 @@ displexpr(tnode_t *tn, int offs)
(long)uq & 0xffffffffl);
} else if (tn->tn_op == CON) {
if (tn->tn_type->t_tspec != PTR)
- lerror("displexpr() 1");
+ LERROR("displexpr()");
(void)printf("0x%0*lx ", (int)(sizeof (void *) * CHAR_BIT / 4),
(u_long)tn->tn_val->v_quad);
} else if (tn->tn_op == STRING) {
@@ -3477,7 +3583,7 @@ chkmisc(tnode_t *tn, int vctx, int tctx, int eqwarn, int fcall, int rvdisc,
break;
case CALL:
if (ln->tn_op != AMPER || ln->tn_left->tn_op != NAME)
- lerror("chkmisc() 1");
+ LERROR("chkmisc()");
if (!szof)
outcall(tn, vctx || tctx, rvdisc);
break;
@@ -3632,6 +3738,7 @@ chkaidx(tnode_t *tn, int amper)
static void
chkcomp(op_t op, tnode_t *ln, tnode_t *rn)
{
+ char buf[64];
tspec_t lt, rt;
mod_t *mp;
@@ -3663,11 +3770,12 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *rn)
rn->tn_op == CON && rn->tn_val->v_quad <= 0) {
if (rn->tn_val->v_quad < 0) {
/* comparison of %s with %s, op %s */
- warning(162, tyname(ln->tn_type), "negative constant",
- mp->m_name);
+ warning(162, tyname(buf, sizeof(buf), ln->tn_type),
+ "negative constant", mp->m_name);
} else if (op == LT || op == GE || (hflag && op == LE)) {
/* comparison of %s with %s, op %s */
- warning(162, tyname(ln->tn_type), "0", mp->m_name);
+ warning(162, tyname(buf, sizeof(buf), ln->tn_type),
+ "0", mp->m_name);
}
return;
}
@@ -3675,11 +3783,12 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *rn)
ln->tn_op == CON && ln->tn_val->v_quad <= 0) {
if (ln->tn_val->v_quad < 0) {
/* comparison of %s with %s, op %s */
- warning(162, "negative constant", tyname(rn->tn_type),
- mp->m_name);
+ warning(162, "negative constant",
+ tyname(buf, sizeof(buf), rn->tn_type), mp->m_name);
} else if (op == GT || op == LE || (hflag && op == GE)) {
/* comparison of %s with %s, op %s */
- warning(162, "0", tyname(rn->tn_type), mp->m_name);
+ warning(162, "0", tyname(buf, sizeof(buf), rn->tn_type),
+ mp->m_name);
}
return;
}
@@ -3689,7 +3798,7 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *rn)
* Takes an expression an returns 0 if this expression can be used
* for static initialisation, otherwise -1.
*
- * Constant initialisation expressions must be costant or an address
+ * Constant initialisation expressions must be constant or an address
* of a static object with an optional offset. In the first case,
* the result is returned in *offsp. In the second case, the static
* object is returned in *symp and the offset in *offsp.
@@ -3707,7 +3816,9 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
switch (tn->tn_op) {
case MINUS:
- if (tn->tn_right->tn_op != CON)
+ if (tn->tn_right->tn_op == CVT)
+ return conaddr(tn->tn_right, symp, offsp);
+ else if (tn->tn_right->tn_op != CON)
return (-1);
/* FALLTHROUGH */
case PLUS:
@@ -3743,9 +3854,9 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
case CVT:
t = tn->tn_type->t_tspec;
ot = tn->tn_left->tn_type->t_tspec;
- if ((!isityp(t) && t != PTR) || (!isityp(ot) && ot != PTR)) {
+ if ((!isityp(t) && t != PTR) || (!isityp(ot) && ot != PTR))
return (-1);
- } else if (psize(t) != psize(ot)) {
+ else if (psize(t) != psize(ot)) {
return (-1);
}
if (conaddr(tn->tn_left, symp, offsp) == -1)
diff --git a/usr.bin/xlint/lint2/read.c b/usr.bin/xlint/lint2/read.c
index 0ffd611..c6e6847 100644
--- a/usr.bin/xlint/lint2/read.c
+++ b/usr.bin/xlint/lint2/read.c
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */
+/* $NetBSD: read.c,v 1.19 2007/09/28 21:53:50 uwe Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $");
+__RCSID("$NetBSD: read.c,v 1.19 2007/09/28 21:53:50 uwe Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -87,7 +87,8 @@ static hte_t **renametab;
static int csrcfile;
-static void inperr(void);
+#define inperr() inperror(__FILE__, __LINE__)
+static void inperror(const char *, size_t);
static void setsrc(const char *);
static void setfnid(int, const char *);
static void funccall(pos_t *, const char *);
@@ -213,10 +214,10 @@ readfile(const char *name)
static void
-inperr(void)
+inperror(const char *file, size_t line)
{
- errx(1, "input file error: %s", fnames[srcfile]);
+ errx(1, "%s,%zd: input file error: %s", file, line, fnames[srcfile]);
}
/*
@@ -361,9 +362,7 @@ decldef(pos_t *posp, const char *cp)
used = 0;
- while ((c = *cp) == 't' || c == 'd' || c == 'e' || c == 'u' ||
- c == 'r' || c == 'o' || c == 's' || c == 'v' ||
- c == 'P' || c == 'S') {
+ while (strchr("tdeurosvPS", (c = *cp)) != NULL) {
cp++;
switch (c) {
case 't':
@@ -545,7 +544,7 @@ inptype(const char *cp, const char **epp)
type_t *tp;
int narg, i, osdef = 0;
size_t tlen;
- u_short tidx;
+ u_short tidx, sidx;
int h;
/* If we have this type already, return it's index. */
@@ -621,10 +620,12 @@ inptype(const char *cp, const char **epp)
case ARRAY:
tp->t_dim = (int)strtol(cp, &eptr, 10);
cp = eptr;
- tp->t_subt = TP(inptype(cp, &cp));
+ sidx = inptype(cp, &cp); /* force seq. point! (ditto below) */
+ tp->t_subt = TP(sidx);
break;
case PTR:
- tp->t_subt = TP(inptype(cp, &cp));
+ sidx = inptype(cp, &cp);
+ tp->t_subt = TP(sidx);
break;
case FUNC:
c = *cp;
@@ -641,11 +642,13 @@ inptype(const char *cp, const char **epp)
tp->t_vararg = 1;
cp++;
} else {
- tp->t_args[i] = TP(inptype(cp, &cp));
+ sidx = inptype(cp, &cp);
+ tp->t_args[i] = TP(sidx);
}
}
}
- tp->t_subt = TP(inptype(cp, &cp));
+ sidx = inptype(cp, &cp);
+ tp->t_subt = TP(sidx);
break;
case ENUM:
tp->t_tspec = INT;
diff --git a/usr.bin/xlint/xlint/lint.1 b/usr.bin/xlint/xlint/lint.1
index 13ffce1..30731d2 100644
--- a/usr.bin/xlint/xlint/lint.1
+++ b/usr.bin/xlint/xlint/lint.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: lint.1,v 1.21 2002/01/03 04:25:18 thorpej Exp $
+.\" $NetBSD: lint.1,v 1.29 2004/01/26 21:59:42 wiz Exp $
.\"
.\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
.\" Copyright (c) 1994, 1995 Jochen Pohl
@@ -32,7 +32,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 24, 2001
+.Dd Mar 23, 2015
.Dt LINT 1
.Os
.Sh NAME
@@ -49,6 +49,7 @@
.Op Fl I Ar directory
.Op Fl d Ar directory
.Op Fl L Ar directory
+.Op Fl MD
.Op Fl l Ar library
.Op Fl o Ar outputfile
.Op Fl B Ar directory
@@ -269,6 +270,8 @@ With the
flag,
.Dv __STRICT_ANSI__
is a predefined preprocessor macro.
+.It Fl S
+C9X mode. Currently not fully implemented.
.It Fl t
Traditional C mode.
.Dv __STDC__
@@ -369,6 +372,13 @@ If a complaint stems from an included file
.Nm
prints the name of the included file instead of the source file name
followed by a question mark.
+.It Fl MD
+Pass
+.Fl MD
+to
+.Xr cpp 1
+causing cpp to create files containing dependency information for
+each source file.
.It Fl o Ar outputfile
Name the output file
.Ar outputfile .
@@ -415,7 +425,7 @@ The
utility recognizes the following C comments as commands.
.Bl -tag -width indent
.It Li /* ARGSUSED Ns Ar n Li */
-makes
+Makes
.Nm
check only the first
.Ar n
diff --git a/usr.bin/xlint/xlint/xlint.c b/usr.bin/xlint/xlint/xlint.c
index 7980d6c..7c9994d 100644
--- a/usr.bin/xlint/xlint/xlint.c
+++ b/usr.bin/xlint/xlint/xlint.c
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.27 2002/01/31 19:09:33 tv Exp $ */
+/* $NetBSD: xlint.c,v 1.36 2005/02/09 21:24:48 dsl Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.27 2002/01/31 19:09:33 tv Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.36 2005/02/09 21:24:48 dsl Exp $");
#endif
__FBSDID("$FreeBSD$");
@@ -104,7 +104,7 @@ static char **libsrchpath;
static char *libexec_path;
/* flags */
-static int iflag, oflag, Cflag, sflag, tflag, Fflag, dflag, Bflag;
+static int iflag, oflag, Cflag, sflag, tflag, Fflag, dflag, Bflag, Sflag;
/* print the commands executed to run the stages of compilation */
static int Vflag;
@@ -145,7 +145,7 @@ static void cat(char *const *, const char *);
/*
* Some functions to deal with lists of strings.
- * Take care that we get no surprises in case of asyncron signals.
+ * Take care that we get no surprises in case of asynchronous signals.
*/
static void
appstrg(char ***lstp, char *s)
@@ -286,13 +286,13 @@ usage(void)
{
(void)fprintf(stderr,
- "usage: lint [-abceghprvwxzHF] [-s|-t] [-i|-nu] [-Dname[=def]]"
+ "usage: lint [-abceghprvwxzHFS] [-s|-t] [-i|-nu] [-Dname[=def]]"
" [-Uname] [-X <id>[,<id>]...\n");
(void)fprintf(stderr,
"\t[-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile]"
" file...\n");
(void)fprintf(stderr,
- " lint [-abceghprvwzHF] [-s|-t] -Clibrary [-Dname[=def]]\n"
+ " lint [-abceghprvwzHFS] [-s|-t] -Clibrary [-Dname[=def]]\n"
" [-X <id>[,<id>]...\n");
(void)fprintf(stderr, "\t[-Idirectory] [-Uname] [-Bpath] file"
" ...\n");
@@ -345,6 +345,9 @@ main(int argc, char *argv[])
appcstrg(&cflags, "-U__GNUC__");
appcstrg(&cflags, "-undef");
#endif
+#if 0
+ appcstrg(&cflags, "-Wp,-$");
+#endif
appcstrg(&cflags, "-Wp,-C");
appcstrg(&cflags, "-Wcomment");
appcstrg(&cflags, "-D__LINT__");
@@ -359,8 +362,7 @@ main(int argc, char *argv[])
(void)signal(SIGINT, terminate);
(void)signal(SIGQUIT, terminate);
(void)signal(SIGTERM, terminate);
-
- while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:U:VX:")) != -1) {
+ while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:M:SU:VX:")) != -1) {
switch (c) {
case 'a':
@@ -426,6 +428,13 @@ main(int argc, char *argv[])
sflag = 1;
break;
+ case 'S':
+ if (tflag)
+ usage();
+ appcstrg(&l1flags, "-S");
+ Sflag = 1;
+ break;
+
#if !HAVE_CONFIG_H
case 't':
if (sflag)
@@ -465,6 +474,7 @@ main(int argc, char *argv[])
case 'D':
case 'I':
+ case 'M':
case 'U':
(void)sprintf(flgbuf, "-%c", c);
appstrg(&cflags, concat2(flgbuf, optarg));
diff --git a/usr.bin/xo/Makefile b/usr.bin/xo/Makefile
index c7b51d8..b199207 100644
--- a/usr.bin/xo/Makefile
+++ b/usr.bin/xo/Makefile
@@ -10,7 +10,6 @@ MAN= xo.1
# XXX For xoversion.h
CFLAGS+=-I${LIBXO}/libxo
-DPADD= ${LIBXO}
-LDADD= -lxo
+LIBADD= xo
.include <bsd.prog.mk>
diff --git a/usr.bin/xz/Makefile b/usr.bin/xz/Makefile
index 13703fd..7894174 100644
--- a/usr.bin/xz/Makefile
+++ b/usr.bin/xz/Makefile
@@ -22,6 +22,7 @@ SRCS= args.c \
list.c \
main.c \
message.c \
+ mytime.c \
options.c \
signals.c \
suffix.c \
@@ -42,7 +43,6 @@ CFLAGS+= -DHAVE_CONFIG_H \
-I${LZMALIBDIR} \
-I${XZDIR}/common
-DPADD= ${LIBLZMA}
-LDADD= -llzma
+LIBADD= lzma
.include <bsd.prog.mk>
diff --git a/usr.bin/xz/Makefile.depend b/usr.bin/xz/Makefile.depend
index b7653d1..4915738 100644
--- a/usr.bin/xz/Makefile.depend
+++ b/usr.bin/xz/Makefile.depend
@@ -11,6 +11,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/liblzma \
+ lib/libthr \
.include <dirdeps.mk>
diff --git a/usr.bin/xzdec/Makefile b/usr.bin/xzdec/Makefile
index daef296..f78a16c 100644
--- a/usr.bin/xzdec/Makefile
+++ b/usr.bin/xzdec/Makefile
@@ -22,7 +22,6 @@ CFLAGS+= -DHAVE_CONFIG_H \
-I${LZMALIBDIR} \
-I${XZDIR}/common
-DPADD= ${LIBLZMA}
-LDADD= -llzma
+LIBADD= lzma
.include <bsd.prog.mk>
diff --git a/usr.bin/xzdec/Makefile.depend b/usr.bin/xzdec/Makefile.depend
index b7653d1..4915738 100644
--- a/usr.bin/xzdec/Makefile.depend
+++ b/usr.bin/xzdec/Makefile.depend
@@ -11,6 +11,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/liblzma \
+ lib/libthr \
.include <dirdeps.mk>
OpenPOWER on IntegriCloud