Commit Graph

3576 Commits

Author SHA1 Message Date
joerg
cfe7161816 Add includes guards since we can include the header twice and typedef
redefinitions are a C11 feature.
2017-03-21 10:52:46 +00:00
kre
996a70951c At the suggestion of Matthew Sporleder (on current-users@) reword some
of the description of arithmetic expressions to make it a bit more
human friendly.

While here fix a few other minor errors, and bump date.
2017-03-20 22:17:56 +00:00
kre
ae3f786bf5 That will teach me to commit from the version I've actually
been testing, rather than the "other version" ...
2017-03-20 13:12:35 +00:00
kre
bda1f28d90 PR bin/52090 - fix expansion of unquoted $* 2017-03-20 11:48:01 +00:00
kre
4d6f79f52d Alternative way of writing (part of) the arithmetic lexical analyzer
- committed separately to make it easier to swap back if desired.

This version avoids open coding is_name() and isdigit() - measurements
show it is perhaps fractionally faster (though the difference is so small
as to probably be statistically insignifigant - if I were a statician
I might understand that) and just a little larger than the previous version.
2017-03-20 11:31:00 +00:00
kre
cc8e58edf3 Finish support for all required $(( )) (shell arithmetic) operators,
closing PR bin/50958

That meant adding the assignment operators ('=', and all of the +=, *= ...)
Currently, ++, --, and ',' are not implemented (none of those are required
by posix) but support for them (most likely ',' first) might be added later.

To do this, I removed the yacc/lex arithmetic parser completely, and
replaced it with a hand written recursive descent parser, that I obtained
from FreeBSD, who earlier had obtained it from dash (Herbert Xu).

While doing the import, I cleaned up the sources (changed some file names
to avoid requiring a clean build, or signifigant surgery to the obj
directories if "build.sh -u" was to be used - "build.sh -u" should work
fine as it is now) removed some dashisms, applied some KNF, ...
2017-03-20 11:26:07 +00:00
kre
9d15d213f4 Undo local changes not intended to be committed (and certainly not
with that commit message) in the previous update.   This stuff works,
and will probably appear sometime, but not right now.
2017-03-16 13:21:59 +00:00
kre
d58ec7fc4b Have "make clean" remove sh.html1 and adapt it to clean trace files
the way they have been generated the past 20 years or so...
2017-03-16 13:09:06 +00:00
kre
df029fcc1b Fix for the "${unset-var#$(cmd1)}$(cmd2)" runs the wrong command bug.
... From FreeBSD
2017-03-12 04:19:29 +00:00
rin
1eca2a869b white space 2017-02-06 21:06:04 +00:00
wiz
7754e6dee9 Remove trailing space. 2017-02-04 23:35:15 +00:00
kre
0ff2aa1043 Fiddle the (new) fdflags implementation:
Remove some unnecessary cuteness that limited error reporting.
Permit just one -s arg to fdflags
Be deterministic in the case of fdflags -s +cloexec,-cloexec 0
	(and similar) - use the last specified, always.
Allow:
	FD_0_FLAGS=$( fdflags -v 0 )
	# do stuff, manipulating the flags
	fdflags -s "FD_0_FLAGS" 0
to save/restore flags for a fd.
Correctly mask result of fcntl(fd, F_GETFD) with FD_CLOEXEC as the
specs require before deciding close on exec is set.

Improve portability as a tool, don't assume strtoi(), nor __arraycount()
and avoid needlessly requiring recent C versions (ie: there's no need to
sprinkle declarations in the middle of the code, it just makes them hard
to find, and benefits nothing.)

Still to do:  As currently implemented, both user, and shell internal fds
are reported, and can be manipulated.  Allowing users to touch the shell's
internal fds is bogus, and providing this easy way to allow users to
discover which values they have is poor.   Fixing this means getting rid
of the use of fcntl(F_MAXFD) and replacing it with a shell maintained
memory of what fds the user (script) has allocated.   The shell's fd
manipulation really still needs major work (including properly fixing
bin/48875)
2017-02-03 23:16:38 +00:00
christos
168f1d4a50 Add fdflags builtin. Discussed with Chet and he has implemented it for
bash too.
2017-02-02 20:00:40 +00:00
christos
afa63a6672 Who Ride Wit Us? 2017-02-02 19:26:37 +00:00
christos
9666b979fc Don't let set cloexec for "exec n>&1" like ksh does (but not bash). Unit
tests pass... If we don't like that, we should add some unittests that fail.
2017-01-21 23:03:36 +00:00
maya
f959afb267 reorganize the code so we test if open fails at the open call.
this doesn't actually make a functional difference as ftruncate can
handle it, but it's a bit clearer and appeases static analyzers.

ok riastradh
2017-01-14 18:35:43 +00:00
christos
bad8f1c071 need <time.h> for time(3) 2017-01-10 20:44:05 +00:00
christos
7792ef1ac5 add missing <sys/stat.h> 2017-01-10 20:43:08 +00:00
abhinav
1bd07c5d11 The range of the SS field is [0,60]
From the POSIX time.h man page:
"The formal definition of UTC does not permit double leap seconds, so all mention of double leap seconds has been removed, and the range shortened from the former [0,61] seconds seen in previous versions of POSIX."
2017-01-03 16:01:05 +00:00
rin
f637bb05bd simplify logic; there must be no CPU usage when p_swtime is zero 2016-12-26 20:52:39 +00:00
christos
56b5e39636 Don't trash the logical $PWD if a component is a symlink; no other shell
does this.
2016-12-26 02:27:57 +00:00
christos
6721aabc1e Handle functions that use the offset from either kinfo_proc2/kinfo_lwp properly. 2016-12-12 20:35:36 +00:00
christos
5a6cfab10a provide a tree like display with -d, from FreeBSD 2016-12-02 21:59:03 +00:00
rin
cc1877ba3a Calculate CPU usage (pcpu) once per process if it is required. This change
significantly improves performance for slow machines when output is sorted
by pcpu.

