This source file includes following definitions.
- pty_close
- pty_copy
- pty_write
- pty_open
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 if (!tty)
26 return;
27 wake_up_interruptible(&tty->read_q.proc_list);
28 if (!tty->link)
29 return;
30 wake_up_interruptible(&tty->link->write_q.proc_list);
31 if (IS_A_PTY_MASTER(tty->line))
32 tty_hangup(tty->link);
33 }
34
35 static inline void pty_copy(struct tty_struct * from, struct tty_struct * to)
36 {
37 int c;
38
39 while (!from->stopped && !EMPTY(&from->write_q)) {
40 if (FULL(&to->read_q)) {
41 if (FULL(&to->secondary))
42 break;
43 TTY_READ_FLUSH(to);
44 continue;
45 }
46 c = get_tty_queue(&from->write_q);
47 put_tty_queue(c, &to->read_q);
48 if (current->signal & ~current->blocked)
49 break;
50 }
51 TTY_READ_FLUSH(to);
52 wake_up_interruptible(&from->write_q.proc_list);
53 }
54
55
56
57
58
59
60 static void pty_write(struct tty_struct * tty)
61 {
62 if (tty->link)
63 pty_copy(tty,tty->link);
64 }
65
66 int pty_open(struct tty_struct *tty, struct file * filp)
67 {
68 if (!tty || !tty->link)
69 return -ENODEV;
70 tty->write = tty->link->write = pty_write;
71 tty->close = tty->link->close = pty_close;
72 wake_up_interruptible(&tty->read_q.proc_list);
73 if (filp->f_flags & O_NDELAY)
74 return 0;
75 while (!tty->link->count && !(current->signal & ~current->blocked))
76 interruptible_sleep_on(&tty->link->read_q.proc_list);
77 if (!tty->link->count)
78 return -ERESTARTSYS;
79 return 0;
80 }