root/kernel/chr_drv/pty.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pty_close
  2. pty_copy
  3. pty_write
  4. pty_open

   1 /*
   2  *  linux/kernel/chr_drv/pty.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 /*
   8  *      pty.c
   9  *
  10  * This module exports the following pty function:
  11  * 
  12  *      int  pty_open(struct tty_struct * tty, struct file * filp);
  13  */
  14 
  15 #include <linux/errno.h>
  16 #include <linux/sched.h>
  17 #include <linux/tty.h>
  18 #include <linux/fcntl.h>
  19 #include <linux/interrupt.h>
  20 
  21 #include <asm/system.h>
  22 #include <asm/bitops.h>
  23 
  24 static void pty_close(struct tty_struct * tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26         if (!tty || (tty->count > 1))
  27                 return;
  28         wake_up_interruptible(&tty->read_q.proc_list);
  29         if (!tty->link)
  30                 return;
  31         wake_up_interruptible(&tty->link->write_q.proc_list);
  32         if (IS_A_PTY_MASTER(tty->line)) {
  33                 tty_hangup(tty->link);
  34                 flush_input(tty);
  35                 flush_output(tty);
  36         }
  37 }
  38 
  39 static inline void pty_copy(struct tty_struct * from, struct tty_struct * to)
     /* [previous][next][first][last][top][bottom][index][help] */
  40 {
  41         int c;
  42 
  43         while (!from->stopped && !EMPTY(&from->write_q)) {
  44                 if (FULL(&to->read_q)) {
  45                         if (FULL(&to->secondary))
  46                                 break;
  47                         TTY_READ_FLUSH(to);
  48                         continue;
  49                 }
  50                 c = get_tty_queue(&from->write_q);
  51                 put_tty_queue(c, &to->read_q);
  52                 if (current->signal & ~current->blocked)
  53                         break;
  54         }
  55         TTY_READ_FLUSH(to);
  56         wake_up_interruptible(&from->write_q.proc_list);
  57         if (from->write_data_cnt) {
  58                 set_bit(from->line, &tty_check_write);
  59                 mark_bh(TTY_BH);
  60         }
  61 }
  62 
  63 /*
  64  * This routine gets called when tty_write has put something into
  65  * the write_queue. It copies the input to the output-queue of it's
  66  * slave.
  67  */
  68 static void pty_write(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70         if (tty->link)
  71                 pty_copy(tty,tty->link);
  72 }
  73 
  74 int pty_open(struct tty_struct *tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         if (!tty || !tty->link)
  77                 return -ENODEV;
  78         tty->write = tty->link->write = pty_write;
  79         tty->close = tty->link->close = pty_close;
  80         wake_up_interruptible(&tty->read_q.proc_list);
  81         if (filp->f_flags & O_NDELAY)
  82                 return 0;
  83         while (!tty->link->count && !(current->signal & ~current->blocked))
  84                 interruptible_sleep_on(&tty->link->read_q.proc_list);
  85         if (!tty->link->count)
  86                 return -ERESTARTSYS;
  87         return 0;
  88 }

/* [previous][next][first][last][top][bottom][index][help] */