From: Joe Peterson <joe@skyrush.com>
To: Elias Oltmanns <eo@nebensachen.de>
Cc: "Török Edwin" <edwintorok@gmail.com>,
"Alan Cox" <alan@lxorguk.ukuu.org.uk>,
"Linux Kernel" <linux-kernel@vger.kernel.org>
Subject: Re: Ctrl+C doesn't interrupt process waiting for I/O
Date: Wed, 02 Jul 2008 16:26:10 -0500 [thread overview]
Message-ID: <486BF272.2010703@skyrush.com> (raw)
In-Reply-To: <87fxqurqpz.fsf@denkblock.local>
Elias Oltmanns wrote:
> - /*
> - * Echo character, and then send the signal.
> - * Note that we do not use isig() here because we want
> - * the order to be:
> - * 1) flush, 2) echo, 3) signal
> - */
> - if (!L_NOFLSH(tty)) {
> - n_tty_flush_buffer(tty);
> - tty_driver_flush_buffer(tty);
> - }
> if (L_ECHO(tty))
> echo_char(c, tty);
> - if (tty->pgrp)
> - kill_pgrp(tty->pgrp, signal, 1);
> + isig(signal, tty, 0);
> return;
I've been doing some experimenting with the order of the three
operations (flush, echo, and signal), and the behavior is slightly
different with each.
The way I have it in the code now matches the order used by FreeBSD, so
there may actually be a good reason to flush the tty buffers *before*
issuing the signal. Here is their snippet of code:
if (ISSET(lflag, ISIG)) {
if (CCEQ(cc[VINTR], c) || CCEQ(cc[VQUIT], c)) {
if (!ISSET(lflag, NOFLSH))
ttyflush(tp, FREAD | FWRITE);
ttyecho(c, tp);
if (tp->t_pgrp != NULL) {
PGRP_LOCK(tp->t_pgrp);
pgsignal(tp->t_pgrp,
CCEQ(cc[VINTR], c) ? SIGINT : SIGQUIT, 1);
PGRP_UNLOCK(tp->t_pgrp);
}
goto endcase;
}
if (CCEQ(cc[VSUSP], c)) {
if (!ISSET(lflag, NOFLSH))
ttyflush(tp, FREAD);
ttyecho(c, tp);
if (tp->t_pgrp != NULL) {
PGRP_LOCK(tp->t_pgrp);
pgsignal(tp->t_pgrp, SIGTSTP, 1);
PGRP_UNLOCK(tp->t_pgrp);
}
goto endcase;
}
}
The first section handles ^C and ^\ (and flushes read and write), and
the second handles ^Z (only flushes read).
In any case, we should consider if the flush in Linux should precede the
signal. Perhaps interrupting before the flush can happen is bad?
Perhaps this has something to do with anomalies observed (below) with
other ordering, or maybe I'm seeing other latent bugs not involved with
this at all.
Now to the results of the ordering...
flush, echo, signal (the way it is now)
-------------------
* Follows FreeBSD's ordering
* works on both console and xterm
* seems to delay interrupt when process is IO bound
echo, signal, flush (proposed in Elias' patch)
-------------------
* seems to fix IO bound issue
* echo works in console but not xterm
signal, flush, echo
-------------------
* works in both console and xterm
* may cause late echo (and does not match BSD order)
* I tested inserting an artificial delay between flush and echo:
strange result: in console, echo does not appear; in xterm,
^C appears right before next prompt, but sometimes
echo does not appear, along with final program output
(something eats the output)
signal, echo, flush
-------------------
* same as above
So changing the order seems to always introduce some bugs or issues.
I'm still experimenting; feedback welcome!
-Joe
next prev parent reply other threads:[~2008-07-02 21:27 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-28 10:38 Ctrl+C doesn't interrupt process waiting for I/O Török Edwin
2008-06-29 2:44 ` Jeremy Fitzhardinge
2008-06-29 2:45 ` Jeremy Fitzhardinge
2008-06-29 3:42 ` Avi Kivity
2008-06-29 5:13 ` Jeremy Fitzhardinge
2008-06-29 5:39 ` Avi Kivity
2008-06-29 6:25 ` Jeremy Fitzhardinge
2008-06-29 7:45 ` Török Edwin
2008-06-29 23:57 ` Bill Davidsen
2008-06-29 12:37 ` Alan Cox
2008-06-30 17:35 ` J. Bruce Fields
2008-06-29 7:09 ` Török Edwin
2008-06-29 7:23 ` David Newall
2008-06-29 12:10 ` Andi Kleen
2008-06-29 16:02 ` Jeremy Fitzhardinge
2008-06-30 10:30 ` Helge Hafting
2008-07-01 7:47 ` Elias Oltmanns
2008-07-01 8:02 ` Elias Oltmanns
2008-07-01 8:28 ` Török Edwin
2008-07-01 9:59 ` Elias Oltmanns
2008-07-01 12:07 ` Joe Peterson
2008-07-01 8:50 ` David Newall
2008-07-01 9:01 ` Török Edwin
2008-07-01 9:12 ` David Newall
2008-07-01 14:12 ` Joe Peterson
2008-07-01 14:48 ` Elias Oltmanns
2008-07-01 16:27 ` Joe Peterson
2008-07-02 21:26 ` Joe Peterson [this message]
2008-07-04 20:10 ` Joe Peterson
2008-07-04 20:23 ` Alan Cox
2008-07-04 21:17 ` Joe Peterson
2008-07-11 14:47 ` Alan Cox
2008-07-12 0:44 ` Joe Peterson
2008-07-12 10:37 ` Alan Cox
2008-07-04 21:21 ` Andi Kleen
2008-07-04 21:14 ` Alan Cox
2008-07-04 21:36 ` Andi Kleen
2008-07-04 21:44 ` Alan Cox
2008-07-04 22:09 ` Andi Kleen
2008-07-05 10:34 ` Alan Cox
2008-07-05 11:00 ` Andi Kleen
2008-07-05 11:34 ` Alan Cox
2008-07-05 12:49 ` Elias Oltmanns
2008-07-05 14:01 ` Andi Kleen
2008-07-05 19:58 ` Joe Peterson
2008-07-06 8:28 ` Elias Oltmanns
-- strict thread matches above, loose matches on Subject: below --
2008-07-03 0:59 Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=486BF272.2010703@skyrush.com \
--to=joe@skyrush.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=edwintorok@gmail.com \
--cc=eo@nebensachen.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox