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 
  20 #include <asm/system.h>
  21 #include <asm/io.h>
  22 
  23 static void pty_close(struct tty_struct * tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25         if (!tty)
  26                 return;
  27         wake_up_interruptible(&tty->read_q.proc_list);
  28         if (!tty->link)
  29                 return;
  30         wake_up_interruptible(&tty->link->write_q.proc_list);
  31         if (IS_A_PTY_MASTER(tty->line))
  32                 tty_hangup(tty->link);
  33 }
  34 
  35 static inline void pty_copy(struct tty_struct * from, struct tty_struct * to)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37         int c;
  38 
  39         while (!from->stopped && !EMPTY(&from->write_q)) {
  40                 if (FULL(&to->read_q)) {
  41                         if (FULL(&to->secondary))
  42                                 break;
  43                         TTY_READ_FLUSH(to);
  44                         continue;
  45                 }
  46                 c = get_tty_queue(&from->write_q);
  47                 put_tty_queue(c, &to->read_q);
  48                 if (current->signal & ~current->blocked)
  49                         break;
  50         }
  51         TTY_READ_FLUSH(to);
  52         wake_up_interruptible(&from->write_q.proc_list);
  53 }
  54 
  55 /*
  56  * This routine gets called when tty_write has put something into
  57  * the write_queue. It copies the input to the output-queue of it's
  58  * slave.
  59  */
  60 static void pty_write(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62         if (tty->link)
  63                 pty_copy(tty,tty->link);
  64 }
  65 
  66 int pty_open(struct tty_struct *tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68         if (!tty || !tty->link)
  69                 return -ENODEV;
  70         tty->write = tty->link->write = pty_write;
  71         tty->close = tty->link->close = pty_close;
  72         wake_up_interruptible(&tty->read_q.proc_list);
  73         if (filp->f_flags & O_NDELAY)
  74                 return 0;
  75         while (!tty->link->count && !(current->signal & ~current->blocked))
  76                 interruptible_sleep_on(&tty->link->read_q.proc_list);
  77         if (!tty->link->count)
  78                 return -ERESTARTSYS;
  79         return 0;
  80 }

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