Commit Graph

4108 Commits

Author SHA1 Message Date
lukem 2756562594 pax: fix -Wformat for host tool 2023-07-20 20:10:59 +00:00
lukem 21fbd5bbde pax: need <strings.h> for ffs()
Fixes warning as host tool on NetBSD 9.99
2023-07-20 20:09:49 +00:00
msaitoh 418b48633c Fix typo in a debug message. 2023-06-24 05:17:02 +00:00
lukem 230c41e44c adapt to ${CC_WNO_IMPLICIT_FALLTHROUGH}
Use ${CC_WNO_IMPLICIT_FALLTHROUGH} instead of
the older style more complex expressions.
2023-06-03 21:30:20 +00:00
lukem c4b7a9e794 bsd.own.mk: rename GCC_NO_* to CC_WNO_*
Rename compiler-warning-disable variables from
	GCC_NO_warning
to
	CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
2023-06-03 09:09:01 +00:00
andvar cb40c69b16 follow the steps of Andrew Doran (ad) commit and fix more s/loose/lose/ typos.
also s/beyound/beyond/ and few others along the way, mainly in comments.
2023-06-02 08:51:46 +00:00
uwe a2db434eb1 date(1): sync two [[[[[CC]yy]mm]dd]HH]MM[.SS] instances
The markup was the same (modulo Li vs Cm for the dot before the
seconds), but use the same source markup grouping/layout in both to
make this fact more obvious.
2023-05-31 18:04:00 +00:00
kim 219c5cc723 Add -R to usage 2023-05-31 17:56:54 +00:00
uwe 8710cd3b8d date(1): minor markup fixes 2023-05-31 17:52:02 +00:00
kim 04f2a3c19d Add -R option for displaying time in RFC 5322 format, similar to GNU date. 2023-05-31 16:01:53 +00:00
lukem d2813c5205 pax: don't overwrite destination if -r -w copy fails
Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.
The partial temporary file is removed.  pax still exists non-zero.

Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.

Should fix PR misc/33753.
2023-05-28 21:42:40 +00:00
lukem 81f726b0e0 pax: exit 0 if stdin filelist is used and empty
If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.
2023-05-28 17:01:46 +00:00
rillig f00c946f6d cat: fix misleading indentation
Found by indent, but not by GCC 10.

