Commit Graph

520 Commits

Author SHA1 Message Date
jmmv aba1ca99ae Include strings.h, needed for index's prototype. 2003-08-26 18:14:24 +00:00
jmmv 6d82007582 Use '\0' instead of NULL in two checks (we are not checking for a pointer
value).  While here, add a missing whitespace.
2003-08-26 18:13:25 +00:00
jmmv 5199a59afa s/FD_SETFD/F_SETFD/ 2003-08-26 18:12:33 +00:00
jmmv 534b18e585 Move an assignment that was using a variable out of scope to fix a build
problem on !NetBSD.
2003-08-25 20:08:12 +00:00
itojun 59a105b48a remove \r (agc, are you using MS-DOS?) 2003-08-22 14:21:12 +00:00
agc 3538d2653b Move 4 more files from UCB 4 clause to 3 clause licence.
Thanks to Julio Merino for pointing them out.
2003-08-22 11:22:23 +00:00
christos e9a8269bb0 remove clause 3 2003-08-21 17:57:53 +00:00
agc b5b2954259 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22249, verified by myself.
2003-08-07 09:05:01 +00:00
itojun a69cd45b93 use bounded string op 2003-07-13 08:31:13 +00:00
wiz 5127f8f2c1 Quote some punctuation. 2003-06-27 09:11:12 +00:00
dsl a9fc176e82 Don't close any script files if vfork is set.
If a fork() is done later in order to feed a 'here' document into a pipe
then it is possible that one end of the pipe might get closed.
2003-05-15 13:26:45 +00:00
dsl 49e6852272 Fix problems with parallel makes. 2003-05-15 10:13:36 +00:00
dsl 6285ef062c Use echo instead of cat to add prologue to builtins.[ch]
Under some circumstances the headers got overwritten.
2003-05-15 10:11:01 +00:00
christos dd61e68e1f Use ${HOST_SH} 2003-05-08 13:03:19 +00:00
wiz f0b76593e4 Drop trailing space. 2003-05-06 08:33:08 +00:00
dsl 534ba36ad4 Recognise octal and hexadecimal constants in expressions.
- as required by SUSv3
2003-05-06 08:10:42 +00:00
gmcgarry 5e5ffccb2b ANSIify. 2003-05-04 06:36:50 +00:00
gmcgarry f8d2e9e189 Add new builtin 'inputrc' which allows keybindings to be redefined
for the current shell.  From Arne H Juul in PR#10097.
2003-05-04 01:05:24 +00:00
gmcgarry 62bb6faae3 Expand documentation of emacs and vi modes. From
Jeremy C. Reed in PR#14578.
2003-05-02 09:00:14 +00:00
itojun e6a384fc32 %d is 12 chars, not 10 chars. hinted by deraadt 2003-04-15 07:40:56 +00:00
zuntum 1a2ec1a713 add missing parenthesis 2003-04-12 16:39:19 +00:00
kristerw 7fee304b15 Change "if" to "if and only if" per discussion in PR 20794. 2003-03-22 11:37:49 +00:00
lukem c61fa8df18 If building as a CRUNCHEDPROG, use "lex -L" and "yacc -l" to suppress #line
generation.  This may solve [bin/20637].
2003-03-10 17:58:21 +00:00
wiz 990562bfef .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
2003-02-25 10:34:36 +00:00
wiz 4cc7cdbc5c New sentence, new line; bump date for last change. 2003-02-12 18:58:50 +00:00
gmcgarry 8a0ced42ec Introduce LANG environment variable and Xref to nls(7).
Comment out the statement: "We expect POSIX conformance
by the time 4.4BSD is released."
2003-02-12 02:55:14 +00:00
dsl 51d94f2156 Fix bin/20185 - builtin called from function of same name mustn't be hashed.
Make 'hash' only report utilities that are not builtins (posix), the
non-posix 'hash -v' will report everything.
(agreed by christos)
2003-02-04 08:51:30 +00:00
dsl 0871280204 Parse end of line comments correctly
(approved by christos)
2003-02-02 21:10:45 +00:00
christos 66b9125762 - use FD_CLOEXEC properly
- move ttyfd to a high fd
suggested by Tim Robbins at FreeBSD.
2003-01-27 12:54:08 +00:00
wiz 6ce643e53c Fix indentation of continuation of first line in SYNOPSIS. 2003-01-23 18:32:07 +00:00
agc 53ed48f326 Make this build on platforms where size_t != int, i.e. sparc, arm, ppc, ... 2003-01-23 14:58:07 +00:00
rafal 0923f4be26 Make this build again. 2003-01-23 03:33:16 +00:00
wiz e254f6a849 More markup, more commas, less typos. 2003-01-22 22:05:45 +00:00
dsl e314f958bd Support command -p, -v and -V as posix
Stop temporary PATH assigments messing up hash table
Fix sh -c -e "echo $0 $*" -a x (as posix)
(agreed by christos)
2003-01-22 20:36:03 +00:00
kleink b3df6303a9 Rename `sigset' locals to avoid symbol shadowing warning. 2003-01-16 09:38:37 +00:00
christos 51457e8842 Make sure that UPEOF is compared to the right type on the left hand
side. Sometimes it was compared to int, which was -1 on EOF, and on
unsigned char machines UPEOF was (unsigned char)-1. This worked
by chance because isalpha((unsigned char)-1) returns false usually,
but it does not when the locale is invalid!
2003-01-12 20:26:53 +00:00
christos a17201f05e allow this to be compiled with unsigned-chars. 2003-01-09 13:57:26 +00:00
wiz 617b132aac Spell output with two ts. 2003-01-04 23:43:02 +00:00
uebayasi 80a4544dcd trap '' SIGINT -> trap '' INT. 2002-12-28 05:08:27 +00:00
kleink 9273e5b038 Another it's -> its. 2002-12-19 18:04:41 +00:00
uebayasi 60ad876a43 `` [n1]>&n2 Duplicate standard output (or n1) _TO_ n2.'' 2002-12-12 11:50:40 +00:00
christos aa0e549885 PR/19453: Christopher Richards: Call setlocale() in /bin/sh 2002-12-11 19:12:18 +00:00
agc 1aafd1a470 Include <stdio.h> to get the prototype for sprintf(3) - macppc needs this. 2002-11-25 21:55:58 +00:00
agc ea1d615943 Make this compile on some of the more esoteric architectures (e.g. those
which are not i386)
2002-11-25 12:13:03 +00:00
christos c02b3bbdf4 Fixes from David Laight:
- ansification
- format of output of jobs command (etc)
- job identiers %+, %- etc
- $? and $(...)
- correct quoting of output of set, export -p and readonly -p
- differentiation between nornal and 'posix special' builtins
- correct behaviour (posix) for errors on builtins and special builtins
- builtin printf and kill
- set -o debug (if compiled with DEBUG)
- cd src obj (as ksh - too useful to do without)
- unset -e name, remove non-readonly variable from export list.
  (so I could unset -e PS1 before running the test shell...)
2002-11-24 22:35:38 +00:00
wrstuden 5b0a9938fd Use signed char to replace int8_t, not just char. Should fix macppc
cross-build problems introduced in rev 1.59.

Pointed out by Valeriy E. Ushakov uwe at ptc dot spbu dot ru on
tech-toolchain.
2002-10-31 17:14:46 +00:00
christos dde7426849 From David Laight
> The wrong process is aborting when variable assignment fails
> in the vfork path.  So the following command fails to execute
> the second echo (shown here with the correct output).
>
> $ (readonly r; r= /bin/echo a; echo b)
> r: is read only
> b
>
> fix: defer the mklocal() to the child shell.
2002-10-23 19:46:34 +00:00
christos f3dfd6e686 From David Laight:
> Also 'jobs' fails in a non-interactive shell.
> In showjobs(), the code that puts the process back into its
> own process group should only be run if the shell is actually
> doing job control - eg if 'mflag' is set.
2002-10-23 19:46:06 +00:00
christos 6166cc6e93 Fix interrupt problam from David Laight
$ /fred # non existant command
$ ^C # stops working

He says:
    Ok the extra INTOFF is the one in exverror().
    In almost all cases this doesn't matter because the longjmp()s
    all end up in main() and the FORCEINTON call sorts it out
    for the next command.
    (There are a significant number of INTON/OFF mismatches through
    the error paths...)

    In any case the above failure can be 'fixed' by changing 2 (I think
    they are both needed) INTON calls to FORCEINTON within evalcommand.
    The following patch seems to work:

We should really look in the code and fix the INTON->INTOFF pairs.
2002-10-23 13:25:24 +00:00
lukem e490a5c798 don't compile in `-h' as a synonym for the command that the argument is for.
this fix is hokey, but works as well as the previous solution for -j.
2002-10-15 04:15:58 +00:00
christos 1ce87c4b29 - it is wrong to put inton/intoff arount ckmalloc(), because the code
around it is the one that does this.
- whitespace fixes.
2002-10-07 14:26:49 +00:00
christos 202746f803 explain what's breaking with alignments > 16, but no fix yet. 2002-10-07 14:26:08 +00:00
christos b9d3050e20 Rename ALIGN to SHELL_ALIGN and simplify macro so that it does not have side
effects, and add double to it, so that it aligns doubles correctly too. This
is just a workaround to fix the sparc64 problem where ALIGN() is now defined
in some include file to be 16 instead of 8. Thanks to martin for debugging this.
2002-10-04 13:15:51 +00:00
wiz 1da66f1f4c filesystem -> file system, automaticly -> automatically. 2002-10-02 10:01:46 +00:00
wiz 2e6e2165c0 Use more mdoc, particularly to get rid of some \*[Lt] and \*[Gt]. 2002-10-01 15:06:31 +00:00
mycroft 6092f7d52b Revert the previous for now. This is truly gross. 2002-09-28 03:15:43 +00:00
mycroft 7973b7a0ac Remove the duplicate setpgid() in forkparent(). The real bug was freeing the
job structure in the child and referencing freed memory.
2002-09-28 03:08:00 +00:00
christos 4783843fdc Revert previous change. No need to save rootshell. It is only affecting
the non-vfork case. Having said that, it would be nice if pipelines of
simple commands were vforked too. Right now they are not.
Explain that setpgid() might fail because we are doing it both in the
parent and the child case, because we don't know which one will come
first.
Suspending a pipeline prints %1 Suspended n times where n is the number
of processes, but that was there before. It is easy to fix, but I'll
leave the code alone for now.
2002-09-28 01:25:01 +00:00
christos 6f48233483 Deal with rootshell not being maintained correctly in the vfork() case.
Propagate isroot, throughout the eval process and maintain it properly.
Fixes sleep 10 | cat^C not exiting because sleep and cat ended up in
their own process groups, because wasroot was always true in the children.
2002-09-27 22:56:24 +00:00
mycroft d84d36165d Clean up INTOFF/INTON usage a little -- none of fork{shell,parent,child}()
screw with them now, only their callers.
2002-09-27 21:32:24 +00:00
christos ad1e7bca30 off by one in nprocs. 2002-09-27 21:04:08 +00:00
christos 35975338b0 Put back charles' fixes from -r1.60 2002-09-27 20:24:36 +00:00
christos edcb454443 VFork()ing shell: From elric@netbsd.org:
Plus my changes:
	- walking process group fix in foregrounding a job.
	- reset of process group in parent shell if interrupted before the wait.
	- move INTON lower in the dowait so that the job structure is
	  consistent.
	- error check all setpgid(), tcsetpgrp() calls.
	- eliminate unneeded strpgid() call.
	- check that we don't belong in the process group before we try to
	  set it.
