summaryrefslogtreecommitdiffstats
path: root/bin/sh/main.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Make various functions static.jilles2012-01-011-1/+2
|
* 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: Read .profile from the home directory (or / if HOME is not set).jilles2011-06-121-1/+1
| | | | | | | | | | 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
* sh: Do parameter expansion on ENV before using it.jilles2011-06-101-4/+10
| | | | | | This is required by POSIX, and allows things like ENV=\$HOME/.shrc. Note that tilde expansion is explicitly not performed.
* sh: Reduce more needless differences between error messages.jilles2011-06-041-1/+1
|
* sh: Fix bss-based buffer overflow in . builtin.jilles2011-05-221-4/+7
| | | | | | | | | | | 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
* sh: Add \u/\U support (in $'...') for UTF-8.jilles2011-05-081-2/+2
| | | | | | | | | | 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: Track if the current locale's charset is UTF-8 or not.jilles2011-05-061-0/+2
|
* sh: Allow EV_EXIT through function calls, make {...} <redir more consistent.jilles2011-04-231-1/+2
| | | | | | | | | | | | | | | | | | | | | If EV_EXIT causes an exit, use the exception mechanism to unwind redirections and local variables. This way, if the final command is a redirected command, an EXIT trap now executes without the redirections. Because of these changes, EV_EXIT can now be inherited by the body of a function, so do so. This means that a function no longer prevents a fork before an exec being skipped, such as in f() { head -1 /etc/passwd; }; echo $(f) Wrapping a single builtin in a function may still cause an otherwise unnecessary fork with command substitution, however. An exit command or -e failure still invokes the EXIT trap with the original redirections and local variables in place. Note: this depends on SHELLPROC being gone. A SHELLPROC depended on keeping the redirections and local variables and only cleaning up the state to restore them.
* sh: Remove special code for shell scripts without magic number.jilles2011-02-041-16/+2
| | | | | | | | | | 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: Make exit without parameters from EXIT trap POSIX-compliant.jilles2011-01-081-5/+2
| | | | | | | It should use the original exit status, just like falling off the end of the trap handler. Outside an EXIT trap, 'exit' is still equivalent to 'exit $?'.
* sh: Code size optimizations to buffered output.jilles2010-11-201-4/+2
| | | | | | This is mainly less use of the outc macro. No functional change is intended, but code size is about 2K less on i386.
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-131-4/+4
| | | | and its usage.
* sh: Fix break/continue/return sometimes not skipping the rest of dot script.jilles2010-08-151-2/+3
| | | | | | | | | | | | | In our implementation and most others, a break or continue in a dot script can break or continue a loop outside the dot script. This should cause all further commands in the dot script to be skipped. However, cmdloop() did not know about this and continued to parse and execute commands from the dot script. As described in the man page, a return in a dot script in a function returns from the function, not only from the dot script. There was a similar issue as with break and continue. In various other shells, the return appears to return from the dot script, but POSIX seems not very clear about this.
* sh: Recognize "--" in . and exec.jilles2010-05-281-2/+8
| | | | | | | | | | | | | | | | | | Although "--" historically has not been required to be recognized for certain special builtins that do not take options in POSIX, some other implementations recognize options for them, requiring scripts to use "--" or avoid operands starting with "-". Operands starting with "-" can be avoided with eval by prepending a space, and cannot occur with break, continue, exit, return and shift as they only take numbers, nor with times as it does not take operands. With . and exec, avoiding "-" is not so easy as it may require reimplementing the PATH search; therefore the current proposal for POSIX is to require recognition of "--" for them. We continue to accept other strings starting with "-" as operands to . and exec, and also "--" if it is alone to . (which would otherwise be invalid anyway).
* sh: On startup of the shell, use PWD from the environment if it is valid.jilles2010-04-171-4/+1
| | | | | | | | | | | | | | | Unset PWD if it is incorrect and no value for it can be determined. This preserves the logical current directory across shell invocations. Example (assuming /home is a symlink): $ cd $ pwd /home/foo $ sh $ pwd /home/foo Formerly the second pwd would show the physical path (symlinks resolved).
* sh: Do not stat() $MAIL/$MAILPATH in non-interactive shells.jilles2010-02-061-0/+2
| | | | | These may be NFS mounted, and we should not touch them unless we are going to do something useful with the information.
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):jilles2009-12-271-4/+2
| | | | | | | - const - initializations to silence -Wuninitialized (it was safe anyway) - remove nested extern declarations - rename "index" locals to "idx"
* sh: Do not run callers' exception handlers in subshells.jilles2009-12-251-3/+3
| | | | | | | Reset the exception handler in the child to main's. This avoids inappropriate double cleanups or shell duplication when the exception is caught, such as 'fc' and future 'command eval' and 'command .'.
* sh: Constify various strings.jilles2009-12-241-2/+2
| | | | | 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-4/+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'
* sh: Some changes to stderr flushing:jilles2009-11-211-2/+2
| | | | | | | | | * increase buffer size from 100 to 256 bytes * remove implied flush from out2str(), in particular this avoids unnecessary flushing in the middle of a -x tracing line * rename dprintf() to out2fmt_flush(), make it flush out2 and use this function in various places where flushing is desired after an error message
* Avoid leaving unnecessary waiting shells in many forms of sh -c COMMAND.jilles2009-06-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | This change only affects strings passed to -c, when the -s option is not used. The approach is to check if there may be additional data in the string after parsing each command. If there is none, use the EV_EXIT flag so that a fork may be omitted in specific cases. If there are empty lines after the command, the check will not see the end and forks will not be omitted. The same thing seems to happen in bash. Example: sh -c 'ps lT' No longer shows a shell process waiting for ps to finish. PR: bin/113860 Reviewed by: stefanf Approved by: ed (mentor)
* Fix the eval command in combination with set -e. Before this change the shellstefanf2009-05-311-1/+1
| | | | | | | | | would always terminate if eval returned with a non-zero exit status regardless if the status was actually tested. Unfortunately a new file-scope variable is needed, the alternative would only be to add a new parameter to all built-ins. PR: 134881
* Add the POSIX option -p to the jobs builtin command. It prints the PID of thestefanf2006-10-071-1/+1
| | | | | | | | process leader for each job. Now the last specified option for the output format (-l, -p or -s) wins, previously -s trumped -l. PR: 99926 Submitted by: Ed Schouten and novel (patches modified by me)
* Issue an error when . (dot) is invoked without a filename. The synopsisstefanf2006-04-021-8/+10
| | | | | | | is just ". file" according to POSIX, however many other shells allow arguments to be passed after the file. For compatibility (we even use that feature in buildworld) additional arguments are not considered to be an error, even though this shell does not do anything with the arguments at all.
* Initialize PWD early on (don't expect it to be inherited from theschweikh2006-02-041-0/+2
| | | | | | environment or set it only when changing directories with cd). PR: standards/92640
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Remove some kind of profiling support that required the 4.2BSD monitor()tjr2002-10-011-12/+0
| | | | function in libc.
* Remove bits and pieces of support for atty, which was made obsolete bytjr2002-10-011-5/+1
| | | | | | 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.
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* Add -s (output PID's only) and -l (show PID's) options to the jobs(1)tjr2002-05-311-1/+1
| | | | builtin. Modify the output format to match what SUSv3 requires.
* o __P has been reovedimp2002-02-021-32/+10
| | | | | | | | | | | | | | | | | | 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) { ...
* From submitter:cracauer2000-08-161-1/+2
| | | | | | | | | | | | | | | | | growstackblock() sometimes relocates a stack_block considered empty without properly relocating stack marks referencing that block. The first call to popstackmark() with the unrelocated stack mark as argument then causes sh to abort. Relocating the relevant stack marks seems to solve this problem. The patch changes the semantics of popstackmark() somewhat. It can only be called once after a call to setstackmark(), thus cmdloop() in main.c needs an extra call to setstackmark(). PR: bin/19983 Submitted by: Tor.Egge@fast.no Reviewed by: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* Use #include <errno.h> rather than extern int errno;.imp2000-04-141-2/+1
|
* Include strerror(errno) in error messages after failed system calls.cracauer1999-11-291-1/+1
| | | | Fix a warning.
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Various spelling/formatting changes.kris1999-05-081-2/+2
| | | | Submitted by: Philippe Charnier <charnier@xp11.frmug.org>
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Don't source $ENV unless this is an interactive shell.steve1997-05-051-2/+2
|
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | 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.
* Make sh(1) a little braver in the face of adversity. sh(1)steve1996-12-211-2/+3
| | | | | | | now handles the getpwd() init problem the same way as bash and ksh do. Also while I was in here, I cleaned up the format a little, removed some unnnecessary #if SYMLINKS cruft, and changed the pwd builtin to use getcwd(3) as Joerg suggested.
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-17/+39
| | | | Obtained from: NetBSD, me
* Add the -p (privileged) commandline switchsteve1996-10-291-3/+6
| | | | | | found in bash, zsh, and friends. Reviewed by: joerg
* Mend 'exit' without breaking 'exit 1'adam1996-09-121-3/+4
| | | | | | *blush* %-\ Pointed out by: bruce
* Backed out last change. It broke even `exit 1'.bde1996-09-121-4/+2
|
* let the "exit" command return status when it is implicitadam1996-09-081-2/+4
|
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-23/+75
| | | | | | | | | | | | | | 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
* Localize itache1996-08-111-1/+4
|
OpenPOWER on IntegriCloud