LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Adam Tlałka" <atlka@pg.gda.pl>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: 7eggert@gmx.de, linux-kernel@vger.kernel.org, torvalds@osdl.org
Subject: Re: [PATCH 0/2] SIGWINCH problem with terminal apps still alive
Date: Sun, 12 Oct 2008 14:32:31 +0200 [thread overview]
Message-ID: <20081012143231.6ef9e590@merlin.oi.pg.gda.pl> (raw)
In-Reply-To: <20081011185821.0dab4c81@lxorguk.ukuu.org.uk>
[-- Attachment #1: Type: text/plain, Size: 1390 bytes --]
Welcome,
generally speaking terminal resize could be made from vc or other
terminal device module code, from terminal ioctl on tty master
or tty slave. As we read the code we will see that the problem is to
use a proper mutex. Also we should use a one variable in which we set
terminal sizes. So in case of tty master and slave we have tty and
real_tty structures. TIOCSWINSZ and TIOCGWINSZ ioctls could be
called on tty and real_tty at the same time. To avoid race condition
we should use a mutex. But this must be the same mutex in all cases
- tty or real_tty. For the best we should also use the same
winsize variable. Proposed previously code change only simplifies
the code and eliminates SIGWINCH signal race but an app could read
terminal sizes at any time so this patch not closes all race
possibilities. So I propose a patch in which we have some code
movements and always use real_tty->termios_mutex and also
real_tty->winsize. In no pty case tty == real_tty so it works properly
as before and in pty situaction we use the same mutex and variable so
it removes all race conditions according to access to winsize now.
Signed-off-by: Adam Tla/lka <atlka@pg.gda.pl>
Regards
--
Adam Tlałka mailto:atlka@pg.gda.pl ^v^ ^v^ ^v^
System & Network Administration Group - - - ~~~~~~
Computer Center, Gdańsk University of Technology, Poland
[-- Attachment #2: 2.6.27_tty_io_2.patch --]
[-- Type: text/x-patch, Size: 1719 bytes --]
--- drivers/char/tty_io_orig.c 2008-10-10 05:37:30.000000000 +0200
+++ drivers/char/tty_io.c 2008-10-12 13:37:11.000000000 +0200
@@ -2524,27 +2524,26 @@ int tty_do_resize(struct tty_struct *tty
/* For a PTY we need to lock the tty side */
mutex_lock(&real_tty->termios_mutex);
- if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
- goto done;
- /* Get the PID values and reference them so we can
- avoid holding the tty ctrl lock while sending signals */
- spin_lock_irqsave(&tty->ctrl_lock, flags);
- pgrp = get_pid(tty->pgrp);
- rpgrp = get_pid(real_tty->pgrp);
- spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+ flags = memcmp(ws, &real_tty->winsize, sizeof(*ws));
+ real_tty->winsize = *ws;
+ mutex_unlock(&real_tty->termios_mutex);
+ if (flags){
+ /* Get the PID values and reference them so we can
+ avoid holding the tty ctrl lock while sending signals */
+ spin_lock_irqsave(&tty->ctrl_lock, flags);
+ pgrp = get_pid(tty->pgrp);
+ rpgrp = get_pid(real_tty->pgrp);
+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
- if (pgrp)
- kill_pgrp(pgrp, SIGWINCH, 1);
- if (rpgrp != pgrp && rpgrp)
- kill_pgrp(rpgrp, SIGWINCH, 1);
+ if (pgrp)
+ kill_pgrp(pgrp, SIGWINCH, 1);
+ if (rpgrp != pgrp && rpgrp)
+ kill_pgrp(rpgrp, SIGWINCH, 1);
- put_pid(pgrp);
- put_pid(rpgrp);
+ put_pid(pgrp);
+ put_pid(rpgrp);
+ }
- tty->winsize = *ws;
- real_tty->winsize = *ws;
-done:
- mutex_unlock(&real_tty->termios_mutex);
return 0;
}
@@ -2996,7 +2995,7 @@ long tty_ioctl(struct file *file, unsign
case TIOCSTI:
return tiocsti(tty, p);
case TIOCGWINSZ:
- return tiocgwinsz(tty, p);
+ return tiocgwinsz(real_tty, p);
case TIOCSWINSZ:
return tiocswinsz(tty, real_tty, p);
case TIOCCONS:
next prev parent reply other threads:[~2008-10-12 12:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bjXel-4CU-17@gated-at.bofh.it>
[not found] ` <bjYap-5Q0-25@gated-at.bofh.it>
[not found] ` <bk30i-3Gx-1@gated-at.bofh.it>
[not found] ` <bk6AV-8ms-7@gated-at.bofh.it>
[not found] ` <bkrvO-1HF-49@gated-at.bofh.it>
[not found] ` <blePJ-6rI-3@gated-at.bofh.it>
[not found] ` <blmDC-7ZU-7@gated-at.bofh.it>
2008-10-11 14:04 ` [PATCH 0/1] " Bodo Eggert
2008-10-11 17:58 ` Alan Cox
2008-10-12 12:32 ` Adam Tlałka [this message]
2008-10-12 14:22 ` [PATCH 0/2] " Alan Cox
2008-10-12 17:59 ` Adam Tlałka
2008-10-12 18:03 ` Alan Cox
2008-10-12 19:01 ` Adam Tlałka
2008-10-12 20:22 ` Alan Cox
2008-10-13 9:59 ` Bodo Eggert
2008-10-13 10:01 ` Alan Cox
2008-10-13 12:07 ` Bodo Eggert
2008-10-14 12:51 ` [PATCH 0/3] " Adam Tlałka
2008-10-14 14:11 ` [PATCH 0/4] " Adam Tlałka
2008-10-16 10:27 ` [PATCH 0/5] " Adam Tlałka
2008-10-16 10:52 ` Alan Cox
2008-10-16 11:43 ` Adam Tlałka
2008-10-17 8:39 ` Adam Tlałka
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=20081012143231.6ef9e590@merlin.oi.pg.gda.pl \
--to=atlka@pg.gda.pl \
--cc=7eggert@gmx.de \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
--subject='Re: [PATCH 0/2] SIGWINCH problem with terminal apps still alive' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).