Commit Graph

3862 Commits

Author SHA1 Message Date
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
kre da46072561 Fix a logic botch that prevented "wait -n" (with no pid args) from
finding a job that had previously terminated.

Now in that case JOBWANTED is set on all jobs (since any will do)
which then simplifies a later test which no longer needs to special
case "wait -n".   Further, we always look to see if any wanted
job has already terminated, even if there are still running jobs
we can wait upon - if anything is already ready, that's where we start
harvesting (and finish, if -n is specified).
2019-03-26 13:32:26 +00:00
mlelstv a7b9d4bbeb When buffers are at least page sized, explicitely request page alignment. 2019-03-23 09:33:16 +00:00
gutteridge ee05db8218 pax: fix typos in comments in file_subs.c & tar.c
Stamp out "greengrocers' apostrophes" in various places (arguably there
are still more present, but style guides vary on that, and my energies
spent corralling wayward punctuation marks could be spent elsewhere).
2019-03-20 03:13:39 +00:00
gutteridge 01205dd53a pax: minor adjustments to comments in pat_rep.c
Amend several comments to match present reality (the functionality was
added back in 2007).
2019-03-20 02:50:50 +00:00
wiz c9960b6dc5 Whitespace nits. 2019-03-19 10:14:46 +00:00
gutteridge b96bf3b04c pax.1 & tar.1: add a minor clarification about "-s"
As a somewhat pedantic clarification, "-s" does not accept backslashes
as delimiters. (While here, also make the macro use of an expression
shared between pax.1 and tar.1 consistent.)
2019-03-19 00:36:14 +00:00
gutteridge 76144f4ebd pax.1: document the "s" flag of the "s" option
Note the "s" option has an "s" flag that "prevents substitutions from
being performed on symbolic link destinations". Carry over r. 1.25 from
christos@ and part of r. 1.26 from wiz@ from tar.1, since this
functionality is available in pax as well as tar.
2019-03-19 00:12:08 +00:00
kre b0172d2346 Deal with overflow when the sleep duration given is a simple
integer (previously it was just clamped at the max possible value).
This would have caused
	sleep 10000000000000000000
(or anything bigger) to have only actually slept for 9223372036854775807
secs.   Someone would have noticed that happen, one day, in some other
universe.

This is now an error, as it was previously if this had been entered as
	sleep 1e19

Also detect an attempt to sleep for so long that a time_t will no longer
be able to represent the current time when the sleep is done.

Undo the attempts to work around a broken kernel nanosleep()
implementation (by only ever issuing shortish sleep requests,
and looping).   That code was broken (idiot botch of mine) though
you would have had to wait a month to observe it happen.  I was going
to just fix it, but sanity prevailed, and the kernel got fixed instead.

That allows this to be much simplified, only looping as needed to
handle dealing with SIGINFO.   Switch to using clock_nanosleep()
to implement the delay, as while our nanosleep() uses CLOCK_MONOTONIC
the standards say it should use CLOCK_REALTIME, and if that we
ever changed that, the old way would alter "sleep 5" from
"sleep for 5 seconds" to "sleep until now + 5 secs", which is
subtly different.

Always use %g format to print the original sleep duration in reports of how
much time remains - this works best for both long and short durations.
A couple of other minor (frill) mods to the SIGINFO report message as well.
2019-03-10 15:18:45 +00:00
kre 8d9b075152 The previous commit was obviously made by a broken mindless automoton
with an IQ that underflows when one attempts to enter it as an
unnormalised 160 bit long long double...

Whoever would believe that (~0 & anything) was a meaningful thing
to write?   And three times in one #define.   That could not possibly
have been me, could it?

Simplify, simplify, simplify.		NFC.
2019-03-01 06:15:01 +00:00
kre f2dc75406d Inspired by (really the need for) Maya's patch to pkgsrc/shells/bash
to allow bash to build fdflags on Solaris 10, here are some mods that
fix that, and some other similar issues in the NetBSD version of fdflags.

