root/kernel/chr_drv/pty.c

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

DEFINITIONS

This source file includes following definitions.
  1. pty_open
  2. pty_close
  3. pty_copy
  4. mpty_write
  5. spty_write

   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 implements the pty functions
  11  *      void mpty_write(struct tty_struct * queue);
  12  *      void spty_write(struct tty_struct * queue);
  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 int pty_open(unsigned int dev, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25         struct tty_struct * tty;
  26 
  27         tty = tty_table + dev;
  28         if (!tty->link)
  29                 return -ENODEV;
  30         wake_up(&tty->read_q->proc_list);
  31         if (filp->f_flags & O_NDELAY)
  32                 return 0;
  33         while (!tty->link->count && !(current->signal & ~current->blocked))
  34                 interruptible_sleep_on(&tty->link->read_q->proc_list);
  35         if (!tty->link->count)
  36                 return -ERESTARTSYS;
  37         return 0;
  38 }
  39 
  40 void pty_close(unsigned int dev, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42         struct tty_struct * tty;
  43 
  44         tty = tty_table + dev;
  45         wake_up(&tty->read_q->proc_list);
  46         wake_up(&tty->link->write_q->proc_list);
  47         if (IS_A_PTY_MASTER(dev)) {
  48                 if (tty->link->pgrp > 0)
  49                         kill_pg(tty->link->pgrp,SIGHUP,1);
  50         }
  51 }
  52 
  53 static inline void pty_copy(struct tty_struct * from, struct tty_struct * to)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         int c;
  56 
  57         while (!from->stopped && !EMPTY(from->write_q)) {
  58                 if (FULL(to->read_q)) {
  59                         if (FULL(to->secondary))
  60                                 break;
  61                         TTY_READ_FLUSH(to);
  62                         continue;
  63                 }
  64                 c = get_tty_queue(from->write_q);
  65                 put_tty_queue(c,to->read_q);
  66                 if (current->signal & ~current->blocked)
  67                         break;
  68         }
  69         TTY_READ_FLUSH(to);
  70         wake_up(&from->write_q->proc_list);
  71 }
  72 
  73 /*
  74  * This routine gets called when tty_write has put something into
  75  * the write_queue. It copies the input to the output-queue of it's
  76  * slave.
  77  */
  78 void mpty_write(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         if (tty->link)
  81                 pty_copy(tty,tty->link);
  82 }
  83 
  84 void spty_write(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         if (tty->link)
  87                 pty_copy(tty,tty->link);
  88 }

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