Commit Graph

2846 Commits

Author SHA1 Message Date
Jilles Tjoelker
422c281c83 sh: Use C99 flexible array instead of accessing array beyond bounds.
Although sufficient memory is available for a longer string in cmdname,
this is undefined behaviour anyway.

Side effect: for alignment reasons, an additional byte of memory is
allocated per hashed command.
2012-11-03 22:23:08 +00:00
Joel Dahl
8850c7d71f Add a couple of examples.
Obtained from:	OpenBSD
2012-11-02 22:32:47 +00:00
Ed Schouten
eccad22277 More -Wmissing-variable-declarations fixes.
In addition to adding missing `static' keywords:
- bin/dd: Pull in `extern.h' to guarantee consistency with source file.
- libexec/rpc.rusersd: Move shared globals into an extern.h.
- libexec/talkd: Move `debug' and `hostname' into extern.h.
- usr.bin/cksum: Put counters in extern.h, as they are used by ckdist/mtree.
- usr.bin/m4: Move `end_result' into extern.h.
- usr.sbin/services_mkdb: Move shared globals into an extern.h.
2012-10-20 10:33:15 +00:00
Ed Schouten
bf70becee6 More -Wmissing-variable-declarations fixes.
In addition to adding `static' where possible:

- bin/date: Move `retval' into extern.h to make it visible to date.c.
- bin/ed: Move globally used variables into ed.h.
- sbin/camcontrol: Move `verbose' into camcontrol.h and fix shadow warnings.
- usr.bin/calendar: Remove unneeded variables.
- usr.bin/chat: Make `line' local instead of global.
- usr.bin/elfdump: Comment out unneeded function.
- usr.bin/rlogin: Use _Noreturn instead of __dead2.
- usr.bin/tset: Pull `Ospeed' into extern.h.
- usr.sbin/mfiutil: Put global variables in mfiutil.h.
- usr.sbin/pkg: Remove unused `os_corres'.
- usr.sbin/quotaon, usr.sbin/repquota: Remove unused `qfname'.
2012-10-19 14:49:42 +00:00
Ed Schouten
ae824d80f2 Fix warnings found by -Wmising-variable-declarations.
This self-written compiler warning, which is hopefully going to be
committed into LLVM sources soon, warns about potentially missing
`static' keywords, similar to -Wmissing-prototypes.

- bin/pax: Move external declaration of chdname and s_mask into extern.h.
- bin/setfacl: Move setfacl.c-specific stuff out of setfacl.h.
- sbin/mount_fusefs: Remove char *progname; use getprogname().
- others: add `static' where possible.
2012-10-19 05:43:38 +00:00
Joel Dahl
a2442c2fa9 mdoc: don't nest displays. The markup here isn't adding anything anyway.
Fixes a mandoc lint warning.

Discussed with:	brueffer, Jason McIntyre <jmc@kerhand.co.uk>
2012-10-14 13:59:17 +00:00
Matthew D Fleming
6db1a7f11e Fix bin/ build with a 64-bit ino_t.
Original code by:	Gleb Kurtsou
2012-09-27 23:31:12 +00:00
Andrey Zonov
08c62f8deb - Bump date.
Submitted by:	pluknet
Approved by:	kib (mentor)
X-MFC-With:	r240645
2012-09-18 13:24:14 +00:00
Andrey Zonov
38f2be1c54 - Add 'dsiz' and 'ssiz' keywords to show data and stack size respectively.
Approved by:	kib (mentor)
MFC after:	1 week
2012-09-18 12:25:14 +00:00
Eitan Adler
65e415b16e Revert 240527:
mntbuf can poit to memory allocated by getmntinfo(3) which can't be freed

PR:		bin/171634
Approved by:	cperciva (implicit)
2012-09-16 16:08:20 +00:00
Jilles Tjoelker
7cbda73825 sh: Prefer internal nextopt() to libc getopt().
This reduces code duplication and code size.

/usr/bin/printf is not affected.

Side effect: different error messages when certain builtins are passed
invalid options.
2012-09-15 21:56:30 +00:00
Eitan Adler
c5c62e5900 Free memory before exiting in order to
help tools understand that we're not leaking it.

PR:		bin/171634
Submitted by:	Erik Cederstrand <erik@cederstrand.dk>
Approved by:	cperciva
MFC after:	3 days
2012-09-14 23:47:23 +00:00
Jilles Tjoelker
d902a66b99 sh: Reduce code duplication: use setinputfile instead of open/setinputfd
combination.

MFC after:	2 weeks
2012-09-14 15:22:15 +00:00
Joel Dahl
afc5a69a1d Minor mdoc fix. 2012-09-11 17:57:03 +00:00
Jilles Tjoelker
36f7fbeae8 sh: Remove XXX comment about removing nextopt().
Using nextopt() avoids depending on the BSD-specific optreset feature in
getopt() and reduces code size (both source and binary).
2012-09-08 19:24:03 +00:00
Kevin Lo
d11ed2f6de Use "e.g.", not "i.e.", to introduce an example.
Obtained from:	NetBSD
2012-09-07 09:00:25 +00:00
Edward Tomasz Napierala
c55e0c62a1 Explicitly mention that "cp -p" copies ACLs.
PR:		docs/168962
MFC after:	1 month
2012-09-04 12:27:23 +00:00
Edward Tomasz Napierala
6e924edbde Fix an error in setfacl(1) that manifested like this:
# setfacl -m u:trasz:rwx x
# setfacl -m u:root:rwx x
# getfacl x
# file: x
# owner: root
# group: wheel
user::rw-
user:root:rwx
user:trasz:rwx
group::r--
mask::rwx
other::r--
# setfacl -m u:root:rwx x
setfacl: x: acl_calc_mask() failed: Invalid argument
setfacl: x: failed to set ACL mask

