History log of /freebsd-9.3-release/bin/sh/var.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

# 264644 18-Apr-2014 jilles

MFC r263847: sh: Fix memory leak with an assignment before a regular builtin


# 264643 18-Apr-2014 jilles

MFC r263846: sh: Fix memory leak when trying to set a read only variable.


# 264629 17-Apr-2014 jilles

MFC r263777: sh: Fix possible memory leaks and double frees with unexpected
SIGINT.


# 249242 07-Apr-2013 jilles

MFC r230998,r233792: 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.

Various incarnations of this patch have been shown to bring performance
improvements:
http://lists.freebsd.org/pipermail/freebsd-hackers/2012-January/037581.html

The use of vfork() can be disabled by setting a variable named
SH_DISABLE_VFORK.


# 231529 11-Feb-2012 jilles

MFC r231001: sh: Fix swapped INTON/INTOFF.

A possible consequence of this bug was a memory leak if SIGINT arrived
during a 'set' command (listing variables).


# 225736 22-Sep-2011 kensmith

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

Approved by: re (implicit)


# 223183 17-Jun-2011 jilles

sh: Skip variables with invalid names in "set", "export -p", "readonly -p".

This ensures the output of these commands is valid shell input.


# 223060 13-Jun-2011 jilles

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.


# 223024 12-Jun-2011 jilles

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.


# 221975 15-May-2011 jilles

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

No functional change is intended.


# 221669 08-May-2011 jilles

sh: Add \u/\U support (in $'...') for UTF-8.

Because we have no iconv in base, support for other charsets is not
possible.

Note that \u/\U are processed using the locale that was active when the
shell started. This is necessary to avoid behaviour that depends on the
parse/execute split (for example when placing braces around an entire
script). Therefore, UTF-8 encoding is implemented manually.


# 221668 08-May-2011 jilles

sh: Optimize variable code by storing the length of the name.

Obtained from: NetBSD


# 221559 06-May-2011 jilles

sh: Track if the current locale's charset is UTF-8 or not.


# 218306 04-Feb-2011 jilles

sh: Remove special code for shell scripts without magic number.

These are called "shell procedures" in the source.

