Commit graph

3894 commits

Author SHA1 Message Date
Kyle Evans dcef4f65ae vfs: add restrictions to read(2) of a directory [1/2]
Historically, we've allowed read() of a directory and some filesystems will
accommodate (e.g. ufs/ffs, msdosfs). From the history department staffed by
Warner: <<EOF

pdp-7 unix seemed to allow reading directories, but they were weird, special
things there so I'm unsure (my pdp-7 assembler sucks).

1st Edition's sources are lost, mostly. The kernel allows it. The
reconstructed sources from 2nd or 3rd edition read it though.

V6 to V7 changed the filesystem format, and should have been a warning, but
reading directories weren't materially changed.

4.1b BSD introduced readdir because of UFS. UFS broke all directory reading
programs in 1983. ls, du, find, etc all had to be rewritten. readdir() and
friends were introduced here.

SysVr3 picked up readdir() in 1987 for the AT&T fork of Unix. SysVr4 updated
all the directory reading programs in 1988 because different filesystem
types were introduced.

In the 90s, these interfaces became completely ubiquitous as PDP-11s running
V7 faded from view and all the folks that initially started on V7 upgraded
to SysV. Linux never supported this (though I've not done the software
archeology to check) because it has always had a pathological diversity of
filesystems.
EOF

Disallowing read(2) on a directory has the side-effect of masking
application bugs from relying on other implementation's behavior
(e.g. Linux) of rejecting these with EISDIR across the board, but allowing
it has been a vector for at least one stack disclosure bug in the past[0].

By POSIX, this is implementation-defined whether read() handles directories
or not. Popular implementations have chosen to reject them, and this seems
sensible: the data you're reading from a directory is not structured in some
unified way across filesystem implementations like with readdir(2), so it is
impossible for applications to portably rely on this.

With this patch, we will reject most read(2) of a dirfd with EISDIR. Users
that know what they're doing can conscientiously set
bsd.security.allow_read_dir=1 to allow read(2) of directories, as it has
proven useful for debugging or recovery. A future commit will further limit
the sysctl to allow only the system root to read(2) directories, to make it
at least relatively safe to leave on for longer periods of time.

While we're adding logic pertaining to directory vnodes to vn_io_fault, an
additional assertion has also been added to ensure that we're not reaching
vn_io_fault with any write request on a directory vnode. Such request would
be a logical error in the kernel, and must be debugged rather than allowing
it to potentially silently error out.

Commented out shell aliases have been placed in root's chsrc/shrc to promote
awareness that grep may become noisy after this change, depending on your
usage.

A tentative MFC plan has been put together to try and make it as trivial as
possible to identify issues and collect reports; note that this will be
strongly re-evaluated. Tentatively, I will MFC this knob with the default as
it is in HEAD to improve our odds of actually getting reports. The future
priv(9) to further restrict the sysctl WILL NOT BE MERGED BACK, so the knob
will be a faithful reversion on stable/12. We will go into the merge
acknowledging that the sysctl default may be flipped back to restore
historical behavior at *any* point if it's warranted.

[0] https://www.freebsd.org/security/advisories/FreeBSD-SA-19:10.ufs.asc

PR:		246412
Reviewed by:	mckusick, kib, emaste, jilles, cy, phk, imp (all previous)
Reviewed by:	rgrimes (latest version)
MFC after:	1 month (note the MFC plan mentioned above)
Relnotes:	absolutely, but will amend previous RELNOTES entry
Differential Revision:	https://reviews.freebsd.org/D24596
2020-06-04 18:09:55 +00:00
Jilles Tjoelker e0f5c1387d sh: Allow more scripts without #!
Austin Group bugs #1226 and #1250 changed the requirements for shell scripts
without #! (POSIX does not specify #!; this is about the shell execution
when execve(2) returns an [ENOEXEC] error).

POSIX says we shall allow execution if the initial part intended to be
parsed by the shell consists of characters and does not contain the NUL
character.  This allows concatenating a shell script (ending with exec or
exit) and a binary payload.

In order to reject common binary files such as PNG images, check that there
is a lowercase letter or expansion before the last newline before the NUL
character, in addition to the check for the newline character suggested by
POSIX.
2020-05-30 16:00:49 +00:00
Jilles Tjoelker 40b12a0b78 sh: Remove a comment that was obsoleted by r358152
Since r358152, the read builtin has used a buffer.

Also, remove a space at the end of the line in a comment.

No functional change is intended.
2020-05-22 14:46:23 +00:00
Kyle Evans 151a7e1135 ls: fix WITHOUT_LS_COLORS build
*sigh* references to colorflags should be gated by COLORLS.

Pointy hat to:	kevans
Reported by:	jenkins (rescue build)
X-MFC-With:	r361318
2020-05-21 15:15:50 +00:00
Kyle Evans a408dc2018 ls(1): actually restore proper behavior
Highlights:
- CLICOLOR in the environment should imply --color=auto to maintain
  compatibility with historical behavior
- -G should set CLICOLOR and imply --color=auto

The manpage has been updated to draw the connection between -G and --color;
the former is in-fact a sort of compromise between --color=always and
--color=auto, where we'll output color regardless of the environment lacking
CLICOLOR/COLORTERM assuming stdout is a tty.

X-MFC-With: r361318
2020-05-21 14:39:00 +00:00
Kyle Evans c0f34ded0b ls: fix a --color regression from r337956
The regression is in-fact that I flipped the default from never to auto. The
incorrect impression was based on an alias that I failed to notice,
installed by the Linux distribution that I used for testing compatibility
here. Users that want the old default should be doing so with a shell alias
as is done elsewhere, rather than making this decision in ls(1).

Many thanks to rgrimes for pointing out the alias that I clearly overlooked
that resulted in this; if you despised colors in your terminal from this,
consider buying him a beer at the next venue that you see him at.

MFC after:	1 week
Relnotes:	yes
2020-05-21 03:50:56 +00:00
Jilles Tjoelker 6bc7175f31 sh: Fix double INTON with vfork
The shell maintains a count of the number of times SIGINT processing has
been disabled via INTOFF, so SIGINT processing resumes when all disables
have enabled again (INTON).

If an error occurs in a vfork() child, the processing of the error enables
SIGINT processing again, and the INTON in vforkexecshell() causes the count
to become negative.

As a result, a later INTOFF may not actually disable SIGINT processing. This
might cause memory corruption if a SIGINT arrives at an inopportune time. As
of r360452, it causes the shell to abort when it would unsafely allocate or
free memory in certain ways.

Note that various places such as errors in non-special builtins
unconditionally reset the count to 0, so the problem might still not always
be visible.

PR:		246497
Reported by:	jbeich
MFC after:	2 weeks
2020-05-16 16:29:23 +00:00
Jilles Tjoelker 1bb4b6a76a sh/tests: Test some obscure cases with aliasing keywords 2020-05-12 21:59:21 +00:00
Piotr Pawel Stefaniak ca8c0d5e81 ps: extend the non-standard option -d (tree view) to work with -p
Initially it seemed that there were multiple possible ways to do it.

Processing option -p could conditionally add selected processes and
their descendants to the list for further work, but it is not guaranteed
to know whether the -d option has been used or not, and it also doesn't
have access to the process list just yet.

There is also descendant_sort() which has access to all possibly needed
information, but serves the purely post-processing purpose of sorting
output.

Then there is the loop that uses invocation information and full process
list to create a list of processes for final display. It seems the most
natural place to implement this, but indeterminate state of the process
list and volatility of the final list that is being created obstruct
adding an elegant search for all elements of process descendancy trees.

So I opted for adding another loop, just before the one I mentioned
above. For all selected processes it conditionally adds direct
descendants to the end of this list of selected processes.

Possible usage:
* ps -auxd -p $$
* ps -auxd -p 1
* while x=$(pgrep svnlite); do clear; ps auxd -p $x; sleep 2; done
* ps -auxd -p `pgrep make`

