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 #include <linux/interrupt.h>
20
21 #include <asm/system.h>
22 #include <asm/bitops.h>
23
24 static void pty_close(struct tty_struct * tty, struct file * filp)
25 {
26 if (!tty || (tty->count > 1))
27 return;
28 wake_up_interruptible(&tty->read_q.proc_list);
29 if (!tty->link)
30 return;
31 wake_up_interruptible(&tty->link->write_q.proc_list);
32 if (IS_A_PTY_MASTER(tty->line))
33 tty_hangup(tty->link);
34 }
35
36 static inline void pty_copy(struct tty_struct * from, struct tty_struct * to)
37 {
38 int c;
39
40 while (!from->stopped && !EMPTY(&from->write_q)) {
41 if (FULL(&to->read_q)) {
42 if (FULL(&to->secondary))
43 break;
44 TTY_READ_FLUSH(to);
45 continue;
46 }
47 c = get_tty_queue(&from->write_q);
48 put_tty_queue(c, &to->read_q);
49 if (current->signal & ~current->blocked)
50 break;
51 }
52 TTY_READ_FLUSH(to);
53 wake_up_interruptible(&from->write_q.proc_list);
54 if (from->write_data_cnt) {
55 set_bit(from->line, &tty_check_write);
56 mark_bh(TTY_BH);
57 }
58 }
59
60
61
62
63
64
65 static void pty_write(struct tty_struct * tty)
66 {
67 if (tty->link)
68 pty_copy(tty,tty->link);
69 }
70
71 int pty_open(struct tty_struct *tty, struct file * filp)
72 {
73 if (!tty || !tty->link)
74 return -ENODEV;
75 tty->write = tty->link->write = pty_write;
76 tty->close = tty->link->close = pty_close;
77 wake_up_interruptible(&tty->read_q.proc_list);
78 if (filp->f_flags & O_NDELAY)
79 return 0;
80 while (!tty->link->count && !(current->signal & ~current->blocked))
81 interruptible_sleep_on(&tty->link->read_q.proc_list);
82 if (!tty->link->count)
83 return -ERESTARTSYS;
84 return 0;
85 }