History log of /freebsd-9.3-release/bin/sh/miscbltin.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 221975 15-May-2011 jilles

sh: Minor optimization to output from ulimit/export/readonly.

No functional change is intended.


# 215783 23-Nov-2010 jilles

sh: Code size optimizations to "stack string" memory allocation:
* Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC.
* Add STPUTS macro (based on function) and use it instead of loops that add
nul-terminated strings to the stack string.

No functional change is intended, but code size is about 1K less on i386.


# 212339 08-Sep-2010 jilles

sh: Fix 'read' if all chars before the first IFS char are backslash-escaped.

Backslash-escaped characters did not set the flag for a non-IFS character.

MFC after: 2 weeks


# 201053 27-Dec-2009 jilles

sh: Various warning fixes (from WARNS=6 NO_WERROR=1):
- const
- initializations to silence -Wuninitialized (it was safe anyway)
- remove nested extern declarations
- rename "index" locals to "idx"


# 194767 23-Jun-2009 kib

Usermode portion of the support for swap allocation accounting:
- update for getrlimit(2) manpage;
- support for setting RLIMIT_SWAP in login class;
- addition to the limits(1) and sh and csh limit-setting builtins;
- tuning(7) documentation on the sysctls controlling overcommit.

In collaboration with: pho
Reviewed by: alc
Approved by: re (kensmith)


# 193185 31-May-2009 jilles

sh: Make read's timeout (-t) apply to the entire line, not only the first
character.

This avoids using non-standard behaviour of the old (upto FreeBSD 7) TTY
layer: it reprocesses the input queue when switching to canonical mode. The
new TTY layer does not provide this functionality and so read -t worked
very poorly (first character is not echoed, cannot be backspaced but is
still read).

This also agrees with what most other shells with read -t do.

PR: bin/129566
Reviewed by: stefanf
Approved by: ed (mentor)


# 190298 22-Mar-2009 stefanf

Fix the behaviour of the read built-in when IFS is unset.

Obtained from: NetBSD


# 190295 22-Mar-2009 stefanf

Improve the IFS handling of the read built-in.

Obtained from: NetBSD
Submitted by: Jilles Tjoelker


# 189542 08-Mar-2009 ed

Don't disable CR-to-NL translation when waiting for data to arrive.

A difference between the old and the new TTY layer is that the new
implementation does not perform any post-processing before returning
data back to userspace when calling read().

sh(1)'s read turns the TTY into a raw mode before calling select(). This
means that the first character will not receive any ICRNL processing.
Inherit this flag from the original terminal attributes.

Even though this issue is not present on RELENG_*, I'm MFCing it to make
sh(1) in jails behave better.

PR: bin/129566
MFC after: 2 weeks


# 181905 20-Aug-2008 ed

Integrate the new MPSAFE TTY layer to the FreeBSD operating system.

The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:

- Improved driver model:

The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.

If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.

- Improved hotplugging:

With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).

The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.

- Improved performance:

One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.

Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.

Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan


# 155301 04-Feb-2006 schweikh

Remove some white space at EOL.


# 151795 28-Oct-2005 stefanf

Protect malloc, realloc and free calls with INT{ON,OFF} directly in chkalloc,
ckrealloc and ckfree (added), respectively. sh jumps out of the signal handler
using longjmp which is obviously a bad idea during malloc calls.

Note: I think there is still a small race here because volatile sig_atomic_t
only guarantees atomic reads and writes while we're doing increments and
decrements.

Protect a setmode call with INT{ON,OFF} as it calls malloc internally.

PR: 45478
Patch from: Nate Eldredge


# 149918 09-Sep-2005 stefanf

Fix the error message if the mask that is passed to umask -S contains
non-digits.


# 149825 06-Sep-2005 rse

Various small code cleanups resulting from a code reviewing
and linting procedure:

1. Remove useless sub-expression:

