2 * linux/drivers/char/vt_ioctl.c
4 * Copyright (C) 1992 obz under the linux copyright
6 * Dynamic diacritical handling - aeb@cwi.nl - Dec 1993
7 * Dynamic keymap and string allocation - aeb@cwi.nl - May 1994
8 * Restrict VT switching via ioctl() - grif@cs.ucr.edu - Dec 1995
9 * Some code moved for less code duplication - Andi Kleen - Mar 1997
10 * Check put/get_user, cleanups - acme@conectiva.com.br - Jun 2001
13 #include <linux/config.h>
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/sched.h>
17 #include <linux/tty.h>
18 #include <linux/timer.h>
19 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/slab.h>
24 #include <linux/major.h>
26 #include <linux/console.h>
29 #include <asm/uaccess.h>
31 #include <linux/kbd_kern.h>
32 #include <linux/vt_kern.h>
33 #include <linux/kbd_diacr.h>
34 #include <linux/selection.h>
37 extern struct tty_driver *console_driver;
39 #define VT_IS_IN_USE(i) (console_driver->ttys[i] && console_driver->ttys[i]->count)
40 #define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || i == sel_cons)
43 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
44 * experimentation and study of X386 SYSV handling.
46 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
47 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
48 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
49 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
50 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
51 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
52 * to the current console is done by the main ioctl code.
55 struct vt_struct *vt_cons[MAX_NR_CONSOLES];
57 /* Keyboard type: Default is KB_101, but can be set by machine
60 unsigned char keyboard_type = KB_101;
63 #include <linux/syscalls.h>
67 * these are the valid i/o ports we're allowed to change. they map all the
72 #define GPNUM (GPLAST - GPFIRST + 1)
74 #define i (tmp.kb_index)
75 #define s (tmp.kb_table)
76 #define v (tmp.kb_value)
78 do_kdsk_ioctl(int cmd, struct kbentry *user_kbe, int perm, struct kbd_struct *kbd)
81 ushort *key_map, val, ov;
83 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
88 key_map = key_maps[s];
91 if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES)
94 val = (i ? K_HOLE : K_NOSUCHMAP);
95 return put_user(val, &user_kbe->kb_value);
99 if (!i && v == K_NOSUCHMAP) {
100 /* disallocate map */
101 key_map = key_maps[s];
104 if (key_map[0] == U(K_ALLOCATED)) {
112 if (KTYP(v) < NR_TYPES) {
113 if (KVAL(v) > max_vals[KTYP(v)])
116 if (kbd->kbdmode != VC_UNICODE)
119 /* ++Geert: non-PC keyboards may generate keycode zero */
120 #if !defined(__mc68000__) && !defined(__powerpc__)
121 /* assignment to entry 0 only tests validity of args */
126 if (!(key_map = key_maps[s])) {
129 if (keymap_count >= MAX_NR_OF_USER_KEYMAPS &&
130 !capable(CAP_SYS_RESOURCE))
133 key_map = (ushort *) kmalloc(sizeof(plain_map),
137 key_maps[s] = key_map;
138 key_map[0] = U(K_ALLOCATED);
139 for (j = 1; j < NR_KEYS; j++)
140 key_map[j] = U(K_HOLE);
145 break; /* nothing to do */
149 if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN))
152 if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT))
153 compute_shiftstate();
163 do_kbkeycode_ioctl(int cmd, struct kbkeycode *user_kbkc, int perm)
165 struct kbkeycode tmp;
168 if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode)))
172 kc = getkeycode(tmp.scancode);
174 kc = put_user(kc, &user_kbkc->keycode);
179 kc = setkeycode(tmp.scancode, tmp.keycode);
186 do_kdgkb_ioctl(int cmd, struct kbsentry *user_kdgkb, int perm)
188 struct kbsentry *kbs;
193 char *first_free, *fj, *fnw;
197 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
203 /* we mostly copy too much here (512bytes), but who cares ;) */
204 if (copy_from_user(kbs, user_kdgkb, sizeof(struct kbsentry))) {
208 kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
213 sz = sizeof(kbs->kb_string) - 1; /* sz should have been
215 q = user_kdgkb->kb_string;
218 for ( ; *p && sz; p++, sz--)
219 if (put_user(*p, q++)) {
223 if (put_user('\0', q)) {
228 return ((p && *p) ? -EOVERFLOW : 0);
236 first_free = funcbufptr + (funcbufsize - funcbufleft);
237 for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
244 delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string);
245 if (delta <= funcbufleft) { /* it fits in current buf */
246 if (j < MAX_NR_FUNC) {
247 memmove(fj + delta, fj, first_free - fj);
248 for (k = j; k < MAX_NR_FUNC; k++)
250 func_table[k] += delta;
254 funcbufleft -= delta;
255 } else { /* allocate a larger buffer */
257 while (sz < funcbufsize - funcbufleft + delta)
259 fnw = (char *) kmalloc(sz, GFP_KERNEL);
268 memmove(fnw, funcbufptr, fj - funcbufptr);
269 for (k = 0; k < j; k++)
271 func_table[k] = fnw + (func_table[k] - funcbufptr);
273 if (first_free > fj) {
274 memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj);
275 for (k = j; k < MAX_NR_FUNC; k++)
277 func_table[k] = fnw + (func_table[k] - funcbufptr) + delta;
279 if (funcbufptr != func_buf)
282 funcbufleft = funcbufleft - delta + sz - funcbufsize;
285 strcpy(func_table[i], kbs->kb_string);
295 do_fontx_ioctl(int cmd, struct consolefontdesc *user_cfd, int perm, struct console_font_op *op)
297 struct consolefontdesc cfdarg;
300 if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc)))
307 op->op = KD_FONT_OP_SET;
308 op->flags = KD_FONT_FLAG_OLD;
310 op->height = cfdarg.charheight;
311 op->charcount = cfdarg.charcount;
312 op->data = cfdarg.chardata;
313 return con_font_op(fg_console, op);
315 op->op = KD_FONT_OP_GET;
316 op->flags = KD_FONT_FLAG_OLD;
318 op->height = cfdarg.charheight;
319 op->charcount = cfdarg.charcount;
320 op->data = cfdarg.chardata;
321 i = con_font_op(fg_console, op);
324 cfdarg.charheight = op->height;
325 cfdarg.charcount = op->charcount;
326 if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc)))
335 do_unimap_ioctl(int cmd, struct unimapdesc *user_ud, int perm, unsigned int console)
337 struct unimapdesc tmp;
340 if (copy_from_user(&tmp, user_ud, sizeof tmp))
343 i = verify_area(VERIFY_WRITE, tmp.entries,
344 tmp.entry_ct*sizeof(struct unipair));
351 return con_set_unimap(console, tmp.entry_ct, tmp.entries);
353 if (!perm && fg_console != console)
355 return con_get_unimap(console, tmp.entry_ct, &(user_ud->entry_ct), tmp.entries);
361 * We handle the console-specific ioctl's here. We allow the
362 * capability to modify any console, not just the fg_console.
364 int vt_ioctl(struct tty_struct *tty, struct file * file,
365 unsigned int cmd, unsigned long arg)
367 struct vt_struct *vt = (struct vt_struct *)tty->driver_data;
368 struct vc_data *vc = vc_cons[vt->vc_num].d;
369 struct console_font_op op; /* used in multiple places here */
370 struct kbd_struct * kbd;
371 unsigned int console;
375 console = vt->vc_num;
377 if (!vc_cons_allocated(console)) /* impossible? */
381 * To have permissions to do most of the vt ioctls, we either have
382 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
385 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
388 kbd = kbd_table + console;
402 unsigned int ticks, count;
405 * Generate the tone for the appropriate number of ticks.
406 * If the time is zero, turn off sound ourselves.
408 ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
409 count = ticks ? (arg & 0xffff) : 0;
411 count = 1193182 / count;
412 kd_mksound(count, ticks);
420 ucval = keyboard_type;
424 * These cannot be implemented on any machine that implements
425 * ioperm() in user level (such as Alpha PCs) or not at all.
427 * XXX: you should never use these, just call ioperm directly..
433 * KDADDIO and KDDELIO may be able to add ports beyond what
434 * we reject here, but to be safe...
436 if (arg < GPFIRST || arg > GPLAST)
438 return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
442 return sys_ioperm(GPFIRST, GPNUM,
443 (cmd == KDENABIO)) ? -ENXIO : 0;
446 /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
450 struct kbd_repeat kbrep;
453 if (!capable(CAP_SYS_TTY_CONFIG))
456 if (copy_from_user(&kbrep, (void *)arg,
457 sizeof(struct kbd_repeat)))
459 err = kbd_rate(&kbrep);
462 if (copy_to_user((void *)arg, &kbrep,
463 sizeof(struct kbd_repeat)))
470 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
471 * doesn't do a whole lot. i'm not sure if it should do any
472 * restoration of modes or what...
474 * XXX It should at least call into the driver, fbdev's definitely
475 * need to restore their engine state. --BenH
490 if (vt_cons[console]->vc_mode == (unsigned char) arg)
492 vt_cons[console]->vc_mode = (unsigned char) arg;
493 if (console != fg_console)
496 * explicitly blank/unblank the screen if switching modes
498 acquire_console_sem();
500 do_unblank_screen(1);
503 release_console_sem();
507 ucval = vt_cons[console]->vc_mode;
513 * these work like a combination of mmap and KDENABIO.
514 * this could be easily finished.
523 kbd->kbdmode = VC_RAW;
526 kbd->kbdmode = VC_MEDIUMRAW;
529 kbd->kbdmode = VC_XLATE;
530 compute_shiftstate();
533 kbd->kbdmode = VC_UNICODE;
534 compute_shiftstate();
539 if (tty->ldisc.flush_buffer)
540 tty->ldisc.flush_buffer(tty);
544 ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW :
545 (kbd->kbdmode == VC_MEDIUMRAW) ? K_MEDIUMRAW :
546 (kbd->kbdmode == VC_UNICODE) ? K_UNICODE :
550 /* this could be folded into KDSKBMODE, but for compatibility
551 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
555 clr_vc_kbd_mode(kbd, VC_META);
558 set_vc_kbd_mode(kbd, VC_META);
566 ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT);
568 return put_user(ucval, (int *)arg);
572 if(!capable(CAP_SYS_TTY_CONFIG))
574 return do_kbkeycode_ioctl(cmd, (struct kbkeycode *)arg, perm);
578 return do_kdsk_ioctl(cmd, (struct kbentry *)arg, perm, kbd);
582 return do_kdgkb_ioctl(cmd, (struct kbsentry *)arg, perm);
586 struct kbdiacrs *a = (struct kbdiacrs *)arg;
588 if (put_user(accent_table_size, &a->kb_cnt))
590 if (copy_to_user(a->kbdiacr, accent_table, accent_table_size*sizeof(struct kbdiacr)))
597 struct kbdiacrs *a = (struct kbdiacrs *)arg;
602 if (get_user(ct,&a->kb_cnt))
606 accent_table_size = ct;
607 if (copy_from_user(accent_table, a->kbdiacr, ct*sizeof(struct kbdiacr)))
612 /* the ioctls below read/set the flags usually shown in the leds */
613 /* don't use them - they will go away without warning */
615 ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4);
623 kbd->ledflagstate = (arg & 7);
624 kbd->default_ledflagstate = ((arg >> 4) & 7);
628 /* the ioctls below only set the lights, not the functions */
629 /* for those, see KDGKBLED and KDSKBLED above */
631 ucval = getledstate();
633 return put_user(ucval, (char*)arg);
638 setledstate(kbd, arg);
642 * A process can indicate its willingness to accept signals
643 * generated by pressing an appropriate key combination.
644 * Thus, one can have a daemon that e.g. spawns a new console
645 * upon a keypress and then changes to it.
646 * Probably init should be changed to do this (and have a
647 * field ks (`keyboard signal') in inittab describing the
648 * desired action), so that the number of background daemons
653 extern int spawnpid, spawnsig;
654 if (!perm || !capable(CAP_KILL))
656 if (arg < 1 || arg > _NSIG || arg == SIGKILL)
658 spawnpid = current->pid;
669 if (copy_from_user(&tmp, (void*)arg, sizeof(struct vt_mode)))
671 if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS)
673 acquire_console_sem();
674 vt_cons[console]->vt_mode = tmp;
675 /* the frsig is ignored, so we set it to 0 */
676 vt_cons[console]->vt_mode.frsig = 0;
677 vt_cons[console]->vt_pid = current->pid;
678 /* no switch is required -- saw@shade.msu.ru */
679 vt_cons[console]->vt_newvt = -1;
680 release_console_sem();
689 acquire_console_sem();
690 memcpy(&tmp, &vt_cons[console]->vt_mode, sizeof(struct vt_mode));
691 release_console_sem();
693 rc = copy_to_user((void*)arg, &tmp, sizeof(struct vt_mode));
694 return rc ? -EFAULT : 0;
698 * Returns global vt state. Note that VT 0 is always open, since
699 * it's an alias for the current VT, and people can't use it here.
700 * We cannot return state for more than 16 VTs, since v_state is short.
704 struct vt_stat *vtstat = (struct vt_stat *)arg;
705 unsigned short state, mask;
707 if (put_user(fg_console + 1, &vtstat->v_active))
709 state = 1; /* /dev/tty0 is always open */
710 for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask; ++i, mask <<= 1)
713 return put_user(state, &vtstat->v_state);
717 * Returns the first available (non-opened) console.
720 for (i = 0; i < MAX_NR_CONSOLES; ++i)
721 if (! VT_IS_IN_USE(i))
723 ucval = i < MAX_NR_CONSOLES ? (i+1) : -1;
727 * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
728 * with num >= 1 (switches to vt 0, our console, are not allowed, just
729 * to preserve sanity).
734 if (arg == 0 || arg > MAX_NR_CONSOLES)
737 acquire_console_sem();
738 i = vc_allocate(arg);
739 release_console_sem();
746 * wait until the specified VT has been activated
751 if (arg == 0 || arg > MAX_NR_CONSOLES)
753 return vt_waitactive(arg-1);
756 * If a vt is under process control, the kernel will not switch to it
757 * immediately, but postpone the operation until the process calls this
758 * ioctl, allowing the switch to complete.
760 * According to the X sources this is the behavior:
761 * 0: pending switch-from not OK
762 * 1: pending switch-from OK
763 * 2: completed switch-to OK
768 if (vt_cons[console]->vt_mode.mode != VT_PROCESS)
772 * Switching-from response
774 if (vt_cons[console]->vt_newvt >= 0)
778 * Switch disallowed, so forget we were trying
781 vt_cons[console]->vt_newvt = -1;
786 * The current vt has been released, so
787 * complete the switch.
790 acquire_console_sem();
791 newvt = vt_cons[console]->vt_newvt;
792 vt_cons[console]->vt_newvt = -1;
793 i = vc_allocate(newvt);
795 release_console_sem();
799 * When we actually do the console switch,
800 * make sure we are atomic with respect to
801 * other console switches..
803 complete_change_console(newvt);
804 release_console_sem();
809 * Switched-to response
814 * If it's just an ACK, ignore it
816 if (arg != VT_ACKACQ)
823 * Disallocate memory associated to VT (but leave VT1)
826 if (arg > MAX_NR_CONSOLES)
829 /* disallocate all unused consoles, but leave 0 */
830 acquire_console_sem();
831 for (i=1; i<MAX_NR_CONSOLES; i++)
834 release_console_sem();
836 /* disallocate a single console, if possible */
840 if (arg) { /* leave 0 */
841 acquire_console_sem();
843 release_console_sem();
850 struct vt_sizes *vtsizes = (struct vt_sizes *) arg;
854 if (get_user(ll, &vtsizes->v_rows) ||
855 get_user(cc, &vtsizes->v_cols))
857 for (i = 0; i < MAX_NR_CONSOLES; i++) {
858 acquire_console_sem();
859 vc_resize(i, cc, ll);
860 release_console_sem();
867 struct vt_consize *vtconsize = (struct vt_consize *) arg;
868 ushort ll,cc,vlin,clin,vcol,ccol;
871 if (verify_area(VERIFY_READ, (void *)vtconsize,
872 sizeof(struct vt_consize)))
874 __get_user(ll, &vtconsize->v_rows);
875 __get_user(cc, &vtconsize->v_cols);
876 __get_user(vlin, &vtconsize->v_vlin);
877 __get_user(clin, &vtconsize->v_clin);
878 __get_user(vcol, &vtconsize->v_vcol);
879 __get_user(ccol, &vtconsize->v_ccol);
880 vlin = vlin ? vlin : vc->vc_scan_lines;
884 return -EINVAL; /* Parameters don't add up */
899 for (i = 0; i < MAX_NR_CONSOLES; i++) {
902 acquire_console_sem();
904 vc_cons[i].d->vc_scan_lines = vlin;
906 vc_cons[i].d->vc_font.height = clin;
907 vc_resize(i, cc, ll);
908 release_console_sem();
916 op.op = KD_FONT_OP_SET;
917 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
921 op.data = (char *) arg;
922 return con_font_op(fg_console, &op);
926 op.op = KD_FONT_OP_GET;
927 op.flags = KD_FONT_FLAG_OLD;
931 op.data = (char *) arg;
932 return con_font_op(fg_console, &op);
938 return con_set_cmap((char *)arg);
941 return con_get_cmap((char *)arg);
945 return do_fontx_ioctl(cmd, (struct consolefontdesc *)arg, perm, &op);
952 #ifdef BROKEN_GRAPHICS_PROGRAMS
953 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
954 font is not saved. */
958 op.op = KD_FONT_OP_SET_DEFAULT;
960 i = con_font_op(fg_console, &op);
962 con_set_default_unimap(fg_console);
969 if (copy_from_user(&op, (void *) arg, sizeof(op)))
971 if (!perm && op.op != KD_FONT_OP_GET)
973 i = con_font_op(console, &op);
975 if (copy_to_user((void *) arg, &op, sizeof(op)))
983 return con_set_trans_old((unsigned char *)arg);
986 return con_get_trans_old((unsigned char *)arg);
991 return con_set_trans_new((unsigned short *)arg);
994 return con_get_trans_new((unsigned short *)arg);
997 { struct unimapinit ui;
1000 i = copy_from_user(&ui, (void *)arg, sizeof(struct unimapinit));
1001 if (i) return -EFAULT;
1002 con_clear_unimap(console, &ui);
1008 return do_unimap_ioctl(cmd, (struct unimapdesc *)arg, perm, console);
1011 if (!capable(CAP_SYS_TTY_CONFIG))
1015 case VT_UNLOCKSWITCH:
1016 if (!capable(CAP_SYS_TTY_CONFIG))
1021 return -ENOIOCTLCMD;
1026 * Sometimes we want to wait until a particular VT has been activated. We
1027 * do it in a very simple manner. Everybody waits on a single queue and
1028 * get woken up at once. Those that are satisfied go on with their business,
1029 * while those not ready go back to sleep. Seems overkill to add a wait
1030 * to each vt just for this - usually this does nothing!
1032 static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue);
1035 * Sleeps until a vt is activated, or the task is interrupted. Returns
1036 * 0 if activation, -EINTR if interrupted.
1038 int vt_waitactive(int vt)
1041 DECLARE_WAITQUEUE(wait, current);
1043 add_wait_queue(&vt_activate_queue, &wait);
1045 set_current_state(TASK_INTERRUPTIBLE);
1047 if (vt == fg_console)
1050 if (signal_pending(current))
1054 remove_wait_queue(&vt_activate_queue, &wait);
1055 current->state = TASK_RUNNING;
1059 #define vt_wake_waitactive() wake_up(&vt_activate_queue)
1061 void reset_vc(unsigned int new_console)
1063 vt_cons[new_console]->vc_mode = KD_TEXT;
1064 kbd_table[new_console].kbdmode = VC_XLATE;
1065 vt_cons[new_console]->vt_mode.mode = VT_AUTO;
1066 vt_cons[new_console]->vt_mode.waitv = 0;
1067 vt_cons[new_console]->vt_mode.relsig = 0;
1068 vt_cons[new_console]->vt_mode.acqsig = 0;
1069 vt_cons[new_console]->vt_mode.frsig = 0;
1070 vt_cons[new_console]->vt_pid = -1;
1071 vt_cons[new_console]->vt_newvt = -1;
1072 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
1073 reset_palette(new_console) ;
1077 * Performs the back end of a vt switch
1079 void complete_change_console(unsigned int new_console)
1081 unsigned char old_vc_mode;
1083 last_console = fg_console;
1086 * If we're switching, we could be going from KD_GRAPHICS to
1087 * KD_TEXT mode or vice versa, which means we need to blank or
1088 * unblank the screen later.
1090 old_vc_mode = vt_cons[fg_console]->vc_mode;
1091 switch_screen(new_console);
1094 * This can't appear below a successful kill_proc(). If it did,
1095 * then the *blank_screen operation could occur while X, having
1096 * received acqsig, is waking up on another processor. This
1097 * condition can lead to overlapping accesses to the VGA range
1098 * and the framebuffer (causing system lockups).
1100 * To account for this we duplicate this code below only if the
1101 * controlling process is gone and we've called reset_vc.
1103 if (old_vc_mode != vt_cons[new_console]->vc_mode)
1105 if (vt_cons[new_console]->vc_mode == KD_TEXT)
1106 do_unblank_screen(1);
1112 * If this new console is under process control, send it a signal
1113 * telling it that it has acquired. Also check if it has died and
1114 * clean up (similar to logic employed in change_console())
1116 if (vt_cons[new_console]->vt_mode.mode == VT_PROCESS)
1119 * Send the signal as privileged - kill_proc() will
1120 * tell us if the process has gone or something else
1123 if (kill_proc(vt_cons[new_console]->vt_pid,
1124 vt_cons[new_console]->vt_mode.acqsig,
1128 * The controlling process has died, so we revert back to
1129 * normal operation. In this case, we'll also change back
1130 * to KD_TEXT mode. I'm not sure if this is strictly correct
1131 * but it saves the agony when the X server dies and the screen
1132 * remains blanked due to KD_GRAPHICS! It would be nice to do
1133 * this outside of VT_PROCESS but there is no single process
1134 * to account for and tracking tty count may be undesirable.
1136 reset_vc(new_console);
1138 if (old_vc_mode != vt_cons[new_console]->vc_mode)
1140 if (vt_cons[new_console]->vc_mode == KD_TEXT)
1141 do_unblank_screen(1);
1149 * Wake anyone waiting for their VT to activate
1151 vt_wake_waitactive();
1156 * Performs the front-end of a vt switch
1158 void change_console(unsigned int new_console)
1160 if ((new_console == fg_console) || (vt_dont_switch))
1162 if (!vc_cons_allocated(new_console))
1166 * If this vt is in process mode, then we need to handshake with
1167 * that process before switching. Essentially, we store where that
1168 * vt wants to switch to and wait for it to tell us when it's done
1169 * (via VT_RELDISP ioctl).
1171 * We also check to see if the controlling process still exists.
1172 * If it doesn't, we reset this vt to auto mode and continue.
1173 * This is a cheap way to track process control. The worst thing
1174 * that can happen is: we send a signal to a process, it dies, and
1175 * the switch gets "lost" waiting for a response; hopefully, the
1176 * user will try again, we'll detect the process is gone (unless
1177 * the user waits just the right amount of time :-) and revert the
1178 * vt to auto control.
1180 if (vt_cons[fg_console]->vt_mode.mode == VT_PROCESS)
1183 * Send the signal as privileged - kill_proc() will
1184 * tell us if the process has gone or something else
1187 if (kill_proc(vt_cons[fg_console]->vt_pid,
1188 vt_cons[fg_console]->vt_mode.relsig,
1192 * It worked. Mark the vt to switch to and
1193 * return. The process needs to send us a
1194 * VT_RELDISP ioctl to complete the switch.
1196 vt_cons[fg_console]->vt_newvt = new_console;
1201 * The controlling process has died, so we revert back to
1202 * normal operation. In this case, we'll also change back
1203 * to KD_TEXT mode. I'm not sure if this is strictly correct
1204 * but it saves the agony when the X server dies and the screen
1205 * remains blanked due to KD_GRAPHICS! It would be nice to do
1206 * this outside of VT_PROCESS but there is no single process
1207 * to account for and tracking tty count may be undesirable.
1209 reset_vc(fg_console);
1212 * Fall through to normal (VT_AUTO) handling of the switch...
1217 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
1219 if (vt_cons[fg_console]->vc_mode == KD_GRAPHICS)
1222 complete_change_console(new_console);