For NFSv4 ACLs, this sort of situation would result in duplicated
entries.

MFC after:	1 month
2012-09-04 12:19:34 +00:00
Edward Tomasz Napierala
e99fc4b0f8 In getfacl(1) manual page, mention where to read about the ACL syntax.
PR submitter suggested adding it to acl(3) instead, but I don't think
pointing ordinary users at section 3 is a good idea.

PR:		docs/162380
MFC after:	1 month
2012-09-04 12:02:23 +00:00
Edward Tomasz Napierala
8ed068d31c Make "setfacl -bd" an alias for "setfacl -k". Previously it would crash
on assert.

PR:		bin/165807
MFC after:	1 month
2012-09-04 11:50:13 +00:00
Edward Tomasz Napierala
00b2b3a55d Make setfacl(1) behave properly in situations like "setfacl -kd".
MFC after:	1 month
2012-09-04 11:43:00 +00:00
Edward Tomasz Napierala
9828700277 Fix compact form of "synchronize" permission in setfacl(1) manual page - it
should be "s", not "S".

PR:		docs/162380
MFC after:	2 weeks
2012-09-03 17:26:20 +00:00
Ed Schouten
902d9eafbf Rework all non-contributed files that use `struct timezone'.
This structure is not part of POSIX. According to POSIX, gettimeofday()
has the following prototype:

	int gettimeofday(struct timeval *restrict tp, void *restrict tzp);

Also, POSIX states that gettimeofday() shall return 0 (as long as tzp is
not used). Remove dead error handling code. Also use NULL for a
nul-pointer instead of integer 0.

While there, change all pieces of code that only use tv_sec to use
time(3), as this provides less overhead.
2012-09-01 14:45:15 +00:00
John Baldwin
6ce6b6c1d4 Add a -h flag similar to the -h flag for ln to force mv(1) to treat a
symbolic link to a directory for the target as a symbolic link instead of
a directory.  This makes it possible to atomically update a symbolic
link using rename().

Reviewed by:	gj
MFC after:	2 weeks
2012-08-31 14:35:01 +00:00
Ed Maste
4285666880 Avoid passing uninitialized stack to addelem() if called with an empty arg.
PR:		bin/171174
2012-08-29 21:38:34 +00:00
Jilles Tjoelker
1794251add sh: Fix EINTR race condition in "wait" and "set -T" using sigsuspend().
When waiting for child processes using "wait" or if "set -T" is in effect, a
signal interrupts the wait. Make sure there is no window where the signal
handler may be invoked (setting a flag) just before going to sleep.

There is a similar race condition in the shell language, but scripts can
avoid it by exiting from the trap handler or enforcing synchronization using
a fifo.

If SIGCHLD is not trapped, a signal handler must be installed for it. Only
install this handler for the duration of the wait to avoid triggering
unexpected [EINTR] errors elsewhere.

Note that for some reason only SIGINT and SIGQUIT interrupt a "wait"
command. This remains the case.
2012-07-29 18:04:38 +00:00
Jilles Tjoelker
fb05913c5d sh: Do not ask for stopped/continued processes if we do not need them
rather than retrying wait3 if they happen.
2012-07-28 15:13:48 +00:00
Jilles Tjoelker
61fb716ac9 sh: Inline waitproc() into its only caller. 2012-07-28 14:56:50 +00:00
Jilles Tjoelker
faa787d323 sh: Track continued jobs (even if not continued by bg or fg).
This uses wait3's WCONTINUED flag.

There is no message for this. The change is visible in "jobs" or if the job
stops again.
2012-07-28 14:32:55 +00:00
Jaakko Heinonen
e3481b298a Use proper error message when fstat(2) fails on stdout.
PR:		bin/159746
Submitted by:	Alex K.
2012-07-20 08:33:23 +00:00
Jaakko Heinonen
67bf019b10 style(9). 2012-07-20 08:31:36 +00:00
Jilles Tjoelker
989006abe5 stty: Mark usage() __dead2.
This reduces code size a little and should fix a scan-build warning.
2012-07-15 21:12:22 +00:00
Jilles Tjoelker
2aff415a8c ps: Fix memory leak when showing start/lstart for swapped-out process.
Spotted by:	scan-build (uqs)
2012-07-15 15:22:13 +00:00
Jilles Tjoelker
fa7ccda2c4 sh: Reset pendingsigs before checking pending traps, not after.
Otherwise, a signal arriving at exactly the right moment might not be
processed until another signal arrived.
2012-07-15 11:18:52 +00:00
Jilles Tjoelker
184dcee217 sh: Remove unused variable in_dowait. 2012-07-15 10:49:16 +00:00
Jilles Tjoelker
84fbdd8ca0 sh: Expand assignment-like words specially for export/readonly/local.
Examples:
  export x=~
now expands the tilde
  local y=$1
is now safe, even if $1 contains IFS characters or metacharacters.

For a word to "look like an assignment", it must start with a name followed
by an equals sign, none of which may be quoted.

The special treatment applies when the first word (potentially after
"command") is "export", "readonly" or "local". There may be quoting
characters but no expansions. If "local" is overridden with a function there
is no special treatment ("export" and "readonly" cannot be overridden with a
function).

If things like
  local arr=(1 2 3)
are ever allowed in the future, they cannot call a "local" function. This
would either be a run-time error or it would call the builtin.

This matches Austin Group bug #351, planned for the next issue of POSIX.1.

PR:		bin/166771
2012-07-15 10:19:43 +00:00
Pedro F. Giffuni
00c43e0ca4 Merge libedit adjustment from NetBSD.
On recent versions of NetBSD's libedit, el_gets
now sets el_len to -1 on error so we can
distinguish between a NULL string and an error.

This fixes sh from exiting with newer versions
of libedit now allowing EINTR to return.

Obtained from:	NetBSD
Reviewed by:	jilles
MFC after:	3 weeks
2012-07-11 22:17:58 +00:00
Xin LI
930e323894 Polish previous revision: if the fts_* routines have lstat()'ed the
directory entry then use the struct stat from that instead of doing
it again, and skip the rm_overwrite() call if fts_read() indicated
that the entry couldn't be a regular file.

Obtained from:	OpenBSD
MFC after:	1 week
2012-06-20 21:10:38 +00:00
Kevin Lo
4ec1405b39 Fix potential symlink race condition in "rm -P" by adding a check
that the file we have opened is the one we expected.  Also open in
non-blocking mode to avoid a potential hang with FIFOs.

Obtained from:	NetBSD via OpenBSD
2012-06-20 02:21:53 +00:00
Dag-Erling Smørgrav
7aa2051e40 None of these programs actually use auth.conf.
MFC after:	1 week
2012-06-11 16:18:39 +00:00
Marcel Moolenaar
937b0a997b Work better with how make/bmake works:
1.  Avoid a cd back into ${.CURDIR} to run mkbuiltins when we know make
    will first cd into ${.OBJDIR}. Keep the cwd to what make sets it to.
2.  Don't tell mkbuiltins where to write to (= ${.OBJDIR}), but where to
    get sources from (= ${.CURDIR}). This to compensate for point 1.

This fixes a problem with bmake's mk files that optimize ${.OBJDIR} to
expand to "." after changing cwd, not taking into account that the
target is pretty much undoing that and not getting the full path to the
object tree anymore.
2012-05-24 19:48:15 +00:00
Konstantin Belousov
4f1e1f86a1 Add 'cow' keyword to show per-process cow count.
Submitted by:	Andrey Zonov <andrey zonov org>
MFC after:	1 week
2012-05-23 18:11:36 +00:00
Warren Block
7b9da80729 Mention the upper hard limit for -n option. Patch slightly modified
from PR version.

PR:		168255
Submitted by:	Andy Kosela
Approved by:	gjb
MFC after:	3 days
2012-05-23 16:19:19 +00:00
Kevin Lo
fcae0e3887 Remove redundant declaration of yyparse
Reported by:	tinderbox
2012-05-22 03:01:54 +00:00
Marcel Moolenaar
6663ff446e Add build opton MK_LS_COLORS to control whether ls(1) supports colors
(and thus needs to depend on libtermcap). Embedded systems may not
want or need colors.

Obtained from:	Juniper Networks, Inc.
2012-05-19 18:05:00 +00:00
Marcel Moolenaar
aa39c44746 Add build option MK_ED_CRYPTO to control whether ed(1) is to have the
ability to encrypt/decrypt files. Embedded systems can typically have
OpenSSL, but not for ed(1) to use it.

Obtained from:	Juniper Networks, Inc.
2012-05-19 17:55:49 +00:00
Marcel Moolenaar
e7b903bf3d Remove unused header (libutil.h) 2012-05-17 20:29:15 +00:00
Jilles Tjoelker
ad859ed8cf sh: Remove an unused header.
The read builtin no longer does things with termios.
2012-05-15 22:50:47 +00:00
Joel Dahl
35471bf8ef Minor mdoc nits. 2012-05-13 14:16:04 +00:00
Matthew D Fleming
64afb51ccd I forgot to bump the manpage date.
Reminded by:	Garrett Cooper
MFC after:	3 days
X-MFC-with:	r235297
2012-05-12 02:49:40 +00:00
Matthew D Fleming
af68c71a5e Add a -v and -N option to kenv(1), so it can be more easily used in
scripts the way sysctl(8) is.  The -N option, like in sysctl(8),
displays only the kenv names, not their values.  The -v option prints an
individual kenv variable name with its value as name="value".  This is
the inverse of sysctl(8)'s -n flag, since the default behaviour of
kenv(1) is already like sysctl(8) -n.

Submitted by:	Garrett Cooper < yanegomi AT gmail DOT com >
MFC after:	1 week
2012-05-11 23:05:14 +00:00
Joel Dahl
748611c9c0 mdoc: fix column names, indentation, column separation within each row, and
quotation. Also make sure we have the same amount of columns in each row as
the number of columns we specify in the head arguments.

Reviewed by:	brueffer
2012-04-07 09:05:30 +00:00
Jilles Tjoelker
b95fca474d sh: Fix build with -DDEBUG=2.
Reported by:	Kristof Provost
MFC after:	1 week
2012-04-02 17:16:24 +00:00
Joel Dahl
288eac5aed mandoc complains loudly when <TAB>s are misused in columnated lists. Fix
this syntax violation and while I'm here also convert <TAB> to Ta and adjust
quotation marks in order to prevent this problem in the future.
2012-03-29 16:02:40 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Joel Dahl
904d0726c8 Remove superfluous paragraph macro. 2012-03-25 09:20:14 +00:00
Eitan Adler
8c3bbba824 rm[0].rm_so must be zero (an explicit check is made for zero in the
outer if condition)

Reviewed by:	se
Approved by:	cperciva
2012-03-19 00:45:01 +00:00
Konstantin Belousov
28c84226e8 Document P_ORPHAN.
MFC after:	3 days
2012-03-08 13:00:49 +00:00
Eitan Adler
45b586acc4 Bump date to today (since I modified it)
PR:		bin/165321
Approved by:	gjb
MFC after:	3 days
2012-03-03 17:52:19 +00:00
Eitan Adler
2561992179 Direct users to swapinfo and pstat from df
PR:		bin/165321
Submitted by:	jhs
Approved by:	bcr
MFC after:	3 days
2012-03-03 15:38:01 +00:00
Glen Barber
9d496f5ab6 Whitespace cleanup:
o Wrap sentences on to new lines
 o Cleanup trailing whitespace

Found with:	textproc/igor
MFC after:	1 week
X-MFC-With:	r232157
2012-02-25 15:21:43 +00:00
Glen Barber
3102cfe2e2 Fix various typos in manual pages.
Submitted by:	amdmi3
PR:		165431
MFC after:	1 week
2012-02-25 14:31:25 +00:00
Mark Peek
9ccc37e320 Update to tcsh 6.18.01. 2012-02-22 03:36:15 +00:00
Jilles Tjoelker
c0b3cf0676 sh: Make 'hash' return 1 if at least one utility is not found.
Reported by:	lme
2012-02-11 21:06:45 +00:00
Jilles Tjoelker
33233ec76e sh: Fix swapped INTON/INTOFF.
A possible consequence of this bug was a memory leak if SIGINT arrived
during a 'set' command (listing variables).

MFC after:	1 week
2012-02-04 23:29:07 +00:00
Jilles Tjoelker
caf29fab8c sh: Use vfork in a few common cases.
This uses vfork() for simple commands and command substitutions containing a
single simple command, invoking an external program under certain conditions
(no redirections or variable assignments, non-interactive shell, no job
control). These restrictions limit the amount of code executed in a vforked
child.

There is a large speedup (for example 35%) in microbenchmarks. The
difference in buildkernel is smaller (for example 0.5%) but still
statistically significant. See
http://lists.freebsd.org/pipermail/freebsd-hackers/2012-January/037581.html
for some numbers.

The use of vfork() can be disabled by setting a variable named
SH_DISABLE_VFORK.
2012-02-04 23:12:14 +00:00
Philippe Charnier
2fae4c3d95 Add prototypes, ANSIfy functions definitions to reduce WARNS=6 output. 2012-01-25 08:42:19 +00:00
Jilles Tjoelker
6eff4a75d5 sh: Fix $? in the first command of a 'for'.
In the first command of a 'for', $? should be the exit status of the last
pipeline (command substitution in the word list or command before 'for'),
not always 0.
2012-01-22 14:00:33 +00:00
Jilles Tjoelker
0105d7224d sh: Remove "kill" example function, which is superseded by the kill builtin
MFC after:	1 week
2012-01-21 20:39:17 +00:00
Ed Schouten
6aed20fe1a Remove unused variables.
Simply annotate the function parameters with __unused, instead of adding
the ve-variables. This makes the code build with GCC 4.7 and -Werror.
2012-01-17 22:17:10 +00:00
Jean-Sébastien Pédron
01a43bcf7b sh: Fix execution of multiple statements in a trap when evalskip is set
Before this fix, only the first statement of the trap was executed if
evalskip was set. This is for example the case when:
    o  "-e" is set for this shell
    o  a trap is set on EXIT
    o  a function returns 1 and causes the script to abort

Reviewed by:	jilles
MFC after:	2 weeks
2012-01-16 11:07:46 +00:00
Jilles Tjoelker
93fcb2511b sh: Fix some bugs with exit status from case containing ;&.
Also, rework evalcase() to not evaluate any tree. Instead, return the
NCLISTFALLTHRU node and handle it in evaltree().

Fixed bugs:

* If a ;& list with non-zero exit status is followed by an empty ;; or final
  list, the exit status of the case command should be equal to the exit
  status of the ;& list, not 0.

* An empty ;& case should not reset $?.
2012-01-15 21:39:38 +00:00
Jilles Tjoelker
92371efca2 sh: Fix two bugs with case and exit status:
* If no pattern is matched, POSIX says the exit status shall be 0 (even if
  there are command substitutions).
* If a pattern is matched and there are no command substitutions, the first
  command should see the $? from before the case command, not always 0.
2012-01-15 20:04:05 +00:00
Jilles Tjoelker
7f40c1f876 sh: Change input buffer size from 1023 to 1024.
PR:		bin/161756
2012-01-14 22:46:18 +00:00
Jilles Tjoelker
52c450395a sh: Fix out of bounds array access when trap is used with an invalid signal.
MFC after:	1 week
2012-01-14 21:54:12 +00:00
Jilles Tjoelker
e94e3511bd sh: Properly show "Not a directory" error in cd builtin.
The errno message display added in r222292 did not take attempting to
cd to a non-directory or something that cannot be stat()ed into account.

PR:		bin/164070
MFC after:	10 days
2012-01-13 23:32:27 +00:00
Ulrich Spörlein
38494eff98 Spelling fixes for bin/ 2012-01-07 16:10:23 +00:00
Jilles Tjoelker
260fc3f4d2 sh: Make various functions static. 2012-01-01 22:17:12 +00:00
Jilles Tjoelker
f6d3a9b03f sh: Remove unused function scopyn(). 2012-01-01 22:15:38 +00:00
Jilles Tjoelker
820491f824 sh: Make patmatch() non-recursive. 2012-01-01 20:50:19 +00:00
Jilles Tjoelker
3a1b9c9e82 sh: Allow quoting ^ and ] in bracket expressions. 2011-12-28 23:51:17 +00:00
Jilles Tjoelker
6e8db49a44 sh: Use dirent.d_type in pathname generation.
This improves performance for globs where a slash or another component
follows a component with metacharacters by eliminating unnecessary attempts
to open directories that are not.
2011-12-28 23:40:46 +00:00
Jilles Tjoelker
7a2b9d4b38 sh: Cache de->d_namlen in a local variable. 2011-12-28 23:30:17 +00:00
Jilles Tjoelker
a82f5687bf sh: Do not force special builtins non-special in optimized command subst.
This is not necessary: errors are already caught in evalbackcmd() and
forcelocal handles changes to variables.

Note that this depends on r223024.

MFC after:	4 weeks
2011-12-28 22:10:12 +00:00
Dimitry Andric
4bfc2007ab Fix some obtuse fprintf tricks in bin/ed.
MFC after:	1 week
2011-12-16 21:12:23 +00:00
Ed Schouten
469743871e Add static keywords to chio(1).
All other global variables are already marked static, so for consistency
sake, add them to these three arrays as well.
2011-12-11 20:53:12 +00:00
Ed Schouten
7b44b80961 Move 3.5 KB from the data segment to the text segment.
The `struct modes' are only used by the getter-functions in the same
file, so we can safely mark them static and const.
2011-12-11 09:56:48 +00:00
Jilles Tjoelker
03f33e912d sh: Remove impossible evalskip check in 'for'. 2011-11-27 00:09:59 +00:00
Jilles Tjoelker
a157dc4d90 sh: Reduce one level of evaltree() recursion when executing 'case'.
Free expanded case text before executing commands.
Remove impossible evalskip checks (expanding an argument cannot set
evalskip anymore since $(break) and the like are properly executed in a
subshell environment).
2011-11-26 23:28:31 +00:00
Jilles Tjoelker
ba22f6c693 test: Reduce code size of ops table. 2011-11-25 23:45:29 +00:00
Mikolaj Golub
6edf5accb6 Remove yet another outdated note about procfs(5) being required.
Spotted by:	arundel
2011-11-22 21:53:06 +00:00
Mikolaj Golub
57c87bfabb No need in procfs(5).
MFC after:	2 weeks
2011-11-22 21:14:46 +00:00
Jilles Tjoelker
bf3db314f7 sh: Allow unsetting OPTIND.
Note that only assigning the decimal value 1 resets getopts, as before.
2011-11-20 21:48:50 +00:00
Jilles Tjoelker
876f9b7800 sh: Remove undefined behaviour due to overflow in +/-/* in arithmetic.
With i386 base gcc and i386 base clang, arith_yacc.o remains unchanged.
2011-11-08 23:54:39 +00:00
Jilles Tjoelker
ad56ebdc15 sh(1): Improve documentation of field splitting. 2011-11-05 21:56:45 +00:00
Ed Schouten
f9d4afb439 Put some static keywords in the source code.
For these simple utilities, it doesn't harm to make all global variables
static. In fact, this allows the compiler to perform better forms of
optimisation and analysis.
2011-10-31 08:59:17 +00:00
Edward Tomasz Napierala
aa7a15b6bb For processes with no controlling terminal, display "-" in the TTY column
instead of "?".

Submitted by:	arundel
2011-10-30 15:21:27 +00:00
Dag-Erling Smørgrav
4d4dcc7aef If ls was invoked with -i but neither -l nor -s, blocksize was used in
display() to calculate column widths, but was not initialized in
main().  This resulted in a division by zero.

Noticed by:	Michael Butler <imb@protected-networks.net>
2011-10-19 15:35:41 +00:00
Dag-Erling Smørgrav
cf1479392e When calculating the width of the blocksize column, ls(1) used 512-byte
units (as returned by stat(2)) instead of BLOCKSIZE units.

Submitted by:	Paul Schenkeveld
MFC after:	3 weeks
2011-10-18 13:10:46 +00:00
Dag-Erling Smørgrav
16352ac84a Minor clarification
MFC after:	3 weeks
2011-10-18 08:20:36 +00:00
Dag-Erling Smørgrav
7b0514fa02 Simplify df(1) by factoring out most of the common code:
- In the argc == 0 case, just populate the mount list as before, but
   do not calculate widths, update totals or print anything.

 - In the argv > 0 case, collect information about the requested file
   systems and store it in the mount list, but do not calculate
   widths, update totals or print anything.

 - In either case, once all the information has been collected,
   iterate once through the mount list to calculate widths and totals,
   then once more to print everything.

This also fixes two bugs: firstly, column widths were not calculated
correctly if more than one file system was specified on the command
line; and secondly, file systems with MNT_IGNORE were included in the
totals even if -a was not specified.

Noticed by:	Paul Schenkeveld
MFC after:	3 weeks
2011-10-18 08:18:26 +00:00
Ivan Voras
a23ffe9673 Don't chop IO into small pieces, follow cp(1) and just use MAXPHYS. 2011-10-03 21:48:10 +00:00
Glen Barber
6ec3cd078c Correct a typo that was introduced in 225912
Submitted by:		Valentin Nechayev (netch % netch!kiev!ua), arundel
MFC after:		1 week
With-MFC:		225908
2011-10-02 16:05:19 +00:00
Glen Barber
2d455a01bd Tweaks to ps(1):
- there's no reason the semantics of the -x flag are being explained in
  the -a flag description
- be more precise regarding the relation between the -a flag and the
  security.bsd.see_other_uids sysctl
- describe the format of the -t flag's argument
- 'con' no longer is a possible entry in the 'TT' column
- explain that the 'TT' column refers to pseudo-terminals via mere numbers
- add a hint in the 'tt' keyword description that a keyword 'tty' exists,
  which will give the full terminal pathname

Submitted by:		arundel (via docs@) (original)
MFC after:		1 week
With-MFC:		225908
2011-10-01 23:47:37 +00:00
Glen Barber
6401543842 Reorder default ps(1) output according to reality.
Submitted by:	arundel (via docs@)
MFC after:	1 week
2011-10-01 20:56:58 +00:00
Edward Tomasz Napierala
1d1143ec27 Make ps(1) automatically size its column widths. 2011-09-29 06:31:42 +00:00
Ed Schouten
9f365aa1d6 Get rid of major/minor number distinction.
As of FreeBSD 6, devices can only be opened through devfs. These device
nodes don't have major and minor numbers anymore. The st_rdev field in
struct stat is simply based a copy of st_ino.

Simply display device numbers as hexadecimal, using "%#jx". This is
allowed by POSIX, since it explicitly states things like the following
(example taken from ls(1)):

	"If the file is a character special or block special file, the
	size of the file may be replaced with implementation-defined
	information associated with the device in question."

This makes the output of these commands more compact. For example, ls(1)
now uses approximately four columns less. While there, simplify the
column length calculation from ls(1) by calling snprintf() with a NULL
buffer.

Don't be afraid; if needed one can still obtain individual major/minor
numbers using stat(1).
2011-09-28 18:53:36 +00:00
Christian Brueffer
ae568477e7 Fix memory leaks in error cases.
PR:		159011
Submitted by:	Henning Petersen <henning.petersen@t-online.de>
Approved by:	re (kib)
MFC after:	1 week
2011-08-27 15:28:57 +00:00
Bjoern A. Zeeb
925af54487 Rename ki_ocomm to ki_tdname and OCOMMLEN to TDNAMLEN.
Provide backward compatibility defines under BURN_BRIDGES.

Suggested by:	jhb
Reviewed by:	emaste
Sponsored by:	Sandvine Incorporated
Approved by:	re (kib)
2011-07-18 20:06:15 +00:00
Jilles Tjoelker
51a514adf2 sh(1): Extend documentation about subshells.
Because sh executes commands in subshell environments without forking in
more and more cases (particularly from 8.0 on), it makes sense to describe
subshell environments more precisely using ideas from POSIX, together with
some FreeBSD-specific items.

In particular, the hash and times builtins may not behave as if their state
is copied for a subshell environment while leaving the parent shell
environment unchanged.
2011-07-10 15:02:25 +00:00
Stefan Eßer
69759f0829 Fix style, since this file has just been touched in a major way.
No actual code changes.
2011-07-09 12:20:15 +00:00
Stefan Eßer
6fbe7bf4f2 Some refactoring for easier maintenance of the code. This is a follow-up
to re-establishment of 64bit arithmetic, but is committed separately, to
not obscure that conversion. This commit does not change the observed
behaviour of expr in any way. Style will be fixed in a follow-up commit.
2011-07-09 12:14:57 +00:00
Stefan Eßer
fa717604a4 Make /bin/expr support 64bit numeric range and range checks by default,
again. This brings back the behaviour of expr in FreeBSD-4, which had been
reverted due to an assumed incompatbility with POSIX.1 for FreeBSD-5.

This issue has been discussed in the freebsd-standards list, and the
consensus was, that POSIX.1 is in fact not violated by this extension,
since it affects only cases of POSIX undefined behaviour (overflow of
signed long).

Other operating systems did upgrade their versions of expr to support
64bit range, after it had been initially brought to FreeBSD. They have
used it for a decade without problems, meanwhile.

The -e option is retained, but it will only select less strict checking
of numeric parameters (leading white-space, leading "+" are allowed and
skipped, an empty string is considered to represent 0 in numeric context.)
The call of check_utility_compat() as a means of establishing backwards
compatibility with FreeBSD-4 is considered obsolete, but preserved in
this commit. It is expected to be removed in a later revision of this
file.
Reviewed by:	bde, das, jilles
MFC after:	2 month (those parts that do not violate POLA)
2011-07-09 12:05:53 +00:00
Sergey Kandaurov
b758bdf8b3 Bump date after the previous commit. 2011-07-01 10:57:10 +00:00
Sergey Kandaurov
b3178949ee Update and sort the list of the available keywords. 2011-07-01 10:54:47 +00:00
Jilles Tjoelker
4004e05e8a sh: Include <limits.h> instead of non-standard <sys/limits.h>. 2011-06-26 20:12:05 +00:00
Jilles Tjoelker
519c4ef391 sh(1): Improve documentation of shell patterns:
* Shell patterns are also for ${var#pat} and the like.
* An '!' by itself will not trigger pathname generation so do not call it a
  meta-character, even though it has a special meaning directly after an
  '['.
* Character ranges are locale-dependent.
* A '^' will complement a character class like '!' but is non-standard.

MFC after:	1 week
2011-06-24 22:08:26 +00:00
Jilles Tjoelker
b97989d659 sh(1): Document the case command better.
Suggested by:	netchild
Reviewed by:	gjb
2011-06-24 20:23:50 +00:00
Kevin Lo
ecd9e552d0 Remove duplicated header files 2011-06-24 07:29:04 +00:00
Ruslan Ermilov
7a416f3e7d Make `realpath'' behave like `realpath .''. 2011-06-21 19:34:57 +00:00
Jilles Tjoelker
47e5204ee3 sh: Remove special support for background simple commands.
It expands the arguments in the parent shell process, which is incorrect.
2011-06-18 23:58:59 +00:00
Jilles Tjoelker
54b16435b7 sh: Add do-nothing -h option.
POSIX requires a -h option to sh and set, to locate and remember utilities
invoked by functions as they are defined. Given that this
locate-and-remember process is optional elsewhere, it seems safe enough to
make this option do nothing.

POSIX does not specify a long name for this option. Follow ksh in calling it
"trackall".
2011-06-18 23:43:28 +00:00
Jilles Tjoelker
c9afaa6389 sh: Add case statement fallthrough (with ';&' instead of ';;').
Replacing ;; with the new control operator ;& will cause the next list to be
executed as well without checking its pattern, continuing until a list ends
with ;; or until the end of the case statement. This is like omitting
"break" in a C "switch" statement.

The sequence ;& was formerly invalid.

This feature is proposed for the next POSIX issue in Austin Group issue
#449.
2011-06-17 13:03:49 +00:00
Jilles Tjoelker
f5f215e251 sh: Skip variables with invalid names in "set", "export -p", "readonly -p".
This ensures the output of these commands is valid shell input.
2011-06-17 10:21:24 +00:00
Jilles Tjoelker
c5aef5377c sh: Reduce unnecessary forks with eval.
The eval special builtin now runs the code with EV_EXIT if it was run
with EV_EXIT itself.

In particular, this eliminates one fork when a command substitution contains
an eval command that ends with an external program or a subshell.

This is similar to what r220978 did for functions.
2011-06-16 21:50:28 +00:00
Jilles Tjoelker
ff4dc67299 sh: Add support for named character classes in bracket expressions.
Example:
  case x in [[:alpha:]]) echo yes ;; esac
2011-06-15 21:48:10 +00:00
Edward Tomasz Napierala
9acd91270f Add "gid" and "group" keywords to display the effective group ID
and effective group name.  Also, add "egid", "egroup" and "euid" aliases.

PR:		bin/146331
Submitted by:	Jeremie Le Hen <jeremie at le-hen dot org>
2011-06-14 16:50:16 +00:00
Jilles Tjoelker
454a02b372 sh: Fix duplicate prototypes for builtins.
Have mkbuiltins write the prototypes for the *cmd functions to builtins.h
instead of builtins.c and include builtins.h in more .c files instead of
duplicating prototypes for *cmd functions in other headers.
2011-06-13 21:03:27 +00:00
Jilles Tjoelker
c543e1ae9e sh: Save/restore changed variables in optimized command substitution.
In optimized command substitution, save and restore any variables changed by
expansions (${var=value} and $((var=assigned))), instead of trying to
determine if an expansion may cause such changes.

If $! is referenced in optimized command substitution, do not cause jobs to
be remembered longer.

This fixes $(jobs $!) again, simplifies the man page and shortens the code.
2011-06-12 23:06:04 +00:00
Jilles Tjoelker
f5ac5937d3 sh: Fix locale-dependent ranges in bracket expressions.
When I added UTF-8 support in r221646, the LC_COLLATE-based ordering broke
because of sign extension of char.

Because of libc restrictions, this does not work for UTF-8. For UTF-8
locales, ranges always use character code order.
2011-06-12 12:54:52 +00:00
Jilles Tjoelker
c5f4fe06fe sh: Read .profile from the home directory (or / if HOME is not set).
In most cases, login shells are started from the home directory, but not in
all, such as xterm -ls.

This commit depends on r222957 for read_profile() performing parameter
expansion.

PR:		bin/50569
2011-06-12 10:13:48 +00:00
Jilles Tjoelker
1a62d8843d sh: Do parameter expansion on ENV before using it.
This is required by POSIX, and allows things like ENV=\$HOME/.shrc.

Note that tilde expansion is explicitly not performed.
2011-06-10 22:42:00 +00:00
Jilles Tjoelker
292e667663 sh: Do parameter expansion before printing PS4 (set -x).
The function name expandstr() and the general idea of doing this kind of
expansion by treating the text as a here document without end marker is from
dash.

All variants of parameter expansion and arithmetic expansion also work (the
latter is not required by POSIX but it does not take extra code and many
other shells also allow it).

Command substitution is prevented because I think it causes too much code to
be re-entered (for example creating an unbounded recursion of trace lines).

Unfortunately, our LINENO is somewhat crude, otherwise PS4='$LINENO+ ' would
be quite useful.
2011-06-09 23:12:23 +00:00
Jilles Tjoelker
b3f892d9e0 sh: Fix $? in heredocs on simple commands.
PR:		bin/41410
2011-06-05 14:13:15 +00:00
Jilles Tjoelker
af449f7fef sh: Improve error message if the script cannot be opened.
Avoid "<nosuchfile>: cannot open <nosuchfile>: ...".
2011-06-04 22:19:00 +00:00
Jilles Tjoelker
47a5ab295a sh: Reduce more needless differences between error messages. 2011-06-04 15:05:52 +00:00
Jilles Tjoelker
9338c85c31 sh: Honour -n while processing -c string. 2011-06-04 11:28:42 +00:00
Jilles Tjoelker
8d5a14301f sh: Remove the "exp" builtin.
The "exp" builtin is undocumented, non-standard and not very useful.

If exp's return value is not used, something like
VAR=$(exp EXPRESSION)
is equivalent to
VAR=$((EXPRESSION))
except that errors in the expression are fatal and quoting special
characters is not needed in the latter case.

If exp's return value is used, something like
if exp EXPRESSION >/dev/null
can be replaced by
if [ $((EXPRESSION)) -ne 0 ]
with similar differences.

The exp-run showed that "let" is close enough to bash's and ksh's builtin
that removing it would break a few ports. Therefore, "let" remains in 9.x.

PR:		bin/104432
Exp-run done by: pav (with some other sh(1) changes)
2011-05-27 20:53:07 +00:00
Jilles Tjoelker
64fa41f3e1 sh: Correct criterion for using CDPATH in cd.
CDPATH should be ignored not only for pathnames starting with '/' but also
for pathnames whose first component is '.' or '..'.

The man page already describes this behaviour.
2011-05-27 20:01:46 +00:00
Jilles Tjoelker
241f15dfaf sh: Various updates to the TOUR document. 2011-05-27 16:00:37 +00:00
Jilles Tjoelker
715a0dd556 sh: Fix unquoted $@/$* if IFS=''.
If IFS is null, unquoted $@/$* should still expand to separate words.
This differs from quoted $@ (which does not depend on IFS) in that pathname
generation is performed and empty words are removed.
2011-05-27 15:56:13 +00:00
Jilles Tjoelker
168b9dd182 sh: Show errno messages in cd. 2011-05-25 21:38:16 +00:00
Jilles Tjoelker
f3ac36e151 sh: Remove obsolete token type TENDBQUOTE.
This token type was related to Almquist's original version of backquotes
that could not nest and fell into disuse fairly soon.
2011-05-22 15:24:56 +00:00
Ulrich Spörlein
bf2fe08eea Fix some typos under bin/
Found by:	codespell
2011-05-22 14:03:46 +00:00
Ulrich Spörlein
01c9917634 Fix a bunch of typos and a couple of whitespace nits.
Helped by:	codespell and vim's spellchecker
2011-05-22 14:03:38 +00:00
Jilles Tjoelker
c9e93e6739 sh: Fix bss-based buffer overflow in . builtin.
If the length of a directory in PATH together with the given filename
exceeded FILENAME_MAX (which may happen even for pathnames that work), a
static buffer was overflown.

The static buffer is unnecessary, we can use the stalloc() stack.

Obtained from:	NetBSD
MFC after:	1 week
2011-05-22 12:12:28 +00:00
Jilles Tjoelker
05a447d0b9 sh: Expand aliases after assignments and redirections. 2011-05-21 22:03:06 +00:00
Jilles Tjoelker
d6ee26ad02 sh: Implement the cd -e flag proposed for the next POSIX issue.
This reflects failure to determine the pathname of the new directory in the
exit status (1). Normally, cd returns successfully if it did chdir() and the
call was successful.

In POSIX, -e only has meaning with -P; because our -L is not entirely
compliant and may fall back to -P mode, -e has some effect with -L as well.
2011-05-20 22:55:18 +00:00
Jilles Tjoelker
85307c9ed9 sh: Allow terminating a heredoc with a terminator at EOF without a newline.
This is sometimes used with eval or old-style command substitution, and most
shells other than ash derivatives allow it.

It can also be used with scripts that violate POSIX's requirement on the
application that they end in a newline (scripts must be text files except
that line length is unlimited).

Example:
v=`cat <<EOF
foo
EOF`
echo $v

This commit does not add support for the similar construct with new-style
command substitution, like
v=$(cat <<EOF
foo
EOF)
This continues to require a newline after the terminator.
2011-05-20 16:03:36 +00:00
Sergey Kandaurov
9abcf93a91 Spelling in P_HADTHREADS.
MFC after:	1 week
2011-05-20 14:32:28 +00:00