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(&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)
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
59
60
61
62 static void pty_write(struct tty_struct * tty)
63 {
64 if (tty->link)
65 pty_copy(tty,tty->link);
66 }
67
68 int pty_open(struct tty_struct *tty, struct file * filp)
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 }