1 # From RH: TIOCCONS fix and /dev/console write fix
2 # One of them probably fixes CAN-2002-0247, but which??? They didn't tell :/
3 diff -urN S21-rh/drivers/char/tty_io.c S21-rh-tty/drivers/char/tty_io.c
4 --- S21-rh/drivers/char/tty_io.c Sat May 17 11:31:48 2003
5 +++ S21-rh-tty/drivers/char/tty_io.c Sat May 17 11:32:35 2003
7 extern struct tty_driver pts_driver[]; /* Unix98 pty slaves; for /dev/ptmx */
11 - * redirect is the pseudo-tty that console output
12 - * is redirected to if asked by TIOCCONS.
14 -struct tty_struct * redirect;
16 static void initialize_tty_struct(struct tty_struct *tty);
18 static ssize_t tty_read(struct file *, char *, size_t, loff_t *);
23 +static spinlock_t redirect_lock = SPIN_LOCK_UNLOCKED;
24 +static struct file *redirect;
26 * This can be called by the "eventd" kernel thread. That is process synchronous,
27 * but doesn't hold any locks, so we need to make sure we have the appropriate
30 struct tty_struct *tty = (struct tty_struct *) data;
31 struct file * cons_filp = NULL;
32 + struct file *f = NULL;
33 struct task_struct *p;
35 int closecount = 0, n;
38 /* inuse_filps is protected by the single kernel lock */
41 + spin_lock(&redirect_lock);
42 + if (redirect && redirect->private_data == tty) {
46 + spin_unlock(&redirect_lock);
50 check_tty_count(tty, "do_tty_hangup");
55 struct tty_struct * tty;
56 - struct inode *inode;
58 - /* Can't seek (pwrite) on ttys. */
59 - if (ppos != &file->f_pos)
61 + struct inode *inode = file->f_dentry->d_inode;
64 * For now, we redirect writes from /dev/console as
66 is_console = (inode->i_rdev == SYSCONS_DEV ||
67 inode->i_rdev == CONSOLE_DEV);
69 - if (is_console && redirect)
72 - tty = (struct tty_struct *)file->private_data;
74 + struct file *p = NULL;
76 + spin_lock(&redirect_lock);
81 + spin_unlock(&redirect_lock);
84 + ssize_t res = p->f_op->write(p, buf, count, ppos);
90 + /* Can't seek (pwrite) on ttys. */
91 + if (ppos != &file->f_pos)
94 + tty = (struct tty_struct *)file->private_data;
95 if (tty_paranoia_check(tty, inode->i_rdev, "tty_write"))
97 if (!tty || !tty->driver.write || (test_bit(TTY_IO_ERROR, &tty->flags)))
100 * If _either_ side is closing, make sure there aren't any
101 * processes that still think tty or o_tty is their controlling
102 - * tty. Also, clear redirect if it points to either tty.
105 if (tty_closing || o_tty_closing) {
106 struct task_struct *p;
107 @@ -1245,9 +1265,6 @@
108 for_each_task_pid(o_tty->session, PIDTYPE_SID, p,l, pid)
110 read_unlock(&tasklist_lock);
112 - if (redirect == tty || (o_tty && redirect == o_tty))
116 /* check whether both sides are closing ... */
117 @@ -1526,19 +1543,29 @@
121 -static int tioccons(struct inode *inode,
122 - struct tty_struct *tty, struct tty_struct *real_tty)
123 +static int tioccons(struct inode *inode, struct file *file)
125 if (inode->i_rdev == SYSCONS_DEV ||
126 inode->i_rdev == CONSOLE_DEV) {
130 + spin_lock(&redirect_lock);
133 + spin_unlock(&redirect_lock);
139 + spin_lock(&redirect_lock);
141 + spin_unlock(&redirect_lock);
143 - redirect = real_tty;
147 + spin_unlock(&redirect_lock);
151 @@ -1759,7 +1786,7 @@
153 return tiocswinsz(tty, real_tty, (struct winsize *) arg);
155 - return tioccons(inode, tty, real_tty);
156 + return real_tty!=tty ? -EINVAL : tioccons(inode, file);
158 return fionbio(file, (int *) arg);
160 diff -urN S21-rh/include/linux/tty.h S21-rh-tty/include/linux/tty.h
161 --- S21-rh/include/linux/tty.h Sat May 17 11:31:52 2003
162 +++ S21-rh-tty/include/linux/tty.h Sat May 17 11:32:35 2003
164 extern void tty_write_flush(struct tty_struct *);
166 extern struct termios tty_std_termios;
167 -extern struct tty_struct * redirect;
168 extern struct tty_ldisc ldiscs[];
169 extern int fg_console, last_console, want_console;
171 --- drivers/char/tty_io.c Sat May 17 11:14:02 2003
172 +++ linux/drivers/char/tty_io.c Sun May 25 07:49:08 2003
174 struct tty_struct * tty;
175 struct inode *inode = file->f_dentry->d_inode;
177 + /* Can't seek (pwrite) on ttys. */
178 + if (ppos != &file->f_pos)
182 * For now, we redirect writes from /dev/console as
184 @@ -770,15 +774,11 @@
185 spin_unlock(&redirect_lock);
188 - ssize_t res = p->f_op->write(p, buf, count, ppos);
189 + ssize_t res = p->f_op->write(p, buf, count, &p->f_pos);
195 - /* Can't seek (pwrite) on ttys. */
196 - if (ppos != &file->f_pos)
199 tty = (struct tty_struct *)file->private_data;
200 if (tty_paranoia_check(tty, inode->i_rdev, "tty_write"))