- if (*start || (!ifsspc && start > string && (nulonly || 1))) {
+ if (*start || (!ifsspc && start > string)) {

The sub-expression "(nulonly || 1)" always evaluates to true and
according to CVS logs seems to be just a left-over from some
debugging and introduced by accident. Removing the sub-expression
doesn't change semantics and a code inspection showed that the
variable "nulonly" is also not necessary here in any way (and the
expression would require fixing instead of removing).

2. Remove dead code:

- if (backslash && c == '\\') {
- if (read(STDIN_FILENO, &c, 1) != 1) {
- status = 1;
- break;
- }
- STPUTC(c, p);
- } else if (ap[1] != NULL && strchr(ifs, c) != NULL) {
+ if (ap[1] != NULL && strchr(ifs, c) != NULL) {

Inspection of the control and data flow showed that variable
"backslash" is always false (0) when the "if"-expression is
evaluated, hence the whole block is effectively dead code.
Additionally, the skipping of characters after a backslash is already
performed correctly a few lines above, so this code is also not
needed at all. According to the CVS logs and the ASH 0.2 sources,
this code existed in this way already since its early days.

3. Cleanup Style:

- ! trap[signo][0] == '\0' &&
+ ! (trap[signo][0] == '\0') &&

The expression wants to ensure the trap is not assigned the empty
string. But the "!" operator has higher precedence than "==", so the
comparison should be put into parenthesis to form the intended way of
expression. Nevertheless the code was effectively not really broken
as both particular NUL comparisons are semantically equal, of course.
But the parenthesized version is a lot more intuitive.

4. Remove shadowing variable declaration:

- char *q;

The declaration of symbol "q" hides another identical declaration of
"q" in the same context. As the other "q" is already reused multiple
times and also can be reused again without negative side-effects,
just remove the shadowing declaration.

5. Just small cosmetics:

- if (ifsset() != 0)
+ if (ifsset())

The ifsset() macro is already coded by returning the boolean result
of a comparison operator, so no need to compare this boolean result
again against a numerical value. This also aligns the macros usage to
the remaining existing code.

Reviewed by: stefanf@


# 149018 13-Aug-2005 stefanf

First declare the functions to pacify -Wmissing-prototypes.


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 104282 01-Oct-2002 mux

- Don't use quad_t when we really mean rlim_t.
- Cast rlim_t to intmax_t when printing it.

This should fix the last format errors in sh(1).

Tested on: i386, sparc64


# 104208 30-Sep-2002 tjr

Callers of error() don't need to supply a program name prefix in the
error message. Stops ulimit giving error messages like "ulimit: ulimit: xyz".


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 98834 25-Jun-2002 dillon

Add support for RLIMIT_VMEM. The #ifdef's were already there but getopt()
needed to be adjusted.


# 90111 02-Feb-2002 imp

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.
o Change
int
foo() {
...
to
int
foo(void)
{
...


# 80381 26-Jul-2001 sheldonh

Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. The
definitions are more readable, and it's possible that they're
more portable to pathalogical platforms.

Submitted by: David Hill <david@phobia.ms>


# 59436 20-Apr-2000 cracauer

Fix warnings, some of them serious because sh violated name
spaces reserved by the header files it includes.

mkinit.c still produces C code with redundant declarations, although
they are more harmless since they automatically derived from the right
places.


# 52072 09-Oct-1999 green

Implement ulimit -b for RLIMIT_SBSIZE.


# 50471 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 50394 26-Aug-1999 tg

Make the behaviour of `read -e', ie. treating backslashes as special,
the default. Add -r option for the read builtin to reverse this.

PR: 13274
Reviewed by: cpiazza, hoek, sheldonh


# 46684 08-May-1999 kris

Various spelling/formatting changes.

Submitted by: Philippe Charnier <charnier@xp11.frmug.org>


# 41844 16-Dec-1998 imp

Free memory from setmode.

Obtained from: OpenBSD


# 38536 25-Aug-1998 cracauer

Improve bookkeeping of in_waitcmd and style fixes.
Submitted by: Bruce Evans


# 38521 24-Aug-1998 cracauer

Do not exit on SIGINT in non-interactive shells, fixes PR 1206,
i.e. this makes emacs usable from system(3). Programs called from
shellscripts are now required to exit with proper signal status. That
means, they have to kill themself. Exiting with faked numerical exit
code is not sufficient.

Exit with proper signal status if script exits on signal.

Make the wait builtin interruptable, both with and without traps set.

Use volatile sig_atomic_t where (and only where) appropriate.

(Almost) fix printing of newlines on SIGINT.

Make traps setable from trap handlers. This is needed for shellscripts
that catch SIGINT for cleanup work but intend to exit on it, hance
have to kill themself from a trap handler. I.e. mkdep.

While I'm at it, make it -Wall clean. -Wall is not enabled in
Makefile, since vararg warnx() macro calls in usr.bin/printf/printf.c
are not -Wall-able.
PR: 1206
Obtained from: Basic SIGINT fix from Bruce Evans


# 36150 18-May-1998 charnier

Add rcsid. Spelling.


# 29983 29-Sep-1997 msmith

Add the '-t timeout' option to the 'read' builtin. This allows the
'read' command to return an error if the user fails to supply any
input withink a given time period. The behaviour of this option is
similar to that of the like-named option in ksh93.

Reviewed by: joerg


# 25905 18-May-1997 steve

Use the __unused attribute where warranted.


# 25222 28-Apr-1997 steve

Nuke register keyword usage and #if -> #ifdef.

Obtained from: NetBSD


# 22988 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 20425 14-Dec-1996 steve

Merge in NetBSD mods and -Wall cleaning.

Obtained from: NetBSD, me


# 18019 03-Sep-1996 peter

eek, how did that happen? I must have committed something left over from
when I was experimenting looking for an alternate format. *blush*


# 18018 03-Sep-1996 peter

Fix for PR#1287. This makes sh behave sensibly in case statements in the
face of aliases. Note, bash doesn't do aliases while running scripts, but
"real" ksh does..

Also:
Reduce redundant .Nm macros in (unused) bltin/echo.1
nuke error2, it's hardly used.
More -Wall cleanups
dont do certain history operations if NO_HISTORY defined
handle quad_t's from resource limits

Submitted by: Steve Price <sprice@hiwaay.net> (minor tweaks by me)


# 18016 03-Sep-1996 peter

Misc cleanups and fixes from Bruce:
- don't put \n on error() calls, error adds it already.
- don't prepend "ulimit" on error() calls in miscbltin.c.
- getopt typo on ulimit -p -> -u conversion
- get/setrlimit() calls were not being error checked

ulimit formatting cleanup from me, use same wording as bash on Bruce's
suggestion. Add ulimit arg to output on Joerg's suggestion.


# 17987 01-Sep-1996 peter

Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-]

There are some changes to the build that are my fault... mkinit.c was
trying (poorly) to duplicate some of the work that make(1) is designed to
do. The Makefile hackery is my fault too, the depend list was incomplete
because of some explicit OBJS+= entries, so mkdep wasn't picking up their
source file #includes.

This closes a pile of /bin/sh PR's, but not all of them..

Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter


# 11601 20-Oct-1995 joerg

o rename ulimit -p into ulimit -u, so we are in agreement with bash

o fix brokeness for 1>&5 redirection, where `5' was an invalid file
descriptor, but no error message has been generated

o fix brokeness for redirect to/from myself case


# 11571 19-Oct-1995 joerg

Implement the "ulimit" builtin. This is the analogon to csh's "limit"
command and badly needed in sh(1) for everybody who wants to modify
the system-wide limits from inside /etc/rc.

The options are similar to other system's implemantations of this
command, with the FreeBSD additions for -m (memoryuse) and -p (max
processes) that are not available on other systems.


# 3044 24-Sep-1994 dg

Added $Id$


# 1557 26-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1556,
which included commits to RCS files with non-trunk default branches.


# 1556 26-May-1994 rgrimes

BSD 4.4 Lite bin Sources