ok martin
2016-11-28 08:21:10 +00:00
rin
b095bb75a7 for donlist{,_sysctl}:
- obtain log_ccpu = log(ccpu) rather than ccpu itself
- use common default values and warn users appropriately when errors occur
ok martin
2016-11-28 08:19:23 +00:00
rin
078edf9ccc KNF
ok martin
2016-11-28 08:18:27 +00:00
abhinav
056b8cc767 Fix grammar in couple of sentences. 2016-10-25 13:01:59 +00:00
abhinav
602eb66c16 Remove unused variables.
Fixes the sh(1) build when DEBUG is enabled.
2016-10-23 08:24:27 +00:00
dholland
f7f12e2d7d PR 49595 William Ahern: The exit status of "unset NOTSET" should be 0, not 1.
(like 48312 but for ksh)
2016-10-11 06:31:07 +00:00
joerg
acfe9a7761 Add explicit char cast to show that the value change is intended. 2016-10-04 15:09:03 +00:00
abhinav
40e3a09c63 kill(1) is a utility, not a function. 2016-10-02 21:00:54 +00:00
sevan
51fe790c4c Drop main() prototype. 2016-09-05 01:00:07 +00:00
sevan
50517541f0 Move the description of CHANGER variable to ENVIRONMENT section
Bump date.
From OpenBSD src/bin/chio/chio.1 r1.23
2016-08-25 18:16:10 +00:00
sevan
90a4f225ec Remove redundant main() prototype which survived a K&R to ANSI transition. 2016-08-23 21:07:40 +00:00
sevan
03fb25d442 Mark email addresses as mailto links, heads up by Sascha Wildner.
Move email addresses to same line as author name.
Do not split the third author entry on to a new line.
Public domain is not licensed by definition, heads up by Robert Elz.
2016-08-23 20:34:23 +00:00
sevan
9e84015020 Instruction to not split the line needs to be stated separately. 2016-08-23 03:21:16 +00:00
sevan
0f2a09011f Add HISTORY section
Credit author of initial implementation in AUTHORS section
Bump date
Remove contraction highlighted by textproc/igor
2016-08-23 02:58:45 +00:00
sevan
b61c439d62 bump date 2016-08-18 22:43:49 +00:00
sevan
6e78a5b106 dd first appeared in V5, not V1
Heads up by Ingo Schwarze
http://www.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s1/dd.c
2016-08-18 22:42:28 +00:00
sevan
ee4aa55280 While the v2 source and man pages are incomplete, TUHS has a scanned copy of the
printed version of the 2nd edition manual. stty is featured in this copy, in the
table of contents listed as meaning "set typewriter modes" and on the actual manual page
headed correctly as "set teletype options"
http://www.tuhs.org/Archive/PDP-11/Distributions/research/1972_stuff/unix_2nd_edition_manual.pdf
Ammend HISTORY and bump date.
2016-08-14 23:29:43 +00:00
sevan
2881adbdf2 While the v2 source and man pages are incomplete, TUHS has a scanned copy of the
printed version of the 2nd edition manual. echo is featured in this copy.
http://www.tuhs.org/Archive/PDP-11/Distributions/research/1972_stuff/unix_2nd_edition_manual.pdf
Ammend HISTORY and bump date.
2016-08-14 22:59:22 +00:00
sevan
7346e185f5 Document the version test first appeared.
Bump date.
2016-08-12 03:17:41 +00:00
sevan
ca8106df5f sync was there from v4.
Confirmed from the TUHS hosted copies of man pages.
2016-08-12 02:59:23 +00:00
sevan
5dee078da5 Document the version stty first appeared.
Bump date.
2016-08-12 02:49:18 +00:00
sevan
0995d1e872 Document the version sleep first appeared.
Bump date.
2016-08-12 02:36:38 +00:00
sevan
a59caebcc3 Document the version rmdir first appeared.
Bump date.
2016-08-12 02:30:37 +00:00
sevan
15dc5a009b Document the version rm first appeared.
Bump date.
2016-08-12 02:26:42 +00:00
sevan
5ca5543cb0 Document the version pwd first appeared.
Bump date.
2016-08-12 02:03:26 +00:00
sevan
324ed4887a Document the version pax first appeared.
Bump date.
2016-08-12 01:52:22 +00:00
sevan
5da349fba4 Bump date 2016-08-11 22:10:01 +00:00
sevan
a0ee124bc7 Earliest reference of kill in the TUHS archive is v3 AT&T UNIX.
Unfortunately only the source code for the compiler is present for that
release. The v2 archive is missing the manuals & only contains a some of the
commands.
Switch to v3 and reference manual category eight.
2016-08-11 21:56:55 +00:00
sevan
176b67f38f Pp not required before Bd, picked up by mandoc lint 2016-08-11 21:41:17 +00:00
sevan
2c701eeaeb Document the version echo first appeared.
Bump date.
2016-08-11 01:47:15 +00:00
sevan
c616fdebbe Document the version dd first appeared.
Bump date.
2016-08-11 01:23:03 +00:00
sevan
787b668508 Pp not required before Bd, picked up by mandoc lint 2016-08-11 01:20:51 +00:00
sevan
ddd300cc05 The macro to cross-reference is Xr, not Xt.
Fix typo error picked up by mandoc lint.
2016-08-11 01:14:01 +00:00
sevan
72d159d520 Document the version date first appeared.
Bump date.
2016-08-11 00:38:06 +00:00
sevan
04e682230f Document the version cp first appeared.
Bump date.
2016-08-11 00:17:23 +00:00
sevan
7813f5cd7c Document the version chmod first appeared.
Bump date.
2016-08-11 00:10:42 +00:00
sevan
76ed85f7b3 Document the first version chio appeared in.
Bump date.
2016-08-10 23:58:16 +00:00
sevan
a836a50237 Mark Jason's name with An macro in AUTHORS section, warned about missing macro
by mandoc lint.
2016-08-10 23:54:20 +00:00
sevan
4b48d1babd Bump date
Reminded by wiz@
2016-08-10 23:48:14 +00:00
sevan
0b822dfa9c Earliest reference in the TUHS archive is v3
Unfortunately only the source code for the compiler is present for that
release. The v2 archive is missing the manuals & only contains a some of the
commands.
Switch to v3 and reference manual category eight, as per r1.32 of
src/bin/ps/ps.1 from OpenBSD.
Heads up from Ingo Schwarze.
2016-08-10 22:00:56 +00:00
sevan
e687bdc5f3 df was there from v1.
Confirmed from the TUHS & cat-v.org hosted copies of man pages.
2016-08-10 18:58:23 +00:00
sevan
abc56c017d Document the version ps first appeared. 2016-08-10 18:44:50 +00:00
sevan
f8e12af4d6 Grammar 2016-08-10 18:42:00 +00:00
sevan
51c1598dae Forgot to bump date with previous commit 2016-08-10 18:08:14 +00:00
sevan
def22cba82 Document the version mv first appeared. 2016-08-10 18:06:54 +00:00
sevan
cf010966fe Document the version mkdir first appeared. 2016-08-10 17:56:32 +00:00
sevan
614e743689 ls was there from v1.
Confirmed from the TUHS & cat-v.org hosted copies of man pages
2016-08-10 17:45:12 +00:00
sevan
2d92cac8a1 ln was there from v1.
Confirmed from the TUHS & cat-v.org hosted copies of man pages
2016-08-10 17:38:39 +00:00
sevan
a275f45a6c C Shell appeared in 2BSD, not 3BSD 2016-08-10 17:16:47 +00:00
sevan
9edf879ce4 When invoked with -se, print a '$' on blank lines
Obtained from OpenBSD r1.13 of src/bin/cat/cat.c

Closes PR bin/51250
Reviewed by Christos@
2016-06-16 00:52:37 +00:00
sevan
f3ad9a4c7a Revert previous change made by me in r1.55 2016-06-16 00:45:37 +00:00
kre
09ccb20143 PR bin/51207 Only check for ELF bnaries in regular files. 2016-06-01 05:11:52 +00:00
kre
cdb38c6b4d PR bin/43639
Redo earlier fix to only prohibit sourcing directories and block special files.
char specials (/dev/tty, /dev/null, ... incl /dev/rwd0a) and fifos are OK.

