Commit Graph

4143 Commits

Author SHA1 Message Date
gutteridge 1290da4db3 echo.1: borrow advice about printf(1) from the OpenBSD man page 2024-05-14 01:32:24 +00:00
rillig 0866d10930 lint: suppress "used but not defined" for bin, sbin, usr.bin, usr.sbin
These diagnostics are emitted by lint2, and like all diagnostics from
lint2, they don't affect the exit status.

In libc, lint cannot handle the renamings from namespace.h, generating
many false positive diagnostics since 'libc_function' is used but
'_libc_function' is defined. Until this situation is handled properly,
suppress this diagnostic.
2024-05-12 17:55:36 +00:00
nia 509d26c5fb csh: replace malloc(x * y) and realloc(x * y) with reallocarray 2024-04-24 15:49:03 +00:00
nia b544db1689 csh: add a helper definition for the reallocarray function 2024-04-24 15:47:11 +00:00
nia 911d74d44e csh: add a reallocarray function for using inside csh 2024-04-24 15:46:20 +00:00
rillig f56f0d26c4 {usr.,}{s,}bin: replace LINT_SUPPORTED with the standard NOLINT
While here, re-enable lint in those cases where lint was skipped due to
a bug in interpreting abstract types, which was fixed in cgram.y 1.469
from 2023-08-02.
2024-04-20 13:24:48 +00:00
christos eda85bc164 Be more explicit with sort fields to produce consistent results with gnu
sort (Jan-Benedict Glaw)
2024-04-16 23:30:19 +00:00
kre 30112b560c Edgar Fuß pointed out that sh(1) did not mention comments (at all).
This has been true forever, and no-one else (including me) ever seems
to have noticed this ommission.

Correct that.

While in the area, improve the general sections on the Lexical structure
of the shell's input, and including some refinements to how quoting is
described.
2024-04-12 19:09:50 +00:00
rillig c991d4dc63 ed: fix inconsistency in comment 2024-04-10 17:52:41 +00:00
kre 1568b40160 Redo the mktemp(1) part - some mktemp's (including ours) require the
XXXX's to be at the end of the name (like mk*temp(3)) so however well
it will work with mktemp implementations which allow the X's to be
anywhere in the final component of the name, it will work just as
well on them with the X's at the end.

But we don't normally need all of that mess - knowing which temp
file is which is useful only when debugging the script, and that's
(mostly) long done.   So, in normal uses now just use $(mktemp) and
allow mktemp to pick its own name - we don't need to know what it is.
Every mktemp(1) supports that mode of operation.

