vt: add an activate and lock
authorAlan Cox <alan@linux.intel.com>
Sat, 19 Sep 2009 20:13:26 +0000 (13:13 -0700)
committerLive-CD User <linux@linux.site>
Sat, 19 Sep 2009 20:13:26 +0000 (13:13 -0700)
X and other graphical interfaces need to be able to flip to a console
and lock it into graphics mode without races.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/char/vt_ioctl.c
include/linux/vt.h

index d29fbd44bdca0e20e94b46cf51f1aaa5cd806a59..0fceb8f4d6f22622b5d8f70db707b99667eece2c 100644 (file)
@@ -972,6 +972,41 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
                }
                break;
 
+       case VT_SETACTIVATE:
+       {
+               struct vt_setactivate vsa;
+
+               if (!perm)
+                       goto eperm;
+
+               if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg,
+                                               sizeof(struct vt_setactivate)))
+                       return -EFAULT;
+               if (vsa.console == 0 || vsa.console > MAX_NR_CONSOLES)
+                       ret = -ENXIO;
+               else {
+                       vsa.console--;
+                       acquire_console_sem();
+                       ret = vc_allocate(vsa.console);
+                       if (ret == 0) {
+                               struct vc_data *nvc;
+                               /* This is safe providing we don't drop the
+                                  console sem between vc_allocate and
+                                  finishing referencing nvc */
+                               nvc = vc_cons[vsa.console].d;
+                               nvc->vt_mode = vsa.mode;
+                               nvc->vt_mode.frsig = 0;
+                               put_pid(nvc->vt_pid);
+                               nvc->vt_pid = get_pid(task_pid(current));
+                       }
+                       release_console_sem();
+                       if (ret)
+                               break;
+                       /* Commence switch and lock */
+                       set_console(arg);
+               }
+       }
+
        /*
         * wait until the specified VT has been activated
         */
@@ -1342,7 +1377,8 @@ void vc_SAK(struct work_struct *work)
 }
 
 /*
- * Performs the back end of a vt switch
+ * Performs the back end of a vt switch. Called under the console
+ * semaphore.
  */
 static void complete_change_console(struct vc_data *vc)
 {
index 831daf64b90c7f1ef30e1d65bd48c8d9d5dd5329..7afca0d72139f4993b089b5b1761c16f846f3434 100644 (file)
@@ -77,4 +77,11 @@ struct vt_event {
 
 #define VT_WAITEVENT   0x560E  /* Wait for an event */
 
+struct vt_setactivate {
+       unsigned int console;
+       struct vt_mode mode;
+};
+
+#define VT_SETACTIVATE 0x560F  /* Activate and set the mode of a console */
+
 #endif /* _LINUX_VT_H */