Posix actually requires that we find only readable files - that is not yet
implemented (doing it sanely, without opening the file twice, is going to
take some more modifications to code elsewhere).
2016-06-01 05:10:41 +00:00
kre
919211f1ab PR bin/47065 PR bin/39466
When the shell exits after an error (when that is the right thing for
it to do) ensure that it never does exit(0).
2016-06-01 02:50:02 +00:00
kre
95edbff793 PR bin/51145 PR bin/48489
More fixes to the shell parser to prevent empty simple commands (where
empty means no significant text at all) - as discussed on tech-userlevel
this still allows { } (which can be useful in function definitions, not
really anywhere else though) except in posix mode.  ( ) now generates
a syntax error, as should any other place where commands are required but
nothing is present.  (nb, redirections, var assignments, even var expansions
that expand to nothing, are all OK, and avoid the error - just comments, or
whits space, are not.)    This is (aside from allowing { } at all) all in
accordance with the posix spec.
2016-06-01 02:47:05 +00:00
dholland
07c23da28f Don't use the length return from snprintf to write out the result
buffer. If snprintf truncated the output, the length returned will be
greater and we'll write trash. Just call strlen instead. (And since
what we're doing is writing progress messages to the user, checking
carefully for truncation isn't really worthwhile either.)

Spotted when attending to PR 50998 from David Binderman; the issue
there (computation of an unused value) popped up because one of the
prints was already calling strlen.
2016-05-31 03:32:36 +00:00
dholland
c1c801b64b Remove undefined behavior in buf(); use buf() as intended in intarg().
While here also add includes to fix the build. Retires PR 50999 from
David Binderman.
2016-05-30 17:34:35 +00:00
dholland
067a182606 PR 50997 David Binderman: fix format strings 2016-05-30 17:26:29 +00:00
dholland
4142c9b7ca usage nit 2016-05-27 05:50:07 +00:00
kre
3b5786dccc More fallout from the fix for PR bin/48875 - this one found just by
code reading, rather than any actual real use case failing.

With this script
	f()
	{
		echo hello $1
	}

	exec 3>&1
	echo $(
		for i in a b c
		do
			echo @$i
			f >&3
		done >/tmp/foo
	)
	echo foo= $(cat /tmp/foo)

what should be output is

	hello
	hello
	hello

	foo= @a @b @c

but since the (my) 48875 fix the other day, we've been getting

	hello
	@b
	hello
	@c
	hello

	foo= @a

This fixes that.   I think (hope) this is the last of these fixes...
2016-05-13 10:32:52 +00:00
kre
698541ceb7 More work on file descriptors... This is the copyfd() cleanup.
copyfd() duplicates file descriptors - it used to be widely used,
but these days has seen its popularity dwindle.   Strip it of an
option that ceased to be variable (simplifying code) and cause all
its users to check its result, so it does not need to handle errors
itself (simplifying code further), and make it become a private inernal
routine in redir.c (all callers from other places have switched to a
more modern interface.)  Make sure we error() if N>&N fails (if N is closed.)
2016-05-12 13:31:37 +00:00
kre
f112b7e1a3 Document that a N>&N (or N<&N) redirection turns off close-on-exec for N
(where N is a decimal fd number) either when used as
	some-command N>&N
(where fd N is passed, open, to some-command - which is obviously what is
wanted)

Or as
	exec N>&N
which effects fd N for all future commands.

Note that this means
	exec N>foo N>&N
returns to the old behaviour of leaving the file descriptor open
when commands are run (as do most shells, other than ksh) and works for
both new and old NetBSD shells (old ones never set close-on-exec, and treat
N>&N as a rather meaingless no-op request, and just ignore it), new ones
set close-on-exec on the first redirection, then disable it again on the
second.

Everything here about >& for output fds applies to <& for input ones.

OK christos@
2016-05-12 13:15:43 +00:00
kre
1755d8e4a6 Fix the implementation of the ?: $(( )) operator. It is right associative...
ok christos@
2016-05-12 13:05:18 +00:00
kre
fa4e47f7be It was twenty(-two) years ago today
J.T. Conklin told us not this way
Berkeley 4.4 lite's changed which file
And it's traced differently all this while
2016-05-11 17:28:30 +00:00
kre
4a9319b47c PR bin/48875 - minor correction (well, not so minor) - commands in loops
must be assumed to have something following, even if the loop itself doesn't,
so redirected fd's around func calls need to be saved.   Should fix etcupdate
2016-05-10 15:14:30 +00:00
kre
8a99e51de9 PR bin/48875 - avoid holding (replaced) file descriptors open when running a
command in the current shell (so they can be restored for the next command)
in cases where it is obvious that there is not going to be a following
command to use them.   This fixes the problem reported in the PR (though
there are still plenty of situations where a FD could be closed but isn't,
we do not do full fd flow eveluation to determine whether a fd will be
used or not).

This is the change that was just committed and then backed out again...

