summaryrefslogtreecommitdiffstats
path: root/bin/sh/var.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r292360: sh: Fix use-after-free when attempting to modify a read-onlyjilles2015-12-231-1/+1
| | | | | | variable. Reported by: bapt
* MFC r263847: sh: Fix memory leak with an assignment before a regular builtinjilles2014-04-151-2/+8
|
* MFC r263846: sh: Fix memory leak when trying to set a read only variable.jilles2014-04-151-1/+4
|
* MFC r263777: sh: Fix possible memory leaks and double frees with unexpectedjilles2014-04-141-3/+10
| | | | SIGINT.
* Sync sh(1) in stable/10 to head.jmmv2014-03-091-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a MFC of all the commits listed below. My original goal of this change was to only merge the move of the tests from tools/regression/bin/ into the new layout (which include tests for sh(1) and other tools as well). However, doing so is tricky due to the ongoing work in sh(1) and, especially, the many changes to its tests since stable/10 was first branched. Merging everything is the simplest way to achieve this goal and, as a bonus point, we get various fixes and miscellaneous improvements into the branch. Per jilles' suggestion, I'm avoiding the merge of a couple of changes (r256850 and r257506) that required depending kernel changes. I'm also avoiding very recent changes that have not had a long enough time to be validated in current. This is "make tinderbox" clean. r256735 sh: Remove one syscall when waiting for a foreground job. r257399 sh: Allow trapping SIGINT/SIGQUIT after ignore because of '&'. r257504 sh: Reorder union node to reduce its size on 64-bit platforms. r257920 sh: Add a test case for would-be assignments that are not due to quoting. r257929 sh: Properly quote alias output from command -v. r258489 sh: Add tests for the </dev/null implicit in a background command. r258533 sh: Add more tests for the </dev/null implicit in a background command. r258535 sh: Make <&0 disable the </dev/null implicit in a background command. r258776 sh: Prefer memcpy() to strcpy() in most cases. Remove the scopy macro. r259047 sh: Split set -x output into a separate function. r259210 Migrate tools/regression/bin/ tests to the new layout. r259844 sh: Remove an unused variable. r259846 sh: Initialize OPTIND=1 even if it came from the environment. r259874 sh: Simplify code related to PPID variable. r259946 sh: Don't check input for non-whitespace if history is disabled. r260246 sh(1): Discourage use of -e. r260506 Run the sh(1) and test(1) tests as unprivileged. r260586 Mark the bin/pax tests as requiring perl. r260634 Use TAP_TESTS_PERL to register the legacy_test in bin/pax. r260635 Replace hand-crafted Kyuafiles with automatic generation. r260654 sh: Remove SIGWINCH handler and just check for resize before every read. r261121 sh: Add test for nested alias. r261125 sh: Solve the alias recursion problem in a less hackish way. r261141 sh: Do not depend on parse/execute split in new alias test. r261160 sh: Add tests for alias names after another alias. r261192 sh: Allow aliases to force alias substitution on the following word. r262533 sh: Make expari() static. r262565 sh: Do not corrupt internal representation if LINENO inner expansion fails. r262697 sh: Simplify expari(). Reviewed by: jilles
* sh: Recognize "--" as end of options in local builtin.jilles2013-08-141-0/+1
|
* Fix two typoseadler2013-05-091-2/+2
| | | | Reviewed by: jilles
* sh: Remove mkinit's initialization routine.jilles2013-01-201-22/+10
| | | | Instead, call the only init function left directly from main().
* sh: Prefer internal nextopt() to libc getopt().jilles2012-09-151-12/+6
| | | | | | | | | 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.
* sh: Fix swapped INTON/INTOFF.jilles2012-02-041-2/+2
| | | | | | | A possible consequence of this bug was a memory leak if SIGINT arrived during a 'set' command (listing variables). MFC after: 1 week
* sh: Use vfork in a few common cases.jilles2012-02-041-0/+3
| | | | | | | | | | | | | | | | | 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.
* sh: Skip variables with invalid names in "set", "export -p", "readonly -p".jilles2011-06-171-0/+13
| | | | This ensures the output of these commands is valid shell input.
* sh: Fix duplicate prototypes for builtins.jilles2011-06-131-0/+1
| | | | | | 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.
* sh: Save/restore changed variables in optimized command substitution.jilles2011-06-121-3/+7
| | | | | | | | | | | 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.
* sh: Minor optimization to output from ulimit/export/readonly.jilles2011-05-151-6/+5
| | | | No functional change is intended.
* sh: Add \u/\U support (in $'...') for UTF-8.jilles2011-05-081-0/+7
| | | | | | | | | | 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.
* sh: Optimize variable code by storing the length of the name.jilles2011-05-081-124/+124
| | | | Obtained from: NetBSD
* sh: Track if the current locale's charset is UTF-8 or not.jilles2011-05-061-0/+19
|
* sh: Remove special code for shell scripts without magic number.jilles2011-02-041-42/+1
| | | | | | | | | | 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.
* sh: Clean up some old comments:jilles2011-01-251-6/+3
| | | | | | | | | * 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
* sh: Check readonly status for assignments on regular builtins.jilles2011-01-011-2/+6
| | | | | | | | | | 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
* sh: Code size optimizations to buffered output.jilles2010-11-201-9/+12
| | | | | | This is mainly less use of the outc macro. No functional change is intended, but code size is about 2K less on i386.
* sh: Do the additional actions if 'local -' restore changes -i/-m/-E/-V.jilles2010-11-131-0/+1
| | | | | | | Example: f() { local -; set +m; }; f caused failure to execute external programs because the job control tty fd was not opened.
* sh: Tweak some string constants to reduce code size.jilles2010-10-291-1/+1
| | | | | * Reduce some needless differences. * Shorten some error messages that should not happen.
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-131-8/+8
| | | | and its usage.
* Consistently use "STATIC" for all functions in order to be able to setobrien2010-10-131-7/+7
| | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde
* sh: Apply variable assignments left-to-right in bltinlookup().jilles2010-09-111-1/+5
| | | | | Example: HOME=foo HOME=bar cd
* sh: Pass TERM changes to libedit.jilles2010-06-021-0/+5
| | | | | | | | I have changed the patch slightly to ignore TERM changes in subshells. PR: bin/146916 Submitted by: Guy Yur Obtained from: NetBSD
* sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.jilles2010-05-051-7/+68
| | | | | | | | | | | | | | | | 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.
* sh: Do not stat() $MAIL/$MAILPATH in non-interactive shells.jilles2010-02-061-1/+6
| | | | | These may be NFS mounted, and we should not touch them unless we are going to do something useful with the information.
* sh: Change varinit to use const better.jilles2009-12-271-13/+13
|
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):jilles2009-12-271-4/+4
| | | | | | | - const - initializations to silence -Wuninitialized (it was safe anyway) - remove nested extern declarations - rename "index" locals to "idx"
* sh: Constify various strings.jilles2009-12-241-20/+19
| | | | | Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more.
* sh: Remove setting variables from dotcmd/exportcmd.jilles2009-12-241-1/+0
| | | | | | | | | | | | 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'
* Fix various things about SIGINT handling:jilles2009-11-221-0/+3
| | | | | | | | | | | | | | | | | | * 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.
* sh: Improve handling of setjmp/longjmp volatile:jilles2009-06-231-5/+1
| | | | | | | | | | | - 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)
* correctly test for __GNUC__ macro (non-GCC compilers do not have it defined ↵rse2009-06-011-1/+1
| | | | at all)
* Take care that the input to setenv() may actually be a pointer straightscf2007-07-061-14/+28
| | | | | | | | from environ; make a copy before manipulating it and passing it to setenv(). Approved by: wes Approved by: re (kensmith)
* Significantly reduce the memory leak as noted in BUGS section forscf2007-07-041-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* Back out all POSIXified *env() changes.ache2007-05-011-9/+4
| | | | | | | | | 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.
* Simplify previous fix and disallow VTEXTFIXED direct pass for putenv() too,ache2007-04-301-3/+3
| | | | just use savestr()
* Put some safeguards:ache2007-04-301-4/+9
| | | | | | | 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.
* Implement the PS4 variable which is defined by the POSIX User Portabilitystefanf2006-06-151-0/+3
| | | | | | | | | | | | 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
* POSIX demands that set's output (when invoked without arguments) should bestefanf2006-04-291-9/+47
| | | | | | sorted. Sort the variables before printing. PR: 96415
* s/varable/variable/; s/tored/stored/schweikh2006-02-041-2/+2
|
* - Provide a reasonable error message for `export -p var'.stefanf2005-09-091-1/+3
| | | | - Use argv rather than argptr since getopt() is used here.
* Use prototypes in the MKINIT lines collected by mkinit.stefanf2005-08-131-1/+1
|
* Attempting to unset an undefined variable or function should not bedes2004-09-271-1/+1
| | | | | | | | 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
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Changes following CScout analysis:dds2003-07-051-3/+3
| | | | | | | | | | | - 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
OpenPOWER on IntegriCloud