summaryrefslogtreecommitdiffstats
path: root/bin/sh/options.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Remove XXX comment about removing nextopt().jilles2012-09-081-4/+0
| | | | | Using nextopt() avoids depending on the BSD-specific optreset feature in getopt() and reduces code size (both source and binary).
* sh: Allow unsetting OPTIND.jilles2011-11-201-2/+3
| | | | Note that only assigning the decimal value 1 resets getopts, as before.
* 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: Improve error message if the script cannot be opened.jilles2011-06-041-2/+4
| | | | Avoid "<nosuchfile>: cannot open <nosuchfile>: ...".
* sh: Check setuid()/setgid() return values.jilles2011-04-251-2/+4
| | | | | | | | | | | | If the -p option is turned off, privileges from a setuid or setgid binary are dropped. Make sure to check if this succeeds. If it fails, this is an error which will cause the shell to abort except in interactive mode or if 'command' was used to make 'set' or an outer 'eval' or '.' non-special. Note that taking advantage of this feature and writing setuid shell scripts seems unwise. MFC after: 1 week
* sh: Remove duplicate code resetting uid/gid for set +p/+o privileged.jilles2011-04-251-10/+5
| | | | MFC after: 1 week
* sh: Remove special code for shell scripts without magic number.jilles2011-02-041-15/+0
| | | | | | | | | | 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: Code size optimizations to buffered output.jilles2010-11-201-7/+6
| | | | | | 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-8/+8
| | | | and its usage.
* sh: Automatically enable -o emacs in interactive shells with terminals.jilles2010-04-051-1/+4
| | | | | | | This makes sh a bit more friendly in single user mode, make buildenv, chroot and the like, and matches other shells. The -o emacs can be overridden on the command line or in the ENV file.
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):jilles2009-12-271-3/+3
| | | | | | | - 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-2/+3
| | | | | Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more.
* Fix a bug in r177497 which caused the getopts state to be reset when 'set'stefanf2008-08-271-1/+1
| | | | | | was used to set a shell option (and not to change the positional parameters). Submitted by: Martin Kammerhofer
* Reset the internal state used for the 'getopts' built-in when 'shift' or 'set'stefanf2008-03-221-2/+2
| | | | | | | | are used to modify the arguments. Not doing so caused random memory reads or null pointer dereferences when 'getopts' was called again later (SUSv3 says getopts produces unspecified results in this case). PR: 48318
* Implement some of the differences between special built-ins and other builtinsstefanf2006-04-091-1/+1
| | | | | | | | | | | | | | | | | | | | demanded by POSIX. - A redirection error is only fatal (meaning the execution of a shell script is terminated) for special built-ins. Previously it was fatal for all shell builtins, causing problems like the one reported in PR 88845. - Variable assignments remain in effect for special built-ins. - Option or operand errors are only fatal for special built-ins. This change also makes errors from 'fc' non-fatal (I could not find any reasons for this behaviour). Somewhat independently from the above down-grade the error handling in the shift built-in if the operand is bigger than $# from an error() call (which is now fatal) to a return 1. I'm not sure if this should be considered a POSIX "operand error", however this change is needed for now as we trigger that error while building libncurses. Comparing with other shells, zsh does the same as our sh before this change (write a diagnostic, return 1), bash behaves as our sh after this commit (no diagnostic, return 1) and ksh93 and NetBSD's sh treat it as a fatal error.
* Include disabled options in the output of 'set +o'. POSIX says the output ofstefanf2005-10-291-11/+8
| | | | | | | | | | | | set +o can be used to reload previous settings, for this to work disabled options must be printed as well or otherwise options that were set in the mean time won't be turned off. To avoid an excessively long output line I formatted the output to print only six options per line. Submitted by: Jilles Tjoelker PR: 73500
* A second attempt to adjust option-parsing on a shell command, for thegad2005-05-161-1/+20
| | | | | | | | | | benefit of scripts start out as: #!/bin/sh -- # -*- perl -*- With this fix in place, we can commit a change to kern/imgact_shell.c so FreeBSD will process the `#!' line in shell-scripts in a more standard fashion. PR: 16393 Mentioned on: freebsd-arch
* Change /bin/sh so *it* implements the processing needed for scripts togad2005-02-161-11/+43
| | | | | | | | | | | | | | | | | | | | | | work as expected when they have a "shebang line" of: #!/bin/sh -- # -*- perl -*- -p This specific line is recommended in some perl documentation, and I think I've seen similar lines in documentation for ruby and python. Those write-ups expect `sh' to ignore everything after the '--' if the first thing after the '--' is a '#'. See chapter 19, "The Command-Line Interface" in 3rd edition of "Programming Perl", for some discussion of why perl recommends using this line in some circumstances. The above line does work on solaris, irix and aix (as three data points), and it used to work on FreeBSD by means of a similar patch to execve(). However, that change to execve() effected *all* shells (which caused other problems), and that processing was recently removed. PR: 16393 (the original request to fix the same issue) Reviewed by: freebsd-current (looking at a slightly different patch) MFC after: 1 week
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* Implement `set +o', which displays the currently set options in a formattjr2002-05-251-5/+20
| | | | suitable for re-input into the shell.
* Usage style sweep: spell "usage" with a small 'u'.des2002-04-221-1/+1
| | | | | Also change one case of blatant __progname abuse (several more remain) This commit does not touch anything in src/{contrib,crypto,gnu}/.
* o __P has been reovedimp2002-02-021-43/+22
| | | | | | | | | | | | | | | | | | 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) { ...
* Fix warnings, some of them serious because sh violated namecracauer2000-04-201-2/+2
| | | | | | | | 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.
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Avoid a possible NULL pointer dereference, nuke register usage,steve1997-04-281-6/+5
| | | | | | and remove an unnecessary reset. Obtained from: NetBSD
* 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.
* Fix a problem caused by finger failure on my part. The builtinsteve1996-12-211-3/+7
| | | | | | | | getopts should now work as expected. This fix was in the NetBSD code that I was merging from but missed getting into FreeBSD's version because of 'drain bamage' on my part. Submitted by: NetBSD, joerg
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-32/+109
| | | | Obtained from: NetBSD, me
* Add the -p (privileged) commandline switchsteve1996-10-291-1/+10
| | | | | | found in bash, zsh, and friends. Reviewed by: joerg
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-20/+39
| | | | | | | | | | | | | | 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
* Fix my breakage of the $0 handling during $ENV processing.joerg1995-10-091-2/+2
| | | | Since the broken version went into 2.1, this fix should, too.
* Posixize:joerg1995-10-011-1/+4
| | | | | | | | | | | | | | sh -c [-aCefinuvx] command_string [ command_name [argument ...] ] 1 4.56.3 Options -c Read commands from the command_string operand. Set the value of special parameter 0 (see 3.5.2) from the value of the command_name operand and the positional parameters ($1, $2, etc.) in sequence from the remaining argument operands. Pointed out by: Kaleb Keithly (kaleb@x.org)
* Fix /bin/sh's broken handling of the builtin getopts(1). The optionsjoerg1995-08-061-3/+2
| | | | | | | ``-ffoo'' and ``-f foo'' have been treated differently. This has been in violation of Posix.2 (that deprecates -ffoo, but doesn't disallow it).
* Remove trailing whitespace.rgrimes1995-05-301-2/+2
| | | | Reviewed by: phk
* Added $Id$dg1994-09-241-0/+2
|
* BSD 4.4 Lite bin Sourcesrgrimes1994-05-261-0/+433
OpenPOWER on IntegriCloud