/[linux-patches]/genpatches-2.6/historical/2.6.10/1185_tty-process.patch
Gentoo

Contents of /genpatches-2.6/historical/2.6.10/1185_tty-process.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download) (as text)
Sat Jun 11 23:16:54 2005 UTC (15 years ago) by dsd
File MIME type: text/x-diff
File size: 5081 byte(s)
Import historical releases
1 diff -urNpX dontdiff linux-2.6.10/drivers/char/tty_io.c linux-dsd/drivers/char/tty_io.c
2 --- linux-2.6.10/drivers/char/tty_io.c 2004-12-24 21:34:58.000000000 +0000
3 +++ linux-dsd/drivers/char/tty_io.c 2005-03-19 14:49:01.000000000 +0000
4 @@ -918,9 +918,11 @@ void disassociate_ctty(int on_exit)
5
6 lock_kernel();
7
8 + down(&tty_sem);
9 tty = current->signal->tty;
10 if (tty) {
11 tty_pgrp = tty->pgrp;
12 + up(&tty_sem);
13 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
14 tty_vhangup(tty);
15 } else {
16 @@ -928,6 +930,7 @@ void disassociate_ctty(int on_exit)
17 kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
18 kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
19 }
20 + up(&tty_sem);
21 unlock_kernel();
22 return;
23 }
24 @@ -937,15 +940,19 @@ void disassociate_ctty(int on_exit)
25 kill_pg(tty_pgrp, SIGCONT, on_exit);
26 }
27
28 + /* Must lock changes to tty_old_pgrp */
29 + down(&tty_sem);
30 current->signal->tty_old_pgrp = 0;
31 tty->session = 0;
32 tty->pgrp = -1;
33
34 + /* Now clear signal->tty under the lock */
35 read_lock(&tasklist_lock);
36 do_each_task_pid(current->signal->session, PIDTYPE_SID, p) {
37 p->signal->tty = NULL;
38 } while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
39 read_unlock(&tasklist_lock);
40 + up(&tty_sem);
41 unlock_kernel();
42 }
43
44 @@ -1171,12 +1178,6 @@ static int init_dev(struct tty_driver *d
45 struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
46 int retval=0;
47
48 - /*
49 - * Check whether we need to acquire the tty semaphore to avoid
50 - * race conditions. For now, play it safe.
51 - */
52 - down(&tty_sem);
53 -
54 /* check whether we're reopening an existing tty */
55 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
56 tty = devpts_get_tty(idx);
57 @@ -1365,7 +1366,6 @@ success:
58
59 /* All paths come through here to release the semaphore */
60 end_init:
61 - up(&tty_sem);
62 return retval;
63
64 /* Release locally allocated memory ... nothing placed in slots */
65 @@ -1561,9 +1561,14 @@ static void release_dev(struct file * fi
66 * each iteration we avoid any problems.
67 */
68 while (1) {
69 + /* Guard against races with tty->count changes elsewhere and
70 + opens on /dev/tty */
71 +
72 + down(&tty_sem);
73 tty_closing = tty->count <= 1;
74 o_tty_closing = o_tty &&
75 (o_tty->count <= (pty_master ? 1 : 0));
76 + up(&tty_sem);
77 do_sleep = 0;
78
79 if (tty_closing) {
80 @@ -1599,6 +1604,8 @@ static void release_dev(struct file * fi
81 * both sides, and we've completed the last operation that could
82 * block, so it's safe to proceed with closing.
83 */
84 +
85 + down(&tty_sem);
86 if (pty_master) {
87 if (--o_tty->count < 0) {
88 printk(KERN_WARNING "release_dev: bad pty slave count "
89 @@ -1612,7 +1619,8 @@ static void release_dev(struct file * fi
90 tty->count, tty_name(tty, buf));
91 tty->count = 0;
92 }
93 -
94 + up(&tty_sem);
95 +
96 /*
97 * We've decremented tty->count, so we need to remove this file
98 * descriptor off the tty->tty_files list; this serves two
99 @@ -1759,10 +1767,14 @@ retry_open:
100 noctty = filp->f_flags & O_NOCTTY;
101 index = -1;
102 retval = 0;
103 +
104 + down(&tty_sem);
105
106 if (device == MKDEV(TTYAUX_MAJOR,0)) {
107 - if (!current->signal->tty)
108 + if (!current->signal->tty) {
109 + up(&tty_sem);
110 return -ENXIO;
111 + }
112 driver = current->signal->tty->driver;
113 index = current->signal->tty->index;
114 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
115 @@ -1787,14 +1799,18 @@ retry_open:
116 noctty = 1;
117 goto got_driver;
118 }
119 + up(&tty_sem);
120 return -ENODEV;
121 }
122
123 driver = get_tty_driver(device, &index);
124 - if (!driver)
125 + if (!driver) {
126 + up(&tty_sem);
127 return -ENODEV;
128 + }
129 got_driver:
130 retval = init_dev(driver, index, &tty);
131 + up(&tty_sem);
132 if (retval)
133 return retval;
134
135 @@ -1880,7 +1896,10 @@ static int ptmx_open(struct inode * inod
136 }
137 up(&allocated_ptys_lock);
138
139 + down(&tty_sem);
140 retval = init_dev(ptm_driver, index, &tty);
141 + up(&tty_sem);
142 +
143 if (retval)
144 goto out;
145
146 diff -urNpX dontdiff linux-2.6.10/kernel/exit.c linux-dsd/kernel/exit.c
147 --- linux-2.6.10/kernel/exit.c 2004-12-24 21:35:27.000000000 +0000
148 +++ linux-dsd/kernel/exit.c 2005-03-19 14:49:01.000000000 +0000
149 @@ -332,7 +332,9 @@ void daemonize(const char *name, ...)
150 exit_mm(current);
151
152 set_special_pids(1, 1);
153 + down(&tty_sem);
154 current->signal->tty = NULL;
155 + up(&tty_sem);
156
157 /* Block and flush all signals */
158 sigfillset(&blocked);
159 diff -urNpX dontdiff linux-2.6.10/kernel/sys.c linux-dsd/kernel/sys.c
160 --- linux-2.6.10/kernel/sys.c 2005-03-19 14:50:03.000000000 +0000
161 +++ linux-dsd/kernel/sys.c 2005-03-19 14:49:01.000000000 +0000
162 @@ -23,6 +23,7 @@
163 #include <linux/security.h>
164 #include <linux/dcookies.h>
165 #include <linux/suspend.h>
166 +#include <linux/tty.h>
167
168 #include <linux/compat.h>
169 #include <linux/syscalls.h>
170 @@ -1075,6 +1076,7 @@ asmlinkage long sys_setsid(void)
171 if (!thread_group_leader(current))
172 return -EINVAL;
173
174 + down(&tty_sem);
175 write_lock_irq(&tasklist_lock);
176
177 pid = find_pid(PIDTYPE_PGID, current->pid);
178 @@ -1088,6 +1090,7 @@ asmlinkage long sys_setsid(void)
179 err = process_group(current);
180 out:
181 write_unlock_irq(&tasklist_lock);
182 + up(&tty_sem);
183 return err;
184 }
185

  ViewVC Help
Powered by ViewVC 1.1.20