This source file includes following definitions.
- pty_open
- pty_close
- pty_copy
- mpty_write
- spty_write
1
2
3
4
5
6
7
8
9
10
11
12
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)
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)
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)
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
75
76
77
78 void mpty_write(struct tty_struct * tty)
79 {
80 if (tty->link)
81 pty_copy(tty,tty->link);
82 }
83
84 void spty_write(struct tty_struct * tty)
85 {
86 if (tty->link)
87 pty_copy(tty,tty->link);
88 }