2 * Copyright (C) 1992 obz under the linux copyright
4 * Dynamic diacritical handling - aeb@cwi.nl - Dec 1993
5 * Dynamic keymap and string allocation - aeb@cwi.nl - May 1994
6 * Restrict VT switching via ioctl() - grif@cs.ucr.edu - Dec 1995
7 * Some code moved for less code duplication - Andi Kleen - Mar 1997
8 * Check put/get_user, cleanups - acme@conectiva.com.br - Jun 2001
11 #include <linux/types.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/tty.h>
15 #include <linux/timer.h>
16 #include <linux/kernel.h>
17 #include <linux/compat.h>
18 #include <linux/module.h>
21 #include <linux/string.h>
22 #include <linux/slab.h>
23 #include <linux/major.h>
25 #include <linux/console.h>
26 #include <linux/consolemap.h>
27 #include <linux/signal.h>
28 #include <linux/suspend.h>
29 #include <linux/timex.h>
32 #include <asm/uaccess.h>
34 #include <linux/nospec.h>
36 #include <linux/kbd_kern.h>
37 #include <linux/vt_kern.h>
38 #include <linux/kbd_diacr.h>
39 #include <linux/selection.h>
43 static inline bool vt_in_use(unsigned int i)
45 const struct vc_data *vc = vc_cons[i].d;
48 * console_lock must be held to prevent the vc from being deallocated
49 * while we're checking whether it's in-use.
51 WARN_CONSOLE_UNLOCKED();
53 return vc && kref_read(&vc->port.kref) > 1;
56 static inline bool vt_busy(int i)
62 if (vc_is_sel(vc_cons[i].d))
69 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
70 * experimentation and study of X386 SYSV handling.
72 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
73 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
74 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
75 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
76 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
77 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
78 * to the current console is done by the main ioctl code.
82 #include <linux/syscalls.h>
85 static void complete_change_console(struct vc_data *vc);
88 * User space VT_EVENT handlers
91 struct vt_event_wait {
92 struct list_head list;
93 struct vt_event event;
97 static LIST_HEAD(vt_events);
98 static DEFINE_SPINLOCK(vt_event_lock);
99 static DECLARE_WAIT_QUEUE_HEAD(vt_event_waitqueue);
103 * @event: the event that occurred
107 * Post an VT event to interested VT handlers
110 void vt_event_post(unsigned int event, unsigned int old, unsigned int new)
112 struct list_head *pos, *head;
116 spin_lock_irqsave(&vt_event_lock, flags);
119 list_for_each(pos, head) {
120 struct vt_event_wait *ve = list_entry(pos,
121 struct vt_event_wait, list);
122 if (!(ve->event.event & event))
124 ve->event.event = event;
125 /* kernel view is consoles 0..n-1, user space view is
126 console 1..n with 0 meaning current, so we must bias */
127 ve->event.oldev = old + 1;
128 ve->event.newev = new + 1;
132 spin_unlock_irqrestore(&vt_event_lock, flags);
134 wake_up_interruptible(&vt_event_waitqueue);
137 static void __vt_event_queue(struct vt_event_wait *vw)
140 /* Prepare the event */
141 INIT_LIST_HEAD(&vw->list);
143 /* Queue our event */
144 spin_lock_irqsave(&vt_event_lock, flags);
145 list_add(&vw->list, &vt_events);
146 spin_unlock_irqrestore(&vt_event_lock, flags);
149 static void __vt_event_wait(struct vt_event_wait *vw)
151 /* Wait for it to pass */
152 wait_event_interruptible(vt_event_waitqueue, vw->done);
155 static void __vt_event_dequeue(struct vt_event_wait *vw)
160 spin_lock_irqsave(&vt_event_lock, flags);
162 spin_unlock_irqrestore(&vt_event_lock, flags);
166 * vt_event_wait - wait for an event
169 * Waits for an event to occur which completes our vt_event_wait
170 * structure. On return the structure has wv->done set to 1 for success
171 * or 0 if some event such as a signal ended the wait.
174 static void vt_event_wait(struct vt_event_wait *vw)
176 __vt_event_queue(vw);
178 __vt_event_dequeue(vw);
182 * vt_event_wait_ioctl - event ioctl handler
183 * @arg: argument to ioctl
185 * Implement the VT_WAITEVENT ioctl using the VT event interface
188 static int vt_event_wait_ioctl(struct vt_event __user *event)
190 struct vt_event_wait vw;
192 if (copy_from_user(&vw.event, event, sizeof(struct vt_event)))
194 /* Highest supported event for now */
195 if (vw.event.event & ~VT_MAX_EVENT)
199 /* If it occurred report it */
201 if (copy_to_user(event, &vw.event, sizeof(struct vt_event)))
209 * vt_waitactive - active console wait
213 * Helper for event waits. Used to implement the legacy
214 * event waiting ioctls in terms of events
217 int vt_waitactive(int n)
219 struct vt_event_wait vw;
221 vw.event.event = VT_EVENT_SWITCH;
222 __vt_event_queue(&vw);
223 if (n == fg_console + 1) {
224 __vt_event_dequeue(&vw);
227 __vt_event_wait(&vw);
228 __vt_event_dequeue(&vw);
231 } while (vw.event.newev != n);
236 * these are the valid i/o ports we're allowed to change. they map all the
239 #define GPFIRST 0x3b4
241 #define GPNUM (GPLAST - GPFIRST + 1)
244 do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_data *vc)
246 struct unimapdesc tmp;
248 if (copy_from_user(&tmp, user_ud, sizeof tmp))
251 if (!access_ok(VERIFY_WRITE, tmp.entries,
252 tmp.entry_ct*sizeof(struct unipair)))
258 return con_set_unimap(vc, tmp.entry_ct, tmp.entries);
260 if (!perm && fg_console != vc->vc_num)
262 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp.entries);
267 /* deallocate a single console, if possible (leave 0) */
268 static int vt_disallocate(unsigned int vc_num)
270 struct vc_data *vc = NULL;
277 vc = vc_deallocate(vc_num);
280 if (vc && vc_num >= MIN_NR_CONSOLES)
281 tty_port_put(&vc->port);
286 /* deallocate all unused consoles, but leave 0 */
287 static void vt_disallocate_all(void)
289 struct vc_data *vc[MAX_NR_CONSOLES];
293 for (i = 1; i < MAX_NR_CONSOLES; i++)
295 vc[i] = vc_deallocate(i);
300 for (i = 1; i < MAX_NR_CONSOLES; i++) {
301 if (vc[i] && i >= MIN_NR_CONSOLES)
302 tty_port_put(&vc[i]->port);
308 * We handle the console-specific ioctl's here. We allow the
309 * capability to modify any console, not just the fg_console.
311 int vt_ioctl(struct tty_struct *tty,
312 unsigned int cmd, unsigned long arg)
314 struct vc_data *vc = tty->driver_data;
315 struct console_font_op op; /* used in multiple places here */
316 unsigned int console = vc->vc_num;
319 void __user *up = (void __user *)arg;
324 * To have permissions to do most of the vt ioctls, we either have
325 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
328 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
333 ret = tioclinux(tty, arg);
339 * The use of PIT_TICK_RATE is historic, it used to be
340 * the platform-dependent CLOCK_TICK_RATE between 2.6.12
341 * and 2.6.36, which was a minor but unfortunate ABI
342 * change. kd_mksound is locked by the input layer.
345 arg = PIT_TICK_RATE / arg;
353 unsigned int ticks, count;
356 * Generate the tone for the appropriate number of ticks.
357 * If the time is zero, turn off sound ourselves.
359 ticks = msecs_to_jiffies((arg >> 16) & 0xffff);
360 count = ticks ? (arg & 0xffff) : 0;
362 count = PIT_TICK_RATE / count;
363 kd_mksound(count, ticks);
372 ret = put_user(ucval, (char __user *)arg);
376 * These cannot be implemented on any machine that implements
377 * ioperm() in user level (such as Alpha PCs) or not at all.
379 * XXX: you should never use these, just call ioperm directly..
385 * KDADDIO and KDDELIO may be able to add ports beyond what
386 * we reject here, but to be safe...
388 * These are locked internally via sys_ioperm
390 if (arg < GPFIRST || arg > GPLAST) {
394 ret = sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
399 ret = sys_ioperm(GPFIRST, GPNUM,
400 (cmd == KDENABIO)) ? -ENXIO : 0;
404 /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
408 struct kbd_repeat kbrep;
410 if (!capable(CAP_SYS_TTY_CONFIG))
413 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) {
417 ret = kbd_rate(&kbrep);
420 if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat)))
427 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
428 * doesn't do a whole lot. i'm not sure if it should do any
429 * restoration of modes or what...
431 * XXX It should at least call into the driver, fbdev's definitely
432 * need to restore their engine state. --BenH
449 if (vc->vc_mode == (unsigned char) arg) {
453 vc->vc_mode = (unsigned char) arg;
454 if (console != fg_console) {
459 * explicitly blank/unblank the screen if switching modes
462 do_unblank_screen(1);
475 * these work like a combination of mmap and KDENABIO.
476 * this could be easily finished.
484 ret = vt_do_kdskbmode(console, arg);
486 tty_ldisc_flush(tty);
490 uival = vt_do_kdgkbmode(console);
491 ret = put_user(uival, (int __user *)arg);
494 /* this could be folded into KDSKBMODE, but for compatibility
495 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
497 ret = vt_do_kdskbmeta(console, arg);
501 /* FIXME: should review whether this is worth locking */
502 uival = vt_do_kdgkbmeta(console);
504 ret = put_user(uival, (int __user *)arg);
509 if(!capable(CAP_SYS_TTY_CONFIG))
511 ret = vt_do_kbkeycode_ioctl(cmd, up, perm);
516 ret = vt_do_kdsk_ioctl(cmd, up, perm, console);
521 ret = vt_do_kdgkb_ioctl(cmd, up, perm);
524 /* Diacritical processing. Handled in keyboard.c as it has
525 to operate on the keyboard locks and structures */
530 ret = vt_do_diacrit(cmd, up, perm);
533 /* the ioctls below read/set the flags usually shown in the leds */
534 /* don't use them - they will go away without warning */
539 ret = vt_do_kdskled(console, cmd, arg, perm);
543 * A process can indicate its willingness to accept signals
544 * generated by pressing an appropriate key combination.
545 * Thus, one can have a daemon that e.g. spawns a new console
546 * upon a keypress and then changes to it.
547 * See also the kbrequest field of inittab(5).
551 if (!perm || !capable(CAP_KILL))
553 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
556 spin_lock_irq(&vt_spawn_con.lock);
557 put_pid(vt_spawn_con.pid);
558 vt_spawn_con.pid = get_pid(task_pid(current));
559 vt_spawn_con.sig = arg;
560 spin_unlock_irq(&vt_spawn_con.lock);
571 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) {
575 if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) {
581 /* the frsig is ignored, so we set it to 0 */
582 vc->vt_mode.frsig = 0;
584 vc->vt_pid = get_pid(task_pid(current));
585 /* no switch is required -- saw@shade.msu.ru */
597 memcpy(&tmp, &vc->vt_mode, sizeof(struct vt_mode));
600 rc = copy_to_user(up, &tmp, sizeof(struct vt_mode));
607 * Returns global vt state. Note that VT 0 is always open, since
608 * it's an alias for the current VT, and people can't use it here.
609 * We cannot return state for more than 16 VTs, since v_state is short.
613 struct vt_stat __user *vtstat = up;
614 unsigned short state, mask;
616 if (put_user(fg_console + 1, &vtstat->v_active))
619 state = 1; /* /dev/tty0 is always open */
620 console_lock(); /* required by vt_in_use() */
621 for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask;
626 ret = put_user(state, &vtstat->v_state);
632 * Returns the first available (non-opened) console.
635 console_lock(); /* required by vt_in_use() */
636 for (i = 0; i < MAX_NR_CONSOLES; ++i)
640 uival = i < MAX_NR_CONSOLES ? (i+1) : -1;
644 * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
645 * with num >= 1 (switches to vt 0, our console, are not allowed, just
646 * to preserve sanity).
651 if (arg == 0 || arg > MAX_NR_CONSOLES)
655 arg = array_index_nospec(arg, MAX_NR_CONSOLES);
657 ret = vc_allocate(arg);
667 struct vt_setactivate vsa;
672 if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg,
673 sizeof(struct vt_setactivate))) {
677 if (vsa.console == 0 || vsa.console > MAX_NR_CONSOLES)
681 vsa.console = array_index_nospec(vsa.console,
684 ret = vc_allocate(vsa.console);
687 /* This is safe providing we don't drop the
688 console sem between vc_allocate and
689 finishing referencing nvc */
690 nvc = vc_cons[vsa.console].d;
691 nvc->vt_mode = vsa.mode;
692 nvc->vt_mode.frsig = 0;
693 put_pid(nvc->vt_pid);
694 nvc->vt_pid = get_pid(task_pid(current));
699 /* Commence switch and lock */
700 /* Review set_console locks */
701 set_console(vsa.console);
707 * wait until the specified VT has been activated
712 if (arg == 0 || arg > MAX_NR_CONSOLES)
715 ret = vt_waitactive(arg);
719 * If a vt is under process control, the kernel will not switch to it
720 * immediately, but postpone the operation until the process calls this
721 * ioctl, allowing the switch to complete.
723 * According to the X sources this is the behavior:
724 * 0: pending switch-from not OK
725 * 1: pending switch-from OK
726 * 2: completed switch-to OK
733 if (vc->vt_mode.mode != VT_PROCESS) {
739 * Switching-from response
741 if (vc->vt_newvt >= 0) {
744 * Switch disallowed, so forget we were trying
751 * The current vt has been released, so
752 * complete the switch.
755 newvt = vc->vt_newvt;
757 ret = vc_allocate(newvt);
763 * When we actually do the console switch,
764 * make sure we are atomic with respect to
765 * other console switches..
767 complete_change_console(vc_cons[newvt].d);
771 * Switched-to response
774 * If it's just an ACK, ignore it
776 if (arg != VT_ACKACQ)
783 * Disallocate memory associated to VT (but leave VT1)
786 if (arg > MAX_NR_CONSOLES) {
791 vt_disallocate_all();
793 ret = vt_disallocate(--arg);
798 struct vt_sizes __user *vtsizes = up;
804 if (get_user(ll, &vtsizes->v_rows) ||
805 get_user(cc, &vtsizes->v_cols))
809 for (i = 0; i < MAX_NR_CONSOLES; i++) {
813 vc->vc_resize_user = 1;
814 /* FIXME: review v tty lock */
815 vc_resize(vc_cons[i].d, cc, ll);
828 if (copy_from_user(&v, up, sizeof(struct vt_consize)))
830 /* FIXME: Should check the copies properly */
832 v.v_vlin = vc->vc_scan_lines;
834 int rows = v.v_vlin/v.v_clin;
835 if (v.v_rows != rows) {
836 if (v.v_rows) /* Parameters don't add up */
841 if (v.v_vcol && v.v_ccol) {
842 int cols = v.v_vcol/v.v_ccol;
843 if (v.v_cols != cols) {
853 for (i = 0; i < MAX_NR_CONSOLES; i++) {
862 int save_scan_lines = vcp->vc_scan_lines;
863 int save_cell_height = vcp->vc_cell_height;
866 vcp->vc_scan_lines = v.v_vlin;
868 vcp->vc_cell_height = v.v_clin;
869 vcp->vc_resize_user = 1;
870 ret = vc_resize(vcp, v.v_cols, v.v_rows);
872 vcp->vc_scan_lines = save_scan_lines;
873 vcp->vc_cell_height = save_cell_height;
887 ret = con_set_cmap(up);
891 ret = con_get_cmap(up);
895 if (copy_from_user(&op, up, sizeof(op))) {
899 if (!perm && op.op != KD_FONT_OP_GET)
901 ret = con_font_op(vc, &op);
904 if (copy_to_user(up, &op, sizeof(op)))
913 ret = con_set_trans_old(up);
917 ret = con_get_trans_old(up);
924 ret = con_set_trans_new(up);
928 ret = con_get_trans_new(up);
934 con_clear_unimap(vc);
939 ret = do_unimap_ioctl(cmd, up, perm, vc);
943 if (!capable(CAP_SYS_TTY_CONFIG))
945 vt_dont_switch = true;
947 case VT_UNLOCKSWITCH:
948 if (!capable(CAP_SYS_TTY_CONFIG))
950 vt_dont_switch = false;
952 case VT_GETHIFONTMASK:
953 ret = put_user(vc->vc_hi_font_mask,
954 (unsigned short __user *)arg);
957 ret = vt_event_wait_ioctl((struct vt_event __user *)arg);
966 void reset_vc(struct vc_data *vc)
968 vc->vc_mode = KD_TEXT;
969 vt_reset_unicode(vc->vc_num);
970 vc->vt_mode.mode = VT_AUTO;
971 vc->vt_mode.waitv = 0;
972 vc->vt_mode.relsig = 0;
973 vc->vt_mode.acqsig = 0;
974 vc->vt_mode.frsig = 0;
978 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
982 void vc_SAK(struct work_struct *work)
985 container_of(work, struct vc, SAK_work);
987 struct tty_struct *tty;
992 /* FIXME: review tty ref counting */
995 * SAK should also work in all raw modes and reset
1005 #ifdef CONFIG_COMPAT
1007 struct compat_console_font_op {
1008 compat_uint_t op; /* operation code KD_FONT_OP_* */
1009 compat_uint_t flags; /* KD_FONT_FLAG_* */
1010 compat_uint_t width, height; /* font size */
1011 compat_uint_t charcount;
1012 compat_caddr_t data; /* font data with height fixed to 32 */
1016 compat_kdfontop_ioctl(struct compat_console_font_op __user *fontop,
1017 int perm, struct console_font_op *op, struct vc_data *vc)
1021 if (copy_from_user(op, fontop, sizeof(struct compat_console_font_op)))
1023 if (!perm && op->op != KD_FONT_OP_GET)
1025 op->data = compat_ptr(((struct compat_console_font_op *)op)->data);
1026 i = con_font_op(vc, op);
1029 ((struct compat_console_font_op *)op)->data = (unsigned long)op->data;
1030 if (copy_to_user(fontop, op, sizeof(struct compat_console_font_op)))
1035 struct compat_unimapdesc {
1036 unsigned short entry_ct;
1037 compat_caddr_t entries;
1041 compat_unimap_ioctl(unsigned int cmd, struct compat_unimapdesc __user *user_ud,
1042 int perm, struct vc_data *vc)
1044 struct compat_unimapdesc tmp;
1045 struct unipair __user *tmp_entries;
1047 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1049 tmp_entries = compat_ptr(tmp.entries);
1051 if (!access_ok(VERIFY_WRITE, tmp_entries,
1052 tmp.entry_ct*sizeof(struct unipair)))
1058 return con_set_unimap(vc, tmp.entry_ct, tmp_entries);
1060 if (!perm && fg_console != vc->vc_num)
1062 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp_entries);
1067 long vt_compat_ioctl(struct tty_struct *tty,
1068 unsigned int cmd, unsigned long arg)
1070 struct vc_data *vc = tty->driver_data;
1071 struct console_font_op op; /* used in multiple places here */
1072 void __user *up = (void __user *)arg;
1077 * To have permissions to do most of the vt ioctls, we either have
1078 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
1081 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1086 * these need special handlers for incompatible data structures
1089 ret = compat_kdfontop_ioctl(up, perm, &op, vc);
1094 ret = compat_unimap_ioctl(cmd, up, perm, vc);
1098 * all these treat 'arg' as an integer
1117 case VT_DISALLOCATE:
1123 * the rest has a compatible data structure behind arg,
1124 * but we have to convert it to a proper 64 bit pointer.
1127 arg = (unsigned long)compat_ptr(arg);
1134 return vt_ioctl(tty, cmd, arg);
1138 #endif /* CONFIG_COMPAT */
1142 * Performs the back end of a vt switch. Called under the console
1145 static void complete_change_console(struct vc_data *vc)
1147 unsigned char old_vc_mode;
1148 int old = fg_console;
1150 last_console = fg_console;
1153 * If we're switching, we could be going from KD_GRAPHICS to
1154 * KD_TEXT mode or vice versa, which means we need to blank or
1155 * unblank the screen later.
1157 old_vc_mode = vc_cons[fg_console].d->vc_mode;
1161 * This can't appear below a successful kill_pid(). If it did,
1162 * then the *blank_screen operation could occur while X, having
1163 * received acqsig, is waking up on another processor. This
1164 * condition can lead to overlapping accesses to the VGA range
1165 * and the framebuffer (causing system lockups).
1167 * To account for this we duplicate this code below only if the
1168 * controlling process is gone and we've called reset_vc.
1170 if (old_vc_mode != vc->vc_mode) {
1171 if (vc->vc_mode == KD_TEXT)
1172 do_unblank_screen(1);
1178 * If this new console is under process control, send it a signal
1179 * telling it that it has acquired. Also check if it has died and
1180 * clean up (similar to logic employed in change_console())
1182 if (vc->vt_mode.mode == VT_PROCESS) {
1184 * Send the signal as privileged - kill_pid() will
1185 * tell us if the process has gone or something else
1188 if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
1190 * The controlling process has died, so we revert back to
1191 * normal operation. In this case, we'll also change back
1192 * to KD_TEXT mode. I'm not sure if this is strictly correct
1193 * but it saves the agony when the X server dies and the screen
1194 * remains blanked due to KD_GRAPHICS! It would be nice to do
1195 * this outside of VT_PROCESS but there is no single process
1196 * to account for and tracking tty count may be undesirable.
1200 if (old_vc_mode != vc->vc_mode) {
1201 if (vc->vc_mode == KD_TEXT)
1202 do_unblank_screen(1);
1210 * Wake anyone waiting for their VT to activate
1212 vt_event_post(VT_EVENT_SWITCH, old, vc->vc_num);
1217 * Performs the front-end of a vt switch
1219 void change_console(struct vc_data *new_vc)
1223 if (!new_vc || new_vc->vc_num == fg_console || vt_dont_switch)
1227 * If this vt is in process mode, then we need to handshake with
1228 * that process before switching. Essentially, we store where that
1229 * vt wants to switch to and wait for it to tell us when it's done
1230 * (via VT_RELDISP ioctl).
1232 * We also check to see if the controlling process still exists.
1233 * If it doesn't, we reset this vt to auto mode and continue.
1234 * This is a cheap way to track process control. The worst thing
1235 * that can happen is: we send a signal to a process, it dies, and
1236 * the switch gets "lost" waiting for a response; hopefully, the
1237 * user will try again, we'll detect the process is gone (unless
1238 * the user waits just the right amount of time :-) and revert the
1239 * vt to auto control.
1241 vc = vc_cons[fg_console].d;
1242 if (vc->vt_mode.mode == VT_PROCESS) {
1244 * Send the signal as privileged - kill_pid() will
1245 * tell us if the process has gone or something else
1248 * We need to set vt_newvt *before* sending the signal or we
1251 vc->vt_newvt = new_vc->vc_num;
1252 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
1254 * It worked. Mark the vt to switch to and
1255 * return. The process needs to send us a
1256 * VT_RELDISP ioctl to complete the switch.
1262 * The controlling process has died, so we revert back to
1263 * normal operation. In this case, we'll also change back
1264 * to KD_TEXT mode. I'm not sure if this is strictly correct
1265 * but it saves the agony when the X server dies and the screen
1266 * remains blanked due to KD_GRAPHICS! It would be nice to do
1267 * this outside of VT_PROCESS but there is no single process
1268 * to account for and tracking tty count may be undesirable.
1273 * Fall through to normal (VT_AUTO) handling of the switch...
1278 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
1280 if (vc->vc_mode == KD_GRAPHICS)
1283 complete_change_console(new_vc);
1286 /* Perform a kernel triggered VT switch for suspend/resume */
1288 static int disable_vt_switch;
1290 int vt_move_to_console(unsigned int vt, int alloc)
1295 /* Graphics mode - up to X */
1296 if (disable_vt_switch) {
1302 if (alloc && vc_allocate(vt)) {
1303 /* we can't have a free VC for now. Too bad,
1304 * we don't want to mess the screen for now. */
1309 if (set_console(vt)) {
1311 * We're unable to switch to the SUSPEND_CONSOLE.
1312 * Let the calling function know so it can decide
1319 if (vt_waitactive(vt + 1)) {
1320 pr_debug("Suspend: Can't switch VCs.");
1327 * Normally during a suspend, we allocate a new console and switch to it.
1328 * When we resume, we switch back to the original console. This switch
1329 * can be slow, so on systems where the framebuffer can handle restoration
1330 * of video registers anyways, there's little point in doing the console
1331 * switch. This function allows you to disable it by passing it '0'.
1333 void pm_set_vt_switch(int do_switch)
1336 disable_vt_switch = !do_switch;
1339 EXPORT_SYMBOL(pm_set_vt_switch);