The bash implementation of fdflags is based upon the one Christos did for
the NetBSD sh, so the issues are similar ... the NetBSD sh cannot yet
(easily anyway) build on anything except NetBSD, so this change makes
no current difference at all (just adds some compile time tests (#ifdef)
which always work out the way things did before, when built on NetBSD).

However, there is no system on which any modern shell can hope to work
which does not support close on exec, or fcntl(F_SETFD,...) to set it.
The O_CLOEXEC and FD_CLOEXEC definitions might not exist, but close on
exec can still be manipulated.   Since the primary rationale for
the fdflags builtin was to be able to manipulate that state bit from
scripts, it would be annoying to lose that one, and keep all the (less
important) others, just because O_CLOEXEC is not defined, so do the
fix (workaround) a different way than was done in the bash patch.

Further, more than fdflags() will fail if O_CLOEXEC is not defined,
so handle that as well.

Also fix another oddity ... (noticed by reading the code) - if
fcntl(F_GETFL,...) returned any bits set that we don't understand,
the code was supposed to simply print their values as a hex constant,
when fdflags is run with -v.    However, the getflags() function was
clearing all bits that the code did not know about ... so there is
no way any unknown bit could ever make it out to be printed.  Handle
that a different way - instead of clearing unknown bits, clear any
bits that get returned which we understand, but do not want to deal
with (stuff like O_WRONLY, which should not be returned from the
fcntl(), but who knows...)   Leave any unknown bits that happen to be
set, set, so that printone() can display them if appropriate.
(This is most likely to happen when running an older shell on a new
kernel where the kernel supports some new flag that the shell has
not been taught to understand).

NFCI that anyone should notice anytime soon.
2019-03-01 05:23:35 +00:00
kre 256d645df3 Finish the fixes from Feb 4 for handling of random data that
matches the internal CTL* chars.

The earlier fixes handled CTL* char values in var expansions,
but not in various other places they can occur (positional
parameters, $@ $* -- even potentially $0 and ~ expansions,
as well as byte strings generated from a \u in a $'' string).

These should all be correctly handled now.   There is a new
ISCTL() macro to make the test, rather than using the old
BASESYNTAX[c]==CCTL form (which us still a viable alternative)
as the new way allows compiler optimisations, and less mem
references, so it should be smaller and faster.

Also, be sure in all cases to remove any CTLESC (or other)
CTL* chars from all strings before they are made available
for any external use (there was one case missed - which didn't
matter when we weren't bothering to escape the CTL* chars at
all.)

XXX pullup-8 (will need to be via a patch) along with the Feb 4 fixes.
2019-02-27 04:10:56 +00:00
kre 2ec3f71485 DEBUG mode only change. When pretty-printing a word from a parse
tree, don't display a CTLESC which is there only to protect a CTL*
char (a data char that happens to have the same value).  No actual
CTL* chars are printed as data, so no escaping is needed to protect
data which just happens to look the same.  Dropping this avoids the
possibility of confusion/ambiguity in what the word actually contains.

NFC for any normal shell build (very little of this file gets compiled there)
2019-02-14 13:27:59 +00:00
kre 727a664bee Add the "specialvar" built-in command. Discussed (well, mentioned
anway) on tech-userlevel with no adverse response.

This allows the magic of vars like HOSTNAME SECONDS, ToD (etc) to be
restored should it be lost - perhaps by having a var of the same name
imported from the environment (which needs to remove the magic in case
a set of scripts are using the env to pass data, and the var name chosen
happens to be one of our magic ones).

No change to SMALL shells (or smaller) - none of the magic vars (except
LINENO, which is exempt from all of this) exist in those, hence such a
shell has no need for this command either.
2019-02-14 11:15:24 +00:00
kre ec83c7c484 Delete a no-longer-used #define that referred to a struct field that
no longer exists.   Also correct a couple of typos in comments.    NFC.
2019-02-13 21:40:50 +00:00
kre 72c6780ab3 Remove a function prototype which was added to <histedit.h> in 2005.
I think we can trust it to be stable by now, and doin't need the dup.
2019-02-10 19:21:52 +00:00
kre 4d2988311a Add a check that the file descriptor mentioned in a N> or N< type
redirect operator is within range of what the code tree node can
hold.   Currently this is a no-op change (the new error can never
occur) as the code already checks that N is in range for an int
(and errors if not) and the field in the node in which we store N
is also an int, so we cannot overflow - but fd's do not really need
to be that big (the max a typical kernel supports is < 10000) so
this just adds validation in case it ever happens that we decide we
can save some node size (ie: sh memory) by making that field smaller.

Note this is parse time error detection, and has no bearing upon
the execution time error that will occur if a script attempts to use
an fd that exceeds the process's max fd limit.

NFCI (for now anyway.)
2019-02-09 09:50:31 +00:00
kre 83735e242c DTRT when dynamically generated variables return "unset" instead of
a value.   There are none which do that at the minute, so this is a NFCI
change, which is just making the code correct even though nothing
currently triggers any bugs.
2019-02-09 09:38:11 +00:00
kre 733a465e66 DEBUG mode change only. Add one extra trace point. NFC for normal builds. 2019-02-09 09:34:43 +00:00
kre 750dbf249a When an interactive shell exits due to an EOF on stdin, send a newline
to stderr (to follow the previous prompt) and cleanup more nicely.
2019-02-09 09:33:20 +00:00
kre ccf5ffdbe9 In the unlikely event that restarting a job fails (the fg bg and various
%x commands) generate the most useful error message (from errno value)
rather than whichever happened last.

In posix mode, cause the "jobs" command to delete records of completed
jobs it reports on (as posix requires) as is done in interactive shells.
We don't (won't) do this in !posix mode, as the ability to throw in a
"jobs" command in a script to debug what is happening is too useful to
lose -- and any script that is relying on "jobs" instead of "wait" to
cleanup background processes (from the sh jobs table, sh always collects
zombies from the kernel) is absurd and not worth considering (besides
which I've never seen one).
2019-02-09 09:31:33 +00:00
kre b4a242b5e2 KNF - white space changes, indent using tabs not spaces. NFC. 2019-02-09 09:20:47 +00:00
kre 39879a1c65 DEBUG mode build changes - add extra trace output.
NFC for any normal shell build.
2019-02-09 09:17:59 +00:00
kre f42ddab0ac Delete extern decl for trap[] - hasn't been needed for a while now. 2019-02-09 09:15:22 +00:00
kre 3dbd860142 Allocate alias pointers for qsort() to use on the stack, rather than
directly via malloc() so they get cleaned up correctly on error/intr.

NFCI.
2019-02-09 09:11:07 +00:00