OK christos@
2016-05-09 21:03:10 +00:00
kre
baf83b5f55 Revert previous. These changes are intended to get made (and will
be in a minute or two) but not as part of that commit...   The log
entry certainly does not apply.
2016-05-09 20:55:51 +00:00
kre
07ee700a7e Finish the fd reassignment fixes from 1.43 and 1.45 ... if we are moving
a fd to an unspecified high fd number, we certainly do not want to hand
that high fd off to other processes after an exec, so always set close-on-exec
on the result (even if lack of fd's means no fd alteration happens.)
This will (eventually) allow some other code that sets close-on-exec to
be removed, but for now, doing it twice won't hurt.   Also, in a N>&M
type redirection, do not set close-on-exec if we don't want it.

OK christos@
2016-05-09 20:50:08 +00:00
kre
183536927f PR bin/48489 -- Shell "simple commands" are now not allowed to be
completely empty, they must have something (var assignment, redirect,
or command, or multiple of those) to avoid a syntax error.  This
matches the requirements of the grammar in the standard.   Correct the
parser (using FreeBSD's sh as a guide) and update the man page to
remove text that noted a couple of places this was previously OK.

OK christos@
2016-05-09 20:36:07 +00:00
kre
ed8202014d PR bin/51123 - make >&- work in all cases, and while doing that fix
things so that >/dev/stdout </dev/stdin (etc) work as well (in all cases).

ok christos@
2016-05-08 20:14:27 +00:00
kre
d4f114089f Whitespace fixes. No functional change. 2016-05-08 03:51:15 +00:00
kre
09ecfab926 Slightly improve "jobs" command output in cases where a job includes
embedded background commands or pipelines.   (just slightly...)
OK christos@
2016-05-07 20:07:47 +00:00
kre
3eee147437 PR bin/51119 - don't leak FDs in unusual error cases. OK christos@ 2016-05-07 20:06:30 +00:00
kre
0fe4e12852 Unbreak build ... again... gcc is insane. 2016-05-03 23:55:12 +00:00
kre
3c6d76cd74 PR bin/51114 - print the correct values for >&- and >& N (N > 9)
in output from the "jobs" command (and other places that use the
same routines.)
2016-05-03 20:46:35 +00:00
christos
ddfe742084 add missing forward declaration for the STATIC= case. 2016-05-03 17:21:02 +00:00
kre
404b1d0271 Fix things so that STATIC can me made static (-DSTATIC=static)
and have the shell still compile, link, and run...

ok christos@
2016-05-03 13:47:58 +00:00
kre
a18b822d05 Allow function names to be any shell word not containing '/'.
This allows anything that could be a filesystem command to be
implemented as a function instead.  The restriction on '/'
is because of the way that functions are (required to be) searched
for relative to PATH searching - a function with a name containing '/'
could never be executed, so simply prohibit defining such a thing.

ok christos@
2016-05-03 03:16:55 +00:00
kre
1d68040618 PR bin/43639 - check that a file being read by the '.' command
is a regular file, even when it is given as a full pathname.
2016-05-03 03:12:40 +00:00
kre
54c1af73d6 Remove unnecessary extern var declaration that was a
remnant of an earlier version of the previous (fd>10) fixes.

ok christos@
2016-05-03 03:08:21 +00:00
christos
1fad4bb60c Fix handing of user file descriptors outside the 0..9 range.
Also, move (most of) the shell's internal use fd's to much
higher values (depending upon what ulimit -n allows) so they
are less likely to clash with user supplied fd numbers.  A future
patch will (hopefully) avoid this problem completely by dynamically
moving the shell's internal fds around as needed. (From kre@)
2016-05-02 01:46:31 +00:00
wiz
6b7f9f8932 Remove some double quotes.
Parity is kept.
2016-04-04 13:05:56 +00:00
christos
478a0487ac Allow a heredoc to be positioned outside a `` command substitution.
POSIX just says "here docs begin after the next newline [token]".
Nothing about "provided it is inside any `` the redirect operator
appears in...    As best I can tell, NetBSD now has the only shell to
handle this "correctly" (which raises the question whether it is
correct - but if not, only erroneous scripts are affected.)
This is required by some (probably broken) autoconfigure related
scripts. (from kre@)
2016-04-04 12:39:08 +00:00
mrg
6d27b0e86e for GCC 5.3 pass -fwrapv as this relies upon well-defined integer overflow. 2016-04-01 08:19:31 +00:00
christos
65cf828420 After discussions with Jilles Tjoelker (FreeBSD shell) and
following a suggestion from him, the way the fix to PR bin/50993
was implemented has changed a little.   There are three steps involved
in processing a here document, reading it, parsing it, and then
evaluating it before applying it to the correct file descriptor for
the command to use.  The third of those is not related to this
problem, and has not changed.  The bug was caused by combining the
first two steps into one (and not doing it correctly - which would be
hard that way.)  The fix is to split the first two stages into
separate events.   The original fix moved the 2nd stage (parsing)
to just immediately before the 3rd stage (evaluation.)  Jilles
pointed out some unwanted side effects from doing it that way, and
suggested moving the 2nd stage to immediately after the first.
This commit makes that change.  The effect is to revert the changes
to expand.c and parser.h (which are no longer needed) and simplify
slightly the change to parser.c. (from kre@)
2016-03-31 23:11:05 +00:00
christos
b732ccab17 replace with standard copyright :-) 2016-03-31 16:28:23 +00:00
christos
26427ea787 Document the NETBSD_SHELL variable, the enhancements to export,
the posix option, and a whole bunch of miscellaneous updates and
corrections. (from kre@)
2016-03-31 16:18:22 +00:00
christos
9302f8ef1a Implement the NETBSD_SHELL readonly unexportable unimportable
variable (with its current value set at 20160401) as discussed on
current-users and tech-userlevel. This also includes the necessary
support to implement it properly (particularly the unexportable
part) and adds options to the export command to support unexportable
variables. Also implement the "posix" option (no single letter
equivalent) which gets its default value from whether or not
POSIXLY_CORRECT is set in the environment when the shell starts
(but can be changed just like any other option using -o and +o on
the command line, or the set builtin command.) While there, fix
all uses of options so it is possible to have options that have a
short (one char) name, and no long name, just as it has been possible
to have options with a long name and no short name, though there
are currently none (with no long name).  For now, the only use of
the posix option is to control whether ${ENV} is read at startup
by a non-interactive shell, so changing it with set is not usful
- that might change in the future. (from kre@)
2016-03-31 16:16:35 +00:00
christos
ddf72776f1 PR bin/51027 - fix the parsing of references to shell parameters
when given without braces (ie: $2 etc).  Only the first 9 shell
parameters ($1 .. $9) and the special parameter ($0) can be
referenced this way, $10 is ${1}0 not ${10}.   Make it so.
This bug brought to notice by Sven Mascheck's web pages which
discuss (among other things) the history of this (and other ash
based) shells .. see http://www.in-ulm.de/~mascheck/ (from kre@)
2016-03-31 16:12:52 +00:00
christos
21cf17379f This is an internally visible change - no effect visible to the
user is expected. With the previous commits to parser.c, we no
longer need to handle reading here documents in the (massive)
readtoken1() function. That allows its code to be simplified and
made easier to read and understand (several goto's goto goto heaven.
RIP) (from kre@)
2016-03-31 16:12:09 +00:00
christos
b322b670f0 After discussions with Jilles Tjoelker (FreeBSD shell) and following
a suggestion from him, the way the fix to PR bin/50993 was implemented
has changed a little.   There are three steps involved in processing
a here document, reading it, parsing it, and then evaluating it
before applying it to the correct file descriptor for the command
to use.  The third of those is not related to this problem, and
has not changed.  The bug was caused by combining the first two
steps into one (and not doing it correctly - which would be hard
that way.)  The fix is to split the first two stages into separate
events.   The original fix moved the 2nd stage (parsing) to just
immediately before the 3rd stage (evaluation.)  Jilles pointed out
some unwanted side effects from doing it that way, and suggested
moving the 2nd stage to immediately after the first.  This commit
makes that change.  The effect is to revert the changes to expand.c
and parser.h (which are no longer needed) and simplify slightly
the change to parser.c. (from kre@)
2016-03-31 13:27:44 +00:00
christos
7c8885a4e7 Move the parseredir internal subroutine out of readtoken1() into being
a real function of its own (also inspired by FreeBSD - though for
this one other sh differences require slightly different code.) (from kre@)
2016-03-27 14:40:20 +00:00
christos
1d1484aa26 PR bin/50993 - this is a significant rewrite of the way that here
documents are processed.  Now, when first detected, they are
simply read (the only change made to the text is to join lines
ended with a \ to the subsequent line, otherwise end marker detection
does not work correctly (for here docs with an unquoted endmarker
only of course.)  This patch also moves the "internal subroutine"
for looking for the end marker out of readtoken1() (which had to
happen as readtoken1 is no longer reading the here doc when it is
needed) - that uses code mostly taken from FreeBSD's sh (thanks!)
and along the way results in some restrictions on what the end
marker can be being removed.   We still do not allow all we should.
(from kre@)
2016-03-27 14:39:33 +00:00
christos
1d4fbce984 Cease "support" for <redirect> fn() { ...
Any redirect (or redirects) before a function definition were
allowed by the parser, but otherwise totally ignored.  The standard
syntax does not permit redirects there, now, neither do we. (from kre@)
2016-03-27 14:36:29 +00:00
christos
f9acd92dd8 Finish constifying the new parsebackquote() function. Save a
variable or two...   Should change nothing. (from kre@)
2016-03-27 14:35:30 +00:00
christos
ca12a0b88a General KNF and source code cleanups, avoid scattering the
magic string " \t\n" all over the place, slightly improved
syntax error messages, restructured some of the code for
clarity, don't allow IFS to be imported through the environment,
and remove the (never) conditionally compiled ATTY option.
Apart from one or two syntax error messages, and ignoring IFS
if present in the environment, this is intended to have no
user visible changes. (from kre@)
2016-03-27 14:34:46 +00:00
christos
29494835fd fix constness (from kre) 2016-03-21 02:37:26 +00:00
christos
db56d5516c Move the command substitution "internal subroutine" part of
readtoken1() into a real function of its own (inspired by a
similar change made by FreeBSD - the other internal routines
they moved out are expected to move out here as well soon.)
This change helps avoid gcc 5.3 demanded (not required!) volatile
noise which would slow down parsing. (from kre)
2016-03-20 22:56:39 +00:00
christos
fc55d6ef49 sprinkle more volatile (needed for the rescue build with gcc-5.3) 2016-03-18 18:07:28 +00:00
christos
9c9fb684e0 s/sed/${SED}/ 2016-03-17 13:59:02 +00:00
christos
c6f7781d4f put back the complex sed/awk since the code can't handle unsorted or repeated
entries (Rin Okuyama)
2016-03-17 13:54:31 +00:00
christos
1a51ba6b13 Put back awk, other scripts need it. 2016-03-16 23:02:23 +00:00
christos
702bd67153 We don't need all this magic to build the signals lists. Do the work at
compile time.
2016-03-16 23:01:33 +00:00
christos
90f49946eb Sprinkle volatile for gcc 5! 2016-03-16 22:36:40 +00:00
christos
e448e849b1 Avoid warning by using gcc'ism 2016-03-16 22:36:21 +00:00
christos
c1d7b11ef3 add Will Robinson comment. 2016-03-16 22:35:44 +00:00
christos
b4f0f90a59 Avoid gcc-5 conversion warning (|= expands to int) 2016-03-16 22:25:05 +00:00
christos
0c73873e5c Keep redirs for subshells. 2016-03-16 21:20:59 +00:00
christos
3b6be3a09c parenthesize for safety. 2016-03-16 19:02:26 +00:00
christos
6f9ac0be1e Remove wrong unsigned cast, index can be negative. Cast char to int so that
gcc does not warn. Probably better to do the offset at runtime, but that
would cost more.
2016-03-16 17:01:39 +00:00
christos
58a5df4203 factor out common code in macro. 2016-03-16 15:48:01 +00:00
christos
5f0a664efb Revert (kind of) the change in 1.12 of the ancient mksyntax.sh script
(undoing the effect of that commit on syntax.h when it was
being dynamically generated) from 1996.   This means that the shell
parser is now locale independent, so scripts that work anywhere will
work consistently everywhere.   Inspired by a similar change in
FreeBSD's sh (from 2010) - the original change in the other direction
came from FreeBSD as well....   Note that this does not in any way
add any kind of support for locales to sh (which is a whole different
problem.) (from kre)
2016-03-16 15:45:40 +00:00
christos
8c844a2ebd PR/19832, PR/35423: Fix handling 0x81 and 0x82 characters in expansions
($VAR etc) that are used to generate filenames for redirections. (from kre)
2016-03-16 15:44:35 +00:00
christos
5b34482515 PR/50960: The || and && operators in $(( )) should always have a 0 or 1
result, never anything different. (from kre)
2016-03-16 15:43:38 +00:00
christos
9815d7fee4 PR/50958: (partial fix) - support ?: expressions in arith expansions
(from kre)
2016-03-16 15:42:33 +00:00
christos
fc1f924a3b PR bin/50959 - allow consistent use of 0X hex constants (not just 0x)
(from kre)
2016-03-16 15:41:55 +00:00
christos
2baec48ec5 We want this to work too:
$ cat sep1
	#!/bin/sh
	{ ./sep2; } 3>out

	$ cat sep2
	#!/bin/sh
	echo sep2 >&3

	$ ./sep1
2016-03-13 15:57:30 +00:00
christos
e47a2585c4 dedup. 2016-03-13 01:22:42 +00:00
christos
284daf11ca Test for REDIR_KEEP in the non-copy case:
$ cat other1
	#!/bin/sh
	./other2 3>out

	$ cat other2
	#!/bin/sh
	echo other2 1>&3

	$ ./other1
2016-03-13 00:52:05 +00:00
christos
5047abd140 Don't close-on-exec redirections created explicitly for the command being
ran; i.e. we want this to work:
	$ cat succ1
	#!/bin/sh
	./succ2 6>out

	$ cat succ2
	#!/bin/sh
	echo succ2 >&6

	$ ./succ1

And this to fail:
	$ cat fail1
	#!/bin/sh
	exec 6> out
	echo "fail1" >&6
	./fail2
	exec 6>&-

	$ cat fail2
	#!obj.amd64/sh
	echo "fail2" >&6

	$ ./fail1
	./fail2: 6: Bad file descriptor

XXX: Do we want a -k (keep flag on exec to make redirections not close-on-exec?
2016-03-12 21:35:13 +00:00
christos
f87bc150c8 Improve quoting in the output from sh -x - use less unnecessary
quotes ('_' and '.' do not need quoting) and never quote the '=' in
an assignment (or it would not be one.) From kre, with some refactoring
to be blamed to me.
2016-03-12 14:59:26 +00:00
christos
1dd2c2fdec Move the PPID installation to the init() section. 2016-03-08 23:24:51 +00:00
christos
40cc189704 avoid duplicate includes (from kre) 2016-03-08 23:23:31 +00:00
christos
2c7c3a0713 - don't export $PPID (from kre)
- include <stdio.h>
2016-03-08 18:16:11 +00:00
christos
ae3fe60ef5 Provide $PPID, kill vvers (unused) 2016-03-08 14:32:34 +00:00
christos
65639a43f1 put back some volatile, gcc complains (x86_64) 2016-03-08 14:11:56 +00:00
christos
b506e0ff4c Remove most volatility from readtoken1() restoring execution
speed to approximately where it was before the changes made
in version 1.96 (which assumed this would eventually happen.)
2016-03-08 14:10:04 +00:00
christos
dec2ca90b9 PR bin/50834o: fix expansions of (unquoted) ${unset_var-} and ""$@ (from kre) 2016-03-08 14:09:07 +00:00
christos
bff14f8dfa PR bin/50896: make shift with more than 1 arg give a usage message, from kre 2016-03-08 14:08:39 +00:00
uwe
0d7369c54b The '-i' flag should work regardless of whether the standard input is
a terminal.  The Open Group notes this historic behavior and correctly
notes that it doesn't make much sense.  Note also, that mv(1) has
always respected its '-i' regardless of whether the standard input is
a terminal.

From Timo Buhrmester.
2016-03-05 19:48:55 +00:00
kamil
6b1cac1128 Correct display of df(1) with the -i parameter
Now the "Mounted on" column should be aligned with /entries.

Patch by Michal Mazurek.
2016-03-05 08:15:01 +00:00
christos
fa7bb8d201 PR/50879: David Binderman: remove redundant code. 2016-03-02 19:11:28 +00:00
martin
5902f7d619 Fix wrong condition in previous causing bogus 'Use "exit" to leave
shell.' messages (from kre)
2016-03-01 21:10:40 +00:00
christos
476468ab31 Even more debugging improvements (from kre) 2016-02-29 23:52:04 +00:00
christos
a584b40f8d Complete implementation of the noexec option (-n) including
disabling noexec, if the shell is interactive, each time that
a new command is about to be read.  Also correct the -I
(ignoreeof) option so that it only applies to interactive shells,
as required by posix. (from kre)
2016-02-29 23:51:36 +00:00
christos
8cfa226b64 delete clauses 3,4 2016-02-29 23:50:59 +00:00
mrg
9bb33dce89 for display in the (post) SIGINFO handler use off_t not size_t for
file sizes.  fixes incorrect reporting errors on 32 bit platforms
with >4GB file sizes.
2016-02-29 04:22:21 +00:00
christos
0c52b5f165 Bug fixes to handling of unterminated here documents
(they should be, and now are, a syntax error), and
miscellaneous other minor cleanups. (from kre)
2016-02-28 23:12:23 +00:00
mrg
0f6eb69275 add SIGINFO for mv(1), largely based upon the support in cp(1). 2016-02-28 10:59:29 +00:00
christos
ed090bddf8 More nodenames fixes. 2016-02-27 23:50:13 +00:00
christos
bc8cfb7d77 Improve debugging, from kre (I hooked it to the build). 2016-02-27 18:34:12 +00:00
christos
78204bbf10 remove useless casts 2016-02-27 16:28:50 +00:00
christos
d73fcc53c6 CID 1354293: handle EOF 2016-02-27 16:23:22 +00:00
wiz
4cf0de9860 file system police. 2016-02-24 15:28:36 +00:00
christos
8b2383fc90 PR/46327: David Mandelberg: Fix exit codes of background jobs (from kre) 2016-02-24 14:57:12 +00:00
christos
59f04ac937 Simple script to create node names for debugging 2016-02-24 14:51:20 +00:00
christos
750aa9221b If we don't have shared address space vfork fail back to using fork since
we are depending on the shared address space feature (from kre)
2016-02-24 14:38:40 +00:00
christos
57f3725a64 Make sh.1 catch up with reality. Document -h (such as it is...)
and also added doc for some other stuff that was missing.

Take the opportunity to clean up the way the flags are set in the
man page, so every new flag doesn't have to be added 6 times!
(Some of the lists were different from others, in ordering, and
content, for no good reason at all.)

Make a few other cleanups ... Add text about AND-OR lists,
This can be also used to justify closing an open PR:
(that "sh -c 'command &&'" is not a syntax error...).

Add doc for -F, which should default to set if the shell somehow
gets compiled without DO_SHAREDVFORK defined, (to be committed
separately)

XXX: Consider disabling DO_SHAREDVFORK if SMALL is defined?

From kre
2016-02-24 14:35:51 +00:00
christos
95b061168f name the long option after the ksh name (trackall) to indicate the intended
posix behavior not the bash one.
2016-02-23 18:30:16 +00:00
christos
a9d1a1847c update that -n is implemented and add -h using the long name that bash
uses. (from kre, long name from me)
2016-02-23 16:22:43 +00:00
christos
aeba4f7b70 Fix quoting inside heredoc's. (from kre) 2016-02-23 14:51:25 +00:00
christos
9e6b737d5a PR/43255: Make -n apply to the -c string so sh -n -c 'commands' works
as it should. Also, other places where the shell parses strings of
commands are also now controlled by -n (traps, eval, ...)  (from kre)
2016-02-22 20:03:48 +00:00
christos
606614c83d PR bin/43469 - correctly handle quoting of the pattern part of ${var%pat}
type expansions. (from kre)
2016-02-22 20:02:00 +00:00
christos
863fff4621 Fix for PR bin/48631 - allow commands controlled
by case statements to be nothing more than redirects (from kre)
2016-02-22 19:42:46 +00:00
christos
b8f416fe8e Finish the fix for PR/48631 - that is, make the parser correctly
handle the token syntax it really should be handling (including
some that posix does not require, but is right anyway.) This is
quite similar to, and to some extent inspired by the way the FreeBSD
sh parser.c works, but the actual implementation is quite different.
(from kre)
2016-02-22 19:38:10 +00:00
christos
87624d803c KNF / whitespace fixes. No changes of substance. (from kre) 2016-02-22 19:25:26 +00:00
christos
2f573a20ed PR/50827: Richard Hansen: Fix default variable assignment with arithmetic,
from kre.
2016-02-19 13:50:37 +00:00
christos
ac40619997 PR/50747: David Binderman: check bounds before dereference.
While here add some continues before semicolons.
2016-02-03 05:26:16 +00:00
christos
ded9763f6b PR/50734: David Binderman: check bounds before dereferencing. 2016-02-01 17:34:00 +00:00
wiz
29ce88a214 Whitespace. 2016-01-06 00:22:21 +00:00
christos
30042120ad Document close-on-exec redirection behavior. 2016-01-05 18:16:20 +00:00
christos
0a9b959049 PR/50619: Fix reversed test. 2016-01-04 13:57:15 +00:00
christos
d18385a5a2 Don't leak redirected rescriptors to exec'ed processes. This is what ksh
does, but bash does not. For example:

    $ cat test1
    #!/bin/sh
    exec 6> out
    echo "test" >&6
    sh ./test2
    exec 6>&-
    $ cat test2
    echo "test2" >&6
    $ ./test1
    ./test2: 6: Bad file descriptor

This fixes by side effect the problem of the rc system leaking file descriptors
7 and 8 to all starting daemons:

    $ fstat -p 1359
    USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
    root     powerd      1359   wd /              2 drwxr-xr-x     512 r
    root     powerd      1359    0 /          63029 crw-rw-rw-    null rw
    root     powerd      1359    1 /          63029 crw-rw-rw-    null rw
    root     powerd      1359    2 /          63029 crw-rw-rw-    null rw
    root     powerd      1359    3* kqueue pending 0
    root     powerd      1359    4 /          64463 crw-r-----   power r
    root     powerd      1359    7 flags 0x80034<ISTTY,MPSAFE,LOCKSWORK,CLEAN>
    root     powerd      1359    8 flags 0x80034<ISTTY,MPSAFE,LOCKSWORK,CLEAN>
    root     powerd      1359    9* pipe 0xfffffe815d7bfdc0 -> 0x0 w

Note fd=7,8 pointing to the revoked pty from the parent rc process.
2016-01-04 03:00:24 +00:00
christos
b357ba3056 We don't have RLIMIT_SWAP 2015-12-30 22:26:26 +00:00
wiz
c78bed405e Remove trailing whitespace. 2015-12-19 18:48:41 +00:00
wiz
2c25669eb0 Use An in AUTHORS section. 2015-12-19 18:48:33 +00:00
christos
015658bfe0 Add the timestamp option to the pax front end. 2015-12-19 18:45:52 +00:00
christos
9158fb657d PR/50119: Thomas Klausner: Add --timestamp option to tar. 2015-12-19 18:28:54 +00:00
christos
3296beefcd PR/50422: Robert Elz: df -G prints the wrong value for fragsize (+FIX)
For df -G, print the block and fragment size instead of the iosize
and the blocksize. If we need to print the iosize, it should be done
in a different field. Nevertheless printing the blocksize in the fragment
size field is just wrong.
XXX: pullup-6, pullup-7
2015-11-12 17:59:21 +00:00
wiz
349f15a5e8 Use An in AUTHORS section. 2015-11-04 09:24:14 +00:00
pgoyette
4a0bba4840 By my count, [[[[[cc]yy]mm]dd]hh]mm[.ss] has seven fields, not six! 2015-11-03 03:01:35 +00:00
joerg
09dfb13f83 Be explicit about what is negated. 2015-08-28 11:29:48 +00:00
christos
19d6b8392c PR/50179: Timo Buhrmester: sh(1) variable expansion bug 2015-08-27 07:46:47 +00:00
christos
f95d5940cc report the signal that wait was interrupted by, which is not always SIGINT
anymore.
2015-08-22 12:12:47 +00:00
christos
c0195771da Process pending signals while waiting for a job:
$ cat << EOF > hup.sh
    #!/bin/sh
    trap 'echo SIGHUP; exit 1' 1
    sleep 10000 &
    wait
    EOF
    $ chmod +x ./hup.sh
    $ ./hup.sh &
    $ kill -HUP %1
2015-08-22 09:55:23 +00:00
sevan
bf748072f6 Drop the case '?' which is defined after case 'default'.
case 'default' statement introduced in the last commit to cat.c in the CSRG archive.
Obtained from OpenBSD bin/cat/cat.c r1.3.
2015-07-25 16:17:01 +00:00
wiz
dfb9651eda Add serial comma, use upper case for abbreviation, and remove apostrophe for plural. 2015-06-28 16:22:54 +00:00
christos
7da746ab02 remove \n from error messages 2015-06-16 22:31:08 +00:00
joerg
3eb04a3615 Use an explicit body for a "until not EINTR" loop. 2015-06-06 15:22:58 +00:00
christos
ac33f4ea5e Drop privileges when executed set{u,g}id unless -p is specified like other
shells do to avoid system() and popen() abuse.
2015-05-26 21:35:15 +00:00
joerg
66e60a49ac Include printf by default even for SMALL builds. It is used e.g. by
dhcpcd and as such required by most ramdisk images. Allow turning it off
again by TINYPROG.
2015-05-10 20:30:54 +00:00
christos
9c27fd2a44 CID 1225078: check getrlimit return 2015-05-09 13:28:55 +00:00
christos
f49d3ada41 CID 1225088: check return of getrlimit 2015-05-09 13:26:06 +00:00
christos
4b6d6c838f CID 1225077: check getrlimit return 2015-05-09 13:22:37 +00:00
christos
78d721faf9 Simplify by splitting the "simple" mode setting and the "special" ones. 2015-05-01 17:01:08 +00:00
jmcneill
fa0ed62f53 document ulimit -r 2015-04-12 17:05:03 +00:00
wiz
5fe5275d9f Use An in AUTHORS section. 2015-04-11 16:22:07 +00:00
christos
23c362a5b1 Add -J/--xz to specifically decompress xz compressed files. We don't really
need this because -z autodetects the compression format; this is for syntax
compatibility with other tar implementations. From Joachim Henke
2015-04-11 15:41:33 +00:00
wiz
bb4a52d96c New sentence, new line. Fix typos. Bump date for previous. 2015-03-18 13:30:13 +00:00
manu
ea3c6ee530 Add iflag and oflag operands to dd(1)
Like GNU dd(1) similar operands, iflag and oflag allow specifying the
O_* flags given to open(2) for the input and the output file. The values
are comma-sepratated, lower-case, O_ prefix-stripped constants documented
in open(2).

Since iflag and oflag override default values, specifying oflag means
O_CREATE is not set by default and must be specified explicitely.

Some values do not make sense (e.g.: iflag=directory) but are still used
and will raise a warning. For oflag, values rdonly, rdwr and wronly are
filtered out with a warning (dd(1) attempts open(2) with O_RDWR and
then O_WRONLY on failure).

Specifying oflag=trunc along with (seek, oseek or conv=notrunc) is
contradictory and will raise an error.

iflag and oflag are disabled if building with -DMALLPROG
2015-03-18 13:23:49 +00:00
sevan
7c1a019ea3 From OpenBSD r1.49
Fix comment grammar
2015-03-09 23:38:08 +00:00
enami
80c6af722d Fix the name of failed function in warning message. 2015-03-03 00:20:38 +00:00
enami
c1e351a1b2 Don't truncate at microseconds while preserving timestamps.
One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html
2015-03-02 03:17:24 +00:00
joerg
14bd6a1392 Make cast warnings for clang non-fatal. 2015-01-29 20:46:31 +00:00
christos
334f5d77c6 Define an undocumented -F option to only use fork instead of vfork for
debugging purposes.
2015-01-02 19:56:20 +00:00
joerg
0bab8dfecf Use l_wmesg if the string is not empty. Don't bother checking l_name for
nullness.
2014-11-15 01:58:34 +00:00
christos
9e91d16823 simplify and eliminate TOCTOU. 2014-10-23 21:03:25 +00:00
jschauma
8e9bed0cec Remove the confusing reference to 'file sizes' in the short description of
the '-l' flag.  As explained in the Long Format section, the total is of
the blocks used by the files, and only applies to directories.
2014-10-18 01:49:01 +00:00
christos
a25724438f PR/48201: Miwa Susumu: Fix set -C (no clobber) for POSIX; from FreeBSD
Can't use O_EXCL because of device nodes; also truncate.
2014-10-15 14:54:25 +00:00
dholland
33586bcc4e Provide real error messages.
Inspired by PR 49169 from David H. Gutteridge, but a much broader patch :-)
2014-09-01 21:42:21 +00:00
christos
5cad352e4f remove unused assignment 2014-08-29 09:35:19 +00:00
christos
d03f4b6b66 Eat trailing backslash like bash and pdksh (not zsh). CBACK+CEOF = TEOF 2014-08-29 09:26:39 +00:00
christos
7de48e21c0 PR/49125: Havard Eidnes: /bin/sh does not support redirecting to or from FDs > 9
According to:
http://pubs.opengroup.org/onlinepubs/009604599/utilities/xcu_chap02.html#tag_02_07

Redirection support for fds > 9 is optional but allowed.
2014-08-19 12:36:58 +00:00
joerg
694cb36aee Fix RCS ID. 2014-08-08 14:48:55 +00:00
dholland
d54dab14a9 remove .if make(install) 2014-07-05 23:13:41 +00:00
dholland
076d336118 remove .if make(install)
these are seriously bad juju
2014-07-05 23:12:33 +00:00
dholland
dcc711d503 Reorg docs, part 2:
Rename the following reference documents to match their programs:
   shell -> sh
   viref -> vi

and rename the following to match their topic better:
   ipctut -> sockets
   ipc -> sockets-advanced

Also, the old "timed" and "timedop" docs are now ref5/timed and
ref8/timed respectively, as the first of these documented the
protocol.
2014-07-05 19:23:00 +00:00
dholland
b7b7574d3b Reorg docs, part 1:
Move all the reference manuals to subdirs of /usr/share/doc/reference.
We have subdirs ref1-ref9, corresponding to man page sections 1-9.

Everything that's the reference manual for a program (sections 1, 6,
8), C interface (sections 2, 3), driver or file system (section 4),
format or configuration (section 5), or kernel internal interface
(section 9) belongs in here.

Section 7 is a little less clear: some things that might go in section
7 if they were a man page aren't really reference manuals. So I'm only
putting things in reference section 7 that are (to me) clearly
reference material, rather than e.g. tutorials, guides, FAQs, etc.
This obviously leaves some room for debate, especially without first
editing the docs with this distinction in mind, but if people hate
what I've done things can always be moved again.

Note also that while roff macro man pages traditionally go in section
7, I have put all the roff documentation (macros, tools, etc.) in one
place in reference/ref1/roff. This will make it easier to find and
also easier to edit it into some kind of coherent form.
2014-07-05 19:22:41 +00:00
dholland
c3ab26950f Rework /usr/share/doc.
Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
   - explicit use of soelim
   - refer
   - tbl
   - pic
   - eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
2014-07-05 19:22:02 +00:00
dholland
f86ebf3938 Don't print junk errnos. Avoids:
% ps -tfoo
  ps: /dev/ttyfoo: Undefined error: 0
  Exit 1
2014-06-28 17:32:27 +00:00
christos
f032129312 Adjust to the new alias text libedit API. 2014-06-18 18:17:30 +00:00
wiz
a5aae24aeb Bump date for previous. 2014-06-15 07:27:22 +00:00
dbj
2b213458d4 update list of flags which are extensions to the specification 2014-06-15 07:00:24 +00:00
mrg
26f35dd6b6 remove the build support for GCC 4.1, and any hacks i found for it.
there could still be more -- i only looked for lines matching
both "HAVE_GCC" and "4" as words (grep -w.)
2014-06-13 01:17:45 +00:00
christos
2e317a68f7 PR/48843: Jarmo Jaakkola: Soften the language in the manual page,
making less promises about behavior not explicitly stated in the standard.
2014-06-01 17:46:06 +00:00
christos
01f35fcceb PR/48843: Jarmo Jaakkola: dot commands mess up scope nesting tracking
Evaluation of commands goes completely haywire if a file containing
a break/continue/return command outside its "intended" scope is sourced
using a dot command inside its "intended" scope.  The main symptom is
not exiting from the sourced file when supposed to, leading to evaluation
of commands that were not supposed to be evaluated.  A secondary symptom
is that these extra commands are not evaluated correctly, as some of them
are skipped.  Some examples are listed in the How-To-Repeat section.

According to the POSIX standard, this is how it should work:
    dot:
        The shell shall execute commands from the file in the current
        environment.
    break:
        The break utility shall exit from the smallest enclosing for, while,
        or until loop, [...]
    continue:
        The continue utility shall return to the top of the smallest
        enclosing for, while, or until loop, [...]
    return:
        The return utility shall cause the shell to stop executing
        the current function or dot script.  If the shell is not currently
        executing a function or dot script, the results are unspecified.

It is clear that return should return from a sourced file, which
it does not do.  Whether break and continue should work from the sourced
file might be debatable.  Because the dot command says "in the current
environment", I'd say yes.  In any case, it should not fail in weird
ways like it does now!

The problems occur with return (a) and break/continue (b) because:
    1)  dotcmd() does not record the function nesting level prior to
        sourcing the file nor does it touch the loopnest variable,
        leading to either
    2   a) returncmd() being unable to detect that it should not set
           evalskip to SKIPFUNC but SKIPFILE, or
        b) breakcmd() setting evalskip to SKIPCONT or SKIPBREAK,
        leading to
    3)  cmdloop() not detecting that it should skip the rest of
        the file, due to only checking for SKIPFILE.