No binary change.
2023-05-19 05:28:54 +00:00
kre da39777e71 If chown and chgrp can grow -d flags to suppress performing the
operation when it will have no effect (other than changing the
inode's ctime value) then chmod and chflags should also have -d
flags for the same purpose.   Make it so.
2023-05-05 04:14:02 +00:00
kre 5409234e44 Remove an end of file trailing blank line that served no purpose.
NFCI
2023-04-07 10:42:28 +00:00
kre 0827e1f954 The great shell trailing whitespace cleanup of 2023...
Inspired by private e-mail comments from mouse@

NFCI.
2023-04-07 10:34:13 +00:00
hannken f438a6a065 Use "sigjmp_buf loc" after switch to sigsetjmp()/siglongjmp().
Fixes errors and aborts on sparc at least.
2023-03-21 08:31:30 +00:00
kre 98b2eb3607 Do a better job handling EACCES errors from exec() calls. If the
EACCES is from the namei(), treat it just like ENOENT or ENOTDIR
(and if that is the final error, the exit status from a failed exec
will be 127).   If the EACCES is from the exec() itself, that indicates
the file to be run exists, but has no 'x' permission.   That's a
meaningful error (as distinct from just "yet another PATH element
search failure").

While here, return the first meaingful error we encountered while
searching PATH, rather than the last (and ENOENT if there are none
of those).

This change results in some failed command executions returning status
127 now, where they returned 126 before - which better reflects the
intent of those values (127 is simply "not found" whereas 126 is "found
but couldn't be executed").

We still do nothing to distinguish errors encountered looking up the
command name give, with errors encountered (by the kernel) attempting to
run an interpreter needed for the exec to succeed (#! line path, or
/libexec/ld.elf_so and similar - or anything else of a similar nature).
2023-03-19 17:55:57 +00:00
kre 91522b5b9d Switch from using _setjmp()/_longjmp() (on BSD systems which aren't SVR4)
(and setjmp()/longjmp() elsewhere) to using sigsetjmp()/siglongjmp()
everywhere.

NFCI.
2023-03-19 17:47:48 +00:00
kre d45073cdfd Change a few #defines from octal to hex (pdp11 days are long gone).
Improve the layout of those definitions at the same time.

NFC.
2023-03-19 17:45:29 +00:00
kre 726d188a97 Adjust tilde expansion as will be documented in the forthcoming
version of the POSIX standard (Issue 8).   I believe we were already
compliant with what is to be required, but POSIX is now encouraging
(and will likely require in a later version) that if a tilde expansion
produces a string which ends in a '/' and the '~' that was expanded
is immediately followed by a '/' in the input word, that one of those
two slashes be omitted.   The worst (current) example of this is
when HOME=/ and we expand ~/foo - previously producing //foo which is
(in POSIX) a path with implementation defined semantics, and so not
what we should be generating by accident.   Change that, so now if
the ~ prefix expansion ends in a '/' and there is a '/' following
immediately after, the resulting word contains only one of those
chars (in the example just given, we will now produce /foo instead).

POSIX is also making it clear that the expansion that results from
the tilde expansion is treated as quoted (not subject to pathname
expansion, or field splitting, or any var/arith/command substitutions)
and that if HOME="" the expansion of ~ must generate "" (not nothing).
Our implementation did all of that already (though older versions
used to treat an empty expansion of HOME the same as if HOME was
unset - that was fixed some time ago).

The actual modification made here is probably smaller than this log entry,
and without added comments, certainly is!
2023-03-06 05:54:34 +00:00
kre 64c7eea502 Allow (but do not require) the magic '--' option terminator in
the builtin 'alias' command.   This allows portability (not that
anyone should really care with aliases) for scripts from other
shells in which the alias command has options, and the -- is
required to allow the first alias name to begin with a '-'.

That is, for us, alias -x='echo x'  works fine, always has,
and still does.   But other shells treat that as an attempt
to use the -x option (and maybe -= etc), and require
alias -- -x='echo x'.   For us that variant used to complain
about the alias -- not existing (as an arg with no '=' is
treated as a request to extract the value of the alias).

Posix also generally requires all standard commands (or
which "alias" is one, unfortunately) to support '--' even
if they have no options, for precisely this reason.
2023-02-24 19:04:54 +00:00
uwe a525a2707f sleep(1): minor markup tweaks 2023-02-19 10:54:35 +00:00
kre d1668f2837 More markup errors. \+ was intended to be \&+ and .EV .Ev of course.
As best I can tell, the rest of what mandoc -Wall complains about is
incorrect (it could probably be avoided by adding more markup, but
there doesn't seem to be any point).
2022-12-20 17:51:54 +00:00
kre d51e0a2e8a Using .Cm Cm makes no sense at all - no idea what I was thinking there
(perhaps just an editing error).
2022-12-20 16:48:57 +00:00
uwe c14a7046e4 sh(1): Fix markup. -compact must be last. 2022-12-20 01:18:42 +00:00
kre e2731928b1 It appears that POSIX intends to add a -d X option to the read command
in its next version, so it can be used as -d '' (to specify a \0 end
character for the record read, rather than the default \n) to accompany
find -print0 and xargs -0 options (also likely to be added).

Add support for -d now.   While here fix a bug where escaped nul
chars (\ \0) in non-raw mode were not being dropped, as they are
when not escaped (if not dropped, they're still not used in any
useful way, they just ended the value at that point).
2022-12-11 08:23:10 +00:00
andvar 8a36802c94 fix various typos in comments and one output message. 2022-10-31 21:22:05 +00:00
kre 1c627bdffa PR bin/57053 is related (peripherally) here.
sh has been remembering the process group of a job for a while now, but
using that for almost nothing.

The old way to resume a job, was to try each pid in the job with a
SIGCONT (using it as the process group identifier via killpg()) until
one worked (or none did, in which case resuming would be impossible,
but that never actually happened).   This wasn't as bad as it seems,
as in practice the first process attempted was *always* the correct
one.  Why the loop was considered necessary I am not sure.  Nothing
but the first could possibly work.

This worked until a fix for an obscure possible bug was added a
while ago - now a process which has already finished, and had its
zombie collected via wait*() is no longer ever considered to have
a pid which is a candidate for use in any system call.  That's
because the kernel might have reassigned that pid for some newly
created process (we have no idea how much time might have passed
since the pid was returned to the kernel for reuse, it might have
happened weeks ago).

This is where the example in bin/57053 revealed a problem.

That PR is really about a quite different problem in zsh (from pksrc)
and should be pkg/57053, but as the test case also hit the problem
here, it was assumed (by some) they were the same issue.

The example is (in a small directory)
	ls | less
which is then suspended (^Z), and resumed (fg).   Since the directory
is small, ls will be finished, and reaped by sh - so the code would
now refuse to use its pid for the killpg() call to send the SIGCONT.
The (useless) loop would attempt to use less's pid for this purpose
(it is still alive at this point) but that would fail, as that pid
is not a process group identifier, of anything.   Hence the job
could not be resumed.

Before the PR (or preceding mailing list discussion) the change here
had already been made (part of a much bigger set of changes, some of
which might follow - sometime).   We now actually use the job's
remembered process group identifier when we want the process group
identifier, instead of trying to guess which pid it happens to be
(which actually never took any guessing, it was, and is always the
pid of the first process created for the job).   A couple of minor
fixes to how the pgrp is obtained, and used, accompany the changes
to use it when appropriate.
2022-10-30 01:46:16 +00:00
kre ec520a6a57 Note in the description of "jobs -p" that the process id returned is
also the process group identifier (that's a requirement from POSIX, and
is what we have always done - just not been explicit about in sh.1).
Add a note that this value and $! are not necessarily the same (currently,
and perhaps forever, never the same in a pipeline with 2 or more elements).
2022-10-30 01:19:08 +00:00
christos 9337b5ddea Add -f option to set the time. From FreeBSD. 2022-10-22 20:11:43 +00:00
kre 9eccf618bb Oops, somehow managed to commit an older version where NBSH_INVOCATION
start char was '@' rather than '!' (which meant not lexically ordered).
This is how it was intended to be (and is documented).
2022-09-18 17:11:33 +00:00
kre e7b0505e69 Add the -l option (aka -o login): be a login shell. Meaningful only on
the command line (with both - and + forms) - overrides the presence (or
otherwise) of a '-' as argv[0][0].

Since this allows any shell to be a login shell (which simply means that
it runs /etc/profile and ~/.profile at shell startup - there are no other
side effects) add a new, always set at startup, variable NBSH_INVOCATION
which has a char string as its value, where each char has a meaning,
more or less related to how the shell was started.   See sh(1).
This is intended to allow those startup scripts to tailor their behaviour
to the nature of this particular login shell (it is possible to detect
whether a shell is a login shell merely because of -l, or whether it would
have been anyway, before the -l option was added - and more).   The
var could also be used to set different values for $ENV for different
uses of the shell.
2022-09-18 06:03:19 +00:00
kre e1f658a30d More wording improvements. There might be more to come. 2022-09-16 19:25:09 +00:00
kre f9baa2eaae Minor wording improvements.
Note these do not alter anything about what the man page specifies,
just say a couple of things in a slightly better way, hence no Dd
update accompanies this change (deliberately).
2022-09-16 17:32:18 +00:00
kre c5917dbfa8 Move a comment that used to be in the correct place, once upon a time,
back where it belongs, and make it stand out more, so other text is
less likely to find itself pushed between the comment and the text
to which it appears.   This change should make no visible difference
to the man page displayed.
2022-09-16 17:29:21 +00:00
kre 65d376a4f6 Whitespace. 2022-09-16 17:25:09 +00:00
kre 258641d776 Correct spelling of terminal (it doesn't have a 2nd m). 2022-09-15 18:00:36 +00:00
martin ea9288bf30 Fix the build for variants that do not define EDIT. 2022-09-15 11:35:06 +00:00
christos e473cf6a19 Update editing before prompt printing. 2022-09-14 17:06:16 +00:00
christos d0aa7ee82f defer editing setup/cleanup to when we are interactive. 2022-09-14 16:15:51 +00:00
hgutch ec184f3bfb Change back various occurrences of \*[Le], \*[Ge] (less/greater equal)
and \*(ua (upwards arrow) to literal "<=", ">=" and "^" whenever
appropriate (e.g., in code examples).
2022-08-28 10:48:15 +00:00
dholland cc9598fccf PR 56983 Izumi Tsutsui: fix confusing message in test(1) with -DSMALL 2022-08-27 21:18:39 +00:00
kre f5b9e602e2 Add debugging trace points for history and the editline interface.
NFC for any normal shell (not compiled with debugging (sh DEBUG) enabled.

We have had a defined debug mode for this for years, but since I have
not often played in this arena, never used it.  Until recently (relatively).
This (or a small part of it) played a part in discovering the fc -e
bug cause.   I have had it in my tree a while now - recent changes
kept causing merge conflicts (all because I hadn't bothered to commit
this), so I think now is the time...
2022-08-22 17:33:11 +00:00
nia 29c67fe23d sh(1): revert previous because it interferes with custom user bindings 2022-08-21 21:35:36 +00:00
uwe 21531a4577 ksh(1): fix pasto in the description of the -l option. 2022-08-21 20:12:37 +00:00
kre 16e67595a2 Improve the description of the read builtin command. 2022-08-19 13:37:03 +00:00
kre a1f6605654 Don't output the error for bad usage (no var name given)
after already writing the prompt (set with the -p option).

That results in nonsense like:

	$ read -p foo
	fooread: arg count

While here, improve the error message so it means something.

Now we will get:

$ read -p foo
read: variable name required
Usage: read [-r] [-p prompt] var...

[Detected by code reading while doing the work for the previous fix]
2022-08-19 12:52:31 +00:00
kre 143e8d551e PR bin/56972 Fix escape ('\') handling in sh read builtin.
In 1.35 (March 2005) (the big read fixup), most escape handling and IFS
processing in the read builtin was corrected.  However 2 cases were missed,
one is a word (something to be assigned to any variable but the last) in
which every character is escaped (the code was relying on a non-escaped char
to set the "in a word" status), and second trailing IFS whitespace at
the end of the line was being deleted, even if the chars had been escaped
(the escape chars are no longer present).

See the PR for more details (including the case that detected the problem).

After fixing this, I looked at the FreeBSD code (normally might do it
before, but these fixes were trivial) to check their implementation.
Their code does similar things to ours now does, but in a completely
different way, their read builtin is more complex than ours needs to
be (they handle more options).   For anyone tempted to simply incorporate
their code, note that it relies upon infrastructure changes elsewhere
in the shell, so would not be a simple cut and drop in exercise.

This needs pullups to -3 -4 -5 -6 -7 -8 and -9 (fortunately this is
happening before -10 is branched, so will never be broken this way there).
2022-08-19 12:17:18 +00:00
nia 16c8f5ddd4 sh(1): Allow an explicit set -o vi or set -o emacs to override ~/.editrc 2022-08-18 14:10:05 +00:00