History log of /freebsd-current/bin/sh/input.c
Revision Date Author Comments
# e043f372 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 90aea514 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 971677d5 24-Nov-2021 Bryan Drewery <bdrewery@FreeBSD.org>

sh: Avoid some headers when NO_HISTORY is set.

This is more simpler compatibility with using this source on older
systems before libedit was made to install filecomplete.h in
commit b315a7296d2.


# d2c23317 23-Sep-2021 Stephane Rochoy <stephane.rochoy@stormshield.eu>

sh: Add -o verify to use O_VERIFY when sourcing scripts

Add -o verify to sh to make it use O_VERIFY when
sourcing scripts and reading profiles.

Useful in conjunction with mac_veriexec to help protect at
least some parts of the boot sequence, e.g., /etc/rc*.

Differential revision: https://reviews.freebsd.org/D30464
Reviewed by: jilles, sjg
Obtained from: Stormshield


# becf15d7 28-Mar-2020 Kyle Evans <kevans@FreeBSD.org>

sh: remove duplicate el definition

el is declared extern in myhistedit.h and defined in histedit.c. Remove the
duplicate definition in input.c to appease the -fno-common build.

-fno-common will become the default in GCC10/LLVM11.

MFC after: 3 days


# 77da4a95 27-Nov-2018 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Use 126 and 127 exit status for failures opening a script

This affects scripts named on the command line, named with a '.' special
builtin and found via the PATH %func autoloading mechanism.

PR: 231986


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 84f18910 23-Feb-2016 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Fix set -v and multiline history after r295825.

r295825 erroneously dropped the newline from the input data for 'set -v'
output and multiline history.

Reported by: vangyzen


# 3b3c9ccf 21-Feb-2016 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove unnecessary flushouts while reading script.

Output is flushed when a builtin is done or immediately after writing it
(error messages, set -v output, prompts).


# dcd95d8a 19-Feb-2016 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Rework code to remove '\0' from shell input.

This fixes bugs where '\0' was not removed correctly and speeds up the
parser.


# 72238faa 14-Sep-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove arbitrary length limit on << EOF markers.

This also simplifies the code.


# 5545fadd 14-Sep-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Add some const keywords.


# 48f49aac 26-Jan-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Allow aliases to force alias substitution on the following word.

If an alias's value ends with a space or tab, the next word is also
checked for aliases.

This is a POSIX feature. It is useful with utilities like command and
nohup (alias them to themselves followed by a space).


# 4b489a60 24-Jan-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Solve the alias recursion problem in a less hackish way.

Add the space to avoid alias recursion when the alias is expanded, not when
it is added.

As a result, displaying an alias via command -v, command -V or type no
longer erroneously appends a space. Adjust the tests so they now require
this bug to be absent.


# d78fdfde 14-Jan-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove SIGWINCH handler and just check for resize before every read.

The SIGWINCH handler triggers breakage in libedit which is hard to fix; see
PR bin/169773.

Also, window size changes while a program is in foreground (and it rather
than sh will receive SIGWINCH) will now be picked up automatically.

Downside: it is now certain that a resize is only processed after pressing
<Enter>. If libedit is fixed, sh will most likely have to be changed also.

PR: bin/180146


# cac001aa 27-Dec-2013 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Don't check input for non-whitespace if history is disabled.

preadbuffer() maintained a flag whether there was any non-whitespace
character. This flag is only useful when history is enabled (in that case,
lines containing only whitespace are not added to history). Instead, check
using strspn() when history is enabled.

There is an approximate 2% speedup when running
sh -c '. /etc/rc.subr; . /etc/defaults/rc.conf; source_rc_confs'
with hot cache.


# 0bdd3871 25-Jul-2013 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove #define MKINIT.

MKINIT only served for the removed mkinit. Many variables can be static now.


# 338b821b 25-Jul-2013 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove mkinit.

Replace the RESET blocks with regular functions and a reset() function that
calls them all.

This code generation tool is unusual and does not appear to provide much
benefit. I do not think isolating the knowledge about which modules need to
be reset is worth an almost 500-line build tool and wider scope for
variables used by the reset functions.

Also, relying on reset functions is often wrong: the cleanup should be done
in exception handlers so that no stale state remains after 'command eval'
and the like.


# 5aa6dfda 05-May-2013 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call.


# 46c6b52d 01-Apr-2013 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Fix various compiler warnings.

It now passes WARNS=7 with clang on i386.

GCC 4.2.1 does not understand setjmp() properly so will always trigger
-Wuninitialized. I will not add the volatile keywords to suppress this.


# 60a6bf2a 19-Jan-2013 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Replace an mkinit use with an initialization.


# 22bec20b 14-Nov-2012 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove an unused variable.


# 35dab859 11-Nov-2012 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Forward-declare struct alias instead of giving up type safety via void *


# 00c43e0c 11-Jul-2012 Pedro F. Giffuni <pfg@FreeBSD.org>

Merge libedit adjustment from NetBSD.

On recent versions of NetBSD's libedit, el_gets
now sets el_len to -1 on error so we can
distinguish between a NULL string and an error.

This fixes sh from exiting with newer versions
of libedit now allowing EINTR to return.

Obtained from: NetBSD
Reviewed by: jilles
MFC after: 3 weeks


# 7f40c1f8 14-Jan-2012 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Change input buffer size from 1023 to 1024.

PR: bin/161756


# 260fc3f4 01-Jan-2012 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Make various functions static.


# 47a5ab29 04-Jun-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Reduce more needless differences between error messages.