The result is that cmdloop() keeps executing lines from the file
whilst evalskip is set, which is the main symptom.  Because
evalskip is checked in multiple places in eval.c, the secondary
symptom appears.
>How-To-Repeat:
Run the following script:

    printf "break\necho break1; echo break2" >break
    printf "continue\necho continue1; echo continue2" >continue
    printf "return\necho return1; echo return2" >return

    while true; do . ./break; done

    for i in 1 2; do . ./continue; done

    func() {
        . ./return
    }
    func

No output should be produced, but instead this is the result:
    break1
    continue1
    continue1
    return1

The main symptom is evident from the unexpected output and the secondary
one from the fact that there are no lines with '2' in them.
>Fix:
Here is patch to src/bin/sh to fix the above problems.  It keeps
track of the function nesting level at the beginning of a dot command
to enable the return command to work properly.

I also changed the undefined-by-standard functionality of the return
command when it's not in a dot command or function from (indirectly)
exiting the shell to being silently ignored.  This was done because
the previous way has at least one bug: the shell exits without asking
for confirmation when there are stopped jobs.

Because I read the standard to mean that break and continue should have
an effect outside the sourced file, that's how I implemented it.  For what
it's worth, this also seems to be what bash does.  Also laziness, because
this way required no changes to loopnesting tracking.  If this is not
wanted, it might make sense to move the nesting tracking to the inputfile
stack.

