diff options
author | Alan Cox <alan@redhat.com> | 2009-01-02 08:43:17 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-02 13:19:36 -0500 |
commit | fc6f6238226e6d1248e1967eae2bf556eaf3ac17 (patch) | |
tree | 07cef0fafd30bd622dac1db4751e10734773c863 /drivers/char/pty.c | |
parent | a47d545f5782cbde871b50bdf4a83379ed2da222 (diff) |
pty: simplify resize
We have special case logic for resizing pty/tty pairs. We also have a per
driver resize method so for the pty case we should use it.
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/pty.c')
-rw-r--r-- | drivers/char/pty.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 6d4582712b1..b5daaaa9007 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c | |||
@@ -230,6 +230,55 @@ static void pty_set_termios(struct tty_struct *tty, | |||
230 | tty->termios->c_cflag |= (CS8 | CREAD); | 230 | tty->termios->c_cflag |= (CS8 | CREAD); |
231 | } | 231 | } |
232 | 232 | ||
233 | /** | ||
234 | * pty_do_resize - resize event | ||
235 | * @tty: tty being resized | ||
236 | * @real_tty: real tty (not the same as tty if using a pty/tty pair) | ||
237 | * @rows: rows (character) | ||
238 | * @cols: cols (character) | ||
239 | * | ||
240 | * Update the termios variables and send the neccessary signals to | ||
241 | * peform a terminal resize correctly | ||
242 | */ | ||
243 | |||
244 | int pty_resize(struct tty_struct *tty, struct winsize *ws) | ||
245 | { | ||
246 | struct pid *pgrp, *rpgrp; | ||
247 | unsigned long flags; | ||
248 | struct tty_struct *pty = tty->link; | ||
249 | |||
250 | /* For a PTY we need to lock the tty side */ | ||
251 | mutex_lock(&tty->termios_mutex); | ||
252 | if (!memcmp(ws, &tty->winsize, sizeof(*ws))) | ||
253 | goto done; | ||
254 | |||
255 | /* Get the PID values and reference them so we can | ||
256 | avoid holding the tty ctrl lock while sending signals. | ||
257 | We need to lock these individually however. */ | ||
258 | |||
259 | spin_lock_irqsave(&tty->ctrl_lock, flags); | ||
260 | pgrp = get_pid(tty->pgrp); | ||
261 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); | ||
262 | |||
263 | spin_lock_irqsave(&pty->ctrl_lock, flags); | ||
264 | rpgrp = get_pid(pty->pgrp); | ||
265 | spin_unlock_irqrestore(&pty->ctrl_lock, flags); | ||
266 | |||
267 | if (pgrp) | ||
268 | kill_pgrp(pgrp, SIGWINCH, 1); | ||
269 | if (rpgrp != pgrp && rpgrp) | ||
270 | kill_pgrp(rpgrp, SIGWINCH, 1); | ||
271 | |||
272 | put_pid(pgrp); | ||
273 | put_pid(rpgrp); | ||
274 | |||
275 | tty->winsize = *ws; | ||
276 | pty->winsize = *ws; /* Never used so will go away soon */ | ||
277 | done: | ||
278 | mutex_unlock(&tty->termios_mutex); | ||
279 | return 0; | ||
280 | } | ||
281 | |||
233 | static int pty_install(struct tty_driver *driver, struct tty_struct *tty) | 282 | static int pty_install(struct tty_driver *driver, struct tty_struct *tty) |
234 | { | 283 | { |
235 | struct tty_struct *o_tty; | 284 | struct tty_struct *o_tty; |
@@ -290,6 +339,7 @@ static const struct tty_operations pty_ops = { | |||
290 | .chars_in_buffer = pty_chars_in_buffer, | 339 | .chars_in_buffer = pty_chars_in_buffer, |
291 | .unthrottle = pty_unthrottle, | 340 | .unthrottle = pty_unthrottle, |
292 | .set_termios = pty_set_termios, | 341 | .set_termios = pty_set_termios, |
342 | .resize = pty_resize | ||
293 | }; | 343 | }; |
294 | 344 | ||
295 | /* Traditional BSD devices */ | 345 | /* Traditional BSD devices */ |
@@ -319,6 +369,7 @@ static const struct tty_operations pty_ops_bsd = { | |||
319 | .unthrottle = pty_unthrottle, | 369 | .unthrottle = pty_unthrottle, |
320 | .set_termios = pty_set_termios, | 370 | .set_termios = pty_set_termios, |
321 | .ioctl = pty_bsd_ioctl, | 371 | .ioctl = pty_bsd_ioctl, |
372 | .resize = pty_resize | ||
322 | }; | 373 | }; |
323 | 374 | ||
324 | static void __init legacy_pty_init(void) | 375 | static void __init legacy_pty_init(void) |
@@ -561,7 +612,8 @@ static const struct tty_operations ptm_unix98_ops = { | |||
561 | .unthrottle = pty_unthrottle, | 612 | .unthrottle = pty_unthrottle, |
562 | .set_termios = pty_set_termios, | 613 | .set_termios = pty_set_termios, |
563 | .ioctl = pty_unix98_ioctl, | 614 | .ioctl = pty_unix98_ioctl, |
564 | .shutdown = pty_unix98_shutdown | 615 | .shutdown = pty_unix98_shutdown, |
616 | .resize = pty_resize | ||
565 | }; | 617 | }; |
566 | 618 | ||
567 | static const struct tty_operations pty_unix98_ops = { | 619 | static const struct tty_operations pty_unix98_ops = { |