aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-06-21 00:52:31 +0000
committerRob Landley <rob@landley.net>2006-06-21 00:52:31 +0000
commit2d6af16035cf71b5e08b3f87c482feb12be31c0e (patch)
tree3fab440445e176d1c93d950c8b77c7f7c221b305
parentb049c0ec196fe3fd89c0b92b3d2d70bce095fba0 (diff)
downloadbusybox-w32-2d6af16035cf71b5e08b3f87c482feb12be31c0e.tar.gz
busybox-w32-2d6af16035cf71b5e08b3f87c482feb12be31c0e.tar.bz2
busybox-w32-2d6af16035cf71b5e08b3f87c482feb12be31c0e.zip
Zubicaray reported a bug in vi that causes it to eat 100% cpu when you close
an xterm it's running in. The vi signal behavior would catch and restarts lots of signals, like SIGHUP, that should just kill the thing. (Leftover behavior from when it would segfault all the time.) Filtered out the more obviously bad ones. If it segfaults, we should find and fix the problem.
-rw-r--r--editors/vi.c89
1 files changed, 2 insertions, 87 deletions
diff --git a/editors/vi.c b/editors/vi.c
index df37affac..3937675b1 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -7,14 +7,6 @@
7 */ 7 */
8 8
9/* 9/*
10 * To compile for standalone use:
11 * gcc -Wall -Os -s -DSTANDALONE -o vi vi.c
12 * or
13 * gcc -Wall -Os -s -DSTANDALONE -DCONFIG_FEATURE_VI_CRASHME -o vi vi.c # include testing features
14 * strip vi
15 */
16
17/*
18 * Things To Do: 10 * Things To Do:
19 * EXINIT 11 * EXINIT
20 * $HOME/.exrc and ./.exrc 12 * $HOME/.exrc and ./.exrc
@@ -30,50 +22,20 @@
30 * An "ex" line oriented mode- maybe using "cmdedit" 22 * An "ex" line oriented mode- maybe using "cmdedit"
31 */ 23 */
32 24
33//---- Feature -------------- Bytes to implement 25
34#ifdef STANDALONE 26#include "busybox.h"
35#define vi_main main
36#define CONFIG_FEATURE_VI_COLON // 4288
37#define CONFIG_FEATURE_VI_YANKMARK // 1408
38#define CONFIG_FEATURE_VI_SEARCH // 1088
39#define CONFIG_FEATURE_VI_USE_SIGNALS // 1056
40#define CONFIG_FEATURE_VI_DOT_CMD // 576
41#define CONFIG_FEATURE_VI_READONLY // 128
42#define CONFIG_FEATURE_VI_SETOPTS // 576
43#define CONFIG_FEATURE_VI_SET // 224
44#define CONFIG_FEATURE_VI_WIN_RESIZE // 256 WIN_RESIZE
45// To test editor using CRASHME:
46// vi -C filename
47// To stop testing, wait until all to text[] is deleted, or
48// Ctrl-Z and kill -9 %1
49// while in the editor Ctrl-T will toggle the crashme function on and off.
50//#define CONFIG_FEATURE_VI_CRASHME // randomly pick commands to execute
51#endif /* STANDALONE */
52
53#include <stdio.h>
54#include <stdlib.h>
55#include <string.h> 27#include <string.h>
56#include <strings.h> 28#include <strings.h>
57#include <termios.h>
58#include <unistd.h> 29#include <unistd.h>
59#include <sys/ioctl.h> 30#include <sys/ioctl.h>
60#include <sys/types.h>
61#include <sys/stat.h>
62#include <time.h> 31#include <time.h>
63#include <fcntl.h> 32#include <fcntl.h>
64#include <signal.h> 33#include <signal.h>
65#include <setjmp.h> 34#include <setjmp.h>
66#include <regex.h> 35#include <regex.h>
67#include <ctype.h> 36#include <ctype.h>
68#include <assert.h>
69#include <errno.h> 37#include <errno.h>
70#include <stdarg.h>
71#ifndef STANDALONE
72#include "busybox.h"
73#define vi_Version BB_VER " " BB_BT 38#define vi_Version BB_VER " " BB_BT
74#else
75#define vi_Version "standalone"
76#endif /* STANDALONE */
77 39
78#ifdef CONFIG_LOCALE_SUPPORT 40#ifdef CONFIG_LOCALE_SUPPORT
79#define Isprint(c) isprint((c)) 41#define Isprint(c) isprint((c))
@@ -81,10 +43,6 @@
81#define Isprint(c) ( (c) >= ' ' && (c) != 127 && (c) != ((unsigned char)'\233') ) 43#define Isprint(c) ( (c) >= ' ' && (c) != 127 && (c) != ((unsigned char)'\233') )
82#endif 44#endif
83 45
84#ifndef TRUE
85#define TRUE ((int)1)
86#define FALSE ((int)0)
87#endif /* TRUE */
88#define MAX_SCR_COLS BUFSIZ 46#define MAX_SCR_COLS BUFSIZ
89 47
90// Misc. non-Ascii keys that report an escape sequence 48// Misc. non-Ascii keys that report an escape sequence
@@ -288,7 +246,6 @@ static void colon(Byte *); // execute the "colon" mode cmds
288static void winch_sig(int); // catch window size changes 246static void winch_sig(int); // catch window size changes
289static void suspend_sig(int); // catch ctrl-Z 247static void suspend_sig(int); // catch ctrl-Z
290static void catch_sig(int); // catch ctrl-C and alarm time-outs 248static void catch_sig(int); // catch ctrl-C and alarm time-outs
291static void core_sig(int); // catch a core dump signal
292#endif /* CONFIG_FEATURE_VI_USE_SIGNALS */ 249#endif /* CONFIG_FEATURE_VI_USE_SIGNALS */
293#ifdef CONFIG_FEATURE_VI_DOT_CMD 250#ifdef CONFIG_FEATURE_VI_DOT_CMD
294static void start_new_cmd_q(Byte); // new queue for command 251static void start_new_cmd_q(Byte); // new queue for command
@@ -461,29 +418,10 @@ static void edit_file(Byte * fn)
461 418
462#ifdef CONFIG_FEATURE_VI_USE_SIGNALS 419#ifdef CONFIG_FEATURE_VI_USE_SIGNALS
463 catch_sig(0); 420 catch_sig(0);
464 core_sig(0);
465 signal(SIGWINCH, winch_sig); 421 signal(SIGWINCH, winch_sig);
466 signal(SIGTSTP, suspend_sig); 422 signal(SIGTSTP, suspend_sig);
467 sig = setjmp(restart); 423 sig = setjmp(restart);
468 if (sig != 0) { 424 if (sig != 0) {
469 const char *msg = "";
470
471 if (sig == SIGWINCH)
472 msg = "(window resize)";
473 if (sig == SIGHUP)
474 msg = "(hangup)";
475 if (sig == SIGINT)
476 msg = "(interrupt)";
477 if (sig == SIGTERM)
478 msg = "(terminate)";
479 if (sig == SIGBUS)
480 msg = "(bus error)";
481 if (sig == SIGSEGV)
482 msg = "(I tried to touch invalid memory)";
483 if (sig == SIGALRM)
484 msg = "(alarm)";
485
486 psbs("-- caught signal %d %s--", sig, msg);
487 screenbegin = dot = text; 425 screenbegin = dot = text;
488 } 426 }
489#endif /* CONFIG_FEATURE_VI_USE_SIGNALS */ 427#endif /* CONFIG_FEATURE_VI_USE_SIGNALS */
@@ -2165,33 +2103,10 @@ static void suspend_sig(int sig ATTRIBUTE_UNUSED)
2165//----- Come here when we get a signal --------------------------- 2103//----- Come here when we get a signal ---------------------------
2166static void catch_sig(int sig) 2104static void catch_sig(int sig)
2167{ 2105{
2168 signal(SIGHUP, catch_sig);
2169 signal(SIGINT, catch_sig); 2106 signal(SIGINT, catch_sig);
2170 signal(SIGTERM, catch_sig);
2171 signal(SIGALRM, catch_sig);
2172 if(sig) 2107 if(sig)
2173 longjmp(restart, sig); 2108 longjmp(restart, sig);
2174} 2109}
2175
2176//----- Come here when we get a core dump signal -----------------
2177static void core_sig(int sig)
2178{
2179 signal(SIGQUIT, core_sig);
2180 signal(SIGILL, core_sig);
2181 signal(SIGTRAP, core_sig);
2182 signal(SIGABRT, core_sig);
2183 signal(SIGFPE, core_sig);
2184 signal(SIGBUS, core_sig);
2185 signal(SIGSEGV, core_sig);
2186#ifdef SIGSYS
2187 signal(SIGSYS, core_sig);
2188#endif
2189
2190 if(sig) { // signaled
2191 dot = bound_dot(dot); // make sure "dot" is valid
2192 longjmp(restart, sig);
2193 }
2194}
2195#endif /* CONFIG_FEATURE_VI_USE_SIGNALS */ 2110#endif /* CONFIG_FEATURE_VI_USE_SIGNALS */
2196 2111
2197static int mysleep(int hund) // sleep for 'h' 1/100 seconds 2112static int mysleep(int hund) // sleep for 'h' 1/100 seconds