shell: add comments about SIGINT-related problems

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2022-01-16 23:54:46 +01:00
parent c2788f88f4
commit a277506a64
2 changed files with 9 additions and 5 deletions

View File

@ -664,7 +664,7 @@ raise_exception(int e)
/*
* Called when a SIGINT is received. (If the user specifies
* that SIGINT is to be trapped or ignored using the trap builtin, then
* this routine is not called.) Suppressint is nonzero when interrupts
* this routine is not called.) suppress_int is nonzero when interrupts
* are held using the INT_OFF macro. (The test for iflag is just
* defensive programming.)
*/
@ -695,14 +695,13 @@ raise_interrupt(void)
} while (0)
#endif
static IF_ASH_OPTIMIZE_FOR_SIZE(inline) void
static IF_NOT_ASH_OPTIMIZE_FOR_SIZE(inline) void
int_on(void)
{
barrier();
if (--suppress_int == 0 && pending_int) {
if (--suppress_int == 0 && pending_int)
raise_interrupt();
}
}
#if DEBUG_INTONOFF
# define INT_ON do { \
TRACE(("%s:%d INT_ON(%d)\n", __func__, __LINE__, suppress_int-1)); \
@ -711,7 +710,7 @@ int_on(void)
#else
# define INT_ON int_on()
#endif
static IF_ASH_OPTIMIZE_FOR_SIZE(inline) void
static IF_NOT_ASH_OPTIMIZE_FOR_SIZE(inline) void
force_int_on(void)
{
barrier();
@ -10785,6 +10784,10 @@ preadfd(void)
# endif
reinit_unicode_for_ash();
again:
//BUG: not in INT_OFF/INT_ON section - SIGINT et al would longjmp out of read_line_input()!
//This would cause a memory leak in interactive shell
//(repeated internal allocations in read_line_input):
// (while kill -INT $$; do :; done) &
nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ);
if (nr == 0) {
/* ^C pressed, "convert" to SIGINT */

View File

@ -196,6 +196,7 @@ shell_builtin_read(struct builtin_read_params *params)
*/
errno = 0;
pfd[0].events = POLLIN;
//TODO race with a signal arriving just before the poll!
if (poll(pfd, 1, timeout) <= 0) {
/* timed out, or EINTR */
err = errno;