The patch also does some clean-up to reduce the amount of global
variables by moving the dotcmd() and the find_dot_file() functions from
main.c to eval.c and making in_function() a proper function.
2014-05-31 14:42:18 +00:00
martin
062900c4c2 PR bin/48798: fix format for ino_t.
Slightly modifed variant of the patch provided by Thomas Schmitt.
2014-05-10 09:39:18 +00:00
dholland
a468ec4988 Don't bother using variables whose value is never changed from the
initialization value.
2014-04-20 23:31:40 +00:00
dholland
4e3b1a0bd4 Use an enum type for PRINTMODE vs. WIDTHMODE. Compiler output diffs have
been checked.
2014-04-20 22:48:59 +00:00
christos
318c2b5cda PR/48729: Torbjörn Granlund: Avoid negative index in array ref. 2014-04-11 01:49:45 +00:00
wiz
b0b52b7f33 Wording improvement for previous.
From jmc@OpenBSD via Igor Sobrado.
2014-04-02 19:54:30 +00:00
wiz
ac632886e5 Apply diff from Igor Sobrado <isd@orion.ciencias.uniovi.es>:
We have written a diff to our ls(1) to recover the traditional behaviour
of -f implying -a.  This change does not only accommodates POSIX.1
but also matches traditional UNIX.

