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

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