diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-19 23:09:58 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-19 23:09:58 +0000 |
commit | b21f379639386c68c182e55ae61c6f1e80159c4d (patch) | |
tree | 922c3da9d2660b3a46f7ac2333eb79ddae047556 | |
parent | 653d8e79b21f39fa97c3043296e36971bb8ef555 (diff) | |
download | busybox-w32-b21f379639386c68c182e55ae61c6f1e80159c4d.tar.gz busybox-w32-b21f379639386c68c182e55ae61c6f1e80159c4d.tar.bz2 busybox-w32-b21f379639386c68c182e55ae61c6f1e80159c4d.zip |
ash: fix TRACE commands
-rw-r--r-- | shell/ash.c | 13 | ||||
-rw-r--r-- | shell/ash_doc.txt | 77 |
2 files changed, 81 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c index a8383d805..d969b20a2 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -39,7 +39,7 @@ | |||
39 | * When debugging is on, debugging info will be written to ./trace and | 39 | * When debugging is on, debugging info will be written to ./trace and |
40 | * a quit signal will generate a core dump. | 40 | * a quit signal will generate a core dump. |
41 | */ | 41 | */ |
42 | #define DEBUG 0 | 42 | #define DEBUG 2 |
43 | /* Tweak debug output verbosity here */ | 43 | /* Tweak debug output verbosity here */ |
44 | #define DEBUG_TIME 0 | 44 | #define DEBUG_TIME 0 |
45 | #define DEBUG_PID 1 | 45 | #define DEBUG_PID 1 |
@@ -3834,7 +3834,8 @@ dowait(int wait_flags, struct job *job) | |||
3834 | * NB: _not_ safe_waitpid, we need to detect EINTR */ | 3834 | * NB: _not_ safe_waitpid, we need to detect EINTR */ |
3835 | pid = waitpid(-1, &status, | 3835 | pid = waitpid(-1, &status, |
3836 | (doing_jobctl ? (wait_flags | WUNTRACED) : wait_flags)); | 3836 | (doing_jobctl ? (wait_flags | WUNTRACED) : wait_flags)); |
3837 | TRACE(("wait returns pid=%d, status=0x%x\n", pid, status)); | 3837 | TRACE(("wait returns pid=%d, status=0x%x, errno=%d(%s)\n", |
3838 | pid, status, errno, strerror(errno))); | ||
3838 | if (pid <= 0) | 3839 | if (pid <= 0) |
3839 | return pid; | 3840 | return pid; |
3840 | 3841 | ||
@@ -8003,7 +8004,7 @@ dotrap(void) | |||
8003 | want_exexit = evalstring(t, SKIPEVAL); | 8004 | want_exexit = evalstring(t, SKIPEVAL); |
8004 | exitstatus = savestatus; | 8005 | exitstatus = savestatus; |
8005 | if (want_exexit) { | 8006 | if (want_exexit) { |
8006 | TRACE(("dotrap returns %d\n", skip)); | 8007 | TRACE(("dotrap returns %d\n", want_exexit)); |
8007 | return want_exexit; | 8008 | return want_exexit; |
8008 | } | 8009 | } |
8009 | } | 8010 | } |
@@ -8051,11 +8052,13 @@ evaltree(union node *n, int flags) | |||
8051 | if (err) { | 8052 | if (err) { |
8052 | /* if it was a signal, check for trap handlers */ | 8053 | /* if it was a signal, check for trap handlers */ |
8053 | if (exception_type == EXSIG) { | 8054 | if (exception_type == EXSIG) { |
8054 | TRACE(("exception %d (EXSIG) in evaltree, err=%d\n", exception, err)); | 8055 | TRACE(("exception %d (EXSIG) in evaltree, err=%d\n", |
8056 | exception_type, err)); | ||
8055 | goto out; | 8057 | goto out; |
8056 | } | 8058 | } |
8057 | /* continue on the way out */ | 8059 | /* continue on the way out */ |
8058 | TRACE(("exception %d in evaltree, propagating err=%d\n", exception, err)); | 8060 | TRACE(("exception %d in evaltree, propagating err=%d\n", |
8061 | exception_type, err)); | ||
8059 | exception_handler = savehandler; | 8062 | exception_handler = savehandler; |
8060 | longjmp(exception_handler->loc, err); | 8063 | longjmp(exception_handler->loc, err); |
8061 | } | 8064 | } |
diff --git a/shell/ash_doc.txt b/shell/ash_doc.txt index d8a48c114..2aa44434c 100644 --- a/shell/ash_doc.txt +++ b/shell/ash_doc.txt | |||
@@ -46,8 +46,77 @@ done | |||
46 | of exiting. (true) in subshell does not seem to matter, as another user | 46 | of exiting. (true) in subshell does not seem to matter, as another user |
47 | reports the same with: | 47 | reports the same with: |
48 | 48 | ||
49 | while true | 49 | trap "echo USR1" USR1 |
50 | do | 50 | while true; do |
51 | echo Kill me | 51 | echo Sleeping |
52 | sleep 1 | 52 | sleep 5 |
53 | done | 53 | done |
54 | |||
55 | Compat note. | ||
56 | Bash version 3.2.0(1) exits this script at the receipt of SIGINT | ||
57 | _only_ if it had two last children die from it. | ||
58 | The following trace was obtained while periodically running | ||
59 | "killall -SIGINT sleep; sleep 0.1; kill -SIGINT <bash_PID>": | ||
60 | |||
61 | 23:48:32.376707 clone(...) = 13528 | ||
62 | 23:48:32.388706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted) | ||
63 | 23:48:32.459761 --- SIGINT (Interrupt) @ 0 (0) --- | ||
64 | kill -SIGINT <bash_PID> is ignored, back to waiting: | ||
65 | 23:48:32.463706 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13528 | ||
66 | sleep exited with 0 | ||
67 | 23:48:37.377557 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
68 | 23:48:37.378451 clone(...) = 13538 | ||
69 | 23:48:37.390708 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13538 | ||
70 | sleep was killed by "killall -SIGINT sleep" | ||
71 | 23:48:38.523944 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
72 | 23:48:38.524861 clone(...) = 13542 | ||
73 | 23:48:38.538706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted) | ||
74 | 23:48:38.624761 --- SIGINT (Interrupt) @ 0 (0) --- | ||
75 | kill -SIGINT <bash_PID> is ignored, back to waiting: | ||
76 | 23:48:38.628706 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13542 | ||
77 | sleep exited with 0 | ||
78 | 23:48:43.525674 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
79 | 23:48:43.526563 clone(...) = 13545 | ||
80 | 23:48:43.538709 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13545 | ||
81 | sleep was killed by "killall -SIGINT sleep" | ||
82 | 23:48:44.466848 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
83 | 23:48:44.467735 clone(...) = 13549 | ||
84 | 23:48:44.481706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted) | ||
85 | 23:48:44.567757 --- SIGINT (Interrupt) @ 0 (0) --- | ||
86 | kill -SIGINT <bash_PID> is ignored, back to waiting: | ||
87 | 23:48:44.571706 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13549 | ||
88 | sleep exited with 0 | ||
89 | 23:48:49.468553 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
90 | 23:48:49.469445 clone(...) = 13551 | ||
91 | 23:48:49.481708 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13551 | ||
92 | sleep was killed by "killall -SIGINT sleep" | ||
93 | 23:48:50.515837 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
94 | 23:48:50.516718 clone(...) = 13555 | ||
95 | 23:48:50.530706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted) | ||
96 | 23:48:50.615761 --- SIGINT (Interrupt) @ 0 (0) --- | ||
97 | kill -SIGINT <bash_PID> is ignored, back to waiting: | ||
98 | 23:48:50.619705 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13555 | ||
99 | sleep was killed by "killall -SIGINT sleep". | ||
100 | This is the second one in a row. Kill ourself: | ||
101 | 23:48:51.504604 kill(13515, SIGINT) = 0 | ||
102 | 23:48:51.504689 --- SIGINT (Interrupt) @ 0 (0) --- | ||
103 | 23:48:51.504915 +++ killed by SIGINT +++ | ||
104 | |||
105 | As long as there is at least one "sleep 5" which exited successfully | ||
106 | (not killed by SIGINT), bash continues. This is not documented anywhere | ||
107 | AFAIKS. | ||
108 | |||
109 | Why keyboard ^C acts differently? | ||
110 | |||
111 | 00:08:07.655985 clone(...) = 14270 | ||
112 | 00:08:07.669707 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 14270 | ||
113 | 00:08:12.656872 --- SIGCHLD (Child exited) @ 0 (0) --- | ||
114 | 00:08:12.657743 clone(...) = 14273 | ||
115 | 00:08:12.671708 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 14273 | ||
116 | 00:08:13.810778 --- SIGINT (Interrupt) @ 0 (0) --- | ||
117 | 00:08:13.818705 kill(14269, SIGINT) = 0 | ||
118 | 00:08:13.820103 --- SIGINT (Interrupt) @ 0 (0) --- | ||
119 | 00:08:13.820925 +++ killed by SIGINT +++ | ||
120 | |||
121 | Perhaps because at the moment bash got SIGINT it had no children? | ||
122 | (it did not manage to spawn new sleep yet, see the trace) | ||