OpenBSD commit message:

CVSROOT:        /cvs
Module name:    src
Changes by:     sobrado@cvs.openbsd.org 2014/03/31 14:54:37

Modified files:
        bin/ls         : ls.1 ls.c

Log message:
restore the traditional behavior of -f implying -a; apparently Keith Bostic
forgot to restore it when the -f flag was put back on 2nd of September 1989,
after being removed on 16th of August as a consequence of issues getting it
working over NFS, so deviation from traditional UNIX behavior in all BSDs
looks like an historical accident; as a side effect, this change accommodates
behavior of this option to IEEE Std 1003.1-2008 (``POSIX.1'').

joint work with jmc@ (who found the inaccuracy in our implementation),
schwarze@ (who provided a detailed tracking of historical facts) and millert@

ok millert@, schwarze@
2014-04-02 10:55:47 +00:00
christos
e8c3f5b299 PR/48692: Henning Petersen: Missplaced paranthesis in bin/ed gbl.c and main.c 2014-03-31 12:55:46 +00:00
joerg
f18d1e6774 Use __printflike. 2014-03-25 17:23:37 +00:00
dholland
c4044741ea don't use sprintf 2014-03-23 05:07:59 +00:00
dholland
a3542600fb sprintf considered harmful 2014-03-23 05:06:42 +00:00
mlelstv
fa4d72b17c fix -w output 2014-02-22 13:11:42 +00:00