Commit c313089
Cygwin: console: Correct previous NOFLSH fix
The previous fix for NOFLSH mode does not work as intended.
discard_key_events(), added in "Cygwin: console: Fix NOFLSH behaviour a
bit", loops on ReadConsoleInputW() until it has consumed the requested
number of records, but ReadConsoleInputW() blocks while the console
input buffer is empty. sigflush() calls it with a hard-coded count of
one and no guarantee that a record is actually queued: in the
master-thread path the signalling record has already been read out of
the buffer before sigflush() runs, so the call blocks until, and then
swallows, the user's next keystroke.
To avoid this, this patch does not discard input when process_sigs()
is called from cons_master_thread, where the value of `fh` is NULL,
because discarding will be done in cons_master_thread.
And because the ReadConsoleInputW() return value is unchecked, a failed
read leaves the count indeterminate, so "n -= n1" can underflow and spin.
Check return value of ReadConsoleInputW() and abort if it fails.
Moreover, discard_key_event(1) does not work as intended if the first
key event is not a bKeyDown event correspoding to the signalling key.
Use discard_key_events(0) instead. This means discarding input events
to the current position processed. Since the key-strokes prior to the
signalling key are already in the readahead buffer, so this call discards
only the signalling key. The important point here is to discard input
before releasing input_mutex by release_input_mutex_if_necessary(),
because, if not, cons_master_thread starts to process key events before
discarding signalling key event because the thread can acquire
input_mutex. This causes the signalling key is processed twice.
One separate point: the `process_input_message()` caller wraps
`discard_key_events()` in `acquire_attach_mutex()` + `attach_console
(con.owner)`, but the `sigflush()` call site does not, so the
`ReadConsoleInputW()` there runs against whatever console the calling
process happens to be attached to. With the guard above the worst case
is a no-op when the calling process happens not to be attached, so
it would be more correct to move the attach into the helper itself.
This patch also fixes two more special cases. One is done_with_debugger
case. When `gdb cat` is executed and the `cat` is running, Ctrl-C
discards all the key events including the events after Ctrl-C. This
is because tcflush() is used for the purpose. Use discard_key_events(0)
instead. The other case is not_signalled_but_done case. Previously,
when `cat | non-cygwin-app` is executed and Ctrl-C is pressed, but
the `Ctrl-C` is not VINTR, line_edit() wrongly returned
line_edit_signalled even though `cat` is not signalled by Ctrl-C.
In this case, `cat` should receive Ctrl-C as a input char, while
`non-cygwin-app` has been killed by Ctrl-C. Fix this in line_edit().
In the case of not_signalled_but_done case, setting `sawsig` flag
and releasing `output_stopped` has been skipped with this patch,
because this (Ctrl-C) is not a signal key in the case above.
Fixes: 66324ed ("Cygwin: console: Fix NOFLSH behaviour a bit")
Co-authored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
(cherry picked from commit 0d516c2)1 parent 36f40c9 commit c313089
3 files changed
Lines changed: 36 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1665 | 1665 | | |
1666 | 1666 | | |
1667 | 1667 | | |
| 1668 | + | |
1668 | 1669 | | |
1669 | 1670 | | |
1670 | 1671 | | |
| |||
1695 | 1696 | | |
1696 | 1697 | | |
1697 | 1698 | | |
1698 | | - | |
1699 | | - | |
| 1699 | + | |
| 1700 | + | |
1700 | 1701 | | |
1701 | 1702 | | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
| 1703 | + | |
1709 | 1704 | | |
1710 | 1705 | | |
1711 | 1706 | | |
1712 | 1707 | | |
1713 | 1708 | | |
1714 | 1709 | | |
1715 | 1710 | | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
1716 | 1716 | | |
1717 | 1717 | | |
| 1718 | + | |
| 1719 | + | |
1718 | 1720 | | |
1719 | 1721 | | |
1720 | | - | |
| 1722 | + | |
| 1723 | + | |
1721 | 1724 | | |
1722 | 1725 | | |
1723 | 1726 | | |
1724 | 1727 | | |
| 1728 | + | |
| 1729 | + | |
1725 | 1730 | | |
1726 | 1731 | | |
1727 | 1732 | | |
| |||
2305 | 2310 | | |
2306 | 2311 | | |
2307 | 2312 | | |
2308 | | - | |
| 2313 | + | |
| 2314 | + | |
2309 | 2315 | | |
2310 | 2316 | | |
2311 | 2317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
357 | 360 | | |
358 | 361 | | |
359 | 362 | | |
| |||
444 | 447 | | |
445 | 448 | | |
446 | 449 | | |
447 | | - | |
| 450 | + | |
448 | 451 | | |
449 | | - | |
450 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
451 | 458 | | |
452 | 459 | | |
453 | 460 | | |
| |||
460 | 467 | | |
461 | 468 | | |
462 | 469 | | |
| 470 | + | |
| 471 | + | |
463 | 472 | | |
464 | 473 | | |
465 | 474 | | |
| |||
525 | 534 | | |
526 | 535 | | |
527 | 536 | | |
528 | | - | |
529 | 537 | | |
530 | 538 | | |
531 | 539 | | |
| 540 | + | |
| 541 | + | |
532 | 542 | | |
533 | 543 | | |
534 | 544 | | |
| |||
666 | 676 | | |
667 | 677 | | |
668 | 678 | | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
676 | 682 | | |
677 | 683 | | |
678 | 684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2200 | 2200 | | |
2201 | 2201 | | |
2202 | 2202 | | |
| 2203 | + | |
2203 | 2204 | | |
2204 | 2205 | | |
2205 | 2206 | | |
| |||
0 commit comments