summaryrefslogtreecommitdiffstats
path: root/bin/sh/trap.c
Commit message (Collapse)AuthorAgeFilesLines
* trap: do not consider a bad signal name a fatal error.jilles2009-11-211-3/+6
| | | | | POSIX explicitly prescribes this. Continue processing any other signals and return status 1.
* sh: Use sigaction instead of signal/siginterrupt combination.jilles2009-11-111-4/+6
|
* Don't skip forking for an external command if any traps are active.jilles2009-06-131-0/+15
| | | | | | | | | | | | | | | | | Example: sh -c '(trap "echo trapped" EXIT; sleep 3)' now correctly prints "trapped". With this check, it is no longer necessary to check for -T explicitly in that case. This is a useful bugfix by itself and also important because I plan to skip forking more often. PR: bin/113860 (part of) PR: bin/74404 (part of) Reviewed by: stefanf Approved by: ed (mentor)
* Fix the eval command in combination with set -e. Before this change the shellstefanf2009-05-311-2/+2
| | | | | | | | | 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
* Whitespace nits.schweikh2006-04-171-4/+4
|
* Correctly quote the output when showing the installed trap actions.stefanf2005-12-081-6/+5
| | | | | PR: 74043 Submitted by: Jilles Tjoelker
* Various small code cleanups resulting from a code reviewingrse2005-09-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and linting procedure: 1. Remove useless sub-expression: - if (*start || (!ifsspc && start > string && (nulonly || 1))) { + if (*start || (!ifsspc && start > string)) { The sub-expression "(nulonly || 1)" always evaluates to true and according to CVS logs seems to be just a left-over from some debugging and introduced by accident. Removing the sub-expression doesn't change semantics and a code inspection showed that the variable "nulonly" is also not necessary here in any way (and the expression would require fixing instead of removing). 2. Remove dead code: - if (backslash && c == '\\') { - if (read(STDIN_FILENO, &c, 1) != 1) { - status = 1; - break; - } - STPUTC(c, p); - } else if (ap[1] != NULL && strchr(ifs, c) != NULL) { + if (ap[1] != NULL && strchr(ifs, c) != NULL) { Inspection of the control and data flow showed that variable "backslash" is always false (0) when the "if"-expression is evaluated, hence the whole block is effectively dead code. Additionally, the skipping of characters after a backslash is already performed correctly a few lines above, so this code is also not needed at all. According to the CVS logs and the ASH 0.2 sources, this code existed in this way already since its early days. 3. Cleanup Style: - ! trap[signo][0] == '\0' && + ! (trap[signo][0] == '\0') && The expression wants to ensure the trap is not assigned the empty string. But the "!" operator has higher precedence than "==", so the comparison should be put into parenthesis to form the intended way of expression. Nevertheless the code was effectively not really broken as both particular NUL comparisons are semantically equal, of course. But the parenthesized version is a lot more intuitive. 4. Remove shadowing variable declaration: - char *q; The declaration of symbol "q" hides another identical declaration of "q" in the same context. As the other "q" is already reused multiple times and also can be reused again without negative side-effects, just remove the shadowing declaration. 5. Just small cosmetics: - if (ifsset() != 0) + if (ifsset()) The ifsset() macro is already coded by returning the boolean result of a comparison operator, so no need to compare this boolean result again against a numerical value. This also aligns the macros usage to the remaining existing code. Reviewed by: stefanf@
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* style(9): wrap at 80 columns.njl2004-02-121-3/+5
|
* Handle proper formatting and a buffer overrun when running an old sh onnjl2004-02-121-7/+28
| | | | | | | a system that has sys_nsig > NSIG (i.e. when libc is upgraded.) Submitted by: Matt Dillon Reviewed by: bde
* Use sys_nsig instead of NSIG for the length of the signal arrays. Thisnjl2004-01-281-4/+4
| | | | | | | is important if we add new signals later. From DragonflyBSD: jobs.c:1.4, trap.c:1.3. Obtained from: DragonflyBSD
* Avoid calling el_resize() from a signal handler, even though libedittjr2002-07-241-2/+3
| | | | | | | 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
* Catch SIGWINCH in interactive shells and call el_resize() to updatetjr2002-07-231-0/+15
| | | | libedit's idea of the window size.
* Remove broken and incomplete support for old releases of System V,tjr2002-07-191-5/+0
| | | | don't support system that implement getcwd(3) with a pipe to /bin/pwd.
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* o __P has been reovedimp2002-02-021-22/+12
| | | | | | | | | | | | | | | | | | 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) { ...
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Various spelling/formatting changes.kris1999-05-081-2/+2
| | | | Submitted by: Philippe Charnier <charnier@xp11.frmug.org>
* The immediate execution of traps I introduced in September 1998 (tocracauer1999-04-011-2/+3
| | | | | | | | | | make /etc/rc interruptible in cases when programs hang with blocked signals) isn't standard enough. It is now switched off by default and a new switch -T enables it. You should update /etc/rc to the version I'm about to commit in a few minutes to keep it interruptible.
* Narrow down conditions to break wait() to process traps.cracauer1998-09-101-3/+4
| | | | Improve comments.
* Fix an inefficiency I introduced in my last commit.cracauer1998-09-101-9/+4
| | | | Include "expand.h" vom memalloc.c to pull function declartion into scope
* If traps are set, they are now executed even when a signal-blockingcracauer1998-09-081-5/+18
| | | | | | | | | | | | foreground child is running. Formerly, traps were exceuted after the next child exit. The enables the user to put a breaking wrapper around a blocking application: (trap 'echo trap ; exit 1' 2; ./pestyblocker; echo -n) The "echo -n" after the child call is needed to prevent sh from optimizing the trap-executing shell away. I'm working on this.
* Improve bookkeeping of in_waitcmd and style fixes.cracauer1998-08-251-2/+2
| | | | Submitted by: Bruce Evans
* Re-enable killing childs with SIGQUIT. Spotted by Bruce Evans.cracauer1998-08-251-2/+2
|
* Do not exit on SIGINT in non-interactive shells, fixes PR 1206,cracauer1998-08-241-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | i.e. this makes emacs usable from system(3). Programs called from shellscripts are now required to exit with proper signal status. That means, they have to kill themself. Exiting with faked numerical exit code is not sufficient. Exit with proper signal status if script exits on signal. Make the wait builtin interruptable, both with and without traps set. Use volatile sig_atomic_t where (and only where) appropriate. (Almost) fix printing of newlines on SIGINT. Make traps setable from trap handlers. This is needed for shellscripts that catch SIGINT for cleanup work but intend to exit on it, hance have to kill themself from a trap handler. I.e. mkdep. While I'm at it, make it -Wall clean. -Wall is not enabled in Makefile, since vararg warnx() macro calls in usr.bin/printf/printf.c are not -Wall-able. PR: 1206 Obtained from: Basic SIGINT fix from Bruce Evans
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Fixed some type and value mismatches. setsignal() returned a boguslybde1997-11-101-10/+9
| | | | | | cast value that was always ignored. Rev.1.9 of trap.c made this more bogus by returning a semantically different value after calling siginterrupt(). Avoid these problems by not returning a value.
* 1) Fix longstanding bug:ache1997-11-051-3/+10
| | | | | | | | | | | | | | trap 'echo xxx' 1 2 3 15 read x is not interrupted by ^C (due to restartable read syscall) and must be interrupted per POSIX Worse case: read -t 5 x hangs forever after ^C pressed (supposed to timeout after 5 secs) Fixed by adding siginterrupt(signo, 1) after catch handler installed 2) Do not reinstall sighandler immediately after it is called, BSD do it for us
* 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.
* With these changes sh(1)'s trap command should be POSIX-compliant,steve1996-12-241-49/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | while remaining (becoming :) compatible with other popular shells. Specifically these changes include: 1) Implement 'trap -l' to get a list of valid signals names. This is useful if you wanted to do something like reset all signal handlers to there defaults values, in which case something like this will do the trick. trap `trap -l` 2) Reformat the output of 'trap' so it can be saved and later eval'd to restore the saved settings. 3) Allow the use of signal names as well as signal numbers. 4) Fix trap handling of SIGCHLD so that commands like the following (albeit, contrived) won't cause sh(1) to recurse ad infinitum. trap uname 0 20 5) Make variables static that are used only in trap.c. 6) Minor 'style(9) police' mods.
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-9/+9
| | | | Obtained from: NetBSD, me
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-29/+58
| | | | | | | | | | | | | | 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
* Remove trailing whitespace.rgrimes1995-05-301-5/+5
| | | | Reviewed by: phk
* Added $Id$dg1994-09-241-0/+2
|
* BSD 4.4 Lite bin Sourcesrgrimes1994-05-261-0/+348
OpenPOWER on IntegriCloud