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

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