Reviewed by:	kevans, kaktus (earlier version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D24380
2020-05-07 16:56:18 +00:00
Conrad Meyer 530d2d67b5 ls(1): Fix trivial SEGV due to NULL deref in OOM path
Reported by:	Anton Rang <rang AT acm.org>
Sponsored by:	Dell EMC Isilon
2020-05-05 18:06:32 +00:00
Jilles Tjoelker 9f9c9549fd sh: Assert INTOFF rather than applying it in ck*
As I noted in https://reviews.freebsd.org/D22756, INTOFF should be in effect
when calling ckmalloc/ckrealloc/ckfree to avoid memory leaks and double
frees. Therefore, change the functions to check if INTOFF is in effect
instead of applying it.

Reviewed by:	bdrewery
Differential Revision:	https://reviews.freebsd.org/D24599
2020-04-28 20:34:27 +00:00
Xin LI 201ee4ae97 Remove include of stdint.h. It was added in r241014 for uintmax_t,
which is gone in r340330 and is therefore no longer necessary.

MFC after:	2 weeks
2020-04-23 03:46:41 +00:00
Jilles Tjoelker da06ef25e6 sh: Remove remnants to compile out fc completely
r360139 made compiling with NO_HISTORY work. This #define does not remove
the fc and bind builtins completely but makes them always write an error
message.

However, there was also some code in builtins.def and mkbuiltins to remove
the fc builtin entirely (but not the bind builtin). The additional build
system complication to make this work seems not worth it, so remove that
code.
2020-04-22 21:45:43 +00:00
Bryan Drewery 6c346639ba Fix build with NO_HISTORY set
Reviewed by:		jilles
Differential Revision:	https://reviews.freebsd.org/D24458
2020-04-21 00:37:55 +00:00
Adrian Chadd 4d0b267a1f [sh] Fix a "may be unused" warning on mips-gcc
mips-gcc for mips32 was complaining that c was potentially used before
being set.  Setting it to 0 before calling fdgetsc() looks like the right
thing to do in this instance; there's an explicit check for c == 0 later
on.

Tested: mips-gcc mips32 build, running /bin/sh on mips32
2020-04-16 23:31:39 +00:00
Edward Tomasz Napierala f52c431b18 Bump WARNS for sh(1).
Reviewed by:	jilles
MFC after:	2 weeks
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D24181
2020-04-01 15:12:51 +00:00
Kyle Evans becf15d7cb sh: remove duplicate el definition
el is declared extern in myhistedit.h and defined in histedit.c. Remove the
duplicate definition in input.c to appease the -fno-common build.

-fno-common will become the default in GCC10/LLVM11.

MFC after:	3 days
2020-03-28 17:02:32 +00:00
Kyle Evans b63d2d683d sh: fix read builtin on 32-bit systems
Specifically, any system with a 32-bit size_t; -residue is calculated as a
32-bit *then* promoted to the 64-bit off_t and the result is ultimately
wrong. This resulted in what would appear to be truncated output, as only
the first line would be read.

Correct it by just making residue an off_t to begin with, since this is what
lseek will take anyways.

Reported by:	antoine, dim
Triaged by:	cem
Tested by:	kevans
X-MFC-With:	r358152
2020-02-22 03:14:05 +00:00
Hiroki Sato be860ca2a7 Improve performance of "read" built-in command when using a seekable
fd.

The read built-in command calls read(2) with a 1-byte buffer because
newline characters need to be detected even on a byte stream which
comes from a non-seekable file descriptor.  Because of this, the
following script calls >6,000 read(2) to show a 6KiB file:

 while read IN; do echo "$IN"; done < /COPYRIGHT

When the input byte stream is seekable, it is possible to read a data
block and then reposition the file pointer to where a newline
character found.  This change adds a small buffer to do this and
reduces the number of read(2) calls.

Theoretically, multiple built-in commands reading the same seekable
byte stream in a single pipe chain can share the buffer.  However,
this change just makes a single invocation of the read built-in
allocate a buffer and deallocate it every time for simplicity.
Although this causes read(2) to read the same regions multiple times,
the performance penalty should be small compared to the reduction of
read(2) calls.

Reviewed by:		jilles
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D23747
2020-02-20 03:01:27 +00:00
Xin LI 778ac8d371 Remove unused include.
MFC after:	2 weeks
2020-02-02 20:51:28 +00:00
Pawel Jakub Dawidek d731a314d3 Restore previous usage presentation (without "pwait: " prefix).
Pointed out by:	jilles
2020-02-01 09:13:11 +00:00
Pawel Jakub Dawidek 9677354790 Style changes, mostly usage of braces around single line statements -
it is safer and allowed for some time now by style(9).

Sponsored by:	Fudo Security
2020-01-26 11:13:34 +00:00
Pawel Jakub Dawidek dee496fc37 Implement tests for the newly added -o flag.
Sponsored by:	Fudo Security
2020-01-26 11:03:45 +00:00
Pawel Jakub Dawidek 2362bc2cf5 Implement -o flag which tells pwait(1) to exit if any of the given processes
has terminated.

Sponsored by:	Fudo Security
2020-01-26 11:02:51 +00:00
Pawel Jakub Dawidek 5e2e2222ae Don't setup a timeout if we are exiting.
Sponsored by:	Fudo Security
2020-01-26 10:54:16 +00:00
Pawel Jakub Dawidek 3f50bbaf51 Check for duplicated PID without using additional variable.
Sponsored by:	Fudo Security
2020-01-26 10:51:57 +00:00
Pawel Jakub Dawidek 532b3f4791 - Be consistent with using sysexits(3) codes.
- Turn fprintf()+exit() into errx().

Sponsored by:	Fudo Security
2020-01-26 10:49:24 +00:00
Alex Richardson a33ee411d9 Allow building bin/cat on non-FreeBSD systems
`cat -l` is needed during the installworld phase and other system's cat
don't support that flag. To avoid portability issues when compiling on
Linux/macOS (such as the the direct access to &fp->_mbstate), we
disable the entire multibyte support when building as a boostrap tool.

Reviewed By:	brooks, emaste
Differential Revision: https://reviews.freebsd.org/D13939
2020-01-16 14:15:00 +00:00
Jilles Tjoelker d3eae2a68e sh: Fix rare memory leak with SIGINT
If getcwd() failed earlier on but later succeeded in the pwd builtin,
there was no INTOFF protection between calling savestr() and storing its
result.

It is quite rare for getcwd() to fail, and rarer for it to succeed later in
the same directory.

Found via code inspection for changing ckmalloc() and similar to assert
INTOFF protection instead of applying it directly (which protects against
corrupting malloc's internal state but allows memory leaks or double frees).

MFC after:	1 week
2020-01-01 12:06:37 +00:00
Jilles Tjoelker 2a55bade0e sh: Test that executing various binary files is rejected
If executing a file fails with an [ENOEXEC] error, the shell executes the
file as a shell script, except that this execution may instead result in an
error message if the file is binary.

Per a recent Austin Group interpretation, we will need to change this to
allow a concatenation of a shell script and a binary payload. See
Austin Group bugs #1226 and #1250.

MFC after:	1 week
2019-12-30 21:32:55 +00:00
Simon J. Gerraty 2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Simon J. Gerraty 5ab1c5846f Add Makefile.depend.options
Leaf directories that have dependencies impacted
by options need a Makefile.depend.options file
to avoid churn in Makefile.depend

DIRDEPS for cases such as OPENSSL, TCP_WRAPPERS etc
can be set in local.dirdeps-options.mk
which can add to those set in Makefile.depend.options

See share/mk/dirdeps-options.mk

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22469
2019-12-11 17:37:37 +00:00
Matt Macy b52c534bff Add iflag=fullblock to dd
Normally, count=n means read(2) will be called n times on the input to dd. If
the read() returns short, as may happen when reading from a pipe, fewer bytes
will be copied from the input. With conv=sync the buffer is padded with zeros
to fill the rest of the block.

iflag=fullblock causes dd to continue reading until the block is full, so that
count=n means n full blocks are copied. This flag is compatible with illumos
and GNU dd and is used in the ZFS test suite.

Submitted by:	Ryan Moeller
Reviewed by:	manpages, mmacy@
MFC after:	1 week
Sponsored by:	 iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D21441
2019-09-30 22:00:48 +00:00
Matt Macy 919156e34c Add oflag=fsync and oflag=sync capability to dd
Sets the O_FSYNC flag on the output file. oflag=fsync and oflag=sync are
synonyms just as O_FSYNC and O_SYNC are synonyms. This functionality is
intended to improve portability of dd commands in the ZFS test suite.

Submitted by:	Ryan Moeller
Reviewed by:	manpages, mmacy@
MFC after:	1 week
Sponsored by:	 iXsytems, Inc.
Differential Revision:	https://reviews.freebsd.org/D21422
2019-09-30 21:56:42 +00:00
Matt Macy 2048fe7098 dd: Check result of close(2) for errors
close(2) can return errors from previous operations which should not be ignored.

PR: 229616
Submitted by:	Thomas Hurst
Reported by:	Thomas Hurst
Reviewed by:	mmacy@
Obtained from:	Ryan Moeller
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21376
2019-09-30 21:53:26 +00:00
Matt Macy 3b96efbda0 Add conv=fdatasync flag to dd
The fdatasync flag performs an fdatasync(2) on the output file before closing it.
This will be useful for the ZFS test suite.

Submitted by:	Ryan Moeller
Reviewed by:	manpages, mmacy@
MFC after:	1 week
Sponsored by:	iXSystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D21373
2019-09-30 21:48:12 +00:00
Baptiste Daroussin f370355791 Do not use our custom completion function, it is not needed anymore 2019-09-16 07:31:59 +00:00
Emmanuel Vadot 4c1a82cea5 pkgbase: Create a FreeBSD-utilities package and make it the default one
The default package use to be FreeBSD-runtime but it should only contain
binaries and libs enough to boot to single user and repair the system, it
is also very handy to have a package that can be tranform to a small mfsroot.
So create a new package named FreeBSD-utilities and make it the default one.
Also move a few binaries and lib into this package when it make sense.
Reviewed by:	bapt, gjb
Differential Revision:	https://reviews.freebsd.org/D21506
2019-09-05 14:15:47 +00:00
Matt Macy ce1b19d8c8 Add conv=fsync flag to dd
The fsync flag performs an fsync(2) on the output file before closing it.
This will be useful for the ZFS test suite.

Submitted by:	ryan@ixsystems.com
Reviewed by:	jilles@, imp@
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
2019-09-03 18:35:55 +00:00
Warner Losh ab152d0263 Now that we have MK_LS_COLORS, we don't need RELEASE_CRUNCH check here.
The RELEASE_CRUNCH check is redundant here. We don't need it for releases
anymore, and picobsd can control this more directly without making it a special
case.
2019-07-15 07:35:46 +00:00
Bryan Drewery c63c5ab001 Fix .depend files to work for build tools.
This is somewhat of a follow-up to r335746.

MFC after:	2 weeks
Sponsored by:	DellEMC
2019-06-15 17:08:13 +00:00
Stephen Hurd 705aad98c6 Some devices take undesired actions when RTS and DTR are
asserted. Some development boards for example will reset on DTR,
and some radio interfaces will transmit on RTS.

This patch allows "stty -f /dev/ttyu9.init -rtsdtr" to prevent
RTS and DTR from being asserted on open(), allowing these devices
to be used without problems.

Reviewed by:    imp
Differential Revision:  https://reviews.freebsd.org/D20031
2019-06-12 18:07:04 +00:00
Warner Losh 02e2acce1d Convert freebsd-version to using -v
newvers.sh has supported a variable setting only mode, use that in
preference to grep to future proof this script from changes there.

Differential Revision: https://reviews.freebsd.org/D19849
2019-05-23 17:19:00 +00:00
Warner Losh 8b82def341 Restore the -n flag parsing, but ignore it.
Since D19668 was done, new users of the -n flag have surfaced. Parse
and ignore it on the command line until they can be updated.

Suggested by: rgrimes (in D19668).
2019-04-24 05:24:10 +00:00
Edward Tomasz Napierala fd5795b23a .Xr trim(8) from dd(1).
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2019-03-26 15:44:06 +00:00
Warner Losh e77a99c1c1 Remove -n flag, fix setting date / time
r342139 bork setting the date. This fixes it by simply removing the -n
flag.

Differential Revision: https://reviews.freebsd.org/D19668
2019-03-21 06:47:23 +00:00
Warner Losh ab87f59224 Remove the -d and -t flags from the man page
Remove -d and -t flags that were removed in r345050.

Noticed by: rgrimes@
2019-03-12 21:03:56 +00:00
Warner Losh d24ba0bb86 Remove now useless -d and -t flags.
These were used to set dst flag and minutes west of UTC
respectively. These are obsolete and have been removed form the
kernel. These existed primarily to faithfully emulate early
Unix ABIs that have been removed from FreeBSD.

Reviewed by: jbh@, brooks@
Differential Revision: https://reviews.freebsd.org/D19550
2019-03-12 04:49:59 +00:00
Gordon Tetlow 244e58a2df Correct wording around '-' masks.
PR:		236407
Reported by:	Brian Saia
MFC after:	1 week
2019-03-09 00:30:13 +00:00
Jilles Tjoelker 56ada93f8a sh/tests: Improve failure messages of expansion/arith15.0 2019-03-07 22:51:58 +00:00
Jilles Tjoelker 484160a9cf sh: Add set -o pipefail
The pipefail option allows checking the exit status of all commands in a
pipeline more easily, at a limited cost of complexity in sh itself. It works
similarly to the option in bash, ksh93 and mksh.

Like ksh93 and unlike bash and mksh, the state of the option is saved when a
pipeline is started. Therefore, even in the case of commands like
  A | B &
a later change of the option does not change the exit status, the same way
  (A | B) &
works.

Since SIGPIPE is not handled specially, more work in the script is required
for a proper exit status for pipelines containing commands such as head that
may terminate successfully without reading all input. This can be something
like

(
        cmd1
        r=$?
        if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then
                exit 0
        else
                exit "$r"
        fi
) | head

PR:		224270
Relnotes:	yes
2019-02-24 21:05:13 +00:00
Jilles Tjoelker 94b793c497 sh: Send normal output from bind builtin to stdout
PR:		233343
Submitted by:	Yuichiro NAITO (original version)
2019-02-19 21:27:30 +00:00
Jilles Tjoelker aac5464b61 sh: Restore $((x)) error checking after fix for $((-9223372036854775808))
SVN r342880 was designed to fix $((-9223372036854775808)) and things like
$((0x8000000000000000)) but also broke error detection for values of
variables without dollar sign ($((x))).

For compatibility, overflow in plain literals continues to be ignored and
the value is clamped to the boundary (except 9223372036854775808 which is
changed to -9223372036854775808).

Reviewed by:	se (although he would like error checking to be removed)
MFC after:	2 weeks
X-MFC-with:	r342880
Differential Revision:	https://reviews.freebsd.org/D18926
2019-02-10 22:23:05 +00:00
Edward Tomasz Napierala 719fd9fb2c Comment out the default sh(1) aliases for root, introduced in r343416.
The rest of this stuff is still to be discussed, but I think at this
point we have the agreement that the aliases should go.

MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2019-01-25 17:09:26 +00:00
Edward Tomasz Napierala 60315f8f9d Install .shrc for root, and set PS1 for the toor account.
Reviewed by:	jilles
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D18872
2019-01-24 23:34:51 +00:00
Edward Tomasz Napierala d81ca439e7 Make sh(1) support \u in PS1. This removes one fork/exec on interactive
shell startup.

Reviewed by:	0mp (man page), jilles
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D18790
2019-01-24 11:59:46 +00:00
Edward Tomasz Napierala ed1cfd30ce Don't mess with BLOCKSIZE in shell startup files - it's set by login.conf(5);
there's no need to even mention it in shell rc files.  Not that it's wrong;
just pointless and somewhat misleading.

Reviewed by:	jilles
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D18809
2019-01-20 22:08:49 +00:00
Jilles Tjoelker f91d2e2171 sh: Send libedit "ferr" output to fd 2
The libedit "fout" output must be sent to fd 2 since it contains prompts
that POSIX says must be sent to fd 2. However, the libedit "ferr" output
receives error messages such as from "bind" that make no sense to send to fd
1.
2019-01-20 14:25:25 +00:00
Dag-Erling Smørgrav a96301b673 Fix an edge case when parsing large numbers which resulted in inconsistent
results between an expression that refers to a variable by name and the
same expression that includes the same variable by value.

Submitted by:	se@
MFC after:	1 week
2019-01-09 09:36:54 +00:00
Jilles Tjoelker 993b1e419c sh: Add test for exported but unset variables
PR:		233545
2019-01-03 20:23:12 +00:00
Jilles Tjoelker 56f33d07ce sh: Do not place exported but unset variables into the environment
PR:		233545
Submitted by:	Jan Beich
Obtained from:	NetBSD
2019-01-03 20:22:35 +00:00
Chris Rees 64e8790d7e Add a note that the use of -B option does not guarantee a size of fragment
if -z option also used.

Recommend the use of zip(1) if compressed files of predictable size needed.

PR:			docs/41089
Submitted by:		Sevan Janiyan
Reported by:		areilly@bigpond.net.au

While here, pet igor

Reviewed by:		bcr
Differential Revision:	https://reviews.freebsd.org/D18686
2018-12-29 23:08:59 +00:00
Edward Tomasz Napierala 20c9381c98 Make sh(1) collapse $HOME into "~" in PS1.
Reviewed by:	jilles
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D18663
2018-12-28 17:51:40 +00:00
George V. Neville-Neil 53fc043d41 Remove, the now very outdated, timed.
Submitted by:	Kyle Spiers ksspiers at gmail
Reviewed by:	bcr,brooks,bz,sbruno
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D18505
2018-12-15 21:34:40 +00:00
Jilles Tjoelker 1becbc64f8 sh(1): Remove -c string from set builtin documentation
Altering the -c string at run time does not make sense and is not possible.

MFC after:	1 week
2018-12-08 12:49:19 +00:00
Sevan Janiyan d7a570379b Clarify that /dev/kmem is not used.
Move cross ref to right place while here.

Submitted by:	kib
MFC after:	7 days
2018-12-03 20:01:51 +00:00
Sevan Janiyan 9588059256 Note these tools use kvm(3) and not procfs as in Solaris.
Obtained from:	NetBSD
MFC after:	7 days
2018-12-03 18:00:46 +00:00
Guangyuan Yang e4c7371cef Clarify that patterns are extended regular expressions in pkill(1) manual page.
PR:		231060
Submitted by:	naddy
MFC after:	3 days
2018-12-01 05:58:33 +00:00
Maxim Sobolev dead7b5e47 Replace hand-crafted naive byte-by-byte zero block detection routine
with macro based around memcmp(). The latter is expected to be some
8 times faster on a modern 64-bit architectures.

In practice, throughput of doing conv=sparse from /dev/zero to /dev/null
went up some 5-fold here from 1.9GB/sec to 9.7GB/sec with this change
(bs=128k).

MFC after:	2 weeks
2018-11-29 19:28:01 +00:00
Jilles Tjoelker 468ed39612 sh: Fix ${param?} default error message
If word in ${param?word} is missing, the shell shall write a default error
message. So expanding ${param?} when param is not set should write an error
message like

sh: param: parameter not set

This was broken by r316417.

PR:		233585
2018-11-28 20:03:53 +00:00
Jilles Tjoelker 77da4a95e8 sh: Use 126 and 127 exit status for failures opening a script
This affects scripts named on the command line, named with a '.' special
builtin and found via the PATH %func autoloading mechanism.

PR:		231986
2018-11-27 21:49:59 +00:00
Conrad Meyer 900c4ed3ca rm(1): Formalize non-functional status of -P flag
-P was introduced in 4.4BSD-Lite2 around 1994.  It overwrote file contents
with a pass of 0xff, 0x00, then 0xff, in a low effort attempt to "really
delete" files.

It has no user-visible effect; at the end of the day, the file is unlinked via
the filesystem.  Furthermore, the utility of overwriting files with patterned
data is extremely limited due to caveats at every layer of the stack[0] and
therefore mostly futile.  At the least, three passes is likely wasteful on
modern hardware[1].  It could also be seen as a violation of the "Unix
Philosophy" to do one thing per tiny, composable program.

Since 1994, FreeBSD has left it alone; OpenBSD replaced it with a single
pass of arc4random(3) output in 2012[2]; and NetBSD implemented partial, but
explicitly incomplete support for U.S. DoD 5220.22-M, "National Industrial
Security Program Operating Manual" in 2004[3].

NetBSD's enhanced comment above rm_overwrite makes a strong case for removing
the flag entirely:

> This is an expensive way to keep people from recovering files from your
> non-snapshotted FFS filesystems using fsdb(8).  Really.  No more.
>
> It is impossible to actually conform to the exact procedure given in
> [NISPOM] if one is overwriting a file, not an entire disk, because the
> procedure requires examination and comparison of the disk's defect lists.
> Any program that claims to securely erase *files* while conforming to the
> standard, then, is not correct.
>
> Furthermore, the presence of track caches, disk and controller write
> caches, and so forth make it extremely difficult to ensure that data have
> actually been written to the disk, particularly when one tries to repeatedly
> overwrite the same sectors in quick succession.  We call fsync(), but
> controllers with nonvolatile cache, as well as IDE disks that just plain lie
> about the stable storage of data, will defeat this.
>
> [NISPOM] requires physical media destruction, rather than any technique of
> the sort attempted here, for secret data.

As a first step towards evental removal, make it a placebo.  It's not like
it was serving any security function.  It is not defined in or mentioned by
POSIX.

If you are security conscious and need to erase your files, use a
woodchipper.  At a minimum, the entire disk needs to be overwritten, not
just one file.

[0]: https://www.ru.nl/publish/pages/909282/draft-paper.pdf
[1]: https://commons.erau.edu/cgi/viewcontent.cgi?article=1131&context=jdfsl
[2]: https://github.com/openbsd/src/commit/7c5c57ba81b5fe8ff2d4899ff643af18c
[3]: https://github.com/NetBSD/src/commit/fdf0a7a25e59af958fca1e2159921562cd

Reviewed by:	markj, Daniel O'Connor <darius AT dons.net.au> (previous version)
Differential Revision:	https://reviews.freebsd.org/D17906
2018-11-10 20:26:55 +00:00
Jilles Tjoelker bb324af62a sh: Unify EXERROR and EXEXEC
The difference between EXERROR and EXEXEC was that EXEXEC passed along
exitstatus and EXERROR set exitstatus to 2 in the handling code.

By changing the places that raised EXERROR to set exitstatus to 2, the
handling of EXERROR and EXEXEC becomes the same.
2018-11-09 14:58:24 +00:00
Mariusz Zaborski 377421df96 capsicum: use a new capsicum helpers in tools
Use caph_{rights,ioctls,fcntls}_limit to simplify the code.
2018-11-04 19:24:49 +00:00
Conrad Meyer d83db3fb6a Drop ed(1) "crypto"
You should not be using DES.  You should not have been using DES for the
past 30 years.

The ed DES-CBC scheme lacked several desirable properties of a sealed
document system, even ignoring DES itself.  In particular, it did not
provide the "integrity" cryptographic property (detection of tampering), and
it treated ASCII passwords as 64-bit keys (instead of using a KDF like
scrypt or PBKDF2).

Some general approaches ed(1) users might consider to replace the removed
DES mode:

1. Full disk encryption with something like AES-XTS.  This is easy to
conceptualize, design, and implement, and it provides confidentiality for
data at rest.  Like CBC, it lacks tampering protection.  Examples include
GELI, LUKS, FileVault2.

2. Encrypted overlay ("stackable") filesystems (EncFS, PEFS?, CryptoFS,
others).

3. Native encryption at the filesystem layer.  Ext4/F2FS, ZFS, APFS, and
NTFS all have some flavor of this.

4. Storing your files unencrypted.  It's not like DES was doing you much
good.

If you have DES-CBC scrambled files produced by ed(1) prior to this change,
you may decrypt them with:

  openssl des-cbc -d -iv 0 -K <key in hex> -in <inputfile> -out <plaintext>

Reviewed by:	allanjude, bapt, emaste
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D17829
2018-11-04 17:56:16 +00:00
Mark Johnston 49618eacb2 Avoid copying a struct stat for acl_from_stat() calls.
CID:		1375584
MFC after:	2 weeks
2018-11-01 17:45:29 +00:00
Mateusz Piotrowski f11e51a920 ps(1): Pet mandoc and igor
- Use Xr to reference other manual pages.
- Reference execve(2) instead of exec(2) as exec(2) does not exist.
- Remove the deprecated "Tn" macro.
- Improve the formatting of the etime description.

Reviewed by:	bcr
Approved by:	krion (mentor, implicit), mat (mentor, implicit)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D17780
2018-10-31 17:47:08 +00:00
Mateusz Piotrowski c97c08de8a ps(1): Add a standard exit status section
Reviewed by:	bcr, eadler
Approved by:	krion (mentor)
MFC after:      3 days
Differential Revision:	https://reviews.freebsd.org/D17146
2018-10-31 16:10:04 +00:00
Jilles Tjoelker b5532964e7 sh: Use exitstatus instead of exerrno to pass EXEXEC status
No functional change is intended.
2018-10-27 20:17:57 +00:00
Mark Johnston 15e594351a Don't set NFSv4 ACL inheritance flags on non-directories.
They only make sense in the context of directory ACLs, and attempting
to set them on regular files results in errors, causing a recursive
setfacl invocation to abort.

This is derived from patches by Shawn Webb <shawn.webb@hardenedbsd.org>
and Mitchell Horne <mhorne063@gmail.com>.

PR:		155163
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D15061
2018-10-26 21:17:06 +00:00
Mark Johnston 10cb5344fd Don't print pathconf() errors if the target file doesn't exist.
The subsequent acl_get_file(3) call will simply echo the same error.

PR:		229930
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2018-10-26 19:01:52 +00:00
Mark Johnston f024dd3bf0 Avoid leaking memory in error paths.
CID:		1390906
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2018-10-26 18:56:58 +00:00
Conrad Meyer 93806cf9e5 stty.1: Document kern.tty_info_kstacks behavior (r339471)
Reported by:	bdrewery
Reviewed by:	bdrewery
Sponsored by:	Dell EMC Isilon
2018-10-20 18:53:32 +00:00
Kyle Evans ac5d5b054f dd(1): Correct padding in status=progress
Output padding is specified via outlen, which is set using the return value
of fprintf. Because it's printing that padding plus a trailing byte, it
grows by one each iteration rather than reflecting actual length.

Additionally, iec was sized improperly for scaling up similarly to si.
Fixing this revealed that the humanize_number(3) call to populate persec
was using the wrong width.

Submitted by:	Thomas Hurst <tom@hur.st>
Reviewed by:	imp
Approved by:	re (kib)
Differential Revision:	https://reviews.freebsd.org/D16960
2018-09-13 14:54:46 +00:00
Ed Maste 19b4f0dca0 Fix unlink(1) for files starting with -
Restore the original behavior of unlink(1), passing the provided filename
directly to unlink(2), handling the first argument being "--" correctly.

This fixes "unlink -foo", broken in r97533.

PR:		228448
Submitted by:	Brennan Vincent <brennan@umanwizard.com> (original version)
Submitted by:	Yuri Pankov
Reported by:	Brennan Vincent <brennan@umanwizard.com>
Reviewed by:	emaste, kevans, vangyzen, 0mp
Approved by:	re (delphij)
Differential Revision: https://reviews.freebsd.org/D17132
2018-09-12 19:41:16 +00:00
Jilles Tjoelker 4269bba2eb sh: Fix formal overflow in pointer arithmetic
The intention is to lower the value of the pointer, which according to ubsan
cannot be done by adding an unsigned quantity.

Reported by:	kevans
Approved by:	re (kib)
MFC after:	1 week
2018-09-05 19:16:09 +00:00
Brad Davis 94ec7ec758 Finish moving dot.cshrc and dot.profile to bin/csh/ and bin/sh/.
Approved by:	re (gjb), will (mentor)
Differential Revision:	https://reviews.freebsd.org/D16770
2018-08-29 16:59:19 +00:00
Brad Davis b4d1ec6c69 Fix the install of /root/.login missed as part of r337849.
Approved by:	re (rgrimes)
2018-08-28 22:51:45 +00:00
Kyle Evans 517d0a9043 ls(1): Gate the do_color_* definitions behind COLORLS
Pointy hat to:	me
2018-08-18 21:03:19 +00:00
Kyle Evans 041e6eb1c5 ls(1): Support other aliases for --color arguments used by GNU ls(1)
These aliases are supported and documented in the man page. For now, they
will not be mentioned in the error when an invalid argument is encountered,
instead keeping that list to the shorter 'preferred' names of each argument.

Reported by:	rgrimes
2018-08-18 20:55:20 +00:00
Kyle Evans e10ba80063 ls(1): Add --color=when
--color may be set to one of: 'auto', 'always', and 'never'.

'auto' is the default behavior- output colors only if -G or COLORTERM are
set, and only if stdout is a tty.

'always' is a new behavior- output colors always. termcap(5) will be
consulted unless TERM is unset or not a recognized terminal, in which case
ls(1) will fall back to explicitly outputting ANSI escape sequences.

'never' to turn off any environment variable and -G usage.

Reviewed by:	cem, 0mp (both modulo last-minute manpage changes
Differential Revision:	https://reviews.freebsd.org/D16741
2018-08-17 04:15:51 +00:00
Kyle Evans 7db2f1fe08 ls(1): Fix color env var checking
CLICOLOR will behavior as always- if present at all in the environment,
allow colors.

COLORTERM, recently enforced, will have to be both present and not empty.

Submitted by:	imp
2018-08-16 01:27:16 +00:00
Brad Davis 3349f8bb8f Revert parts of r337849 and r337857
This fixes the build and I will redo these changes as part of a future review
that organizes them differently.  The way I tried to do it here could be done
better.  Sorry for the noise.

Approved by:	will (mentor)
Differential Revision:	https://reviews.freebsd.org/D16737
2018-08-15 23:18:34 +00:00
Kyle Evans eceaf4e3c6 dd(1): Kill off duplicate progress definition following r337865
Reported by:	mmacy
2018-08-15 20:50:38 +00:00
Kyle Evans 8acbb227d9 dd: Incorporate some changes from imp for status=progress
Notable changes from what landed in r337505:
- sigalarm handler isn't setup unless we're actually using it
- Humanized versions of the amount of data transferred in the progress
  update

Submitted by:	imp
Reviewed by:	kevans
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D16642
2018-08-15 19:46:13 +00:00
Brad Davis 1da0bddb6d Fix build after r337849
This moves the symlink creation to after where the files are installed.

This also inverts the shell change so that it only happens if MK_TCSH is on.

Approved by:	will (mentor)
Differential Revision:	https://reviews.freebsd.org/D16725
2018-08-15 16:22:12 +00:00
Brad Davis b26c7f7fee Move all sh and csh files into bin/sh/ or bin/csh/
This simplifies pkgbase by migrating these to CONFS so they are properly
tagged as config files.

Approved by:	will (mentor)
Differential Revision:	https://reviews.freebsd.org/D16708
2018-08-15 14:41:24 +00:00
Kyle Evans 33ce7acbb0 ls(1): Enable colors with COLORTERM is set in the environment
COLORTERM is the de facto standard, while CLICOLOR is generally specific to
FreeBSD and ls(1).

PR:		230101
Submitted by:	D Green <dfrg@xsmail.com> (with manpage additions by myself)
Reviewed by:	cem ("LGTM" in PR; pre-manpage changes)
MFC after:	1 week
2018-08-08 21:51:19 +00:00
Kyle Evans 4767c42c11 dd: add status=progress support
This reports the current status on a single line every second, mirroring
similar functionality in GNU dd, and carefully interacts with SIGINFO.

PR:		229615
Submitted by:	Thomas Hurst <tom@hur.st> (modified for style(9) nits by me)
MFC after:	1 week
2018-08-08 21:37:02 +00:00
Conrad Meyer 2c77ec5419 date(1): Add ISO 8601 formatting option
The new flag is named '-I'.  It is documented in the manual page and covered
by basic unit tests.
2018-08-04 21:54:30 +00:00
Mateusz Piotrowski 17e98da88e Describe how to prevent *.core files from being created using ulimit.
While here, pet mandoc.

Reviewed by:	eadler (previous revision), jilles (previous revision), mat (mentor)
Approved by:	manpages (jilles), mat (mentor)
Differential Revision:	https://reviews.freebsd.org/D15609
2018-07-19 13:09:29 +00:00
Jilles Tjoelker 4600b569bb sh: Don't treat % specially in CDPATH 2018-07-15 21:55:17 +00:00
Jilles Tjoelker 7d6f6a3532 sh: Don't use padvance() for MAIL/MAILPATH
Using padvance() requires undoing its append of '/' and prevents adjusting
its '%' logic to allow most directories with '%' in PATH.

No functional change is intended.
2018-07-15 09:14:30 +00:00
Bryan Drewery d717a1d4bc Stop building intermediate .o files.
These are not used to link the final tool anymore.  At some point in the past
the suffix rules changed to not link these in.  The original reason for this in
r19176 is unclear but seems to be related to mkdep.  The .depend handling is
still broken here as it is for all build tool patterns like this.

Sponsored by:	Dell EMC
2018-06-27 21:36:49 +00:00
Bryan Drewery 96a0acc4ce Don't use CCACHE for linking.
MFC after:	2 weeks
Sponsored by:	Dell EMC
2018-06-27 19:29:15 +00:00
Mariusz Zaborski 7672a0148f Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0.
No functional change intended.
2018-06-19 23:43:14 +00:00
Eitan Adler 377da67109 pwd: mark usage as dead 2018-06-17 05:14:50 +00:00
Eitan Adler c6a5ff7153 ps(1): fix some nits
- fracmem and mempages are double. ki_rssize should be too
- remove default case that is fully covered by all existing cases
- mark usage as dead
2018-06-13 00:45:35 +00:00
Edward Tomasz Napierala bc0d110222 Add an example to the chflags(1) man page.
MFC after:	2 weeks
2018-06-12 16:44:13 +00:00
Conrad Meyer 3181398b92 Update other man pages to match leap second reality
Missed these in r334501; see justification there:

https://svnweb.freebsd.org/base?view=revision&revision=334501

Sponsored by:	Dell EMC Isilon
2018-06-01 22:37:59 +00:00
Jilles Tjoelker dc0dbd74c4 sh: Split CNL syntax category to avoid a check on state[level].syntax
No functional change is intended.
2018-05-21 21:52:48 +00:00
Jilles Tjoelker 29988d0ef0 sh: Allow unquoted newlines in word in ${param+word} etc.
POSIX requires accepting unquoted newlines in word in parameter expansions
like ${param+word}, ${param#word}, although the Bourne shell did not support
it, it is not commonly used and might make it harder to find a missing
closing brace.

It was also strange that something like

foo="${bar#
}"

was rejected.

Reported by:	Martijn Dekker via Robert Elz
2018-05-20 17:25:52 +00:00
Jilles Tjoelker 0c6c134f79 sh: Test that backslash-newline within single-quotes is not special
This works correctly, but the test may be helpful when modifying the parser.
2018-05-11 21:56:01 +00:00
Jilles Tjoelker 4d7f36eea5 sh: Don't have [ match any [[:class:]]
Submitted by:	Robert Elz
MFC after:	3 days
2018-04-29 17:46:08 +00:00
Ed Maste b79f74cc64 setfacl: style and break main() into manageable pieces
Submitted by:	Mitchell Horne
MFC with:	r332396
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D15060
2018-04-27 15:25:24 +00:00
Conrad Meyer 41bd31e656 expr(1): Fix overflow detection when operand is INTMAX_MIN
PR:		227329
Submitted by:	Tobias Stoeckmann <tobias AT stoeckmann.org>
2018-04-14 04:35:10 +00:00
Ed Maste 21c5f7dec5 setfacl: minor man page edit to appease igor(1) 2018-04-11 13:33:12 +00:00
Ed Maste 0629b15276 setfacl: add recursive functionality
Add a -R option to setfacl to operate recursively on directories, along
with the accompanying flags -H, -L, and -P (whose behaviour mimics
chmod).

A patch was submitted with PR 155163, but this is a new implementation
based on comments raised in the Phabricator review for that patch
(review D9096).

PR:		155163
Submitted by:	Mitchell Horne <mhorne063@gmail.com>
Reviewed by:	jilles
MFC after:	2 weeks
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D14934
2018-04-10 23:29:57 +00:00
John Baldwin 2f5a9b7661 Add a "jail" keyword to list the name of a jail rather than its ID.
Inspired by:	mwlucas
Reviewed by:	jamie
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D14683
2018-03-13 18:30:26 +00:00
Mike Karels 30417f2cd4 Change ps(1) output width to unlimited if not interactive
Apply patch submitted with PR 217159 to make ps use unlimited
width when not associated with a terminal (i.e., none of stdout, stdin,
or stderr is a tty). Update comments and man page correspondingly.
This change was requested to work around lack of -ww in scripts from
third-party packages, including Hadoop, and adds a small measure of
Linux compatibility. Hopefully few if any non-interactive scripts
depend on the old default of 79.

PR:		217159
Submitted by:	n.deepak at gmail.com
Reviewed by:	vangyzen jhb
Differential Revision:	https://reviews.freebsd.org/D14614
2018-03-10 00:10:47 +00:00
Bryan Drewery fdee29d7d5 chflags: Add SIGINFO support.
This is copied from chmod r311668.

MFC after:	2 weeks
2018-03-07 01:55:38 +00:00
Bryan Drewery 25d90d5c97 chflags: Add -x option to not traverse mount points.
MFC after:	2 weeks
2018-03-05 01:56:07 +00:00
Edward Tomasz Napierala 7a467312ef .Xr pstat(8), so that people have a chance to learn how to get a list
of terminal devices using "pstat -t".

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2018-03-02 14:16:19 +00:00
Mike Karels b93bb974cc Revert r314685 in ps
Revert r314685, and add a comment describing the original
behavior and the intent.

Reviewed by:	dab@ vangyzen@ jhb@
Differential Revision:	https://reviews.freebsd.org/D14530
2018-02-28 00:17:08 +00:00
Mariusz Zaborski 2ad275d20f Capsicumize uuidgen. 2018-02-17 12:32:53 +00:00
Bryan Drewery 3cdd74bb3c Allow overriding VTABSIZE at compile-time.
Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D14339
2018-02-13 16:48:57 +00:00
Brooks Davis e3e9432478 Add a deprecation warning when using the feature which mounts devices
to see how much space it on them.

Adjust MOUNT_CHAR_DEVS to allow the free space of already mounted
devices to be displayed and report an appropriate error if the
device isn't mounted.

Reviewed by:	cem
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8801
2018-02-10 00:22:25 +00:00
Alex Richardson fb1df20368 Don't hardcode /usr/bin as the path for mktemp in build tools
It won't work e.g. when crossbuilding from Ubuntu Linux as mktemp is in
/bin there.

Reviewed By:	bdrewery
Approved By:	jhb (mentor)
Differential Revision: https://reviews.freebsd.org/D13937
2018-02-06 15:41:35 +00:00
Jilles Tjoelker 190bc94a67 sh: Refactor job status printing, preparing for -o pipefail and similar
No functional change is intended.
2018-02-02 22:53:58 +00:00
Pedro F. Giffuni 7aee7c6293 pax(1): Honour the restrict in sigaction().
Use a setup_sig() helper and make it fail when either of sigaction fails.

While there, do not leak fds for "." + minor cleanup.

Obtained from:	OpenBSD (through DragonFly git eca362d0f9bd086cc56d6b5bc4f03f09e040b9db)
2018-01-27 18:24:13 +00:00
Eitan Adler 44e0a832f2 dd(1): Use a local swapbytes() function.
swab(3) has restrict qualifiers for src and dst.
Avoid relying on undefined overlapping swab behavior.

Obtained From: OpenBSD
2018-01-26 03:30:05 +00:00
John Baldwin faf5dd873e Remove some KSE references from ps(1).
- Simplify the description of -H to assume 1:1 threading.
- Drop 'process' from description of 'lwp' field and the corresponding
  XO field name.
- Do add an expansion of LWP in the description of 'lwp' and 'nlwps'.
- Add 'tid' as an alias for the 'lwp' field.

Reviewed by:	imp, kib (older version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D14021
2018-01-23 22:48:06 +00:00
Warner Losh dfb1d80f64 Fill in ut_id. While it's not relevant to the {OLD,NEW}_TIME entries,
we shouldn't leak stack garbage into the field.

Sponsored by: Netflix
2018-01-23 15:34:34 +00:00
Conrad Meyer 0fdf7fa846 Convert ls(1) to not use libxo(3)
libxo imposes a large burden on system utilities. In the case of ls, that
burden is difficult to justify -- any language that can interact with json
output can use readdir(3) and stat(2).

Logically, this reverts r291607, r285857, r285803, r285734, r285425,
r284494, r284489, r284252, and r284198.

Kyua tests continue to pass (libxo integration was entirely untested).

Reported by:	many
Reviewed by:	imp
Discussed with:	manu, bdrewery
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D13959
2018-01-17 22:47:34 +00:00
Xin LI 6d5343e38e stddef.h is not used by cat.c, remove the include. 2018-01-07 07:08:59 +00:00
Warner Losh ca23e64eb4 Sanity check sysconf return value to ensure it's positive before we
use it. Use proper cast to convert long to size_t (instead of
blksize_t) to preclude sign extension issues.

CID: 1193754
2018-01-06 12:45:59 +00:00
Jilles Tjoelker b0125116ca sh: Move various structs from jobs.h to jobs.c
These implementation details of jobs.c need not be exposed.
2018-01-01 22:31:52 +00:00
Eitan Adler 6b35d82c34 Fix a few speelling errors
- man pages
- bin/sh

Reviewed by:		jilles
2017-12-28 08:22:26 +00:00
Eitan Adler dae3a64fb9 userland: Fix several typos and minor errors
- duplicate words
- typos
- references to old versions of FreeBSD

Reviewed by:	imp, benno
2017-12-27 03:23:01 +00:00
Jilles Tjoelker c8a5f66527 sh: Don't leak wait* implementation details from jobs.c 2017-12-26 16:23:18 +00:00
Jilles Tjoelker 6986f58f53 sh(1): Markup and spelling fixes 2017-12-23 22:58:19 +00:00
Benjamin Kaduk f3aff7c91b Fix mandoc -Tlint warnings in bin/
Many style-level issues are still reported.

Submitted by:	Yuri Pankov <yuripv@gmx.com>
Reviewed by:	jilles (previous revision)
Differential Revision:	https://reviews.freebsd.org/D13334
2017-12-07 01:57:27 +00:00
Edward Tomasz Napierala 536062099a Add "vmaddr" ps(1) keyword.
Obtained from:	CheriBSD
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-12-01 11:32:05 +00:00
Pedro F. Giffuni 1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.
2017-11-27 15:37:16 +00:00
Pedro F. Giffuni 8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Dag-Erling Smørgrav 6fd07539f0 Add a -r option to print the running kernel version.
MFC after:	1 week
2017-11-14 10:15:17 +00:00
Enji Cooper 6f74a1c952 Fix cosmetic nit when printing out "override $mode" and "$owner/$group ..."
The wrong index was being checked for == ' ' in the resulting stringified
mode from strmode(3) -- it should have been the 11th value, not the 10th.

MFC after:	3 days
PR:		76711
Submitted by:	Vasil Dimov <vd@datamax.bg>
2017-11-05 21:43:26 +00:00
Bryan Drewery ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Bryan Drewery 3806950135 DIRDEPS_BUILD: Connect new directories.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:04:07 +00:00
Edward Tomasz Napierala 4363782bc3 Undocument "tdnam" (leaving it as an alias), and rename the column
to TDNAME.

Suggested by:	bde
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-10-09 13:53:41 +00:00
Edward Tomasz Napierala 42ee5c3342 Fix long name (used by libxo) for the "tdnam" ps(1) keyword.
Reported by:	pluknet
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-10-09 13:48:10 +00:00
Edward Tomasz Napierala a8373a7c1f Document "tdnam" keyword to ps(1), and add "tdname" alias.
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-10-09 10:24:06 +00:00
Edward Tomasz Napierala d7026b9671 Fix kvm_getprocs(3) error reporting in ps(1).
Previously it just didn't work at all - kvm_getprocs(3) doesn't update
the &nentries when it returns NULL.  The end result was that ps(1) showed
garbage data instead of reporting kinfo_proc size mismatch.

Reviewed by:	cem
Obtained from:	CheriBSD
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D12414
2017-10-06 15:09:28 +00:00
Jeremie Le Hen e415aa2846 Remove rcmds.
If they are still needed, you can find them in the net/bsdrcmds port.

This was proposed June, 20th and approved by various committers [1].
They have been marked as deprecated on CURRENT in r320644 [2] on July, 4th.
Both stable/11 and release/11.1 contain the deprecation notice (thanks to
allanjude@).

Note that ruptime(1)/rwho(1)/rwhod(8) were initially thought to be part of
rcmds but this was a mistake and those are therefore NOT removed.

[1] https://lists.freebsd.org/pipermail/freebsd-arch/2017-June/018239.html
[2] https://svnweb.freebsd.org/base?view=revision&revision=320644

Reviewed by:	bapt, brooks
Differential Revision:	https://reviews.freebsd.org/D12573
2017-10-06 08:43:14 +00:00
Alan Somers 931329f89b Fix Makefile entries from r323275
Reported by:		Vladimir Zakharov <zakharov.vv@gmail.com>
Reviewed by:		ngie
MFC after:		3 weeks
X-MFC-With:		323275
2017-09-29 23:47:23 +00:00
Sevan Janiyan 6d2e5f3ddf Ammend bin/cat/cat.c so the output is the same aside
from blank lines being numbered or unnumbered, depending on whether cat
was invoked with -ne or -be.

At present, when cat is invoked with -be, there is an aditional
difference that the '$' on blank lines is placed on the far left of the
output.

Discussed in bug 210607.

While here, revert the workaround from r304035 which skipped the unit test for
this issue previously.

PR:		210607
Submitted by:	myself
Reviewed by:	bdrewery
Obtained from:	NetBSD
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D12432
2017-09-21 14:14:49 +00:00
Alan Somers 014404db1a Add basic tests for chflags, mkdir, rcp, and rmdir
Add basic command line parsing test coverage for these utilities.  The tests
were automatically generated based on their man pages.  These tests can be
expanded by hand for more thorough coverage.  The aim is to generate very
basic amount of test coverage for all the utilities in the base system.

Submitted by:	shivansh
Reviewed by:	asomers, brooks
MFC after:	3 weeks
Sponsored by:	Google, Inc (GSoC 2017)
Differential Revision:	https://reviews.freebsd.org/D12036
2017-09-07 16:54:47 +00:00
Edward Tomasz Napierala cde94a423f Hint that the "-o emul" option for ps(1) shows the ABI.
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-09-07 10:56:50 +00:00
Edward Tomasz Napierala 6f47d67bfe Make ps(1) flag processes in capsicum(4) capability mode with "C".
Obtained from:	CheriBSD
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-09-06 16:34:42 +00:00
Edward Tomasz Napierala e4d52dfd1b Reflect realtime and idle priorities in ps(1) state flags, same like
we do for the usual nice values.  It could be argued that they should
use another set of indicators, since the underlying mechanism is
different, but they match the description in the manual page, and so
I think it's ok to not overcomplicate things.

PR:		81757
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-09-06 16:18:06 +00:00
Alan Somers 5ad496a252 Pacify GCC on mips32 after r322893
Though technically correct, GCC complains about usingi a "%zd" format
specifier for a long.

Reported by:	cem
MFC after:	3 weeks
X-MFC-With:	322893
Sponsored by:	Spectra Logic
2017-08-25 18:51:10 +00:00
Alan Somers 77a798b30a dd(1): Incorrect casting of arguments
dd(1) casts many of its numeric arguments from uintmax_t to intmax_t and
back again to detect whether or not the original arguments were negative.
This is not correct, and causes problems with boundary cases, for example
when count is SSIZE_MAX-1.

PR:		191263
Submitted by:	will@worrbase.com
Reviewed by:	pi, asomers
MFC after:	3 weeks
2017-08-25 15:31:55 +00:00
Lawrence Stewart cf182be5e2 Only emit the trailing new line added in r322613 when not operating in quiet
mode.

Reported by:	pho
MFC after:	1 week
X-MFC-with:	r322210
2017-08-24 08:20:23 +00:00
Lawrence Stewart 1e781c6f96 The r322210 change to pgrep's PID delimiting behaviour causes pgrep's default
output to not include a trailing new line, which is a potential POLA violation
for existing consumers. Change pgrep to always emit a trailing new line on
completion of its output, regardless of the delimeter in use (which technically
is also a potential POLA violation for existing consumers that rely on the
pre-r322210 buggy behaviour, but a line has to be drawn somewhere).

PR:	221534
Submitted by:	kdrakehp zoho com
Reported by:	kdrakehp zoho com
MFC after:	1 week
X-MFC-with:	r322210
2017-08-17 06:36:21 +00:00
Enji Cooper 188e46ab03 Add supporting changes for Add limited sandbox capability to "make check"
Non-tests/... changes:
- Add HAS_TESTS= to Makefiles with libraries and programs to enable iteration
  and propagate the appropriate environment down to *.test.mk.

tests/... changes:
- Add appropriate support Makefile.inc's to set HAS_TESTS in a minimal manner,
  since tests/... is a special subdirectory tree compared to the others.

MFC after:	2 months
MFC with:	r322511
Reviewed by:	arch (silence), testing (silence)
Differential Revision:	D12014
2017-08-14 19:21:37 +00:00
Jilles Tjoelker 413bf7b083 sh: Add test for sh -c with missing command string.
This already works correctly.
2017-08-13 14:36:10 +00:00
Jilles Tjoelker 2cc32af06f sh: Add tests for sh -c that already pass.
PR:		220587
Submitted by:	Ryan Moeller
2017-08-12 19:17:48 +00:00
Ed Maste 4be62405c0 cat: fix build with -DNO_UDOM_SUPPORT
Sponsored by:	The FreeBSD Foundation
2017-08-09 18:23:46 +00:00
Kyle Evans d0bc27e435 df(1): Add --si as an alias for -H
Reviewed by:	cem (earlier version), emaste
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D11749
2017-08-09 01:24:52 +00:00
Lawrence Stewart 27181846bb pgrep naively appends the delimiter to all PIDs including the last
e.g. "pgrep -d, getty" outputs "1399,1386,1309,1308,1307,1306,1305,1302,"
Ensure the list is correctly delimited by suppressing the emission of the
delimiter after the final PID.

Reviewed by:	imp, kib
MFC after:	1 week
Sponsored by:	Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D8537
2017-08-08 00:31:10 +00:00
Enji Cooper 3783c851d7 Don't check result of chflags in f_flag_cleanup()
This will prevent false positives from occurring if the test is run on
ZFS since ZFS doesn't support fflags throbbing like UFS.

PR:	221189
MFC after:	4 days
MFC with:	r321949
2017-08-05 16:58:02 +00:00
Enji Cooper 86cc58dc96 MFhead@r321960 2017-08-02 22:28:12 +00:00
Enji Cooper 3e46b70f38 Always use first parameter passed to get_filesystem(..) instead of discarding it
and using `.` instead.

MFC after:	1 week
MFC with:	r321949
PR:	221189 [1], 221188 [2]
2017-08-02 21:20:49 +00:00
Enji Cooper 2d3e9c25f1 Add expected failures for ZFS
- :f_flag fails on ZFS because UF_IMMUTABLE isn't supported [1].
- :v_flag fails on ZFS because the mode for foo is [always] updated
  unnecessarily.

get_filesystem(..) (supporting function that was added to the test script)
is based on equivalent logic in usr.bin/extattr/tests/extattr_test.sh .

MFC after:	1 week
PR:	221189 [1], 221188 [2]
2017-08-02 21:18:54 +00:00
Enji Cooper d511b20a69 Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.
2017-08-02 08:50:42 +00:00
Enji Cooper 46b37aa2c4 MFhead@r321912 2017-08-02 08:38:36 +00:00
Enji Cooper 4b330699f8 Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
Enji Cooper 8c09935728 Add HAS_TESTS to all Makefiles that use the SUBDIR.${MK_TESTS}+= tests idiom 2017-08-02 08:14:06 +00:00
Edward Tomasz Napierala 4162d13907 Use the "tree" word in ps(1) -d option description, to make it easier
to find.

MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-07-22 10:38:44 +00:00
Ed Maste 819129649d date: avoid crash on invalid time
localtime(3) returns NULL when passed an invalid time_t but date(1)
previously did not handle it. Exit with an error in that case.

PR:		220828
Reported by:	Vinícius Zavam
Reviewed by:	cem, kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D11660
2017-07-20 15:28:48 +00:00
Jilles Tjoelker 93c3eab50c sh: Remove broken #ifdef NOHACK code (related to sh -c).
Apart from the fact that subtle syntactic changes make a poor compile-time
option, the NOHACK case has been obviously broken since it was added,
because it uses q uninitialized if (*p != '\0').

No functional change is intended.
2017-07-18 19:00:15 +00:00
Enji Cooper 8aea3ca0a7 Remove unnecessary make logic added in r319339
This makes the change cleaner and easier to backport to ^/stable/10.

MFC after:	now
2017-07-18 17:29:12 +00:00
Enji Cooper 01df7d10a5 Remove SUBDIR ordering/uniquifying in *bin/Makefile
After the addition of SUBDIR.yes, uniquifying/ordering the SUBDIRs doesn't
make a whole lot of sense, and it's in effect a half measure.

Ordering SUBDIR (after adding SUBDIR.yes to it) in bsd.subdir.mk is a
separate change that warrants more discussion/testing, because while
the SUBDIR_PARALLEL work largely fixed dependency ordering for SUBDIRs,
there might be downstream FreeBSD consumers that rely on the SUBDIR
ordering.

MFC after:	2 months
Reviewed by:	bdrewery
Differential Revision:	D11398
2017-07-06 04:15:30 +00:00
Allan Jude 1f3f7ac7ba Add deprecation notices for all rcmd tools
Submitted by:	bcr
Reviewed by:	emaste, bapt, jhl
MFC after:	immediate
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D11471
2017-07-04 15:44:30 +00:00
Pedro F. Giffuni be9e8bfaea ed(1): Allow the omission of one address in (.,.) and (.;.) address ranges
With this patch, ",n" is an abbreviation for "1,n", ";n" abbreviates
".;n". The "n," and "n;" variants mean "n,n" and "n;n", respectively.
Also, piping to a shell command does not count as a save, so don't reset
the modified flag.

Obtained from:	OpenBSD (CVS Rev. 1.58, 1.59)
2017-07-03 15:54:44 +00:00
Jilles Tjoelker 6f49cd266b sh: Ignore error when cd writes the directory actually switched to.
If CDPATH is used non-trivially or the operand is "-", cd writes the
directory actually switched to. (We currently do this only in interactive
shells, but POSIX requires this in non-interactive shells as well.)

As mentioned in Austin group bug #1045, cd shall not return an error while
leaving the current directory changed. Therefore, ignore any write error.
2017-06-25 21:53:08 +00:00
Alan Somers f01753c151 style fixes in bin/echo/tests
Submitted by:	shivansh
Reviewed by:	asomers
MFC after:	2 weeks
X-MFC-With:	319626
Sponsored by:	Google, Inc (GSoC 2017)
Differential Revision:	https://reviews.freebsd.org/D11318
2017-06-23 15:02:49 +00:00
Enji Cooper 00bc472686 Don't expect :sF_flag to fail anymore
While here, also add a check to verify that the link target
is updated in the testcase

MFC after:	1 month
MFC with:	r320172
PR:		219943
Differential Revision:	D11167
Submitted by:	shivansh
Sponsored by:	Google (GSoC 2017)
2017-06-20 20:50:54 +00:00
Enji Cooper 63bd650f4b ln(1): fix -F behavior
When '-F' option is used, the target directory needs to be unlinked.
Currently, the modified target ("target/source") is being unlinked, and
since it doesn't yet exist, the original target isn't removed.
This is fixed by skipping the block where target is modified to
"target/source" when '-F' option is set.
Hence, a symbolic link (with the same name as of the original target) to
the source_file is produced.

Update the test for ln(1) to reflect fix for option '-F'

MFC after:	1 month
PR:		219943
Differential Revision:	D11167
Submitted by:	shivansh
Sponsored by:	Google (GSoC 2017)
2017-06-20 20:46:08 +00:00
Phil Shafer dfde8e4b54 Use {T:Capacity} for header so html output looks tidy
Submitted by:	phil
Approved by:	sjg
2017-06-13 05:38:40 +00:00
Enji Cooper 0773ff183a Style fixes: clean up leading whitespace (8 single column spaces -> \t)
MFC after:	1 month
MFC with:	r319714, r319854, r319855, r319856
2017-06-12 16:53:42 +00:00
Enji Cooper b01fe519c3 ln(1): wordsmith -F option description
MFC after:	1 month
2017-06-12 16:43:29 +00:00
Enji Cooper ed66391a6e Add a testcase for ln -sF
The testcase fails today, so mark it with atf_expect_fail: in
particular, the target (B) isn't being unlinked and the documentation
doesn't suggest special handling for directories. Thus, there's either
a doc or an implementation bug in ln(1) that needs to be resolved.

MFC after:	1 month
MFC with:	r319714, r319854, r319855
PR:		219943
Reviewed by:	ngie
Submitted by:	shivansh
Differential Revision:	D11159 (part of a larger diff)
Sponsored by:	Google, Inc (GSoC 2017)
2017-06-12 16:38:37 +00:00
Enji Cooper 07b984360c Use readlink(1)/stat(1) to query symlinks instead of file(1)
file(1) can be compiled out of the system via MK_FILE == no, and the
output isn't guaranteed to be stable. It's better to use stat(1)/readlink(1)
instead to query symlink/file paths.

MFC after:	1 month
MFC with:	r319714, r319854
Reported by:	ngie
Submitted by:	shivansh
Differential Revision:	D11159 (part of a larger diff)
Sponsored by:	Google, Inc (GSoC 2017)
2017-06-12 16:31:32 +00:00
Alan Somers e61b0afc1c bin/ln: Set umask appropriately before creating files for testing
These changes were missed in D11084

Submitted by:	shivansh
Reviewed by:	asomers
MFC after:	1 month
X-MFC-With:	319714
Sponsored by:	Google, Inc (GSoC 2017)
Differential Revision:	https://reviews.freebsd.org/D11158
2017-06-12 14:54:59 +00:00
Jilles Tjoelker 55c2cd6f48 sh: Enable interrupts before executing EXIT trap and doing final flush. 2017-06-11 16:54:04 +00:00
Alan Somers 670f178299 Add tests for ln(1)
* Verify that when creating a hard link to a symbolic link, '-L' option
  creates a hard link to the target of the symbolic link
* Verify that when creating a hard link to a symbolic link, '-P' option
  creates a hard link to the symbolic link itself
* Verify that if the target file already exists, '-f' option unlinks it so
  that link may occur
* Verify that if the target file or directory is a symbolic link, '-shf'
  option prevents following the link
* Verify that if the target file or directory is a symbolic link, '-snf'
  option prevents following the link
* Verify that '-s' option creates a symbolic link
* Verify that '-w' option produces a warning if the source of a symbolic
  link does not currently exist

Submitted by:	shivansh
Reviewed by:	asomers, ngie
MFC after:	1 month
Sponsored by:	Google, Inc (GSoC 2017)
Differential Revision:	https://reviews.freebsd.org/D11084
2017-06-08 19:09:55 +00:00
Enji Cooper 245e210cc6 Add some basic tests for chmod(1)
MFC after:	1 month
Sponsored by:	Dell EMC Isilon
2017-06-07 05:33:56 +00:00
Enji Cooper 7c91b65f54 Add testcases for cat -b
MFC after:	1 month
Sponsored by:	Dell EMC Isilon
2017-06-06 21:50:00 +00:00
Jilles Tjoelker 79fb1e455e sh: Call fc -e editor with interrupts enabled.
Starting the fc -e editor can execute arbitrary script, and executing
arbitrary script with INTOFF in effect may cause unexpected results.

This change (together with other changes) serves mainly to allow asserting
that INTOFF is not in effect when starting the evaluation of a node.
2017-06-06 21:08:05 +00:00
Enji Cooper 9086e0e068 Add additional testcases for cat(1)
Verify the following additional cases:
- -s (in isolation, in addition to the -se testcase obtained via the
      NetBSD test).
- -vt

Submitted by:	shivansh
Reviewed by:	asomers (earlier diff), ngie
MFC after:	1 month
Sponsored by:	Google, Inc (GSoC 2017)
Differential Revision:	D11020
2017-06-06 21:03:43 +00:00
Enji Cooper 2d15c3cb12 Add basic tests for echo(1)
Verify that echo(1) does not...
- ... print the trailing newline character with option '-n'.
- ... print the trailing newline character when '\c' is appended to
      the end of the string.

Submitted by:	shivansh
Reviewed by:	asomers, ngie
MFC after:	1 month
Sponsored by:	Google, Inc (GSoC 2017)
Differential Revision:	D11036
2017-06-06 16:04:27 +00:00
Bryan Drewery 231ad771d9 Clarify -q is only for pgrep.
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-06-05 16:00:10 +00:00
Jilles Tjoelker 8d4cde8e6d sh: Make sure to process SIGINT if SETINTON re-enables processing.
If INTON re-enables interrupts, it processes any interrupt that occurred
while interrupts were disabled. Make SETINTON do the same.
2017-06-04 21:58:02 +00:00
Bryan Drewery 3ecb77f014 Allow defining nofork builtins from builtins.def and move always-safe ones there.
The generated code remains the same.

Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D11042
2017-06-04 21:02:48 +00:00
Jilles Tjoelker eab4998278 sh: Fix INTOFF leak when a redirection on a compound command fails.
Reported by:	bdrewery
2017-06-04 20:52:55 +00:00
Alan Somers 07c19c27d3 Fix bin/dd/dd2_tests:seek_overflow on UFS and TMPFS
Split the postive and negative parts into separate test cases.  The positive
test case can only run on ZFS, because only ZFS supports files that large.

PR:		219757
Reported by:	ngie
MFC after:	18 days
X-MFC-with:	319339
2017-06-03 18:29:18 +00:00
Enji Cooper 141173eb9f Mark :seek_overflow as an expected failure
MFC after:	18 days
MFC with:	r319339
PR:		219757
Sponsored by:	Dell EMC Isilon
2017-06-03 17:59:10 +00:00
Enji Cooper 5f0aff893e Stylistic tweaks
Move opening braces of functions from the last column to column 0.

MFC after:	18 days
MFC with:	r319339
Sponsored by:	Dell EMC Isilon
2017-06-03 17:56:31 +00:00
Alan Somers af2b6af393 Fix integer overflow detection in dd
dd(1) tried to detect whether the seek offset would overflow, but it failed
to account for the case where the provided argument was negative and the
file was a regular file (negative seeks are allowed for character devices).
I fixed it, and added a regression test.

Reported by:	Coverity
CID:		1368659
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-05-31 16:07:32 +00:00
Jilles Tjoelker 29717eb029 sh: Keep output buffer across builtins.
Allocating and deallocating repeatedly the 1024-byte buffer for stdout from
builtins costs CPU time for little or no benefit.

A simple loop containing builtins that write to a file descriptor, such as
  i=0; while [ "$i" -lt 1000000 ]; do printf .; i=$((i+1)); done >/dev/null
is over 10% faster in a simple benchmark on an amd64 virtual machine.
2017-05-18 22:10:04 +00:00
Jilles Tjoelker de29cd0869 sh: Ensure memout.bufsize matches allocated buffer, if it exists. 2017-05-18 21:44:14 +00:00
Jilles Tjoelker 5183ddf2ed sh: Simplify output buffering.
Similarly to how STPUTC was changed, change struct output to store the
pointer just past the end of the available space instead of the size of the
available space, so after writing a character it is only necessary to
increment a pointer and not to decrement a counter.
2017-05-16 21:54:51 +00:00
Jilles Tjoelker 1b21b7fa89 sh: Fix '-' from quoted arithmetic in case/glob pattern range.
It does not make much sense to generate the '-' in a pattern bracket
expression using arithmetic expansion, but it does not make sense to forbid
it either.

Try to avoid reprocessing the string if it is unnecessary.
2017-05-14 13:14:19 +00:00
Jilles Tjoelker 73a73f7bd2 sh: Add test for arithmetic expansion in [x-y] pattern range.
It does not make much sense to generate the '-' in a pattern bracket
expression using arithmetic expansion, but it does not make sense to forbid
it either.

This test already passes.
2017-05-13 20:28:32 +00:00
Bryan Drewery 07676084ec DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-05-09 01:48:23 +00:00
Jilles Tjoelker 3f2da875f7 sh: Fix INTOFF leak after a builtin with different locale settings.
After executing a builtin with different locale settings such as
  LC_ALL=C true
SIGINT handling was left disabled indefinitely.

MFC after:	1 week
2017-05-07 19:49:46 +00:00
Edward Tomasz Napierala 452bdaabb5 .Xr resizewin from stty(1) man page.
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2017-05-07 11:44:25 +00:00
Jilles Tjoelker b98072777f sh: Update TOUR and comments for some code changes, some of them old.
Also, improve some terminology in TOUR and comments.
2017-05-06 13:28:42 +00:00
Jilles Tjoelker d4993b6db2 sh: Simplify handling of newlines in command substitution.
Unless we need to split on newlines, just append them as normal and remove
them at the end.
2017-04-28 16:16:22 +00:00
Jilles Tjoelker 24b55fb76d sh: Add some tests for command substitution final newline stripping. 2017-04-27 18:52:18 +00:00
Jilles Tjoelker 53f6052862 sh: Add tests for NUL byte in command substitution output. 2017-04-23 21:58:17 +00:00
Jilles Tjoelker 3be4e97d2b sh: Simplify setinteractive().
setsignal() does nothing if the signal disposition is already set correctly.
2017-04-22 21:31:37 +00:00
Jilles Tjoelker 026dfd4aef sh: Fix use after free when resetting an in-use alias.
The special case of modifying an existing alias does not work correctly if
the alias is currently in use. Instead, handle this case by unaliasing the
old alias (if any) and then creating a new alias.
2017-04-16 22:10:02 +00:00
Jilles Tjoelker 683bf56cf6 sh: Link the new test to the build. 2017-04-16 21:57:25 +00:00
Jilles Tjoelker 773e27aeee sh: Fix unalias -a while an alias is currently in use.
It is a rare situation to modify aliases while an alias is currently in use,
but this is handled for plain unalias. Handle it for unalias -a as well.
2017-04-16 21:42:43 +00:00
Jilles Tjoelker a9250603fd sh: Reduce size of limits table. 2017-04-12 21:15:55 +00:00
Jilles Tjoelker 5850a75952 sh: Add test for unaliasing an alias that is currently in use.
This already works correctly.
2017-04-08 21:57:59 +00:00
Eric van Gyzen aeaef479fa Fix indentation in dd(1)
Quoting http://mdocml.bsd.lv/mdoc/details/width.html

Do not use macros in the argument specifying the width,
since that's not portable.  While GNU troff can handle it,
mandoc cannot.

MFC after:	3 days
Sponsored by:	Dell EMC
2017-04-02 21:30:05 +00:00
Jilles Tjoelker 05e626c3cf sh: Remove an XXX comment: it is normal for builtins to use argptr. 2017-04-02 15:53:11 +00:00
Jilles Tjoelker c39d3320ab sh: Remove global state from collate_range_cmp().
The global state is not used across invocations of collate_range_cmp().
2017-04-02 14:02:10 +00:00
Jilles Tjoelker e59833ccfe sh: Don't scan word twice in ${param=word}. 2017-04-02 13:43:45 +00:00
Jilles Tjoelker e2708b1624 sh: Don't scan word twice in ${param#%##%%word}.
If word is expanded, use the found end instead of iterating over the data
again.
2017-04-02 13:29:27 +00:00
Jilles Tjoelker 9e1bb30e23 sh: Don't scan word twice in ${param+-word}.
There is no longer a case where argbackq has already been advanced but the
string pointer needs to be advanced.
2017-04-02 12:37:43 +00:00
Dmitry Chagin 19d2e3de75 Update to tcsh 6.20.00 2017-03-25 13:32:28 +00:00
Jilles Tjoelker a54caffda0 sh: Fix build with -DDEBUG=2.
With the new expansion code (word splitting during instead of after other
expansion processing), tracing the result of command substitution is no
longer possible, so stop trying.
2017-03-19 21:18:53 +00:00
Jilles Tjoelker 0620d81993 sh: Remove unused function declaration for arith_lex_reset().
Reported by:	Robert Elz
2017-03-18 20:41:07 +00:00
Jilles Tjoelker 56bf1d616f sh: Remove unused return value of subevalvar_misc(). 2017-03-18 16:09:30 +00:00
Jilles Tjoelker 439948cdf6 sh: Get rid of global variable argbackq. 2017-03-16 21:53:55 +00:00
Jilles Tjoelker 8999a290ab sh: Fix executing wrong command with ${unsetvar#$(cmdsubst)}$(cmdsubst).
The parsed internal representation of words consists of a byte string with a
list of nodes (commands in command substitution). Each unescaped CTLBACKQ or
CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list.

If param in ${param#%##%%word} is not set, the word is not expanded (in a
deviation of POSIX shared with other ash variants and ksh93). Erroneously,
the pointer in the list of commands (argbackq) was not advanced. This caused
the wrong command to be executed later if the outer word contained another
command substitution.

Example:
  echo "${unsetvar#$(echo a)}$(echo b)"
wrote "a" but should write "b".

MFC after:	1 week
2017-03-10 16:04:00 +00:00
Bryan Drewery d11bfd6fb8 Rename some tests to end in _test.
Requested by:	ngie
MFC after:	2 weeks
X-MFC-With:	r314886
2017-03-09 04:20:00 +00:00
Bryan Drewery 0be7e2c09c Remove unneeded -x from tests.
Reported by:	ngie
MFC after:	2 weeks
X-MFC-With:	r314886
2017-03-09 04:19:52 +00:00
Bryan Drewery b06b52baac pwait: Add a -t flag to specify a timeout before exiting, and tests.
The exit status will be 124, as the timeout(1) utility uses.

Reviewed by:	jilles
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D9697
2017-03-07 22:16:55 +00:00
Rodney W. Grimes ce9f2d31b3 Convert absolute links to relative links.
Style.Makefile(9) has been ignored to produce minimal diffs.

Approved by:	grehan (mentor)
MFC after:	1 week
2017-03-07 05:10:38 +00:00
Conrad Meyer ef1d40da16 ps(1): Fix -w + UNLIMITED handling
A follow-up fix for r314685.

Because the -w flag is parsed after ps(1) infers termwidth from COLUMNS and
stdout, and UNLIMITED happens to be the zero value, the single -w flag in
combination with a non-terminal stdout or COLUMNS=0 could result in output
truncated at 131 characters.  (Despite the output being unlimited without
-w.)

Obviously, adding more -w shouldn't truncate output lines.

The committed patch is from bdrewery@, and I've reviewed and tested it.

Submitted by:	bdrewery@
Reported by:	bdrewery@
Sponsored by:	Dell EMC Isilon
2017-03-07 04:51:35 +00:00
Bryan Drewery 27ca6260e0 Don't kill pid -1 on overflow from strtol(3).
Store the result in a proper long and then compare to the proper pid_t
for overflow, so that no MD assumptions are made.

Reviewed by:	jilles
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D9887
2017-03-05 21:56:04 +00:00
Jilles Tjoelker 586fd24857 sh: Fix crash if a -T trap is taken during command substitution.
Code like  t=$(stat -f %m "$file")  segfaulted if -T was active and a trap
was taken while the shell was waiting for the child process to finish.

What happened was that the dotrap() call in waitforjob() was hit. This
re-entered command execution (including expand.c) at a point not expected by
expbackq(), and global state (unallocated stack string and argbackq) was
corrupted.

To fix this, change expbackq() to prepare for command execution to be
re-entered.

Reported by:	bdrewery
MFC after:	1 week
2017-03-04 22:58:34 +00:00
Conrad Meyer 9c4241c3d7 ps(1): Only detect terminal width if stdout is a tty
If stdout isn't a tty, use unlimited width output rather than truncating to
79 characters.  This is helpful for shell scripts or e.g., 'ps | grep foo'.

This hardcoded width has some history: In The Beginning of History[0], the
width of ps was hardcoded as 80 bytes.  In 1985, Bloom@ added detection
using TIOCGWINSZ on stdin.[1]  In 1986, Kirk merged a change to check
stdout's window size instead.  In 1990, the fallback checks to stderr and
stdin's TIOCGWINSZ were added by Marc@, with the commit message "new
version."[2]

OS X Darwin has a very similar modification to ps(1), which simply sets
UNLIMITED for all non-tty outputs.[3]  I've chosen to respect COLUMNS
instead of behaving identically to Darwin here, but I don't feel strongly
about that.  We could match OS X for parity if that is desired.

[0]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?annotate=1065
[1]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=18105&r2=18106
[2]:
https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=40675&r2=40674&pathrev=40675
[3]:
https://opensource.apple.com/source/adv_cmds/adv_cmds-168/ps/ps.c.auto.html

PR:		217159
Reported by:	Deepak Nagaraj <n.deepak at gmail.com>
2017-03-04 22:38:10 +00:00
Enji Cooper caf42d8126 bin: normalize paths using SRCTOP-relative paths or :H when possible
This simplifies make logic/output

MFC after:	1 month
Sponsored by:	Dell EMC Isilon
2017-03-04 11:31:08 +00:00
Jilles Tjoelker 549bbb4fa1 sh: Add some already working tests that exercise new code paths. 2017-03-03 22:46:20 +00:00
Warner Losh fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Konstantin Belousov cdf44896bb Use uintmax_t to print st_nlink.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2017-02-16 06:32:39 +00:00
Baptiste Daroussin 33bf6c45fb Remove empty Li
Reported by:	make manlint
MFC after:	2 days
2017-02-11 23:09:50 +00:00
Baptiste Daroussin ce08d4900c Remove space at and of line
Reported by:	make manlint
MFC after:	2 days
2017-02-11 23:06:53 +00:00
Allan Jude 39f8282b48 Remove bdes(1)
The use of DES for anything is discouraged, especially with a static IV of 0

If you still need bdes(1) to decrypt Kirk's video lectures, see
security/bdes in ports.

This commit brought to you by the FOSDEM DevSummit and the
"remove unneeded dependancies on openssl in base" working group

Reviewed by:	bapt, brnrd
Relnotes:	yes
Sponsored by:	FOSDEM DevSummit
Differential Revision:	https://reviews.freebsd.org/D9424
2017-02-06 08:27:19 +00:00
Baptiste Daroussin b4b4b5304b Revert crap accidentally committed 2017-01-28 16:31:23 +00:00
Baptiste Daroussin 814aaaa7da Revert r312923 a better approach will be taken later 2017-01-28 16:30:14 +00:00
Conrad Meyer a758566cb8 chmod: Add SIGINFO handler
PR:		191884
Submitted by:	Dan McGregor <dan.mcgregor at usask.ca>
Reviewed by:	mjg@ (earlier version)
2017-01-08 06:50:53 +00:00
Konstantin Belousov 1c32456953 Use type-independent formats for printing nlink_t and ino_t.
Extracted from:	ino64 work by gleb, mckusick
Discussed with:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2017-01-06 16:59:33 +00:00
Pedro F. Giffuni 8ad81aaea6 pax(1): Fix a bug with archives smaller than 512 bytes.
The problem here is that the archive is too short (< 512 bytes). The
buffer routines, try to read at least 512 bytes, even when we try to
determine what format file we have, which is wrong.

Obtained from:	NetBSD (CVS rev 1.26)
MFC after:	5 days
2016-12-21 15:26:59 +00:00
Alan Somers f698b621da Fix ls_tests:o_flag with ZFS TMPDIR
Unlike UFS or TMPFS, ZFS sets uarch automatically whenever a file is
updated. The test must explicitly clear uarch to be portable across
filesystems. Also, it doesn't need to run as root.

PR:		215179
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D8741
2016-12-15 16:13:52 +00:00
Brooks Davis facc3cb0ff Use nmount(2) rather than the obsolete mount(2).
Reviewed by:	cem
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8513
2016-12-14 21:30:44 +00:00
Pedro F. Giffuni f50fae318d ed(1): drop redundant parenthesis.
These were Left-over from the cleanup in r309936.
2016-12-14 21:14:43 +00:00
Brooks Davis 9dad1250d7 Mount filesystems without executable permissions since they should never
be used.

Reviewed by:	cem
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8513
2016-12-14 21:13:10 +00:00
Brooks Davis 176d3efd2b Put the undocumented df feature of mounting filesystems from device nodes
under an ifdef.  Leave enabled.

Reviewed by:	cem
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D8513
2016-12-14 21:11:42 +00:00
Pedro F. Giffuni 8bd856de21 ed(1): Simplify some checks.
The return type for both fread(3) and fwrite(3) cannot be negative, this
renders some checks invalid and variable 'ct' unnecessary.
Also bump 'len' to size_t to avoid signed/unsigned comparison warnings.
2016-12-12 20:25:59 +00:00
Bartek Rutkowski 94161f30b7 Fix regression when stdin/out/err fds are are overridden by shell.
Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reported by:	ngie
Approved by:	ngie
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	https://reviews.freebsd.org/D8543
2016-12-12 18:56:40 +00:00
Pedro F. Giffuni 27150ef8bc ed(1): Prevent possible overflows during allocation.
Make sure the parameters used for malloc(3) can hold size_t sizes.
This should help ed(1) handle bigger data in the future.

MFC after:	2 weeks
2016-12-12 03:46:40 +00:00
Bartek Rutkowski 2a65657fc8 Capsicum support for dd(1)
Adds Capsicum sandboxing to dd utility.

Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reviewed by:	allanjude, emaste, oshogbo
Approved by:	oshogbo
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	https://reviews.freebsd.org/D8543
2016-12-09 14:51:05 +00:00
Eric van Gyzen 3d32d4a7c9 Export the whole thread name in kinfo_proc
kinfo_proc::ki_tdname is three characters shorter than
thread::td_name.  Add a ki_moretdname field for these three
extra characters.  Add the new field to kinfo_proc32, as well.
Update all in-tree consumers to read the new field and assemble
the full name, except for lldb's HostThreadFreeBSD.cpp, which
I will handle separately.  Bump __FreeBSD_version.

Reviewed by:	kib
MFC after:	1 week
Relnotes:	yes
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D8722
2016-12-07 15:04:22 +00:00
Xin LI 4dceaf94fa style(9).
MFC after:	2 weeks
2016-11-28 07:21:09 +00:00
Xin LI 305de00ec4 Plug a potential memory leak.
MFC after:	2 weeks
2016-11-28 07:19:45 +00:00
Adrian Chadd 29aee14890 [dd] Revert the capsicum bits for now until it gets fixed.
dd is a bootstrap tool and that header isn't installed as part of the
bootstrap environment for previous releases (eg freebsd-10.)

We'll figure it out in post and then re-commit it.
2016-11-19 18:19:21 +00:00
Ruslan Bukin 6193edf4c5 Restore dd changes included accidentally in r308857. 2016-11-19 17:51:02 +00:00
Ruslan Bukin 9a8f61fb5b Bring in support for Ingenic XBurst JZ4780 and
X1000 systems on chips.

Imgtec CI20 and Ingenic CANNA boards supported.

Submitted by:	Alexander Kabaev <kan@FreeBSD.org>
Reviewed by:	Ruslan Bukin <br@FreeBSD.org>
Sponsored by:	DARPA, AFRL
2016-11-19 17:46:18 +00:00
Bartek Rutkowski 947b83c090 Capsicum support for dd(1)
Adds Capsicum sandboxing to dd utility.

Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reviewed by:	allanjude, emaste, oshogbo
Approved by:	oshogbo
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	https://reviews.freebsd.org/D8543
2016-11-18 21:09:57 +00:00
Bryan Drewery 490a8aa9a1 DIRDEPS_BUILD: Update dependencies.
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
2016-11-13 00:11:30 +00:00
Marcelo Araujo e7d88f5e13 Fix missing '-' for the flags -s and -d on both manpage and usage.
Reported by:	garga, bde
2016-11-09 04:42:09 +00:00
Marcelo Araujo 31500ce90d Add -d flag that prints domain only.
PR:		212875
Submitted by:	Ben RUBSON <ben.rubson@gmail.com>
Reviewed by:	pi
2016-11-08 11:36:33 +00:00
Conrad Meyer cd1693d3f9 Capsicumize some trivial stdio programs
Trivially capsicumize some simple programs that just interact with
stdio.  This list of programs uses 'pledge("stdio")' in OpenBSD.

No objection from:	allanjude, emaste, oshogbo
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8307
2016-11-08 05:31:01 +00:00
Dag-Erling Smørgrav e98bb55f0b Use what(1) instead of strings(1). It's simpler and always available.
PR:		213665
Submitted by:	Pawel Worach <pawel.worach@gmail.com>
MFC after:	1 week
2016-11-04 17:02:42 +00:00
Jilles Tjoelker 3c47cee5c8 sh: Add simple test for 'set -C' (noclobber).
To ensure fast test runs, race conditions are not tested.
2016-11-02 22:33:37 +00:00
Ruslan Bukin 51acc171d1 Increase timeouts so tests have more chances to succeed
on MIPS64EB in QEMU.

Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
2016-10-19 12:23:02 +00:00
Ruslan Bukin 6bfde4a6fb Increase timeout so low-end platforms have a chance to complete test
procedures.

This fixes operation in QEMU/MIPS64.

Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
2016-10-17 10:21:53 +00:00
Jilles Tjoelker 7cca93e61a sh: Do not import IFS's value from the environment.
Per Austin group issue #884, always set IFS to $' \t\n'. As before, IFS will
be exported iff it was in the environment.

Most shells (e.g. bash, ksh93 and mksh) already did this. This change
improves predictability, in that scripts can simply rely on the default
value.

However, the effect on security is little, since applications should not be
calling the shell with attacker-controlled environment variable names in the
first place and other security-sensitive variables such as PATH should be
and are imported by the shell.

When using a new sh with an old (before 10.2) libc wordexp(), IFS is no
longer passed on. Otherwise, wordexp() continues to pass along IFS from the
environment per its documentation.

Discussed with:	pfg
Relnotes:	yes
2016-10-08 13:40:12 +00:00
Sevan Janiyan 2bb154d973 Add history section for test(1)
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/test.c

PR:		211789
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:47:02 +00:00
Sevan Janiyan 3578fc3e0c Add history section for stty(1)
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man1/stty.1

PR:		211788
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:37:46 +00:00
Sevan Janiyan 25907b311b Add history section of pwd(1)
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s2/pwd.c

PR:		211787
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:31:29 +00:00
Sevan Janiyan c5ca929f63 Document origins of expr & authors
http://minnie.tuhs.org/cgi-bin/utree.pl?file=PWB1/usr/man/man1/expr.1

PR:		173979
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:26:35 +00:00
Sevan Janiyan 1e73a8c171 Add history section for echo(1)
Sourced using the draft copy of the second edition manual
http://www.tuhs.org/Archive/PDP-11/Distributions/research/1972_stuff/unix_2nd_edition_manual.pdf

PR:		211785
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:16:55 +00:00
Sevan Janiyan 2a19a3f546 Add history section for dd(1)
First version of UNIX to include dd found using TUHS
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s1/dd.c

PR:		211777
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 18:38:38 +00:00
Sevan Janiyan 58475c0d39 Document where chio(1) originated from & which version of FreeBSD first included it.
PR:		211776
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 18:26:39 +00:00
Sevan Janiyan 5c10b0713b In v3 UNIX, the kill utility is documented in category 8, not 1.
Add a note of it.
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man8/kill.8

PR:		211786
Approved by:	bcr (mentor)
Obtained from:	TUHS
Differential Revision:	https://reviews.freebsd.org/D8105
2016-10-02 23:13:46 +00:00
Sevan Janiyan cc7a063923 Move the description of CHANGER variable to ENVIRONMENT section rather than in the DESCRIPTION section.
From OpenBSD src/bin/chio/chio.1 r1.23

PR:		212158
Approved by:	bjk
Obtained from:	OpenBSD
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8117
2016-10-02 14:42:46 +00:00
Sevan Janiyan 66d39fc6c7 "POSIX doesn't specify -h." - r1.27 from NetBSD
http://man.openbsd.org/?query=chmod&apropos=0&sec=0&arch=default&manpath=POSIX-2013

PR:		212337
Approved by:	bcr (mentor)
Obtained from:	NetBSD
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8118
2016-10-02 14:27:18 +00:00
Sevan Janiyan bc799c51a3 Use .At macro instead of specifying AT&T UNIX literaly.
PR:		212034
Approved by:	bcr (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D8114
2016-10-02 14:22:09 +00:00
Andrey A. Chernov 2aa6b16f74 Implement multibyte encoding support for -v with fallback
MFC after:      7 days
2016-09-15 17:24:39 +00:00
Enji Cooper 637cce3a32 MFhead @ r305314 2016-09-03 00:50:18 +00:00
Jilles Tjoelker 681e94f4d0 sh: Add some tests for non-standard features of the echo builtin.
MFC after:	1 week
2016-09-02 21:13:46 +00:00
Enji Cooper f8fd1a95d9 MFhead @ r305170 2016-09-01 02:57:15 +00:00
Conrad Meyer 246ef54f15 df(1): Allow duplicate -l flags gracefully
Rather than producing a misleading error message when duplicate -l flags are
provided to df(1), simply ignore extra flags and proceed as if only one was
specified.  This seems most reasonable given the usage for -l:

     -l      Only display information about locally-mounted file systems.

l and t flags still conflict, as before.

PR:		208169
Reported by:	by at reorigin.com
Reviewed by:	allanjude
2016-08-31 18:10:41 +00:00
Enji Cooper ed04e0c3dc MFhead @ r304815 2016-08-25 20:02:51 +00:00
Alex Kozlov c650c2f355 Remove last remnants of acd(4), mcd(4), and scd(4) drivers.
Approved by:	jhb
2016-08-25 19:36:58 +00:00
Julio Merino 647672e21f Skip ls tests that use sparse files if these are not supported.
Some of the ls(1) tests create really large sparse files to validate
the number formatting features of ls(1).  Unfortunately, those tests fail
if the underlying test file system does not support sparse files, as is the
case when /tmp is mounted on tmpfs.

Before running these tests, check if the test file system supports sparse
files by using getconf(1) and skip them if not.  Note that the support for
this query was just added to getconf(1) in r304694.

Reviewed by:	ngie
Differential Revision:	https://reviews.freebsd.org/D7609
2016-08-24 10:10:26 +00:00
Enji Cooper 569e901835 MFhead @ r304038 2016-08-13 06:16:38 +00:00
Enji Cooper fbc71595f0 Hack around output differences between FreeBSD and other BSDs
with cat(1)

cat -be on FreeBSD doesn't align the $ with the start of the line
like NetBSD, et al's cat -be does

PR:		210607
Sponsored by:	EMC / Isilon Storage Division
2016-08-13 02:53:02 +00:00
John Baldwin 563e703714 Remove description of P_FOLLOWFORK as this flag was removed. 2016-08-12 16:13:50 +00:00
Warren Block 15919690b5 Correct the history of where ps first appeared.
PR:		211741
Submitted by:	Sevan Janiyan <venture37@geeklan.co.uk>
MFC after:	1 week
2016-08-12 14:10:11 +00:00
Enji Cooper 640235e2c2 Checkpoint initial integration work
- Some of the lib/libc and lib/thr tests fail
- lib/msun/exp_test:exp2_values now passes with clang 3.8.0

The Makefiles in contrib/netbsd-tests were pruned as they have no value

Sponsored by: EMC / Isilon Storage Division
2016-08-12 08:50:05 +00:00
Enji Cooper 014db25b98 Update ^/vendor/NetBSD/tests/dist to a more recent snapshot
Pulled on "Thu Aug 11 18:01:19 PDT 2016"
2016-08-12 01:05:07 +00:00
Mariusz Zaborski e628189fd8 uuid_to_string(3) is allocating memory and can fail on that.
Check if any error accrued.
2016-08-03 18:04:08 +00:00
Jilles Tjoelker 3bb6ada261 sh: Fix a clang warning.
Submitted by:	bdrewery
2016-07-31 13:11:34 +00:00
Konstantin Belousov b7a25e63b6 When a debugger attaches to the process, SIGSTOP is sent to the
target.  Due to a way issignal() selects the next signal to deliver
and report, if the simultaneous or already pending another signal
exists, that signal might be reported by the next waitpid(2) call.
This causes minor annoyance for debuggers, which must be prepared to
take any signal as the first event, then filter SIGSTOP later.

More importantly, for tools like gcore(1), which attach and then
detach without processing events, SIGSTOP might leak to be delivered
after PT_DETACH.  This results in the process being unintentionally
stopped after detach, which is fatal for automatic tools.

The solution is to force SIGSTOP to be the first signal reported after
the attach.  Attach code is modified to set P2_PTRACE_FSTP to indicate
that the attaching ritual was not yet finished, and issignal() prefers
SIGSTOP in that condition.  Also, the thread which handles
P2_PTRACE_FSTP is made to guarantee to own p_xthread during the first
waitpid(2).  All that ensures that SIGSTOP is consumed first.

Additionally, if P2_PTRACE_FSTP is still set on detach, which means
that waitpid(2) was not called at all, SIGSTOP is removed from the
queue, ensuring that the process is resumed on detach.

In issignal(), when acting on STOPing signals, remove the signal from
queue before suspending.  Otherwise parallel attach could result in
ptracestop() acting on that STOP as if it was the STOP signal from the
attach.  Then SIGSTOP from attach leaks again.

As a minor refactoring, some bits of the common attach code is moved
to new helper proc_set_traced().

Reported by:	markj
Reviewed by:	jhb, markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D7256
2016-07-28 08:41:13 +00:00
Konstantin Belousov 81fc45fc23 Addm missed required call to xo_finish() when only header is printed.
Reported by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-07-23 06:30:00 +00:00
Andrey A. Chernov 143d321a30 Path generation was not according to collate
Approved by:    jilles
2016-07-16 13:26:18 +00:00
Andrey A. Chernov fa93fc659f Back out non-collating [a-z] ranges.
Instead of changing the whole course to another POSIX-permitted way
for consistency and uniformity I decide to completely ignore missing
regex fucntionality and focus on fixing bugs in what we have now,
too many small obstacles we have choicing other way, counting ports.
Corresponding libc changes are backed out in r302824.
2016-07-14 09:34:42 +00:00
Andrey A. Chernov 3ea37deb6c After removing collation for [a-z] ranges in r302512, do it here too.
Approved by:    jilles
2016-07-13 08:13:09 +00:00
Conrad Meyer b156d221c9 dd(1): Enable access to SIZE_T_MAX character devices
On machines where SIZE_T_MAX exceeds OFF_MAX (signed 64-bit), permit seeking
character devices to negative off_t values.  This enables dd(1) to interact
with kernel KVA in /dev/kmem on amd64, for example.

Sponsored by:	EMC / Isilon Storage Division
2016-07-09 17:11:54 +00:00
Bryan Drewery 45e1479f95 WITH_META_MODE: Fix bin/csh rebuilding tc.const.h
This is the same issue as r297997, but was missed in it.

The WARNS value changes between 'build-tools' (MK_WARNS=no) and
'everything' resulting in a rebuild of this file.

Approved by:	re (implicit)
Sponsored by:	EMC / Isilon Storage Division
2016-06-14 16:19:49 +00:00
Don Lewis 4af86fb4f9 Explicitly NUL terminate the buffer filled by fread().
The fix in r300649 was not sufficient to convince Coverity that the
buffer was NUL terminated, even with the buffer pre-zeroed.  Swap
the size and nmemb arguments to fread() so that a valid lenght is
returned, which we can use to terminate the string in the buffer
at the correct location.  This should also quiet the complaint about
the return value of fread() not being checked.

Reported by:	Coverity
CID:		1019054, 1009614
MFC after:	1 week
2016-06-08 05:32:39 +00:00
Jilles Tjoelker 535c8d9372 sh: Improve descriptions in 'ulimit -a' output.
The format limits descriptions to 18 characters and is not changed, so
the descriptions do not describe the limits exactly.
2016-06-05 16:09:31 +00:00
Bryan Drewery 92edc96667 WITH_META_MODE: Don't expect meta files for side-effect generated files.
The first file in these lists will generate everything else so only
it should be getting a .meta file.  With bmake's missing=yes meta
feature these would otherwise cause a rebuild without the
.NOMETA hint.

Sponsored by:	EMC / Isilon Storage Division
2016-06-03 19:25:41 +00:00
Conrad Meyer 45ed675344 ps(1): Expand variables to match expanded fields
ki_flag and ki_tdflag have been 'long', not 'int', since 2000 and 2005,
respectively.

Submitted by:	Shawn Wills <swills at isilon dot com>
Sponsored by:	EMC / Isilon Storage Division
2016-06-01 19:54:05 +00:00
Don Lewis eaf2e1e6f7 The (i < PROMPTLEN - 1) test added by r300442 in the code for the default
case of \c in the prompt format string is a no-op.  We already passed
this test at the top of the loop, and i has not yet been incremented in
this path.  Change this test to (i < PROMPTLEN - 2).

Reported by:	Coverity
CID:		1008328
Reviewed by:	cem
MFC after:	1 week
2016-06-01 16:56:29 +00:00
Warren Block 2770ce607c Clarify the explanations for the hostname and FQDN entries.
MFC after:	1 week
2016-05-31 00:23:29 +00:00
Enji Cooper 482537c7a2 Use require.progs with bc instead of require.files with /usr/bin/bc
This will make things more flexible if the program path changes in the future,
and the test in and of itself doesn't call /usr/bin/bc -- it just calls bc

MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division
2016-05-29 04:50:49 +00:00
Don Lewis 92a58a9246 Close the input FILE * in read_file() and the output FILE * in write_file()
if read_stream() or write_stream() fails to avoid leaking the FILE.

Reported by:	Coverity
CID:		977702
Reviewed by:	pfg
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6554
2016-05-25 18:38:30 +00:00
Don Lewis b1b73fc4c9 Fix Coverity CID 1019054 (String not null terminated) in setfacl.
Increase the size of buf[] by one to allow room for a NUL character
at the end.

Reported by:	Coverity
CID:		1019054
MFC after:	1 week
2016-05-25 05:20:34 +00:00
Don Lewis 5912ca59b0 Fix CID 1011370 (Resource leak) in ps.
There is no need to to call strdup() on the value returned by fmt().
The latter calls fmt_argv() which always returns a dynamically
allocated string, and calling strdup() on that leaks the memory
allocated by fmt_argv().  Wave some const magic on ki_args and
ki_env to make the direct assignment happy.  This requires a tweak
to the asprintf() case to avoid a const vs. non-const mismatch.

Reported by:	Coverity
CID:		1011370
MFC after:	1 week
2016-05-25 05:12:56 +00:00
Don Lewis 8dd8cd00e2 Close from_fd if malloc() fails to avoid a file descriptor leak.
Reported by:	Coverity
CID:		1007203
MFC after:	1 week
2016-05-25 02:51:15 +00:00
Don Lewis ae100660d4 Match the descriptions of the \H and \h prompt string sequences to reality.
They were swapped.

X-Confirmed by:	jilles
MFC after:	1 week
2016-05-25 02:10:30 +00:00
Don Lewis 63a4675d89 Hopefully fix Coverity CID 1008328 (Out-of-bounds write) in /bin/sh.
Replace the magic constant 127 in the loop interation count with
"PROMPTLEN - 1".

gethostname() is not guaranteed to NUL terminate the destination
string if it is too short. Decrease the length passed to gethostname()
by one, and add a NUL at the end of the buffer to make sure the
following loop to find the end of the name properly terminates.

The default: case is the likely cause of Coverity CID 1008328.  If
i is 126 at the top of the loop interation where the default case
is triggered, i will be incremented to 127 by the default case,
then incremented to 128 at the top of the loop before being compared
to 127 (PROMPTLENT - 1) and terminating the loop. Then the NUL
termination code after the loop will write to ps[128].  Fix by
checking for overflow before incrementing the index and storing the
second character in the buffer.

These fixes are not guaranteed to satisfy Coverity. The code that
increments i in the 'h'/'H' and 'w'/'W' cases may be beyond its
capability to analyze, but the code appears to be safe.

Reported by:	Coverity
CID:		1008328
Reviewed by:	jilles, cem
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6482
2016-05-23 01:01:23 +00:00
Pedro F. Giffuni 0745a9c965 ed(1): simplify by using arc4random_buf().
Suggested by:	ed
2016-05-21 00:45:42 +00:00
Pedro F. Giffuni d972b6d256 ed(1): Cleanups for the DES mode.
- Use arc4random_uniform(3).
- Prevent a segmentation fault when ed receives a signal
  while being in getpass(). [1]

Obtained from:	OpenBSD [1] (CVS Rev. 1.15)
MFC after:	2 weeks
2016-05-20 19:10:29 +00:00
Baptiste Daroussin a651f2bc6c Rename getline with get_line to avoid collision with getline(3)
When getline(3) in 2009 was added a _WITH_GETLINE guard has also been added.
This rename is made in preparation for the removal of this guard

Obtained from:	NetBSD
2016-05-10 11:11:23 +00:00
Bryan Drewery 29df9f6b75 DIRDEPS_BUILD: Run the staged bootstrap-tools version of build-tools.
This avoids running target binaries.

Sponsored by:	EMC / Isilon Storage Division
2016-05-09 22:21:09 +00:00
Enji Cooper 430f7286a5 Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed
after r298107

Summary of changes:

- Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that
  namespacing is kept with FILES appropriately, and that this shouldn't need
  to be repeated if the namespace changes -- only the definition of PACKAGE
  needs to be changed
- Allow PACKAGE to be overridden by callers instead of forcing it to always be
  `tests`. In the event we get to the point where things can be split up
  enough in the base system, it would make more sense to group the tests
  with the blocks they're a part of, e.g. byacc with byacc-tests, etc
- Remove PACKAGE definitions where possible, i.e. where FILES wasn't used
  previously.
- Remove unnecessary TESTSPACKAGE definitions; this has been elided into
  bsd.tests.mk
- Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES;
  ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk.
- Fix installation of files under data/ subdirectories in lib/libc/tests/hash
  and lib/libc/tests/net/getaddrinfo
- Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup)

Document the proposed changes in share/examples/tests/tests/... via examples
so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of
replacing FILES. share/mk/bsd.README didn't seem like the appropriate method
of communicating that info.

MFC after: never probably
X-MFC with: r298107
PR: 209114
Relnotes: yes
Tested with: buildworld, installworld, checkworld; buildworld, packageworld
Sponsored by: EMC / Isilon Storage Division
2016-05-04 23:20:53 +00:00
Eric van Gyzen 8e3543eebc sh: Handle empty hostname and $PWD when building prompt
If the hostname is empty and \h is used in $PS1,
the remainder of the prompt following \h will be empty.
Likewise for $PWD and \w.  Fix it.

Reviewed by:	jilles
MFC after:	1 week
Sponsored by:	Dell Inc.
Differential Revision:	https://reviews.freebsd.org/D6188
2016-05-04 02:06:46 +00:00
Glen Barber 49dae58b28 Fix including Kyuafile in packaged base system.
Fix a related typo while here.

Note, this change results in the Kyuafile inclusion in the runtime
package, which needs to be fixed, however addresses the PR as far
as I can tell in my tests.

PR:		209114
Submitted by:	ngie
Sponsored by:	The FreeBSD Foundation
2016-04-29 05:28:40 +00:00
Pedro F. Giffuni 8123f597e9 ed(1): switch two statements so we check the index before dereferencing.
This is related to r270256 but was missed in that occasion.

MFC after:	3 days
2016-04-26 14:31:48 +00:00
Andrew Turner 6487f78716 Stop using sbrk in csh. This is a legacy interface and its use within csh
is invalid. It is used to find the size of allocated memory. As malloc may
allocate memory with mmap it will fail to take this memory into account.

Obtained from:	brooks
2016-04-26 11:39:32 +00:00
Marcelo Araujo ec23a76360 Use NULL instead of 0 for pointers.
kvm_open(3) will return NULL when it cannot access kernel virtual memory.

MFC after:	2 weeks.
2016-04-19 00:40:43 +00:00
Marcelo Araujo 172c3b0b5f Use NULL for pointers instead of 0.
MFC after:	2 weeks.
2016-04-19 00:38:07 +00:00
Jilles Tjoelker 7696368682 sh: Write LINENO value to stack string directly. 2016-04-16 12:14:44 +00:00
Glen Barber 0edd2576c0 MFH
Sponsored by:	The FreeBSD Foundation
2016-04-16 02:32:12 +00:00
Bryan Drewery d1dd034d07 META_MODE: Don't rebuild build-tools targets during normal build.
This avoids 'build command changed' due to CFLAGS/CC changes during the
normal build.  Without this the build-tools targets end up rebuilding
for the *target* rather than keeping the native versions built in
build-tools.

Sponsored by:	EMC / Isilon Storage Division
2016-04-14 21:06:10 +00:00
Jilles Tjoelker d72505899b sh: Simplify code by removing variable bracketed_name. 2016-04-13 20:32:35 +00:00
Glen Barber a123f26e92 MFH
Sponsored by:	The FreeBSD Foundation
2016-04-12 17:00:13 +00:00
Pedro F. Giffuni 3b7175bdc7 rcp(1): replace 0 with NULL for pointers.
Found with devel/coccinelle.
2016-04-11 17:24:26 +00:00
Glen Barber 876d357fa7 MFH
Sponsored by:	The FreeBSD Foundation
2016-04-11 15:24:59 +00:00