aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorEli Zaretskii2021-10-16 14:47:32 +0300
committerEli Zaretskii2021-10-16 14:47:32 +0300
commite8488808dfe1460ce07042a1a523097ab90cf079 (patch)
tree0387fb7758ef218db32b26398e49a40c7ff6d4c6 /src/process.c
parent21397cce51dc3f9b6e9b0e7a5cc877b63efa8dd4 (diff)
downloademacs-e8488808dfe1460ce07042a1a523097ab90cf079.tar.gz
emacs-e8488808dfe1460ce07042a1a523097ab90cf079.zip
Avoid aborts when a thread is signaled while "waiting for input".
* src/process.c (kbd_is_ours): New function. (wait_reading_process_output): Set 'waiting_for_input' only if the current thread is monitoring the keyboard descriptor. See also https://lists.gnu.org/archive/html/emacs-devel/2021-10/msg01180.html. (Bug#51229)
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/process.c b/src/process.c
index 746cdc0428a..6731f8808f5 100644
--- a/src/process.c
+++ b/src/process.c
@@ -683,6 +683,22 @@ clear_waiting_thread_info (void)
683 } 683 }
684} 684}
685 685
686/* Return TRUE if the keyboard descriptor is being monitored by the
687 current thread, FALSE otherwise. */
688static bool
689kbd_is_ours (void)
690{
691 for (int fd = 0; fd <= max_desc; ++fd)
692 {
693 if (fd_callback_info[fd].waiting_thread != current_thread)
694 continue;
695 if ((fd_callback_info[fd].flags & (FOR_READ | KEYBOARD_FD))
696 == (FOR_READ | KEYBOARD_FD))
697 return true;
698 }
699 return false;
700}
701
686 702
687/* Compute the Lisp form of the process status, p->status, from 703/* Compute the Lisp form of the process status, p->status, from
688 the numeric status that was returned by `wait'. */ 704 the numeric status that was returned by `wait'. */
@@ -5312,13 +5328,13 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
5312 wait_reading_process_output_1 (); 5328 wait_reading_process_output_1 ();
5313 } 5329 }
5314 5330
5315 /* Cause C-g and alarm signals to take immediate action, 5331 /* Cause C-g signals to take immediate action,
5316 and cause input available signals to zero out timeout. 5332 and cause input available signals to zero out timeout.
5317 5333
5318 It is important that we do this before checking for process 5334 It is important that we do this before checking for process
5319 activity. If we get a SIGCHLD after the explicit checks for 5335 activity. If we get a SIGCHLD after the explicit checks for
5320 process activity, timeout is the only way we will know. */ 5336 process activity, timeout is the only way we will know. */
5321 if (read_kbd < 0) 5337 if (read_kbd < 0 && kbd_is_ours ())
5322 set_waiting_for_input (&timeout); 5338 set_waiting_for_input (&timeout);
5323 5339
5324 /* If status of something has changed, and no input is 5340 /* If status of something has changed, and no input is
@@ -5448,7 +5464,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
5448 { 5464 {
5449 clear_waiting_for_input (); 5465 clear_waiting_for_input ();
5450 redisplay_preserve_echo_area (11); 5466 redisplay_preserve_echo_area (11);
5451 if (read_kbd < 0) 5467 if (read_kbd < 0 && kbd_is_ours ())
5452 set_waiting_for_input (&timeout); 5468 set_waiting_for_input (&timeout);
5453 } 5469 }
5454 5470