Commit Graph

3886 Commits

Author SHA1 Message Date
wiz 9a9e6da05a Add some commas. 2020-02-26 07:14:47 +00:00
gutteridge 22b0f33ce3 echo.1: add a note about other echo implementations
The other BSDs all have a note reminding that many shells have their
own internal echo implementations which may vary from this utility, so
add one. (Much of the wording is borrowed from FreeBSD's man page.)

(The other BSDs also have notes about the -n option not really being
portable, and printf[1] being preferable, we might want to add
something about that, too.)
2020-02-26 02:09:46 +00:00
pgoyette 5df404349f Typo: s/./,/ 2020-02-20 18:24:20 +00:00
kre c69ada4cb6 When expanding a here-doc (NXHERE - the type with an unquoted end delim)
the output will not be further processed (at all) so there is no need
to escape magic chars in the output, and doing so leaves stray CTLESC
chars in the here doc text.  Not good.   So don't do that...

To save a strlen() of the result, to determine the size of the here doc,
make rmescapes() return the length of the resulting string (this isn't
needed for other uses, so didn't happen previously).

Reported on current-users@ (2020-02-06) by Jun Ebihara

XXX pullup -9
2020-02-13 05:19:05 +00:00
kre 7aa4a7e25f Avoid a core dump if a child process that is not one of our
children happens to exit while we are waiting for another child
to exit.

This can happen with code like

	sh -c '
		sleep 5 &
		exec sh -c "sleep 10 & wait !$"
	      '

when the inner "sh" is waiting for the 10 second sleep to be
done, the 5 second sleep started earlier terminates.   It is
a child of our process, as the inner shell is the same process
as the outer one, but not a known child (the inner shell has no
idea what the outer one did before it started).

This was observed in the wild by Martijn Dekker (where the outer
shell was bash but that's irrelevant).

XXX pullup -9
2020-02-07 02:06:12 +00:00
fox 4de0c10694 bin/sh: Fixes -Werror=shadow causing build breaks.
Conflicting variable name, sigset_t sigs has been renamed to sigset_t mask

Reviewed by: kamil@
2020-02-07 01:25:08 +00:00
kre 8a62489758 Actually, the issue with bash (in previous) is more likely that the
SIGCHLD is blocked rather than ignored.   We want neither.   Make sure
SIGCHLD is unblocked as well as SIG_DFL.

XXX pullup -9
2020-02-06 20:08:28 +00:00
kre 0b0dde195c If we are invoked with SIGCHLD ignored, we fail badly, as we assume
that we can always wait(2) for our children, and an ignored SIGCHLD
prevents that.   Recent versions of bash can be convinced (due to a
bug most likely) to invoke us that way.   Always return SIGCHLD to
SIG_DFL during init - we already prevent scripts from fiddling it.

All ash derived shells apparently have this problem (observed by
Martijn Dekker, and notified on the bash-bug list).  Actual issue
diagnosed by Harald van Dijk (same list).
2020-02-06 19:51:59 +00:00
fox bbacb4192b bin/csh: Fix the -Wclobber warning.
Mark the variable as volatile as it can be clobbered when a vfork occurs.

Error was reported when build.sh was run with MKLIBCSANITIZER=yes flag.

Reviewed by: kamil@
2020-02-05 20:06:17 +00:00
kre 92dfd40c67 Oops, the previous didn't do what was promised. Rather that ignoring
just "--" for exec & "." it ignored any first arg starting '-'.
Do it properly.
2020-02-05 14:56:25 +00:00
kre ebc4cf1cc6 After bug report 262 (from 2010)
https://austingroupbugs.net/view.php?id=252
the Austin Group decided to require processing of "--" by the "."
and "exec" commands to solve a problem where some shells did
option processing for those commands (permitted) and others did
not (also permitted) which left no safe way to process a file
with a name beginning with "-".

This has finally made its way into what will be the next version of
the POSIX standard.

Since this shell did no option processing at all for those commands,
we need to update.   This is that update.

The sole effect is that a "--" 'option' (to "." or "exec") is ignored.
This means that if you want to use "--" as the arg to one of those
commands, it needs to be given twice ". -- --".   Apart from that there
should be no difference at all (though the "--" can now be used in other
situations, where we did not require it before, and still do not).
2020-02-04 16:06:59 +00:00
christos f550769e95 Add file completion. 2020-01-12 18:42:41 +00:00
christos 08c40aa982 remove unused 2020-01-12 18:36:55 +00:00
christos a02ac89d43 PR/54853: Greg Oster: unable to 'unset filec' or 'unset edit' in csh
While here allow set edit=vi
2020-01-12 03:50:30 +00:00
kre a6dacc2280 Use fork() rather than vfork() when forking to run a background
process with redirects.   If we use vfork() and a redirect hangs
(eg: opening a fifo) which the parent was intended to unhang,
then the parent never gets to continue to unhang the child.

eg:  mkfifo f; cat <f &; echo foo>f

The parent should not be waiting for a background process, even
just for its exec() to complete.   if there are no redirects there
is (should be) nothing left that might be done that will cause any
noticeable delay, so vfork() should be safe in all other cases.
2019-12-21 18:54:15 +00:00
kre 7af1d9b731 Correct a typo in a comment, 08x0 was meant to be 0x80 (duh!). NFC. 2019-12-10 09:18:37 +00:00
kre ff46268c6a PR bin/54743
If a builtin command or function is the final command intended to be
executed, and is interrupted by a caught signal, the trap handler for
that signal was not executed - the shell simply exited (an exit trap
handler would still have been run - if there was one the handler
for the signal may have been invoked during the execution of the
exit trap handler, which, if it happened, is incorrect sequencing).

Now, if we're exiting, and there are pending signals, run their handlers
just before running the EXIT trap handler, if any.

There are almost certainly plenty more issues with traps that need
solving.   Later,

XXX pullup -9

(-8 is too different in this area, and this problem suitably obscure,
that we won't bother)     (the -7 sh is simply obsolete).
2019-12-09 00:14:30 +00:00
kre 6fc2ffa023 PR bin/54743
Having traps set should not enforce a fork for the next command,
whatever that command happens to be, only for commands which would
normally fork if they weren't the last command expected to be
executed (ie: builtins and functions shouldn't be exexuted in a
sub-shell merely because a trap is set).

As it was (for example)
	trap 'whatever' SIGANY; wait $anypid
was guaranteed to fail the wait, as the subshell it was executed
in could not have any children.

XXX pullup -9
2019-12-09 00:14:24 +00:00
joerg 039ca0edea Avoid arithmetics on strings. 2019-10-29 16:19:59 +00:00
christos d08d589de9 remove masking and cast (requested by kre@) 2019-10-14 13:34:14 +00:00
christos 7a3a738c59 prevent sign extension from making expression always false. 2019-10-13 20:55:04 +00:00
mrg de11d87641 introduce some common variables for use in GCC warning disables:
GCC_NO_FORMAT_TRUNCATION    -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION  -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW    -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE   -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints.  many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
2019-10-13 07:28:04 +00:00
kre e291c05efd Remove a (completely harmless) duplicate assignment introduced in a
code merge from FreeBSD in 2017.   NFC.

Pointed out by Roland Illig.
2019-10-08 03:53:57 +00:00
kre 7dca2b7edd Open code the validity test & copy of the character class name in
a bracket expression in a pattern (ie: [[:THISNAME:]]).   Previously
the code used strspn() to look for invalid chars in the name, and
then memcpy(), now we do the test and copy a character at a time.
This might, or might not, be faster, but it now correctly handles
\ quoted characters in the name (' and " quoting were already
dealt with, \ was too in an earlier version, but when the \ handling
changes were made, this piece of code broke).

Not exactly a vital bug fix (who writes [[:\alpha:]] or similar?)
but it should work correctly regardless of how obscure the usage is.

Problem noted by Harald van Dijk

XXX pullup -9
2019-10-08 03:52:44 +00:00
mrg 924b11844c copy libc's swab.c into dd as dd_swab(), and remove the restrict.
our implementation was fine, but the restrict marker is problematic
as gcc 8 is now more strict about checking for restrict issues.

this is the only actual consumer of swab(3) in our tree, though,
besides the test for it.  oh well.
2019-10-04 08:57:37 +00:00
mrg 21303c93e9 convert HAVE_GCC == 7 to HAVE_GCC >= 7. 2019-09-29 23:44:58 +00:00
mlelstv 6883e45b87 Fix FALLTHROUGH comments. 2019-09-26 11:01:09 +00:00
christos 7790b32131 PR/54564: Jan Schaumann: cp of a fifo yields an empty file
Don't short-circuit 0 sized stat entries if they don't belong to regular files.
Also don't try to mmap non-regular files.
2019-09-23 18:01:09 +00:00
christos 104d898ec7 we don't need root anymore. 2019-09-23 15:24:44 +00:00
christos 02cdd248ec Add a new member to struct vfsstat and grow the unused members
The new member is caled f_mntfromlabel and it is the dkw_wname
of the corresponding wedge. This is now used by df -W to display
the mountpoint name as NAME=
2019-09-22 22:59:37 +00:00
wiz d83135eb3e file system police. Fix typo. Fix macro use. 2019-09-20 13:43:47 +00:00
christos dc03ac3f22 It is not just root, it is device read access (kre) 2019-09-18 23:43:23 +00:00
christos 47f3b76374 mention that -W needs root. 2019-09-18 20:17:46 +00:00
christos d06f528c83 Print the wedge name with -W instead of mntfrom 2019-09-18 20:14:44 +00:00
kamil 597efdbfe5 Drop -D_INCOMPLETE_XOPEN_C063 from dd(1) 2019-09-15 23:58:31 +00:00
kamil 5626006fd5 ps(1): Guard freeing the memory of pinfo with __NO_LEAKS.
No more leaks are detected by LSan/NetBSD as of the LLVM snapshot
(clang10svn) from 2019-09-15.
2019-09-15 15:27:50 +00:00
kamil fd0c6ecff6 Plug memory leak in ps(1)
pinfo is allocated in setpinfo() with calloc(3).

Free it when no longer used, just before the program termination.

Detected with LSan.
2019-09-11 17:02:53 +00:00
christos 0282eceed1 Don't fail when the line discipline ioctl fails (since it secondary
like the other tty ioctls that we only warn about). Do the main
ioctl (tcgetattr) first, since that provides a better error message
(ENOTTY instead of EINVAL).
2019-09-06 16:28:53 +00:00
uwe 9028c79eae Install manual pages for tar and cpio only if ${MKBSDTAR} == "no"
PR bin/54468
2019-08-15 21:05:16 +00:00
kamil 37157e31f8 Restore maxrss, idrss, isrss, ixrss printing in ps(1)
The RSS related statistics are now back in the NetBSD kernel.

These values were disabled since day0 until today.

libkvm(3) users will still receive inappropriate values as RSS statistics
are updated upon sysctl(3) call.

Patch submitted by <Krzysztof Lasocki>
2019-08-06 18:07:51 +00:00
kamil 41a1344d4e Add a fallback definition of LSDEAD in ps(1)
The symbol is no longer available in headers.

Requested by <mrg>
2019-06-19 21:25:50 +00:00
kamil 561652851d Make LSDEAD usage conditional
LSDEAD is not used since NetBSD-5.0 and will be gone.

The same conditional usage is already in ps.c in the same program.
2019-06-18 02:23:29 +00:00
kre c531b5689e When a return occurs in the test part of a loop statement (while/until)
(inside a function or dot script) the exit status of that return
statement should become the exit status of the function (or dot
script) - we were ignoring it,

That is
	fn() { while return 7; do return 9; done; return 11; }
should exit with status 7.   It was exiting 0.

This is apparently another old ash bug that has been fixed
everywhere else in the past.

Issue pointed out by Martijn Dekker, (fairly obvious) fix borrowed
from FreeBSD, due for return sometime next century.
2019-05-04 02:52:55 +00:00
kre b7fc669e75 Fix an (apparent) ancient ash bug, that was apparently fixed sometime
in the past, but managed to re-surface...

The expression "${0+\}}" should expand to "}" not "\}"
Almost all other shells handle it that way (incl FreeBSD & dash).

Issue pointed out by Martijn Dekker.

Add ATF sub-tests for the 4 old var expand operators (${var+word}
${var-word} ${var-word} and ${var?word} - including the forms
with the ':' included) and amongst those tests include test cases
for this issue, so if the bug tries to appear again, we can squash
it quicker.   (The newer pattern matching operators are already
well tested as part of testing patterns.)
2019-05-04 02:52:22 +00:00
kre e904ec4095 Better interactive SIGINT handling (when a trap is set), and other
cleanups to the trap code.   No longer silently ignore attempts to
do anything other than set SIGKILL or SIGSTOP to the default ('-")
state.   Don't include those in trap or trap -p output (the former
because they cannot be other than in default state, so simply aren't
included, the latter because it is pointless) but do list them
when requested with trap -p SIG.

Interactive mode SIGINT traps are now run ASAP, rather than after
a command has been entered (so the sequence ^C \n is no longer needed
to generate one).   Further, when trapped, in interactive mode,
while waiting for a user command, a SIGINT acts (aside from the
trap being run) just like when not trapped, aborts the command being
entered (rather than leaving it, which it did when libedit was in use)
prints a new prompt, and starts again (which is what should happen.)

Traps other than SIGINT (which has always been handled special in
interactive mode) are unaffected by this change, as are SIGINT traps
in non-interactive shells.    Or that is the intent anyway.

Fix an in_dotrap ref count bug (was never being decremented... that
was inserted in a place never executed) (relatively harmless) and
add/improve some trap/signal related DEBUG mode tracing.
2019-04-25 03:54:10 +00:00
cheusov f8f9f44113 Fix compilation failure with gcc-8.
Equal pointers to 'struct sigaction' should not be passed to sigaction(2).
  So, we pass NULL as an "old sigaction" structure.
2019-04-24 17:27:08 +00:00
kre bb952598c8 Bump date for previous. 2019-04-22 04:10:33 +00:00
kre 15fbfbbfd4 PR standards/40554
Update the description of the <& and >& redirection operators
(as indicated would happen in a message appended to the PR a week ago,
which received no opposition - no feedback).

Some rewriting of the section on redirects (including how the word
expansion of the "file" works) to make this simpler & more accurate.
2019-04-22 04:04:35 +00:00
uwe 2dbf991860 -compact must come last 2019-04-15 20:35:25 +00:00
kre 265b061776 PR bin/54112
Fix handling of "$@" (that is, double quoted dollar at), when it
appears in a string which will be subject to field splitting.

Eg:
	${0+"$@" }

More common usages, like the simple "$@" or ${0+"$@"} end up
being entirely quoted, so no field splitting happens, and the
problem was avoided.

See the PR for more details.

This ends up making a bunch of old hack code (and some that was
relatively new) vanish - for now it is just #if 0'd or commented out.
Cleanups of that stuff will happen later.

That some of the worst $@ hacks are now gone does not mean that processing
of "$@" does not retain a very special place in every hackers heart.
RIP extreme ugliness - long live the merely ordinary ugly.

Added a new bin/sh ATF test case to verify that all this remains fixed.
2019-04-10 08:13:11 +00:00