2002-09-27 18:56:50 +00:00
mycroft 2aa6ebd4ed In evalpipe(), move the INTOFF after the waitforjob(), to prevent possible
race conditions -- now we always synchronously wait for the job to finish.
In evalcommand(), add the same INTOFF/INTON locking as evalpipe(), to prevent
leaving internal state inconsistent, and also to insure that we synchronously
wait for the job.
2002-09-27 17:37:12 +00:00
christos 6438e7dcdc no SYSV for eagain, enable EMFILE 2002-09-27 16:56:15 +00:00
wiz 14dfaa4b03 New policy: New sentences start on a new line.
Patches by Robert Elz <kre at munnari oz au>, with minimal changes by me.
2002-09-25 15:18:36 +00:00
thorpej e41b1aa4a2 Use "unsigned char" and "char" instead of "u_int8_t" and "int8_t"
for TARGET_CHAR when building mksyntax.  This isn't perfect, but
it lets the host tool work on non-BSD systems without completely
redoing how sh is built.
2002-09-15 00:19:22 +00:00
lukem 146a774973 Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path (etc). 2002-08-19 09:56:00 +00:00
christos 82886e162e deal with char c; c != -129 warning. Hi jason! 2002-05-31 16:18:48 +00:00
wiz 10610e5a31 __STDC__ is always defined on NetBSD. 2002-05-25 23:12:16 +00:00
wiz 0b398b282c __STDC__ is always defined on NetBSD, so remove #ifdef __STDC__ (and
unnecessary #else cases).
2002-05-25 23:09:06 +00:00
bjh21 84c006d0f8 The printf builtin has been "temporarily" disabled for eight years. Remove
its directory from .PATH to avoid confusion.
2002-05-15 20:45:17 +00:00
bjh21 6f786375c4 Implement sh -a (allexport). Code (all two lines of it) from FreeBSD
(FreeBSD var.c 1.13, sh.1 1.27).
2002-05-15 19:43:29 +00:00
christos f629aa28d9 implement noclobber. From Ben Harris, with minor tweaks from me. Two
unimplemented comments to go. Go Ben!
2002-05-15 16:33:35 +00:00
christos eac955176d Implement unset variable error messages from Ben Harris. 2002-05-15 14:59:21 +00:00
christos de525ac6ca Try harder to find a tty. 2002-04-10 15:52:07 +00:00
thorpej 3ea17f6cff Move the declaration of digit[] into the #ifdef'd code block that
uses it.  Prevents a warning from gcc 3.2.
2002-04-09 00:52:05 +00:00
christos e6ab6d48dc PR/16174: Matthias Buelow: Job control fails on jobs that fd == 2 does not
point to a tty.

