diff options
author | Alexey Fomenko <ext-alexey.fomenko@nokia.com> | 2011-05-20 04:26:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-20 04:26:29 +0200 |
commit | 232ebaa5681790291154cf8e8203a02eec04f6d8 (patch) | |
tree | 626f0aa3749b48c29d1ede53f04781763a192bd9 | |
parent | ea137aa931f1b109a966ff685d9b79b39f7180b4 (diff) | |
download | busybox-w32-232ebaa5681790291154cf8e8203a02eec04f6d8.tar.gz busybox-w32-232ebaa5681790291154cf8e8203a02eec04f6d8.tar.bz2 busybox-w32-232ebaa5681790291154cf8e8203a02eec04f6d8.zip |
lineedit: fix rare SEGV; mark a few FIXMEs
Signed-off-by: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/lineedit.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 0563e6d01..4e3bc0ef7 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -41,6 +41,10 @@ | |||
41 | */ | 41 | */ |
42 | #include "libbb.h" | 42 | #include "libbb.h" |
43 | #include "unicode.h" | 43 | #include "unicode.h" |
44 | #ifndef _POSIX_VDISABLE | ||
45 | # define _POSIX_VDISABLE '\0' | ||
46 | #endif | ||
47 | |||
44 | 48 | ||
45 | #ifdef TEST | 49 | #ifdef TEST |
46 | # define ENABLE_FEATURE_EDITING 0 | 50 | # define ENABLE_FEATURE_EDITING 0 |
@@ -184,6 +188,7 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; | |||
184 | IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines = 1;) \ | 188 | IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines = 1;) \ |
185 | IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ | 189 | IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ |
186 | } while (0) | 190 | } while (0) |
191 | |||
187 | static void deinit_S(void) | 192 | static void deinit_S(void) |
188 | { | 193 | { |
189 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT | 194 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT |
@@ -1676,7 +1681,7 @@ static void ask_terminal(void) | |||
1676 | * write(1, "~/srcdevel/bbox/fix/busybox.t4 # ", 33) = 33 | 1681 | * write(1, "~/srcdevel/bbox/fix/busybox.t4 # ", 33) = 33 |
1677 | * poll([{fd=0, events=POLLIN}], 1, 0) = 0 (Timeout) <-- no input exists | 1682 | * poll([{fd=0, events=POLLIN}], 1, 0) = 0 (Timeout) <-- no input exists |
1678 | * write(1, "\33[6n", 4) = 4 <-- send the ESC sequence, quick! | 1683 | * write(1, "\33[6n", 4) = 4 <-- send the ESC sequence, quick! |
1679 | * poll([{fd=0, events=POLLIN}], 1, 4294967295) = 1 ([{fd=0, revents=POLLIN}]) | 1684 | * poll([{fd=0, events=POLLIN}], 1, -1) = 1 ([{fd=0, revents=POLLIN}]) |
1680 | * read(0, "\n", 1) = 1 <-- oh crap, user's input got in first | 1685 | * read(0, "\n", 1) = 1 <-- oh crap, user's input got in first |
1681 | */ | 1686 | */ |
1682 | struct pollfd pfd; | 1687 | struct pollfd pfd; |
@@ -1834,10 +1839,11 @@ static void win_changed(int nsig) | |||
1834 | { | 1839 | { |
1835 | int sv_errno = errno; | 1840 | int sv_errno = errno; |
1836 | unsigned width; | 1841 | unsigned width; |
1842 | |||
1837 | get_terminal_width_height(0, &width, NULL); | 1843 | get_terminal_width_height(0, &width, NULL); |
1838 | cmdedit_setwidth(width, nsig /* - just a yes/no flag */); | 1844 | //FIXME: cmdedit_setwidth() -> redraw() -> printf() -> KABOOM! (we are in signal handler!) |
1839 | if (nsig == SIGWINCH) | 1845 | cmdedit_setwidth(width, /*redraw_flg:*/ nsig); |
1840 | signal(SIGWINCH, win_changed); /* rearm ourself */ | 1846 | |
1841 | errno = sv_errno; | 1847 | errno = sv_errno; |
1842 | } | 1848 | } |
1843 | 1849 | ||
@@ -2016,14 +2022,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2016 | new_settings.c_cc[VMIN] = 1; | 2022 | new_settings.c_cc[VMIN] = 1; |
2017 | new_settings.c_cc[VTIME] = 0; | 2023 | new_settings.c_cc[VTIME] = 0; |
2018 | /* Turn off CTRL-C, so we can trap it */ | 2024 | /* Turn off CTRL-C, so we can trap it */ |
2019 | #ifndef _POSIX_VDISABLE | ||
2020 | # define _POSIX_VDISABLE '\0' | ||
2021 | #endif | ||
2022 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; | 2025 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; |
2023 | tcsetattr_stdin_TCSANOW(&new_settings); | 2026 | tcsetattr_stdin_TCSANOW(&new_settings); |
2024 | 2027 | ||
2025 | previous_SIGWINCH_handler = signal(SIGWINCH, win_changed); | ||
2026 | win_changed(0); /* do initial resizing */ | ||
2027 | #if ENABLE_USERNAME_OR_HOMEDIR | 2028 | #if ENABLE_USERNAME_OR_HOMEDIR |
2028 | { | 2029 | { |
2029 | struct passwd *entry; | 2030 | struct passwd *entry; |
@@ -2046,6 +2047,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2046 | parse_and_put_prompt(prompt); | 2047 | parse_and_put_prompt(prompt); |
2047 | ask_terminal(); | 2048 | ask_terminal(); |
2048 | 2049 | ||
2050 | /* Install window resize handler (NB: after *all* init is complete) */ | ||
2051 | //FIXME: save entire sigaction! | ||
2052 | previous_SIGWINCH_handler = signal(SIGWINCH, win_changed); | ||
2053 | win_changed(0); /* get initial window size */ | ||
2054 | |||
2049 | read_key_buffer[0] = 0; | 2055 | read_key_buffer[0] = 0; |
2050 | while (1) { | 2056 | while (1) { |
2051 | /* | 2057 | /* |