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 static void pty_close(struct tty_struct * tty, struct file * filp);
24
25 int pty_open(struct tty_struct *tty, struct file * filp)
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)
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)
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
76
77
78
79 void mpty_write(struct tty_struct * tty)
80 {
81 if (tty->link)
82 pty_copy(tty,tty->link);
83 }
84
85 void spty_write(struct tty_struct * tty)
86 {
87 if (tty->link)
88 pty_copy(tty,tty->link);
89 }