Bug when debugging the script (which for current purposes will be
taken to be when the -x flag is passed to the shell running it, to
trace what it does) then we will make the temp files have names we
can recognise (and in that case, also don't delete them when done).

While here, check for mktemp(1) failing, and abort if that
happens (we assume that if it fails it will write an error
message to stderr, so the script does not need to.)

As for the purpose of the script ... of course the header file
generated (or an equivalent elsewhere) could be generated and
maintained by hand, but why would anyone want to do all that
work when software can do it for us, and do it correctly without
human thought?

This also allows the options in the master list (option.list) to be
arranged in a way that is meaningful for them, unrelated to the order
the shell needs to have them in (or rearrange them to be at run time)
and have that order shuffled however is convenient.   Currently all
the posix standard options are first, then the "hybrid" options, and
finally the local ones for this shell.   Currently "pipefail" is in the
final set, but once the next posix version is published, that will
become a standard option, and get moved in the list - the shell won't
even notice as this script puts the options into shell desired order.
2024-04-06 14:20:27 +00:00
christos 3200c2817b From Jan-Benedict Glaw:
Fix a redirection and prepare a stable sort for upper-/lowercase
option letters

This script is a mess, I strongly believe that it should be rewritten.
However, I'm not 100% sure why it was invented in the first place
(come on, the generated header file isn't _that_ complicated that
it couldn't be sanely managed by hand!), but let's fix the sorting
order by using LC_ALL=C.

Also add a few 'X' to the `mktemp` template to make non-BSD
implementations happy. As a bonus, actually *use* the initial `sed`
output instead of throwing it away by piping it into `sort` with
also connecting `sort`'s stdin with the original input file...
2024-04-05 22:22:17 +00:00
andvar 100a3398b8 fix spelling mistakes, mainly in comments and log messages. 2024-02-09 22:08:30 +00:00
andvar 23997cfc64 s/formated/formatted/ in comment and distrib sets descriptions. 2024-02-05 21:20:09 +00:00
christos f2413af6ff PR/57892: Roberto Branco: Print full pathname in error messages 2024-02-02 22:58:26 +00:00
kre f55c8670e1 PR bin/57894
For jobs -p for a non-job-control job, avoid just printing 0 (as
there is no process group pid) and instead output what we used to,
the pid of one of the processes in the job (usually the right one!)

XXX pullup -10 (9 and earlier not affected).
2024-01-30 19:05:07 +00:00
mlelstv ab1ad50d80 Don't use the signal handler to terminate when nothing is to do (count=0, files=0).
The signal handler tries to raise the signal again, so that a parent can retrieve
the signal from the exit code. Calling the terminate handler with signal code 0
doesn't raise a signal and dd continues with exit(127) making this case an error.
2024-01-26 07:10:04 +00:00
christos 4c85ba7382 Handle -d %Y%m%d in the tools version. This is used in the release notes
Makefile.inc when BUILDID is specified. Consider providing parsedate(3)
in libcompat, but then we'd need yacc...
2024-01-21 16:55:56 +00:00
kre acdf05cdcd Remove an ancient incorrect notion which somehow survived intact for ages.
"$@" is (as it is in double quotes) not subject to field splitting.  "$@"
generates (potentially) multiple words, but field splitting has nothing
to do with it.

While here, rename the section from "White Space Splitting (Field Splitting)"
to simply be "Field Splitting" as white space is only relevant if it happens
to occur in IFS (which is the default case, but IFS can be anything, and
isn't required to contain any white space at all).
2024-01-16 14:30:22 +00:00
christos b6787da498 PR/57857: Ricardo Branco: Always copy regular files, even if they appear to
be zero-sized.
2024-01-15 17:41:06 +00:00
kre 6654ff1c5a PR bin/57773
Fix another bug reported by Jarle Fredrik Greipsland and added
to PR bin/57773, which relates to calculating the length of a
positional parameter which contains CTL chars -- yes, this one
really is that specific, though it would also affect the special
param $0 if it were to contain CTL chars, and its length was
requested - that is fixed with the same change.  And note: $0
is not affected because it looks like a positional param (it
isn't, ${00} would be, but is always unset, ${0} isn't) all
special parame would be affected the same way, but the only one
that can ever contain a CTL char is $0 I believe.  ($@ and $*
were affected, but just because they're expanding the positional
params ... ${#@} and ${#*} are both technically unspecified
expansions - and different shells produce different results.

See the PR for the details of this one (and the previous).

Thanks for the PR.

XXX pullup to everything.
2023-12-29 15:49:23 +00:00
kre c6d0f408e8 PR bin/57773
Fix a bug reported by Jarle Fredrik Greipsland in PR bin/57773,
where a substring expansion where the substring to be removed from
a variable expansion is itself a var expansion where the value
contains one (or more) of sh's CTLxxx chars - the pattern had
CTLESC inserted, the string to be matched against did not.  Fail.
We fix that by always inserting CTLESC in var assign expansions.
See the PR for all the gory details.

Thanks for the PR.

XXX pullup to everything.
2023-12-25 04:52:38 +00:00
kre 391d454067 Correct a bizarre piece of source formatting that crept in by
accident several years ago (change a space into newline tab).

NFC
2023-12-25 02:28:47 +00:00
kre 76caabcb82 Correctly compute the "Filesystem" column with when using -W
(that added "NAME=" occupies space!)

XXX pullup -10
2023-12-18 08:27:24 +00:00
rillig 0d42f426f1 cat: repeat storage class 'static' for local functions
No binary change.
2023-12-10 15:31:53 +00:00
rillig 7a4b38d710 cat: reduce visibility of local functions
No functional change.
2023-12-07 20:02:07 +00:00
kre 879813d8b2 Work around a probably gcc12 bug in detecting "potentially clobbered"
variables after longjmp() for some architectures (sh3 at least).

This should allow the workaround to disable those warnings for this
file to be removed.

In the affected function the extra var & assignment added should simply
be deleted by any good optimiser, but if not, it doesn't matter, as
performance of this function (expandonstack()) is almost irrelevant.
2023-10-20 22:08:52 +00:00
mrg d528393cd3 convert gcc12 -O1 into -Wno-error=clobbered.
parser.c wants all the optimisation, and this is very likely a
false positive.
2023-10-19 04:27:24 +00:00
mrg 08e29b5df3 the parser.c longjmp vs gcc12 issue affects a few ports,
make the workaround global.
2023-10-14 06:53:56 +00:00
uwe ce7bd196f3 sh(1): touch up markup for the ENV example
Don't use Dq in a literal display, ascii quotes are \*q
While here mark up as literal a few things around this example.
2023-10-12 01:45:07 +00:00
kre 28b2f4e3f6 If the read builtin is told to read into IFS, we must avoid doing
that until all current uses of IFS are complete (as we have IFS's
value cached in ifs - if IFS alters, ifs might point anywhere).
Handle this by deferring assignments to IFS until everything is done.
This makes us appear to comply with the (currently) proposed requirement
for read by POSIX that field splitting complete before vars are
assigned.   (Other shells, like dash, ksh93, yash, bosh behave like this)

That might end up being unspecified though, as other shells (bosh,
mksh) assign each field to its var as it is delimited (though bosh
appears to have bugs).   If we wanted to go that route, the issue here
could have been handled by re-doing the init of ifs after every
setvar() that is performed here (except the last, after which it is
no longer needed).

XXX pullup -10
2023-10-05 20:33:31 +00:00
kre 4c31efd22f At the request of bad@ enhance the synopsis of the set built-in
command to include explicit mention of the -o opt and +o opt forms.

Fix the synopsis to have the 4 forms that the description of the
utility discusses, rather than expecting users to understand that
the 3rd and 4th forms of the command were combined into the 3rd
synopsis format.   After doing that, the options in the 3rd format
no longer need to be optional, so now all 4 formats are distinct
(previously, the third, omitting everything that was optional, and
the first, could not be distinguished).

While here, some wording and formatting "improvements" as well (nothing
too serious).
2023-09-01 01:57:54 +00:00
mrg 046f28e789 use -O1 on sh3, GCC 12 and parser.c.
this triggers clobbered vs. longjmp/setjmp warnings with -Os that sh3 uses.
2023-08-14 03:18:14 +00:00
jschauma f2c0b7b228 tyops:
* redicection -> redirection
* escaoed -> escaped

Noted by J. Lewis Muir on netbsd-docs@
2023-08-04 15:31:40 +00:00
mrg f386908b27 convert explicit length check before unchecked snprintf() with just a
overflow checked snprintf().  for res_debug.c and res_query.c, convert
from sprintf() to snprintf().

tested scp and rcp fail properly with too-long paths.
tested getaddrinfo fails as expected for too-long domains.
tested dig and ping for similar (res_debug.c/res_query.c).
created a temporary fs with quotas to test edquota with a long EDITOR.
did not test ypserv directly, but it's the same pattern.

avoids GCC 12 snprintf() warnings, and reduces total code size.
2023-08-01 08:47:24 +00:00
mrg f8570f8a97 fix simple mis-matched function prototype and definitions.
most of these are like, eg

   void foo(int[2]);

with either of these

   void foo(int*) { ... }
   void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
2023-08-01 07:04:14 +00:00
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