# 3835f47c 04-Feb-2011 Jilles Tjoelker <jilles@FreeBSD.org>

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.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 88328642 13-Oct-2010 David E. O'Brien <obrien@FreeBSD.org>

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


# aa7b6f82 12-Oct-2010 David E. O'Brien <obrien@FreeBSD.org>

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


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 384aedab 27-Dec-2009 Jilles Tjoelker <jilles@FreeBSD.org>

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"


# 2cac6e36 24-Dec-2009 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Constify various strings.

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


# eaa34893 22-Nov-2009 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Ensure the same command input file is on top after executing a builtin.

This avoids weirdness when 'fc -e vi' or the like is done and there is a
syntax error in the file. Formerly an interactive shell tried to execute
stuff after the syntax error and exited.

This should also avoid similar issues with 'command eval' and 'command .'
when 'command' is implemented properly as in NetBSD sh.

Special builtins did not have this problem since errors in them cause the
shell to exit or to reset various state such as the current command input
file.


# c6204d4a 21-Nov-2009 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Some changes to stderr flushing:
* 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


# 3055b7c6 17-Jun-2009 Jilles Tjoelker <jilles@FreeBSD.org>

Properly flush input after an error in backquotes in interactive mode.

For parsing an old-style backquote substitution (`...`),
a string "file" is used to store the contents of the
substitution (with the special backslash processing done).
If an error occurs, the shell cleans up all these files
(returning to the top level) and flush the top level
file. Erroneously, it first flushed the current file and
then cleaned up all extra files, so that the top level
file (i.e. the terminal) was not flushed.

Example (in interactive mode):
echo `for` echo This should not be printed

Also noticeable in (in interactive mode):
echo `(`
The old version prints an extraneous prompt.

Approved by: ed (mentor)


# 960da934 13-Jun-2009 Jilles Tjoelker <jilles@FreeBSD.org>

Avoid leaving unnecessary waiting shells in many forms of sh -c COMMAND.

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)


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 896229d9 29-Apr-2006 Stefan Farfeleder <stefanf@FreeBSD.org>

Check the buffer size when copying the line returned by el_gets() into our
own buffer. Interactively typing in long lines (>1023 characters)
previously overflowed the buffer. Unlike the NetBSD people I don't see the
need to subtract 8 from BUFSIZ, so I just used BUFSIZ-1.

Obtained from: NetBSD
PR: 91110


# 6195fb41 06-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 7e1c7266 20-Jan-2004 Dag-Erling Smørgrav <des@FreeBSD.org>

Replace home-grown dup2() implementation with actual dup2() calls. This
should slightly reduce the number of system calls in critical portions of
the shell, and select a more efficient path through the fdalloc code.

Reviewed by: bde


# 2ba1b30b 05-Jul-2003 Diomidis Spinellis <dds@FreeBSD.org>

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


# be58cc48 23-Jul-2002 Tim J. Robbins <tjr@FreeBSD.org>

Avoid calling el_resize() from a signal handler, even though libedit
itself does that if you set EL_SIGNAL. Instead, set a flag and check it
before calling el_gets(). This is safer, but slower to respond to changes.

Pointed out by: mp


# 2749b141 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use FBSDID


# 5134c3f7 01-Feb-2002 Warner Losh <imp@FreeBSD.org>

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


# 757eeda0 01-Oct-2001 David E. O'Brien <obrien@FreeBSD.org>

*** empty log message ***


# 6c48b6cf 29-Nov-1999 Martin Cracauer <cracauer@FreeBSD.org>

Include strerror(errno) in error messages after failed system calls.
Fix a warning.


# 2a456239 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 426e9c1d 25-Apr-1999 Warner Losh <imp@FreeBSD.org>

First set of fixes to keep egcs happy. These include {} around single
statement if blocks[*] when the else could be ambiguous, not defaulting
to int type and removal of some unused variables.

[*] This is explicitly allowed by style(9) when the single statement
spans more than one line.

Reviewed by: obrien, chuckr


# 3d7b5b93 18-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Add rcsid. Spelling.


# 4ca7fe3b 27-Apr-1997 Steve Price <steve@FreeBSD.org>

Nuke register keyword usage, rename pread to preadfd, and open
input files FD_CLOEXEC.

Obtained from: NetBSD


# b97fa2ef 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

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.


# ab0a2172 13-Dec-1996 Steve Price <steve@FreeBSD.org>

Merge in NetBSD mods and -Wall cleaning.

Obtained from: NetBSD, me


# 4417f629 03-Sep-1996 Peter Wemm <peter@FreeBSD.org>

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)


# aa9caaf6 01-Sep-1996 Peter Wemm <peter@FreeBSD.org>

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


# 069428af 26-May-1996 Peter Wemm <peter@FreeBSD.org>

Import the 4.4BSD-Lite2 /bin/sh sources

Requested by: joerg

(Note, this is mostly going to be conflicts, which is expected. Our entire
sh source has a mainline, so this should not change anything except for
a few new files appearing. I dont think they are a problem)


# 8f08f33e 03-Nov-1995 Peter Wemm <peter@FreeBSD.org>

Implement allowing 'set -v' in the middle of a script to work.
This means that a script containing:
echo 1
set -v
echo 2
will now produce output, like it does on SYSV machines and other 'proper'
/bin/sh implementations..

This is done by a slight restructure of the input processor allowing it to
read chunks from the file at a time, but process the data by line from the
chunk.

Obtained from: Christos Zoulas for NetBSD. <christos@deshaw.com>


# 2162b2d2 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.

Reviewed by: phk


# 89730b29 23-Sep-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# 4b88c807 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite bin Sources