Commit graph

14836 commits

Author SHA1 Message Date
Mark Johnston
b98b323813 sort: Hook NetBSD tests up to the build
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 186ba88a7c)
2021-05-20 09:15:49 -04:00
Cyril Zhang
df40dcbf7c sort: Cache value of MB_CUR_MAX
Every usage of MB_CUR_MAX results in a call to __mb_cur_max.  This is
inefficient and redundant.  Caching the value of MB_CUR_MAX in a global
variable removes these calls and speeds up the runtime of sort.  For
numeric sorting, runtime is almost halved in some tests.

PR:		255551
PR:		255840
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30170

(cherry picked from commit 71ec05a212)
2021-05-20 09:15:43 -04:00
Cyril Zhang
f80d1c0035 sort: Stop "fixing" obsolete key syntax after -- flag
PR:		255798
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30234

(cherry picked from commit fa43162c63)
2021-05-20 09:15:40 -04:00
Mark Johnston
8aed0580e4 truss: Decode FreeBSD 11 mknod(2) and mknodat(2)
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit cd497bd40b)
2021-05-19 09:32:40 -04:00
Kirk McKusick
daa020139f Clean up copyright messages.
(cherry picked from commit 9e16b9530a)
2021-05-16 23:09:42 -07:00
Ceri Davies
3f5f4078b3 find(1): Document the -f option
PR:	223127
Reported by:	Mathieu Arnold <mat at FreeBSD dot org>
Reviewed by:	bcr, gbe
Differential Revision:	https://reviews.freebsd.org/D30215

(cherry picked from commit 82483ea7ad)
2021-05-16 10:36:53 +02:00
Xin LI
5a485392c4 usr.bin/patch: remove unneeded header.
(cherry picked from commit 9769f6f808)
2021-05-15 21:40:41 -07:00
Xin LI
34dad5e914 usr.bin/netstat: use roundup2 when rounding up to power of 2.
(cherry picked from commit f6b6d216ca)
2021-05-15 21:40:23 -07:00
Alex Richardson
0d0eb707b4 truss: Add missing underscore to compat_prefix for FreeBSD32
I accidentally dropped this in the final version of D27625, so it didn't
actually work as intended. I found this while testing the MFC to stable/13.

MFC after:	immediately
Fixes:		7daca4e204 ("truss: improved support for decoding compat32 arguments")

(cherry picked from commit 3cbad8287a)
2021-05-11 10:54:06 +01:00
Alex Richardson
7736adb5e6 usr.bin/lex: regenerate bootstrap files after d37f81e35b
Reviewed by:	jkim

(cherry picked from commit c6e66cbfbb)
2021-05-11 09:39:30 +01:00
Alex Richardson
46c255b632 truss: improved support for decoding compat32 arguments
Currently running `truss -a -e` does not decode any
argument values for freebsd32_* syscalls (open/readlink/etc.)

This change checks whether a syscall starts with freebsd{32,64}_ and if
so strips that prefix when looking up the syscall information. To ensure
that the truss logs include the real syscall name we create a copy of
the syscall information struct with the updated.

The other problem is that when reading string array values, truss
naively iterates over an array of char* and fetches the pointer value.
This will result in arguments not being loaded if the pointer is not
aligned to sizeof(void*), which can happens in the compat32 case. If it
happens to be aligned, we would end up printing every other value.
To fix this problem, this changes adds a pointer_size member to the
procabi struct and uses that to correctly read indirect arguments
as 64/32 bit addresses in the the compat32 case (and also compat64 on
CheriBSD).

The motivating use-case for this change is using truss for 64-bit
programs on a CHERI system, but most of the diff also applies to 32-bit
compat on a 64-bit system, so I'm upstreaming this instead of keeping it
as a local CheriBSD patch.