Unfortunately the shell assumed that it could do all process group
handling ioctls to fd=2, but this is not correct. Jobs that redirected
fd=2 would be unable to perform the ioctls and silently fail since
the error reporting channel is fd=2... Instead open /dev/tty set
it to close on exec, and use that instead (like all other shells
do). We don't handle the case where the OS does not provide FD_CLOEXEC
or FIOCLEX, because I am lazy.

While I am there:
- Simplify the code by defining functions for tc{g,s}pgrp when OLD_TTY_DRIVER
  is defined.
- make sure that 'sh &' works by stopping itself. Don't kill the shell's
  process group, kill the shell itself.
2002-04-03 14:30:44 +00:00
christos c910c75b83 PR/16010: Andreas Gustafsson: wait is not interruptible. 2002-03-22 19:50:42 +00:00
simonb 668ba50fa3 In forkshell() don't free the current job. Fixes problem with previous
commit where pipeline commands didn't inherit the correct process group.
Reviewed by Christos.

Change a trace format string arg to use %p instead of %x and a long cast.
2002-03-12 03:45:02 +00:00
christos bac9369a06 PR/15877: Ed Ravin: make sure that we cleanup enough of the job structure,
in jobfree() so that we don't fail when we use a malloc where free() trashes
freed memory.
2002-03-12 00:44:16 +00:00
christos ccbeeb7cba get rid of sp completely, we were free-ing a bogus pointer; found by simonb. 2002-03-12 00:14:31 +00:00
lukem b799ed2973 first variable argument to "read" is not optional 2002-02-24 21:41:52 +00:00
christos 8b449b1ee8 enami convinced me that it is a good idea to use the first word of
the allocated area.
2002-02-20 21:42:35 +00:00
christos 06ea4006cb PR/11542: Back-out previous change that caused
set -e
for x in a; do
    BAR="foo"
    false && echo true
    echo mumble
