Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: Reorder proc_set_tty() and related fns

Move the controlling tty-related functions and remove forward
declarations for __proc_set_tty() and proc_set_tty().

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Reviewed-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Peter Hurley and committed by
Greg Kroah-Hartman
11d9befd 8f166e00

+62 -63
+62 -63
drivers/tty/tty_io.c
··· 153 153 static int __tty_fasync(int fd, struct file *filp, int on); 154 154 static int tty_fasync(int fd, struct file *filp, int on); 155 155 static void release_tty(struct tty_struct *tty, int idx); 156 - static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 157 - static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 158 156 159 157 /** 160 158 * free_tty_struct - free a disused tty ··· 490 492 static DEFINE_SPINLOCK(redirect_lock); 491 493 static struct file *redirect; 492 494 495 + 496 + void proc_clear_tty(struct task_struct *p) 497 + { 498 + unsigned long flags; 499 + struct tty_struct *tty; 500 + spin_lock_irqsave(&p->sighand->siglock, flags); 501 + tty = p->signal->tty; 502 + p->signal->tty = NULL; 503 + spin_unlock_irqrestore(&p->sighand->siglock, flags); 504 + tty_kref_put(tty); 505 + } 506 + 507 + /* Called under the sighand lock */ 508 + 509 + static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 510 + { 511 + if (tty) { 512 + unsigned long flags; 513 + /* We should not have a session or pgrp to put here but.... */ 514 + spin_lock_irqsave(&tty->ctrl_lock, flags); 515 + put_pid(tty->session); 516 + put_pid(tty->pgrp); 517 + tty->pgrp = get_pid(task_pgrp(tsk)); 518 + spin_unlock_irqrestore(&tty->ctrl_lock, flags); 519 + tty->session = get_pid(task_session(tsk)); 520 + if (tsk->signal->tty) { 521 + printk(KERN_DEBUG "tty not NULL!!\n"); 522 + tty_kref_put(tsk->signal->tty); 523 + } 524 + } 525 + put_pid(tsk->signal->tty_old_pgrp); 526 + tsk->signal->tty = tty_kref_get(tty); 527 + tsk->signal->tty_old_pgrp = NULL; 528 + } 529 + 530 + static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 531 + { 532 + spin_lock_irq(&tsk->sighand->siglock); 533 + __proc_set_tty(tsk, tty); 534 + spin_unlock_irq(&tsk->sighand->siglock); 535 + } 536 + 537 + struct tty_struct *get_current_tty(void) 538 + { 539 + struct tty_struct *tty; 540 + unsigned long flags; 541 + 542 + spin_lock_irqsave(&current->sighand->siglock, flags); 543 + tty = tty_kref_get(current->signal->tty); 544 + spin_unlock_irqrestore(&current->sighand->siglock, flags); 545 + return tty; 546 + } 547 + EXPORT_SYMBOL_GPL(get_current_tty); 548 + 549 + static void session_clear_tty(struct pid *session) 550 + { 551 + struct task_struct *p; 552 + do_each_pid_task(session, PIDTYPE_SID, p) { 553 + proc_clear_tty(p); 554 + } while_each_pid_task(session, PIDTYPE_SID, p); 555 + } 556 + 493 557 /** 494 558 * tty_wakeup - request more data 495 559 * @tty: terminal ··· 851 791 } 852 792 853 793 EXPORT_SYMBOL(tty_hung_up_p); 854 - 855 - static void session_clear_tty(struct pid *session) 856 - { 857 - struct task_struct *p; 858 - do_each_pid_task(session, PIDTYPE_SID, p) { 859 - proc_clear_tty(p); 860 - } while_each_pid_task(session, PIDTYPE_SID, p); 861 - } 862 794 863 795 /** 864 796 * disassociate_ctty - disconnect controlling tty ··· 3477 3425 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; 3478 3426 } 3479 3427 EXPORT_SYMBOL(tty_devnum); 3480 - 3481 - void proc_clear_tty(struct task_struct *p) 3482 - { 3483 - unsigned long flags; 3484 - struct tty_struct *tty; 3485 - spin_lock_irqsave(&p->sighand->siglock, flags); 3486 - tty = p->signal->tty; 3487 - p->signal->tty = NULL; 3488 - spin_unlock_irqrestore(&p->sighand->siglock, flags); 3489 - tty_kref_put(tty); 3490 - } 3491 - 3492 - /* Called under the sighand lock */ 3493 - 3494 - static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3495 - { 3496 - if (tty) { 3497 - unsigned long flags; 3498 - /* We should not have a session or pgrp to put here but.... */ 3499 - spin_lock_irqsave(&tty->ctrl_lock, flags); 3500 - put_pid(tty->session); 3501 - put_pid(tty->pgrp); 3502 - tty->pgrp = get_pid(task_pgrp(tsk)); 3503 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 3504 - tty->session = get_pid(task_session(tsk)); 3505 - if (tsk->signal->tty) { 3506 - printk(KERN_DEBUG "tty not NULL!!\n"); 3507 - tty_kref_put(tsk->signal->tty); 3508 - } 3509 - } 3510 - put_pid(tsk->signal->tty_old_pgrp); 3511 - tsk->signal->tty = tty_kref_get(tty); 3512 - tsk->signal->tty_old_pgrp = NULL; 3513 - } 3514 - 3515 - static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3516 - { 3517 - spin_lock_irq(&tsk->sighand->siglock); 3518 - __proc_set_tty(tsk, tty); 3519 - spin_unlock_irq(&tsk->sighand->siglock); 3520 - } 3521 - 3522 - struct tty_struct *get_current_tty(void) 3523 - { 3524 - struct tty_struct *tty; 3525 - unsigned long flags; 3526 - 3527 - spin_lock_irqsave(&current->sighand->siglock, flags); 3528 - tty = tty_kref_get(current->signal->tty); 3529 - spin_unlock_irqrestore(&current->sighand->siglock, flags); 3530 - return tty; 3531 - } 3532 - EXPORT_SYMBOL_GPL(get_current_tty); 3533 3428 3534 3429 void tty_default_fops(struct file_operations *fops) 3535 3430 {