Commit Graph

65 Commits

Author SHA1 Message Date
snj a640fe8c43 It's "its." 2006-04-24 19:00:29 +00:00
tv 964f98e703 Make slightly more portable without extra conditionals needed:
- Use getpgrp() rather than getpgid(0).
  (getpgrp() is already used elsewhere in this same file.)

- Use waitpid(-1, a, b) rather than wait3(a, b, NULL).
2005-09-30 18:57:55 +00:00
lukem 5166671bc3 appease gcc -Wuninitialized 2005-06-01 15:41:19 +00:00
christos 08f1ceee65 PR/23786: Robert Nestor: wait command returns the wrong status code. This
seems to be an off-by-one error, since njobs is decremented before we use
it. I hope this does not break the vfork case!
2003-12-18 00:56:05 +00:00
dsl 7983f217c9 Generate command line when SMALL is defined and make buffer full sized.
All the code has been present for a while, and the memory cost is (about)
180 bytes per process.
Fixes PR bin/23545
2003-11-27 21:16:14 +00:00
dsl edecd89511 Add '\n' to "fork failed" trace messages. 2003-11-14 10:27:10 +00:00
jmmv 5199a59afa s/FD_SETFD/F_SETFD/ 2003-08-26 18:12:33 +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
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
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
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
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 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
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 de525ac6ca Try harder to find a tty. 2002-04-10 15:52:07 +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
wiz 456dff6cb8 Spell 'occurred' with two 'r's. 2001-09-16 16:34:23 +00:00
assar 50ed29b359 (waitproc): handle jp == NULL, it happens 2001-09-13 21:33:05 +00:00
christos a7560f06ec Don't wait with UNTRACED for jobs that have not been started with job control
(i.e. processes started from shell scripts). Fixes problem where kill -STOP'ing
a subprocess of a shell script would cause the shell to proceed to the next
command.
2001-09-10 15:47:03 +00:00
lukem c0b18597d8 fix grammar 2001-06-13 08:48:06 +00:00
elric e6bccfe4be Back out previous vfork changes. 2000-05-22 10:18:46 +00:00
elric e8b0f2b813 INTON and FORCEINTON modify global variables, and so should not be
executed while we are vforked.
2000-05-15 03:42:48 +00:00
elric 0eece24a3a Unused variable pgrp on line 576. 2000-05-13 20:59:41 +00:00
elric 756a2ca1bd Now we use vfork(2) instead of fork(2) when we can. 2000-05-13 20:50:14 +00:00
mycroft 2806df576c It turns out that the code disabled in revision 1.30 *does* have an important
function (which nobody was able to explain): it's critical to allowing a
complex command run from an interactive shell to be terminated.  So, reinstate
it and fix it correctly.  See the comment if you really want the gory details.
1999-08-31 08:58:47 +00:00
christos 3d42469030 compile with WARNS = 2 1999-07-09 03:05:49 +00:00
mycroft c06643b836 Disable bogus-looking code that cause us to throw away SIGINTs. 1999-04-05 14:59:35 +00:00
christos 6e50d7a816 PR/4966: Joel Reicher: Implement <> redirections which are documented in
the man page.
1999-02-04 16:17:39 +00:00
mycroft ee9e50eacb Be more retentive about use of NOTREACHED and noreturn. 1998-07-28 11:41:40 +00:00
christos 96133865eb cast pid's to longs for OS's where this is the case. 1998-05-20 00:31:11 +00:00
fair 618cca243b Change a few things to reference /usr/include/paths.h instead of local
references. Fixing the default PATH is a bit more effort.
1998-04-07 10:16:04 +00:00
thorpej b65b5cae9e Sigh, have to cast pointer diffs to long. 1998-02-04 23:49:25 +00:00
thorpej a40a144d00 Fix printf formats so they work on the Alpha. 1998-02-04 20:10:16 +00:00
christos 7f2a271743 PR/3662: David Holland: Make /bin/sh use the symbolic macros for wait(). 1997-10-08 20:31:52 +00:00
christos cd799663e4 Fix compiler warnings. 1997-07-04 21:01:48 +00:00
tls 48250187e6 kill 'register' 1997-01-11 02:04:27 +00:00
christos 846dce0ee3 Fix problems that gcc -Wall found (from Todd Miller, OpenBSD) 1996-11-02 18:26:03 +00:00
christos a20d79429a PR/2808: Don't include <sgtty.h> unless OLD_TTY_DRIVER is defined.
Remove extraneous newline from error messages.
1996-10-16 14:42:20 +00:00
mycroft c65b90450d ioctl(TIOC[GS]PGRP) -> tc[gs]etpgrp() 1996-09-17 14:44:05 +00:00
pk edae5ead03 Relocate pointers after re-allocation of the job table. 1995-07-04 16:26:45 +00:00
christos 07bae7eddd Merge in my changes from vangogh, and fix the x=`false`; echo $? == 0
bug.
1995-05-11 21:28:33 +00:00