done

not to echo mumble...
2002-02-14 21:51:41 +00:00
christos 6c02afd8c4 Since we should be able to handle nested double quotes, don't use
the syntax maps to determine the beginning and end quotes (kill
CENDQUOTE).  Handle single quotes opening and closing via checking
the current syntax map. Keep a bitmap of doublequote state one bit
per variable nesting level.  For the first 32 nested double quotes,
we don't need any additional memory, but for more we allocate
dynamically.
2002-02-12 20:32:35 +00:00
ross 79f9ab6771 back this directory up a day, systems won't even boot (rc.subr splodes)
suggested back-to-the-drawing-board test: $ echo "${PWD:-notlikely}"
2002-02-12 06:39:10 +00:00
christos f63e9a1ed6 PR/15579: Alan Barrett: }'s inside variable specs were taken into account
even if quoted:
    foo=${foo:-"'{}'"}; echo $foo
would display '{'} instead of '{}'.
2002-02-11 18:57:19 +00:00
christos 39d26b8867 Add a commented out -DDEBUG in CPPFLAGS. 2002-02-11 18:55:10 +00:00
christos 4398551708 Fix off by one in the display of var trees. 2002-02-11 18:54:30 +00:00
ross dc5571b22e Generate <>& symbolically. I'm avoiding .../dist/... directories for now. 2002-02-08 01:21:55 +00:00
lukem 9c2af9970a .ifdef SMALLPROG, -DSMALL 2002-02-07 06:25:07 +00:00
wiz 5739c48f68 Punctuation nits, drop unnecessary .Pps, sort sections. 2001-12-20 20:07:40 +00:00
wiz 9f4702dcef Punctuation nit. 2001-12-20 20:06:45 +00:00
wiz 3ebcdc5e43 Whitespace nits. 2001-12-20 19:31:48 +00:00
he ed00fe0aee Plug a memory leak when setting PWD -- don't mark the variable with
VTEXTFIXED because the value is dynamically allocated.  Fix from
Tor Egge, FreeBSD PR#31533.
2001-11-14 18:04:36 +00:00
lukem 678a800f83 change from WARNS?=1 to WARNS?=2 for bin/ 2001-11-03 13:40:30 +00:00
christos 0598afe4d0 Fix switch alias handling. Inspired from FreeBSD, but corrected to handle
alias expansion inside the switch as appropriate. This is achieved by a
flag noalias which is turned on and off in as we parse. In the following
example [1] and [0] indicate the value of noalias.

[0] case <expr> in
[1] <lit> ) [0] <expr> ;;
[1] <lit> ) [0] <expr> ;;
...
[1] esac [0]

FreeBSD does:

[0] case <expr> in [1]
<lit> ) <expr> ;;
<lit> )  <expr> ;;
...
esac [0]

This handles the following shell script:

alias a=ls

case $1 in
a)	echo a;
	a;;
f)	echo f;;
*)	echo default;;
esac
2001-11-02 23:49:14 +00:00
wiz 4c99916337 va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
2001-09-24 13:22:25 +00:00
itojun 31952d578f make sure we do not truncate arith expresssion > 10 digits.
freebsd bin/sh/expand.c revision 1.15.  NetBSD PR 13943.
2001-09-19 06:38:19 +00:00