ash: ^C with SIG_INGed SIGINT should not exit the shell

function                                             old     new   delta
__pgetc                                              501     522     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2022-01-13 01:05:03 +01:00
parent d162a7b978
commit 68b402ee51
3 changed files with 15 additions and 2 deletions

View File

@ -608,7 +608,9 @@ int login_main(int argc UNUSED_PARAM, char **argv)
* But without this, bash 3.0 will not enable ctrl-c either. * But without this, bash 3.0 will not enable ctrl-c either.
* Maybe bash is buggy? * Maybe bash is buggy?
* Need to find out what standards say about /bin/login - * Need to find out what standards say about /bin/login -
* should we leave SIGINT etc enabled or disabled? */ * should we leave SIGINT etc enabled or disabled?
* Also note: sulogin does not do it! Why?
*/
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
/* Exec login shell with no additional parameters */ /* Exec login shell with no additional parameters */

View File

@ -111,6 +111,11 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
} }
} }
/*
* Note: login does this (should we do it too?):
*/
/*signal(SIGINT, SIG_DFL);*/
/* Exec login shell with no additional parameters. Never returns. */ /* Exec login shell with no additional parameters. Never returns. */
exec_login_shell(shell); exec_login_shell(shell);
} }

View File

@ -10784,18 +10784,24 @@ preadfd(void)
line_input_state->path_lookup = pathval(); line_input_state->path_lookup = pathval();
# endif # endif
reinit_unicode_for_ash(); reinit_unicode_for_ash();
again:
nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ); nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ);
if (nr == 0) { if (nr == 0) {
/* ^C pressed, "convert" to SIGINT */ /* ^C pressed, "convert" to SIGINT */
write(STDOUT_FILENO, "^C", 2); write(STDOUT_FILENO, "^C", 2);
raise(SIGINT); raise(SIGINT);
/* raise(SIGINT) did not work! (e.g. if SIGINT
* is SIG_INGed on startup, it stays SIG_IGNed)
*/
if (trap[SIGINT]) { if (trap[SIGINT]) {
buf[0] = '\n'; buf[0] = '\n';
buf[1] = '\0'; buf[1] = '\0';
return 1; return 1;
} }
exitstatus = 128 + SIGINT; exitstatus = 128 + SIGINT;
return -1; /* bash behavior on ^C + ignored SIGINT: */
write(STDOUT_FILENO, "\n", 1);
goto again;
} }
if (nr < 0) { if (nr < 0) {
if (errno == 0) { if (errno == 0) {