If execve() failed with [ENOEXEC], the shell would reinitialize itself
and execute the program as a script. This requires a fair amount of code
which is not frequently used (most scripts have a #! magic number).
Therefore just execute a new instance of sh (_PATH_BSHELL) to run the
script.


# 217847 25-Jan-2011 jilles

sh: Clean up some old comments:
* There is no plan for an alternative to the command "set".
* Attempting to unset a readonly variable has not raised an error for quite
a while, so the order of unsetting a variable and a function with the same
name does not matter.

MFC after: 1 week


# 216870 01-Jan-2011 jilles

sh: Check readonly status for assignments on regular builtins.

An error message is written, the builtin is not executed, nonzero exit
status is returned but the shell does not abort.

This was already checked for special builtins and external commands, with
the same consequences except that the shell aborts for special builtins.

Obtained from: NetBSD


# 215567 20-Nov-2010 jilles

sh: Code size optimizations to buffered output.

This is mainly less use of the outc macro.

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


# 215266 13-Nov-2010 jilles

sh: Do the additional actions if 'local -' restore changes -i/-m/-E/-V.

Example:
f() { local -; set +m; }; f
caused failure to execute external programs because the job control tty fd
was not opened.


# 214538 29-Oct-2010 jilles

sh: Tweak some string constants to reduce code size.

* Reduce some needless differences.
* Shorten some error messages that should not happen.


# 213811 13-Oct-2010 obrien

In the spirit of r90111, depend on c89 and remove the "STATIC" macro
and its usage.


# 213760 13-Oct-2010 obrien

Consistently use "STATIC" for all functions in order to be able to set
breakpoints with in a debugger. And use naked "static" for variables.

Noticed by: bde


# 212467 11-Sep-2010 jilles

sh: Apply variable assignments left-to-right in bltinlookup().

Example:
HOME=foo HOME=bar cd


# 208755 02-Jun-2010 jilles

sh: Pass TERM changes to libedit.

I have changed the patch slightly to ignore TERM changes in subshells.

PR: bin/146916
Submitted by: Guy Yur
Obtained from: NetBSD


# 207678 05-May-2010 jilles

sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.

This allows doing things like LC_ALL=C some_builtin to run a builtin under a
different locale, just like is possible with external programs. The
immediate reason is that this allows making printf(1) a builtin without
breaking things like LC_NUMERIC=C printf '%f\n' 1.2

This change also affects special builtins, as even though the assignment is
persistent, the export is only to the builtin (unless the variable was
already exported).

Note: for this to work for builtins that also exist as external programs
such as /bin/test, the setlocale() call must be under #ifndef SHELL. The
shell will do the setlocale() calls which may not agree with the environment
variables.


# 203576 06-Feb-2010 jilles

sh: Do not stat() $MAIL/$MAILPATH in non-interactive shells.

These may be NFS mounted, and we should not touch them unless we are going
to do something useful with the information.


# 201056 27-Dec-2009 jilles

sh: Change varinit to use const better.


# 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"


# 200956 24-Dec-2009 jilles

sh: Constify various strings.

Most of this is adding const keywords, but setvar() in var.c had to be
changed somewhat more.


# 200943 24-Dec-2009 jilles

sh: Remove setting variables from dotcmd/exportcmd.

It is already done by evalcommand(), unless special-ness has been removed,
in which case variable assignments should not persist. (These are currently
always special builtins, but this will change later: command builtin,
command substitution.)

This also fixes a memory leak when calling . with variable assignments.

Example:
valgrind --leak-check=full sh -c 'x=1 . /dev/null; x=2'


# 199660 22-Nov-2009 jilles

Fix various things about SIGINT handling:
* exception handlers are now run with interrupts disabled, which avoids
many race conditions
* fix some cases where SIGINT only aborts one command and continues the
script, in particular if a SIGINT causes an EINTR error which trumped the
interrupt.

Example:
sh -c 'echo < /some/fifo; echo This should not be printed'
The fifo should not have writers. When pressing ctrl+c to abort the open,
the shell used to continue with the next command.

Example:
sh -c '/bin/echo < /some/fifo; echo This should not be printed'
Similar. Note, however, that this particular case did not and does not work
in interactive mode with job control enabled.


# 194765 23-Jun-2009 jilles

sh: Improve handling of setjmp/longjmp volatile:
- remove ineffective and unnecessary (void) &var; [1]
- remove some unnecessary volatile keywords
- add a necessary volatile keyword
- save the old handler before doing something that could use the saved
value

Submitted by: Christoph Mallon [1]
Approved by: ed (mentor)


# 193222 01-Jun-2009 rse

correctly test for __GNUC__ macro (non-GCC compilers do not have it defined at all)


# 171268 06-Jul-2007 scf

Take care that the input to setenv() may actually be a pointer straight
from environ; make a copy before manipulating it and passing it to
setenv().

Approved by: wes
Approved by: re (kensmith)


# 171195 03-Jul-2007 scf

Significantly reduce the memory leak as noted in BUGS section for
setenv(3) by tracking the size of the memory allocated instead of using
strlen() on the current value.

Convert all calls to POSIX from historic BSD API:
- unsetenv returns an int.
- putenv takes a char * instead of const char *.
- putenv no longer makes a copy of the input string.
- errno is set appropriately for POSIX. Exceptions involve bad environ
variable and internal initialization code. These both set errno to
EFAULT.

Several patches to base utilities to handle the POSIX changes from
Andrey Chernov's previous commit. A few I re-wrote to use setenv()
instead of putenv().

New regression module for tools/regression/environ to test these
functions. It also can be used to test the performance.

Bump __FreeBSD_version to 700050 due to API change.

PR: kern/99826
Approved by: wes
Approved by: re (kensmith)


# 169177 01-May-2007 ache

Back out all POSIXified *env() changes.

Not because I admit they are technically wrong and not because of bug
reports (I receive nothing). But because I surprisingly meets so
strong opposition and resistance so lost any desire to continue that.

Anyone who interested in POSIX can dig out what changes and how
through cvs diffs.


# 169133 30-Apr-2007 ache

Simplify previous fix and disallow VTEXTFIXED direct pass for putenv() too,
just use savestr()


# 169118 30-Apr-2007 ache

Put some safeguards:
1) Under POSIX unsetenv("foo=bar") is explicit error and not equal
to unsetenv("foo")
2) Prepare for upcomig POSIXed putenv() rewrite: make putenv() calls
portable and conforming to standard.


