diff options
author | Paul Fox <pgf@brightstareng.com> | 2008-03-17 15:28:07 +0000 |
---|---|---|
committer | Paul Fox <pgf@brightstareng.com> | 2008-03-17 15:28:07 +0000 |
commit | 2724fa9d8a076f52c158627877d59894789b09a1 (patch) | |
tree | 7b4eece4fb93d44a56b0ef29d06e2bc4721b3f63 | |
parent | fb274df0797f58cda0b3b6809769707fe21e40e7 (diff) | |
download | busybox-w32-2724fa9d8a076f52c158627877d59894789b09a1.tar.gz busybox-w32-2724fa9d8a076f52c158627877d59894789b09a1.tar.bz2 busybox-w32-2724fa9d8a076f52c158627877d59894789b09a1.zip |
remove alarm() calls which were functioning as a primitive
watchdog function, presumably to catch infinite loop bugs.
(control-C can do the same thing, and the alarms were too short in
any case.) also, switch to sigsetjmp/siglongjmp in order to allow
repeated use of control-C -- otherwise it works once, then not again.
-rw-r--r-- | editors/vi.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/editors/vi.c b/editors/vi.c index c2d4457e9..22bd2fffa 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -201,7 +201,7 @@ struct globals { | |||
201 | #endif | 201 | #endif |
202 | /* a few references only */ | 202 | /* a few references only */ |
203 | #if ENABLE_FEATURE_VI_USE_SIGNALS | 203 | #if ENABLE_FEATURE_VI_USE_SIGNALS |
204 | jmp_buf restart; // catch_sig() | 204 | sigjmp_buf restart; // catch_sig() |
205 | #endif | 205 | #endif |
206 | struct termios term_orig, term_vi; // remember what the cooked mode was | 206 | struct termios term_orig, term_vi; // remember what the cooked mode was |
207 | #if ENABLE_FEATURE_VI_COLON | 207 | #if ENABLE_FEATURE_VI_COLON |
@@ -516,7 +516,7 @@ static void edit_file(char *fn) | |||
516 | catch_sig(0); | 516 | catch_sig(0); |
517 | signal(SIGWINCH, winch_sig); | 517 | signal(SIGWINCH, winch_sig); |
518 | signal(SIGTSTP, suspend_sig); | 518 | signal(SIGTSTP, suspend_sig); |
519 | sig = setjmp(restart); | 519 | sig = sigsetjmp(restart, 1); |
520 | if (sig != 0) { | 520 | if (sig != 0) { |
521 | screenbegin = dot = text; | 521 | screenbegin = dot = text; |
522 | } | 522 | } |
@@ -799,7 +799,6 @@ static void colon(char *buf) | |||
799 | else if (strncmp(cmd, "!", 1) == 0) { // run a cmd | 799 | else if (strncmp(cmd, "!", 1) == 0) { // run a cmd |
800 | int retcode; | 800 | int retcode; |
801 | // :!ls run the <cmd> | 801 | // :!ls run the <cmd> |
802 | alarm(0); // wait for input- no alarms | ||
803 | place_cursor(rows - 1, 0, FALSE); // go to Status line | 802 | place_cursor(rows - 1, 0, FALSE); // go to Status line |
804 | clear_to_eol(); // clear the line | 803 | clear_to_eol(); // clear the line |
805 | cookmode(); | 804 | cookmode(); |
@@ -808,7 +807,6 @@ static void colon(char *buf) | |||
808 | printf("\nshell returned %i\n\n", retcode); | 807 | printf("\nshell returned %i\n\n", retcode); |
809 | rawmode(); | 808 | rawmode(); |
810 | Hit_Return(); // let user see results | 809 | Hit_Return(); // let user see results |
811 | alarm(3); // done waiting for input | ||
812 | } | 810 | } |
813 | #endif | 811 | #endif |
814 | else if (strncmp(cmd, "=", i) == 0) { // where is the address | 812 | else if (strncmp(cmd, "=", i) == 0) { // where is the address |
@@ -2153,7 +2151,7 @@ static void catch_sig(int sig) | |||
2153 | { | 2151 | { |
2154 | signal(SIGINT, catch_sig); | 2152 | signal(SIGINT, catch_sig); |
2155 | if (sig) | 2153 | if (sig) |
2156 | longjmp(restart, sig); | 2154 | siglongjmp(restart, sig); |
2157 | } | 2155 | } |
2158 | #endif /* FEATURE_VI_USE_SIGNALS */ | 2156 | #endif /* FEATURE_VI_USE_SIGNALS */ |
2159 | 2157 | ||
@@ -2217,7 +2215,6 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2217 | }; | 2215 | }; |
2218 | enum { ESCCMDS_COUNT = ARRAY_SIZE(esccmds) }; | 2216 | enum { ESCCMDS_COUNT = ARRAY_SIZE(esccmds) }; |
2219 | 2217 | ||
2220 | alarm(0); // turn alarm OFF while we wait for input | ||
2221 | fflush(stdout); | 2218 | fflush(stdout); |
2222 | n = chars_to_parse; | 2219 | n = chars_to_parse; |
2223 | // get input from User- are there already input chars in Q? | 2220 | // get input from User- are there already input chars in Q? |
@@ -2273,7 +2270,6 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2273 | // remove key sequence from Q | 2270 | // remove key sequence from Q |
2274 | chars_to_parse -= n; | 2271 | chars_to_parse -= n; |
2275 | memmove(readbuffer, readbuffer + n, sizeof(readbuffer) - n); | 2272 | memmove(readbuffer, readbuffer + n, sizeof(readbuffer) - n); |
2276 | alarm(3); // we are done waiting for input, turn alarm ON | ||
2277 | return c; | 2273 | return c; |
2278 | } | 2274 | } |
2279 | 2275 | ||
@@ -3054,14 +3050,6 @@ static void do_cmd(char c) | |||
3054 | case VI_K_PAGEUP: // Cursor Key Page Up | 3050 | case VI_K_PAGEUP: // Cursor Key Page Up |
3055 | dot_scroll(rows - 2, -1); | 3051 | dot_scroll(rows - 2, -1); |
3056 | break; | 3052 | break; |
3057 | #if ENABLE_FEATURE_VI_USE_SIGNALS | ||
3058 | case 0x03: // ctrl-C interrupt | ||
3059 | longjmp(restart, 1); | ||
3060 | break; | ||
3061 | case 26: // ctrl-Z suspend | ||
3062 | suspend_sig(SIGTSTP); | ||
3063 | break; | ||
3064 | #endif | ||
3065 | case 4: // ctrl-D scroll down half screen | 3053 | case 4: // ctrl-D scroll down half screen |
3066 | dot_scroll((rows - 2) / 2, 1); | 3054 | dot_scroll((rows - 2) / 2, 1); |
3067 | break; | 3055 | break; |
@@ -4037,7 +4025,6 @@ static void crash_test() | |||
4037 | } | 4025 | } |
4038 | 4026 | ||
4039 | if (msg[0]) { | 4027 | if (msg[0]) { |
4040 | alarm(0); | ||
4041 | printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", | 4028 | printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", |
4042 | totalcmds, last_input_char, msg, SOs, SOn); | 4029 | totalcmds, last_input_char, msg, SOs, SOn); |
4043 | fflush(stdout); | 4030 | fflush(stdout); |
@@ -4045,7 +4032,6 @@ static void crash_test() | |||
4045 | if (d[0] == '\n' || d[0] == '\r') | 4032 | if (d[0] == '\n' || d[0] == '\r') |
4046 | break; | 4033 | break; |
4047 | } | 4034 | } |
4048 | alarm(3); | ||
4049 | } | 4035 | } |
4050 | tim = time(NULL); | 4036 | tim = time(NULL); |
4051 | if (tim >= (oldtim + 3)) { | 4037 | if (tim >= (oldtim + 3)) { |