]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/tty/tty_io.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[karo-tx-linux.git] / drivers / tty / tty_io.c
index 8a5a8b064616a05eb0eefe517c86b2cc9b43f2f6..2ea176b2280e60f201aefec32af4beb8d7892702 100644 (file)
@@ -1166,10 +1166,8 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
        struct file *p = NULL;
 
        spin_lock(&redirect_lock);
-       if (redirect) {
-               get_file(redirect);
-               p = redirect;
-       }
+       if (redirect)
+               p = get_file(redirect);
        spin_unlock(&redirect_lock);
 
        if (p) {
@@ -2264,8 +2262,7 @@ static int tioccons(struct file *file)
                spin_unlock(&redirect_lock);
                return -EBUSY;
        }
-       get_file(file);
-       redirect = file;
+       redirect = get_file(file);
        spin_unlock(&redirect_lock);
        return 0;
 }
@@ -2809,6 +2806,13 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
 }
 #endif
 
+static int this_tty(const void *t, struct file *file, unsigned fd)
+{
+       if (likely(file->f_op->read != tty_read))
+               return 0;
+       return file_tty(file) != t ? 0 : fd + 1;
+}
+       
 /*
  * This implements the "Secure Attention Key" ---  the idea is to
  * prevent trojan horses by killing all processes associated with this
@@ -2836,8 +2840,6 @@ void __do_SAK(struct tty_struct *tty)
        struct task_struct *g, *p;
        struct pid *session;
        int             i;
-       struct file     *filp;
-       struct fdtable *fdt;
 
        if (!tty)
                return;
@@ -2867,27 +2869,12 @@ void __do_SAK(struct tty_struct *tty)
                        continue;
                }
                task_lock(p);
-               if (p->files) {
-                       /*
-                        * We don't take a ref to the file, so we must
-                        * hold ->file_lock instead.
-                        */
-                       spin_lock(&p->files->file_lock);
-                       fdt = files_fdtable(p->files);
-                       for (i = 0; i < fdt->max_fds; i++) {
-                               filp = fcheck_files(p->files, i);
-                               if (!filp)
-                                       continue;
-                               if (filp->f_op->read == tty_read &&
-                                   file_tty(filp) == tty) {
-                                       printk(KERN_NOTICE "SAK: killed process %d"
-                                           " (%s): fd#%d opened to the tty\n",
-                                           task_pid_nr(p), p->comm, i);
-                                       force_sig(SIGKILL, p);
-                                       break;
-                               }
-                       }
-                       spin_unlock(&p->files->file_lock);
+               i = iterate_fd(p->files, 0, this_tty, tty);
+               if (i != 0) {
+                       printk(KERN_NOTICE "SAK: killed process %d"
+                           " (%s): fd#%d opened to the tty\n",
+                                   task_pid_nr(p), p->comm, i - 1);
+                       force_sig(SIGKILL, p);
                }
                task_unlock(p);
        } while_each_thread(g, p);