# 159632 15-Jun-2006 stefanf

Implement the PS4 variable which is defined by the POSIX User Portability
Utilities option. Its value is printed at the beginning of the line if tracing
(-x) is active. PS4 defaults to the string "+ " which is compatible with the
old behaviour to always print "+ ".

We still need to expand variables in PS1, PS2 and PS4.

PR: 46441 (part of)
Submitted by: schweikh
Obtained from: NetBSD


# 158145 29-Apr-2006 stefanf

POSIX demands that set's output (when invoked without arguments) should be
sorted. Sort the variables before printing.

PR: 96415


# 155302 04-Feb-2006 schweikh

s/varable/variable/; s/tored/stored/


# 149919 09-Sep-2005 stefanf

- Provide a reasonable error message for `export -p var'.
- Use argv rather than argptr since getopt() is used here.


# 149016 13-Aug-2005 stefanf

Use prototypes in the MKINIT lines collected by mkinit.


# 135856 27-Sep-2004 des

Attempting to unset an undefined variable or function should not be
considered an error according to the Open Group Base Specification.

PR: standards/45738
Submitted by: Matthias Andree <matthias.andree@web.de>
MFC after: 3 days


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 117261 05-Jul-2003 dds

Changes following CScout analysis:

- Removed dead declarations
- Made objects that should have been declared as static, static.

The changes use STATIC instead of static, following the existing
convention in the rest of the code.

Approved by: schweikh (mentor)
MFC after: 2 weeks


# 114763 05-May-2003 obrien

Centralize _PATH_* definitions.

Submitted by: Tim Kientzle <kientzle@acm.org> (embellished by me)


# 104255 30-Sep-2002 tjr

Remove bits and pieces of support for atty, which was made obsolete by
adding history and vi/emacs-style line editing to the shell itself.
Atty was a user-mode terminal emulator (like screen and window) that did
line editing and history.


# 100663 25-Jul-2002 tjr

Set opterr to zero to avoid duplicate warnings from getopt(3) for unknown
options.


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 97915 06-Jun-2002 tjr

Quote the output of the no-argument form of the `set' builtin for re-input
to the shell.


# 97914 06-Jun-2002 tjr

Add the SUSv3 -p ("portable") option to both the export and readonly
builtins. This makes export/readonly print lines in the form
"export name=value".


# 97689 01-Jun-2002 tjr

Implement $PPID, the parent process ID of the shell.


# 90112 02-Feb-2002 imp

%.* takes an int, not a size_t.


# 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)
{
...


# 50471 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 45621 12-Apr-1999 cracauer

Fix typo in source-explaining comment.


# 45263 03-Apr-1999 cracauer

Implement -a flag. A test shell script can be found at
http://www.cons.org/cracauer/download/sh-interrupt/testsuite/test_export.sh
The PR also had test cases the new version passes.

Fix typo in comment.

PR: bin/1030


# 36150 18-May-1998 charnier

Add rcsid. Spelling.


# 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


# 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


# 17562 12-Aug-1996 ache

Take out 0201-0207 range - those characters abused by sh


# 17525 11-Aug-1996 ache

Localize it


# 8855 29-May-1995 rgrimes

Remove trailing whitespace.

Reviewed by: phk


# 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