Output of `truss -aef ldd32 /usr/bin/ldd32` before:
39113: freebsd32_mmap(0x0,0x1000,0x3,0x1002,0xffffffff,0x0,0x0) = 543440896 (0x20644000)
39113: freebsd32_ioctl(0x1,0x402c7413,0xffffd2a0) = 0 (0x0)
/usr/bin/ldd32:
39113: write(1,"/usr/bin/ldd32:\n",16)		 = 16 (0x10)
39113: fork()					 = 39114 (0x98ca)
39114: <new process>
39114: freebsd32_execve(0xffffd97e,0xffffd680,0x20634000) EJUSTRETURN
39114: freebsd32_mmap(0x0,0x20000,0x3,0x1002,0xffffffff,0x0,0x0) = 541237248 (0x2042a000)
39114: freebsd32_mprotect(0x20427000,0x1000,0x1) = 0 (0x0)
39114: issetugid()				 = 0 (0x0)
39114: openat(AT_FDCWD,"/etc/libmap32.conf",O_RDONLY|O_CLOEXEC,00) ERR#2 'No such file or directory'
39114: openat(AT_FDCWD,"/var/run/ld-elf32.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
39114: read(3,"Ehnt\^A\0\0\0\M^@\0\0\0#\0\0\0\0"...,128) = 128 (0x80)
39114: freebsd32_fstat(0x3,0xffffbd98)		 = 0 (0x0)
39114: freebsd32_pread(0x3,0x2042f000,0x23,0x80,0x0) = 35 (0x23)
39114: close(3)					 = 0 (0x0)
39114: openat(AT_FDCWD,"/usr/lib32/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3)
39114: freebsd32_fstat(0x3,0xffffc7d0)		 = 0 (0x0)
39114: freebsd32_mmap(0x0,0x1000,0x1,0x40002,0x3,0x0,0x0) = 541368320 (0x2044a000)

After:
  783: freebsd32_mmap(0x0,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON|MAP_ALIGNED(12),-1,0x0) = 543543296 (0x2065d000)
  783: freebsd32_ioctl(1,TIOCGETA,0xffffd7b0)    = 0 (0x0)
/usr/bin/ldd32:
  783: write(1,"/usr/bin/ldd32:\n",16)           = 16 (0x10)
  784: <new process>
  783: fork()                                    = 784 (0x310)
  784: freebsd32_execve("/usr/bin/ldd32",[ "(null)" ],[ "LD_32_TRACE_LOADED_OBJECTS_PROGNAME=/usr/bin/ldd32", "LD_TRACE_LOADED_OBJECTS_PROGNAME=/usr/bin/ldd32", "LD_32_TRACE_LOADED_OBJECTS=yes", "LD_TRACE_LOADED_OBJECTS=yes", "USER=root", "LOGNAME=root", "HOME=/root", "SHELL=/bin/csh", "BLOCKSIZE=K", "MAIL=/var/mail/root", "MM_CHARSET=UTF-8", "LANG=C.UTF-8", "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin", "TERM=vt100", "HOSTTYPE=FreeBSD", "VENDOR=amd", "OSTYPE=FreeBSD", "MACHTYPE=x86_64", "SHLVL=1", "PWD=/root", "GROUP=wheel", "HOST=freebsd-amd64", "EDITOR=vi", "PAGER=less" ]) EJUSTRETURN
  784: freebsd32_mmap(0x0,135168,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 541212672 (0x20424000)
  784: freebsd32_mprotect(0x20421000,4096,PROT_READ) = 0 (0x0)
  784: issetugid()                               = 0 (0x0)
  784: sigfastblock(0x1,0x204234fc)              = 0 (0x0)
  784: open("/etc/libmap32.conf",O_RDONLY|O_CLOEXEC,00) ERR#2 'No such file or directory'
  784: open("/var/run/ld-elf32.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
  784: read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\v\0\0\0"...,128) = 128 (0x80)
  784: freebsd32_fstat(3,{ mode=-r--r--r-- ,inode=18680,size=32768,blksize=0 }) = 0 (0x0)
  784: freebsd32_pread(3,"/usr/lib32\0",11,0x80) = 11 (0xb)

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D27625

(cherry picked from commit 7daca4e204)
2021-05-11 09:39:24 +01:00
Alex Richardson
eec6f94ea5 truss: split counting of syscalls and syscall calling convention
This change is a refactoring cleanup to improve support for compat32
syscalls (and compat64 on CHERI systems). Each process ABI now has it's
own struct sycall instead of using one global list. The list of all
syscalls is replaced with a list of seen syscalls. Looking up the syscall
argument passing convention now interates over the fixed-size array instead
of using a link-list that's populated on startup so we no longer need the
init_syscall() function.
The actual functional changes are in D27625.

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D27636

(cherry picked from commit 6019514b0b)
2021-05-11 09:39:23 +01:00
Konstantin Belousov
32bfffcb9a gcore: add option to dump core using kernel facility
(cherry picked from commit 73e8f06ac5)
2021-05-10 04:03:19 +03:00
Konstantin Belousov
7a94e71e05 gcore: split code to open core file into helper
(cherry picked from commit c192228b73)
2021-05-10 04:03:14 +03:00
Xin LI
8c10d2979c less: upgrade to v581.2.
(cherry picked from commit 50d31dbc6e)

less: upgrade to v581.

(cherry picked from commit 2235c7feac)
2021-05-08 19:31:02 -07:00
Baptiste Daroussin
7904a2e5a8 diff: eleminitate useless macros
The diff_output was not bringing any values but was obfuscating
the code.

(cherry picked from commit 7a57c9cb5a)
2021-05-05 10:37:09 +02:00
Baptiste Daroussin
b6b26cecc0 diff: simplify the hash functions
Instead of 3 different complex case they have all been folded into a
simple on based on switch

(cherry picked from commit e43239f514)
2021-05-05 10:37:09 +02:00
Baptiste Daroussin
ffbf0225b7 diff: fix typo in a comment
(cherry picked from commit e52546a3a7)
2021-05-05 10:37:09 +02:00
Baptiste Daroussin
c5820184fe diff: remove stalled entries in headers
(cherry picked from commit 931ad51808)
2021-05-05 10:37:08 +02:00
Baptiste Daroussin
0ce985a23b diff: eliminate space at end of line
No functionnal changes

(cherry picked from commit 15abb23286)
2021-05-05 10:37:08 +02:00
Baptiste Daroussin
07d72ca905 diff: add a test case about the non regular file support
(cherry picked from commit c440e7870a)
2021-05-05 10:37:07 +02:00
Mateusz Piotrowski
061be8f939 Fix zgrep --version
"zgrep --version" is expected to print the version information in the
same way as "zgrep -V". However, the case handling the --version flag
is never reached, so "zgrep --version" prints:
    zgrep: missing pattern
instead of:
    grep (BSD grep, GNU compatible) 2.6.0-FreeBSD

Reviewed by:	yuripv
Approved by:	yuripv (src)
Differential Revision: https://reviews.freebsd.org/D29813

(cherry picked from commit 16e0391f8e)
2021-04-26 15:39:54 +02:00
Jung-uk Kim
bba9922d99 flex: Regen bootstrap files
This also partially reverts r326025 (8a16b7a18f).  I do not see any
point of adding SPDX tag in generated file.

Submitted by:	Dan McGregor <dan.mcgregor@usask.ca> (initial version)
Differential Revision:	https://reviews.freebsd.org/D28596

(cherry picked from commit 686cf5468c)
2021-04-23 11:46:30 -04:00
Alex Richardson
436fcd12f2 du_test: Skip three tests if sparse files are not supported
This fixes running the du tests with /tmp as tmpfs (which is what we do in the
CheriBSD CI).

Obtained from:	CheriBSD
Reviewed By:	ngie
Differential Revision: https://reviews.freebsd.org/D28398

(cherry picked from commit 39a1f858ad)
2021-04-22 10:41:39 +01:00
Michael Reifenberger
70a2e9a3d4 Improve size readability.
Preserve more space for swap devise names.
Prevent line overflow with long devise name.
Don't draw a bar when swap is not used at all.
Simplify and optimize code.
Change the label to end at end of 100%.
PR:		251655
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27496

(cherry picked from commit 8d06c3e7a4)
2021-04-21 21:11:36 +02:00
Mateusz Piotrowski
51a07d6c94 systat.1: Remove Tn macros
They are no longer supported by mdoc(7).

MFC after:	1 week

(cherry picked from commit fcbaf46b76)
2021-04-17 21:01:34 +02:00
Mateusz Piotrowski
56b873b218 systat.1: Fix synopsis
systat does not have a "-display" flag. Use Ar to indicate that
"display" is meant to be substituted with an actual display command.

(cherry picked from commit e6f59be239)
2021-04-17 21:00:24 +02:00
Nathan Whitehorn
ccaa830e17 Add GPT PREP-boot type to mkimg(1) from geom_gpt.
This partition type can be used to boot some PowerKVM VMs. We don't
support it well because of some limitations in SLOF, but it's worth at
least have feature parity in geom and mkimg.

(cherry picked from commit f7aebfbe5c)
2021-04-15 09:27:41 -04:00
Gordon Bergling
f2950759b8 m4(1): Add a SEE ALSO section and reference an AT&T manual
Obtained from:	OpenBSD

(cherry picked from commit 97fa288a66)
2021-04-15 14:43:43 +02:00
Gordon Bergling
1d51d41519 sed(1): Add a reference for a 4.4BSD manual document
Obtained from:	OpenBSD

(cherry picked from commit 9048d9a933)
2021-04-15 14:43:10 +02:00
Stefan Eßer
0ca6ce5e97 [bc] Update to version 4.0.0
This version fixes an issue (missing pop of top-of-stack value in the
"P" command of the dc program).

This issue did not affect the bc program, since it does not use dc as
an back-end to actually perform the calculations as was the case with
the traditional bc and dc programs.

The major number has been bumped due to Windows support that has been
added to this version. It does not correspond to a major change that
might affect FreeBSD.

(cherry picked from commit b55a927bc8)
2021-04-10 16:18:50 +02:00
Alexander V. Chernikov
1260724822 Fix netstat -rs reporting.
rttrash (unused but not yet delete entries) were eliminated
 during routing rework. Remove reading these symbols from the kernel.

PR:		254681
Reported by:	rashey@superbox.pl

(cherry picked from commit 4084b1ab04)
2021-04-04 08:44:01 +00:00
Dmitry Chagin
b4dc951c41 Fix warning about signed comparison and drop WARNS for ktrdump(8).
Reviewed By:		jhb, imp
Differential Revision:	https://reviews.freebsd.org/D29381

(cherry picked from commit 9e5aeba51b)
2021-04-01 10:55:03 +03:00
Alan Somers
aa9ff8f760 fortune: add a tip about gstat
(cherry picked from commit 60a632f047)
2021-03-21 02:15:05 +00:00
Gordon Bergling
0f51ceaad1 find(1): Refine the HISTORY within the manual page.
A simple find command appeared in Version 1 AT&T UNIX and was removed in
Version 3 AT&T UNIX. It was rewritten for Version 5 AT&T UNIX and later
be enhanced for the Programmer's Workbench (PWB). These changes were
later incorporated in AT&T UNIX v7.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D29114

(cherry picked from commit a9275d996c)
2021-03-20 11:20:57 +01:00
Daniel Ebdrup Jensen
001d849a48 find(1): Mark -not as an extensions to POSIX
While here, change mdoc macro from Ic to Fl.

PR:		253499
Reported by:	Michael Siegel <bugcounterism at malbolge.net>

(cherry picked from commit 75e6f664c4)
2021-03-20 11:20:28 +01:00
Chuck Silvers
8c59e863e2 tail: fix "tail -F" file rotation detection
When checking if the newly opened file is the same as the old one,
we need to fstat() the new file descriptor, not the old one again.

Reviewed by:	glebius
Sponsored by:	Netflix

(cherry picked from commit 7787e7eed9)
2021-03-18 13:12:24 -07:00
Emmanuel Vadot
f21c0366f5 backlight(8): Add note that with option it print the current brightness.
MFC after:    3 days
PR: 	      253737

(cherry picked from commit 1df30489a8)
2021-03-10 11:49:31 +01:00
David Schlachter
9ba393f2ca backlight: Fix incr/decr with percent value of 0
This now does nothing instead of incr/decr by 10%

MFC After:    3 days
PR: 	      253736

(cherry picked from commit 3b005d51bd)
2021-03-10 11:49:25 +01:00
Andrew Gierth
872ec7e5b6 service(8): use an environment more consistent with init(8)
init(8) sets the "daemon" login class without specifying a pw
entry (so no substitutions are done on the variables). service(8)'s
use of env -L had the effect of specifying root's pw entry, with two
effects: getpwnam and getpwuid are being called, which may not be
entirely safe depending on what nsswitch is up to and what stage of
boot we are at, and substitutions would have been done.

Fix by teaching env(8) to allow -L -/classname to set the class
environment with no pw entry at all specified, and use it in
service(8).

PR:		253959

(cherry picked from commit 55deb0a5f0)
(cherry picked from commit 0c1a5eaae8)
2021-03-07 15:39:30 -06:00
Emmanuel Vadot
6f6c648004 mkimg: Add support for offset if the source is an image
This allow us to create image with the following format:
mkimg -v -o sdcard -s gpt -p efi:=esp_aarch64.img:1M -p freebsd-ufs::1G

Which will add a efi partition at a 1M offset on the image with its content
coming from the esp_aarch64.img file.

MFC after:	3 days

(cherry picked from commit 8f3c71c85e)
2021-03-02 14:02:51 +01:00
Emmanuel Vadot
9c5f4f8e4e mkimg: We always want the last block of the last inserted partition
Even with an absolute offset we want to know the last block the partition
otherwise we endup with an image the size of the metadata.
This allow to create image with the ESP placed at a specific position which
is useful on arm/arm64 where u-boot have always a hard time to read the ESP
if it's not aligned on 512k.
mkimg -v -o sdcard -s gpt -p efi::54M:1M -p freebsd-ufs::1G
now works.

MFC after:	3 days

(cherry picked from commit 3b6268bb9e)
2021-03-02 14:02:45 +01:00
Konstantin Belousov
ee5ddf4296 procstat: distinguish vm map guards in procstat vm output.
(cherry picked from commit 25c6318c79)
2021-02-21 11:11:34 +02:00
Mark Johnston
d889bc5762 truss: Decode sendfile(2) arguments
(cherry picked from commit 90da2c797b)
2021-02-19 14:54:18 -05:00
Emmanuel Vadot
2142926f63 lastcomm(1): Only install if MK_ACCT is on
MFC after:	3 days

(cherry picked from commit 8af54bdfca)
2021-02-19 19:01:48 +01:00
Dimitry Andric
83b1614a2e Update Subversion to 1.14.1 LTS. See contrib/subversion/CHANGES for a
summary of changes, or for a more thorough overview:

https://subversion.apache.org/docs/release-notes/1.14

NOTE 1: There is no need to dump and reload repositories, and the
working copy format is still the same as Subversion 1.8 through 1.13.

NOTE 2: The upstream release also contains a fix for a security issue in
mod_dav_svn (CVE-2020-17525), but since we do not build or use any
Apache modules, it is not an issue for the FreeBSD base system.

Relnotes:	yes

(cherry-picked from 0ff1014944)
2021-02-18 21:03:57 +01:00
Alex Richardson
a1c1581997 usr.bin/grep: Fix Address OOB read error
I found this when compiling all the bootstrap tools with -fsanitize=addres:

==65590==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62d000008400 at pc 0x000000473053 bp 0x7ffc1c7dd910 sp 0x7ffc1c7dd0b8
READ of size 32769 at 0x62d000008400 thread T0
    #0 0x473052 in regexec (/local/scratch/alr48/cheri/build/freebsd-amd64-build/local/scratch/alr48/cheri/freebsd/amd64.amd64/tmp/legacy/bin/grep+0x473052)
    #1 0x4c9cf3 in procline /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c:539:8
    #2 0x4c8687 in procfile /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c:379:18
    #3 0x4c6596 in main /local/scratch/alr48/cheri/freebsd/usr.bin/grep/grep.c:714:8

0x62d000008400 is located 0 bytes to the right of 32768-byte region [0x62d000000400,0x62d000008400)
allocated by thread T0 here:
    #0 0x493d5d in malloc (/local/scratch/alr48/cheri/build/freebsd-amd64-build/local/scratch/alr48/cheri/freebsd/amd64.amd64/tmp/legacy/bin/grep+0x493d5d)
    #1 0x4cad75 in grep_malloc /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c:656:13
    #2 0x4c8129 in procfile /local/scratch/alr48/cheri/freebsd/usr.bin/grep/util.c
    #3 0x4c6596 in main /local/scratch/alr48/cheri/freebsd/usr.bin/grep/grep.c:714:8

SUMMARY: AddressSanitizer: heap-buffer-overflow (/local/scratch/alr48/cheri/build/freebsd-amd64-build/local/scratch/alr48/cheri/freebsd/amd64.amd64/tmp/legacy/bin/grep+0x473052) in regexec

Reviewed By:	kevans
MFC after:	1 week

(cherry picked from commit 81c3f64110)
2021-02-16 09:50:31 +00:00
Simon J. Gerraty
78968ce3dd Merge bmake-20210206
Changes of interest

  o unit-tests: use private TMPDIR to avoid errors from other users
  o avoid strdup in mkTempFile
  o always use vfork
  o job.c: do not create empty shell files in jobs mode
    reduce unnecessary calls to waitpid
  o cond.c: fix debug output for comparison operators in conditionals

(cherry picked from commit dba7b0ef92)

Approved by: re
2021-02-15 08:53:34 -08:00
Kyle Evans
08f25b50db grep: fix -A handling in conjunction with -m match limitation
The basic issue here is that grep, when given -m 1, would stop all
line processing once it hit the match count and exit immediately.  The
problem with exiting immediately is that -A processing only happens when
subsequent lines are processed and do not match.

The fix here is relatively easy; when bsdgrep matches a line, it resets
the 'tail' of the matching context to the value supplied to -A and
dumps anything that's been queued up for -B. After the current line has
been printed and tail is reset, we check our mcount and do what's
needed. Therefore, at the time that we decide we're doing nothing, we
know that 'tail' of the context is correct and we can simply continue
on if there's still more to pick up.

With this change, we still bail out immediately if there's been no -A
flag. If -A was supplied, we signal that we should continue on. However,
subsequent lines will not even bothere to try and process the line.  We
have reached the match count, so even if the next line would match then
we must process it if it hadn't. Thus, the loop in procfile() can
short-circuit and just process the line as a non-match until
procmatches() indicates that it's safe to stop.

A test has been added to reflect both that we should be picking up the
next line and that the next line should be considered a non-match even
if it should have been.

PR:		253350
(cherry picked from commit 3e2d96ac97)
2021-02-10 20:49:59 -06:00
Kyle Evans
bbce8cbba9 grep: turn off -w if -x is specified
-x overcomes -w in gnugrep, and it should here as well.  Flip it off as
needed to avoid confusing other parts of grep.

(cherry picked from commit 2373acbbb7)
2021-02-10 20:49:55 -06:00