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/types.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/tty.h>
17 #include <linux/timer.h>
18 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/slab.h>
23 #include <linux/major.h>
25 #include <linux/console.h>
26 #include <linux/signal.h>
27 #include <linux/timex.h>
30 #include <asm/uaccess.h>
32 #include <linux/kbd_kern.h>
33 #include <linux/vt_kern.h>
34 #include <linux/kbd_diacr.h>
35 #include <linux/selection.h>
38 extern struct tty_driver
*console_driver
;
40 #define VT_IS_IN_USE(i) (console_driver->ttys[i] && console_driver->ttys[i]->count)
41 #define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || vc_cons[i].d == sel_cons)
44 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
45 * experimentation and study of X386 SYSV handling.
47 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
48 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
49 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
50 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
51 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
52 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
53 * to the current console is done by the main ioctl code.
57 #include <linux/syscalls.h>
60 static void complete_change_console(struct vc_data
*vc
);
63 * these are the valid i/o ports we're allowed to change. they map all the
68 #define GPNUM (GPLAST - GPFIRST + 1)
70 #define i (tmp.kb_index)
71 #define s (tmp.kb_table)
72 #define v (tmp.kb_value)
74 do_kdsk_ioctl(int cmd
, struct kbentry __user
*user_kbe
, int perm
, struct kbd_struct
*kbd
)
77 ushort
*key_map
, val
, ov
;
79 if (copy_from_user(&tmp
, user_kbe
, sizeof(struct kbentry
)))
82 if (!capable(CAP_SYS_TTY_CONFIG
))
87 key_map
= key_maps
[s
];
90 if (kbd
->kbdmode
!= VC_UNICODE
&& KTYP(val
) >= NR_TYPES
)
93 val
= (i
? K_HOLE
: K_NOSUCHMAP
);
94 return put_user(val
, &user_kbe
->kb_value
);
98 if (!i
&& v
== K_NOSUCHMAP
) {
100 key_map
= key_maps
[s
];
103 if (key_map
[0] == U(K_ALLOCATED
)) {
111 if (KTYP(v
) < NR_TYPES
) {
112 if (KVAL(v
) > max_vals
[KTYP(v
)])
115 if (kbd
->kbdmode
!= VC_UNICODE
)
118 /* ++Geert: non-PC keyboards may generate keycode zero */
119 #if !defined(__mc68000__) && !defined(__powerpc__)
120 /* assignment to entry 0 only tests validity of args */
125 if (!(key_map
= key_maps
[s
])) {
128 if (keymap_count
>= MAX_NR_OF_USER_KEYMAPS
&&
129 !capable(CAP_SYS_RESOURCE
))
132 key_map
= kmalloc(sizeof(plain_map
),
136 key_maps
[s
] = key_map
;
137 key_map
[0] = U(K_ALLOCATED
);
138 for (j
= 1; j
< NR_KEYS
; j
++)
139 key_map
[j
] = U(K_HOLE
);
144 break; /* nothing to do */
148 if (((ov
== K_SAK
) || (v
== K_SAK
)) && !capable(CAP_SYS_ADMIN
))
151 if (!s
&& (KTYP(ov
) == KT_SHIFT
|| KTYP(v
) == KT_SHIFT
))
152 compute_shiftstate();
162 do_kbkeycode_ioctl(int cmd
, struct kbkeycode __user
*user_kbkc
, int perm
)
164 struct kbkeycode tmp
;
167 if (copy_from_user(&tmp
, user_kbkc
, sizeof(struct kbkeycode
)))
171 kc
= getkeycode(tmp
.scancode
);
173 kc
= put_user(kc
, &user_kbkc
->keycode
);
178 kc
= setkeycode(tmp
.scancode
, tmp
.keycode
);
185 do_kdgkb_ioctl(int cmd
, struct kbsentry __user
*user_kdgkb
, int perm
)
187 struct kbsentry
*kbs
;
193 char *first_free
, *fj
, *fnw
;
197 if (!capable(CAP_SYS_TTY_CONFIG
))
200 kbs
= kmalloc(sizeof(*kbs
), GFP_KERNEL
);
206 /* we mostly copy too much here (512bytes), but who cares ;) */
207 if (copy_from_user(kbs
, user_kdgkb
, sizeof(struct kbsentry
))) {
211 kbs
->kb_string
[sizeof(kbs
->kb_string
)-1] = '\0';
216 sz
= sizeof(kbs
->kb_string
) - 1; /* sz should have been
218 up
= user_kdgkb
->kb_string
;
221 for ( ; *p
&& sz
; p
++, sz
--)
222 if (put_user(*p
, up
++)) {
226 if (put_user('\0', up
)) {
231 return ((p
&& *p
) ? -EOVERFLOW
: 0);
239 first_free
= funcbufptr
+ (funcbufsize
- funcbufleft
);
240 for (j
= i
+1; j
< MAX_NR_FUNC
&& !func_table
[j
]; j
++)
247 delta
= (q
? -strlen(q
) : 1) + strlen(kbs
->kb_string
);
248 if (delta
<= funcbufleft
) { /* it fits in current buf */
249 if (j
< MAX_NR_FUNC
) {
250 memmove(fj
+ delta
, fj
, first_free
- fj
);
251 for (k
= j
; k
< MAX_NR_FUNC
; k
++)
253 func_table
[k
] += delta
;
257 funcbufleft
-= delta
;
258 } else { /* allocate a larger buffer */
260 while (sz
< funcbufsize
- funcbufleft
+ delta
)
262 fnw
= kmalloc(sz
, GFP_KERNEL
);
271 memmove(fnw
, funcbufptr
, fj
- funcbufptr
);
272 for (k
= 0; k
< j
; k
++)
274 func_table
[k
] = fnw
+ (func_table
[k
] - funcbufptr
);
276 if (first_free
> fj
) {
277 memmove(fnw
+ (fj
- funcbufptr
) + delta
, fj
, first_free
- fj
);
278 for (k
= j
; k
< MAX_NR_FUNC
; k
++)
280 func_table
[k
] = fnw
+ (func_table
[k
] - funcbufptr
) + delta
;
282 if (funcbufptr
!= func_buf
)
285 funcbufleft
= funcbufleft
- delta
+ sz
- funcbufsize
;
288 strcpy(func_table
[i
], kbs
->kb_string
);
298 do_fontx_ioctl(int cmd
, struct consolefontdesc __user
*user_cfd
, int perm
, struct console_font_op
*op
)
300 struct consolefontdesc cfdarg
;
303 if (copy_from_user(&cfdarg
, user_cfd
, sizeof(struct consolefontdesc
)))
310 op
->op
= KD_FONT_OP_SET
;
311 op
->flags
= KD_FONT_FLAG_OLD
;
313 op
->height
= cfdarg
.charheight
;
314 op
->charcount
= cfdarg
.charcount
;
315 op
->data
= cfdarg
.chardata
;
316 return con_font_op(vc_cons
[fg_console
].d
, op
);
318 op
->op
= KD_FONT_OP_GET
;
319 op
->flags
= KD_FONT_FLAG_OLD
;
321 op
->height
= cfdarg
.charheight
;
322 op
->charcount
= cfdarg
.charcount
;
323 op
->data
= cfdarg
.chardata
;
324 i
= con_font_op(vc_cons
[fg_console
].d
, op
);
327 cfdarg
.charheight
= op
->height
;
328 cfdarg
.charcount
= op
->charcount
;
329 if (copy_to_user(user_cfd
, &cfdarg
, sizeof(struct consolefontdesc
)))
338 do_unimap_ioctl(int cmd
, struct unimapdesc __user
*user_ud
, int perm
, struct vc_data
*vc
)
340 struct unimapdesc tmp
;
342 if (copy_from_user(&tmp
, user_ud
, sizeof tmp
))
345 if (!access_ok(VERIFY_WRITE
, tmp
.entries
,
346 tmp
.entry_ct
*sizeof(struct unipair
)))
352 return con_set_unimap(vc
, tmp
.entry_ct
, tmp
.entries
);
354 if (!perm
&& fg_console
!= vc
->vc_num
)
356 return con_get_unimap(vc
, tmp
.entry_ct
, &(user_ud
->entry_ct
), tmp
.entries
);
362 * We handle the console-specific ioctl's here. We allow the
363 * capability to modify any console, not just the fg_console.
365 int vt_ioctl(struct tty_struct
*tty
, struct file
* file
,
366 unsigned int cmd
, unsigned long arg
)
368 struct vc_data
*vc
= (struct vc_data
*)tty
->driver_data
;
369 struct console_font_op op
; /* used in multiple places here */
370 struct kbd_struct
* kbd
;
371 unsigned int console
;
373 void __user
*up
= (void __user
*)arg
;
376 console
= vc
->vc_num
;
378 if (!vc_cons_allocated(console
)) /* impossible? */
382 * To have permissions to do most of the vt ioctls, we either have
383 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
386 if (current
->signal
->tty
== tty
|| capable(CAP_SYS_TTY_CONFIG
))
389 kbd
= kbd_table
+ console
;
395 arg
= CLOCK_TICK_RATE
/ arg
;
403 unsigned int ticks
, count
;
406 * Generate the tone for the appropriate number of ticks.
407 * If the time is zero, turn off sound ourselves.
409 ticks
= HZ
* ((arg
>> 16) & 0xffff) / 1000;
410 count
= ticks
? (arg
& 0xffff) : 0;
412 count
= CLOCK_TICK_RATE
/ count
;
413 kd_mksound(count
, ticks
);
425 * These cannot be implemented on any machine that implements
426 * ioperm() in user level (such as Alpha PCs) or not at all.
428 * XXX: you should never use these, just call ioperm directly..
434 * KDADDIO and KDDELIO may be able to add ports beyond what
435 * we reject here, but to be safe...
437 if (arg
< GPFIRST
|| arg
> GPLAST
)
439 return sys_ioperm(arg
, 1, (cmd
== KDADDIO
)) ? -ENXIO
: 0;
443 return sys_ioperm(GPFIRST
, GPNUM
,
444 (cmd
== KDENABIO
)) ? -ENXIO
: 0;
447 /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
451 struct kbd_repeat kbrep
;
454 if (!capable(CAP_SYS_TTY_CONFIG
))
457 if (copy_from_user(&kbrep
, up
, sizeof(struct kbd_repeat
)))
459 err
= kbd_rate(&kbrep
);
462 if (copy_to_user(up
, &kbrep
, sizeof(struct kbd_repeat
)))
469 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
470 * doesn't do a whole lot. i'm not sure if it should do any
471 * restoration of modes or what...
473 * XXX It should at least call into the driver, fbdev's definitely
474 * need to restore their engine state. --BenH
489 if (vc
->vc_mode
== (unsigned char) arg
)
491 vc
->vc_mode
= (unsigned char) arg
;
492 if (console
!= fg_console
)
495 * explicitly blank/unblank the screen if switching modes
497 acquire_console_sem();
499 do_unblank_screen(1);
502 release_console_sem();
512 * these work like a combination of mmap and KDENABIO.
513 * this could be easily finished.
522 kbd
->kbdmode
= VC_RAW
;
525 kbd
->kbdmode
= VC_MEDIUMRAW
;
528 kbd
->kbdmode
= VC_XLATE
;
529 compute_shiftstate();
532 kbd
->kbdmode
= VC_UNICODE
;
533 compute_shiftstate();
538 tty_ldisc_flush(tty
);
542 ucval
= ((kbd
->kbdmode
== VC_RAW
) ? K_RAW
:
543 (kbd
->kbdmode
== VC_MEDIUMRAW
) ? K_MEDIUMRAW
:
544 (kbd
->kbdmode
== VC_UNICODE
) ? K_UNICODE
:
548 /* this could be folded into KDSKBMODE, but for compatibility
549 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
553 clr_vc_kbd_mode(kbd
, VC_META
);
556 set_vc_kbd_mode(kbd
, VC_META
);
564 ucval
= (vc_kbd_mode(kbd
, VC_META
) ? K_ESCPREFIX
: K_METABIT
);
566 return put_user(ucval
, (int __user
*)arg
);
570 if(!capable(CAP_SYS_TTY_CONFIG
))
572 return do_kbkeycode_ioctl(cmd
, up
, perm
);
576 return do_kdsk_ioctl(cmd
, up
, perm
, kbd
);
580 return do_kdgkb_ioctl(cmd
, up
, perm
);
584 struct kbdiacrs __user
*a
= up
;
586 if (put_user(accent_table_size
, &a
->kb_cnt
))
588 if (copy_to_user(a
->kbdiacr
, accent_table
, accent_table_size
*sizeof(struct kbdiacr
)))
595 struct kbdiacrs __user
*a
= up
;
600 if (get_user(ct
,&a
->kb_cnt
))
604 accent_table_size
= ct
;
605 if (copy_from_user(accent_table
, a
->kbdiacr
, ct
*sizeof(struct kbdiacr
)))
610 /* the ioctls below read/set the flags usually shown in the leds */
611 /* don't use them - they will go away without warning */
613 ucval
= kbd
->ledflagstate
| (kbd
->default_ledflagstate
<< 4);
621 kbd
->ledflagstate
= (arg
& 7);
622 kbd
->default_ledflagstate
= ((arg
>> 4) & 7);
626 /* the ioctls below only set the lights, not the functions */
627 /* for those, see KDGKBLED and KDSKBLED above */
629 ucval
= getledstate();
631 return put_user(ucval
, (char __user
*)arg
);
636 setledstate(kbd
, arg
);
640 * A process can indicate its willingness to accept signals
641 * generated by pressing an appropriate key combination.
642 * Thus, one can have a daemon that e.g. spawns a new console
643 * upon a keypress and then changes to it.
644 * See also the kbrequest field of inittab(5).
648 if (!perm
|| !capable(CAP_KILL
))
650 if (!valid_signal(arg
) || arg
< 1 || arg
== SIGKILL
)
653 spin_lock_irq(&vt_spawn_con
.lock
);
654 put_pid(vt_spawn_con
.pid
);
655 vt_spawn_con
.pid
= get_pid(task_pid(current
));
656 vt_spawn_con
.sig
= arg
;
657 spin_unlock_irq(&vt_spawn_con
.lock
);
667 if (copy_from_user(&tmp
, up
, sizeof(struct vt_mode
)))
669 if (tmp
.mode
!= VT_AUTO
&& tmp
.mode
!= VT_PROCESS
)
671 acquire_console_sem();
673 /* the frsig is ignored, so we set it to 0 */
674 vc
->vt_mode
.frsig
= 0;
676 vc
->vt_pid
= get_pid(task_pid(current
));
677 /* no switch is required -- saw@shade.msu.ru */
679 release_console_sem();
688 acquire_console_sem();
689 memcpy(&tmp
, &vc
->vt_mode
, sizeof(struct vt_mode
));
690 release_console_sem();
692 rc
= copy_to_user(up
, &tmp
, sizeof(struct vt_mode
));
693 return rc
? -EFAULT
: 0;
697 * Returns global vt state. Note that VT 0 is always open, since
698 * it's an alias for the current VT, and people can't use it here.
699 * We cannot return state for more than 16 VTs, since v_state is short.
703 struct vt_stat __user
*vtstat
= up
;
704 unsigned short state
, mask
;
706 if (put_user(fg_console
+ 1, &vtstat
->v_active
))
708 state
= 1; /* /dev/tty0 is always open */
709 for (i
= 0, mask
= 2; i
< MAX_NR_CONSOLES
&& mask
; ++i
, mask
<<= 1)
712 return put_user(state
, &vtstat
->v_state
);
716 * Returns the first available (non-opened) console.
719 for (i
= 0; i
< MAX_NR_CONSOLES
; ++i
)
720 if (! VT_IS_IN_USE(i
))
722 ucval
= i
< MAX_NR_CONSOLES
? (i
+1) : -1;
726 * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
727 * with num >= 1 (switches to vt 0, our console, are not allowed, just
728 * to preserve sanity).
733 if (arg
== 0 || arg
> MAX_NR_CONSOLES
)
736 acquire_console_sem();
737 i
= vc_allocate(arg
);
738 release_console_sem();
745 * wait until the specified VT has been activated
750 if (arg
== 0 || arg
> MAX_NR_CONSOLES
)
752 return vt_waitactive(arg
-1);
755 * If a vt is under process control, the kernel will not switch to it
756 * immediately, but postpone the operation until the process calls this
757 * ioctl, allowing the switch to complete.
759 * According to the X sources this is the behavior:
760 * 0: pending switch-from not OK
761 * 1: pending switch-from OK
762 * 2: completed switch-to OK
767 if (vc
->vt_mode
.mode
!= VT_PROCESS
)
771 * Switching-from response
773 acquire_console_sem();
774 if (vc
->vt_newvt
>= 0) {
777 * Switch disallowed, so forget we were trying
784 * The current vt has been released, so
785 * complete the switch.
788 newvt
= vc
->vt_newvt
;
790 i
= vc_allocate(newvt
);
792 release_console_sem();
796 * When we actually do the console switch,
797 * make sure we are atomic with respect to
798 * other console switches..
800 complete_change_console(vc_cons
[newvt
].d
);
805 * Switched-to response
810 * If it's just an ACK, ignore it
812 if (arg
!= VT_ACKACQ
) {
813 release_console_sem();
817 release_console_sem();
822 * Disallocate memory associated to VT (but leave VT1)
825 if (arg
> MAX_NR_CONSOLES
)
828 /* deallocate all unused consoles, but leave 0 */
829 acquire_console_sem();
830 for (i
=1; i
<MAX_NR_CONSOLES
; i
++)
833 release_console_sem();
835 /* deallocate a single console, if possible */
839 if (arg
) { /* leave 0 */
840 acquire_console_sem();
842 release_console_sem();
849 struct vt_sizes __user
*vtsizes
= up
;
855 if (get_user(ll
, &vtsizes
->v_rows
) ||
856 get_user(cc
, &vtsizes
->v_cols
))
859 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
863 vc
->vc_resize_user
= 1;
864 vc_lock_resize(vc_cons
[i
].d
, cc
, ll
);
873 struct vt_consize __user
*vtconsize
= up
;
874 ushort ll
,cc
,vlin
,clin
,vcol
,ccol
;
877 if (!access_ok(VERIFY_READ
, vtconsize
,
878 sizeof(struct vt_consize
)))
880 __get_user(ll
, &vtconsize
->v_rows
);
881 __get_user(cc
, &vtconsize
->v_cols
);
882 __get_user(vlin
, &vtconsize
->v_vlin
);
883 __get_user(clin
, &vtconsize
->v_clin
);
884 __get_user(vcol
, &vtconsize
->v_vcol
);
885 __get_user(ccol
, &vtconsize
->v_ccol
);
886 vlin
= vlin
? vlin
: vc
->vc_scan_lines
;
890 return -EINVAL
; /* Parameters don't add up */
905 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
908 acquire_console_sem();
910 vc_cons
[i
].d
->vc_scan_lines
= vlin
;
912 vc_cons
[i
].d
->vc_font
.height
= clin
;
913 vc_cons
[i
].d
->vc_resize_user
= 1;
914 vc_resize(vc_cons
[i
].d
, cc
, ll
);
915 release_console_sem();
923 op
.op
= KD_FONT_OP_SET
;
924 op
.flags
= KD_FONT_FLAG_OLD
| KD_FONT_FLAG_DONT_RECALC
; /* Compatibility */
929 return con_font_op(vc_cons
[fg_console
].d
, &op
);
933 op
.op
= KD_FONT_OP_GET
;
934 op
.flags
= KD_FONT_FLAG_OLD
;
939 return con_font_op(vc_cons
[fg_console
].d
, &op
);
945 return con_set_cmap(up
);
948 return con_get_cmap(up
);
952 return do_fontx_ioctl(cmd
, up
, perm
, &op
);
959 #ifdef BROKEN_GRAPHICS_PROGRAMS
960 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
961 font is not saved. */
965 op
.op
= KD_FONT_OP_SET_DEFAULT
;
967 i
= con_font_op(vc_cons
[fg_console
].d
, &op
);
970 con_set_default_unimap(vc_cons
[fg_console
].d
);
977 if (copy_from_user(&op
, up
, sizeof(op
)))
979 if (!perm
&& op
.op
!= KD_FONT_OP_GET
)
981 i
= con_font_op(vc
, &op
);
983 if (copy_to_user(up
, &op
, sizeof(op
)))
991 return con_set_trans_old(up
);
994 return con_get_trans_old(up
);
999 return con_set_trans_new(up
);
1001 case GIO_UNISCRNMAP
:
1002 return con_get_trans_new(up
);
1005 { struct unimapinit ui
;
1008 i
= copy_from_user(&ui
, up
, sizeof(struct unimapinit
));
1009 if (i
) return -EFAULT
;
1010 con_clear_unimap(vc
, &ui
);
1016 return do_unimap_ioctl(cmd
, up
, perm
, vc
);
1019 if (!capable(CAP_SYS_TTY_CONFIG
))
1023 case VT_UNLOCKSWITCH
:
1024 if (!capable(CAP_SYS_TTY_CONFIG
))
1028 case VT_GETHIFONTMASK
:
1029 return put_user(vc
->vc_hi_font_mask
, (unsigned short __user
*)arg
);
1031 return -ENOIOCTLCMD
;
1036 * Sometimes we want to wait until a particular VT has been activated. We
1037 * do it in a very simple manner. Everybody waits on a single queue and
1038 * get woken up at once. Those that are satisfied go on with their business,
1039 * while those not ready go back to sleep. Seems overkill to add a wait
1040 * to each vt just for this - usually this does nothing!
1042 static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue
);
1045 * Sleeps until a vt is activated, or the task is interrupted. Returns
1046 * 0 if activation, -EINTR if interrupted by a signal handler.
1048 int vt_waitactive(int vt
)
1051 DECLARE_WAITQUEUE(wait
, current
);
1053 add_wait_queue(&vt_activate_queue
, &wait
);
1058 * Synchronize with redraw_screen(). By acquiring the console
1059 * semaphore we make sure that the console switch is completed
1060 * before we return. If we didn't wait for the semaphore, we
1061 * could return at a point where fg_console has already been
1062 * updated, but the console switch hasn't been completed.
1064 acquire_console_sem();
1065 set_current_state(TASK_INTERRUPTIBLE
);
1066 if (vt
== fg_console
) {
1067 release_console_sem();
1070 release_console_sem();
1071 retval
= -ERESTARTNOHAND
;
1072 if (signal_pending(current
))
1076 remove_wait_queue(&vt_activate_queue
, &wait
);
1077 __set_current_state(TASK_RUNNING
);
1081 #define vt_wake_waitactive() wake_up(&vt_activate_queue)
1083 void reset_vc(struct vc_data
*vc
)
1085 vc
->vc_mode
= KD_TEXT
;
1086 kbd_table
[vc
->vc_num
].kbdmode
= VC_XLATE
;
1087 vc
->vt_mode
.mode
= VT_AUTO
;
1088 vc
->vt_mode
.waitv
= 0;
1089 vc
->vt_mode
.relsig
= 0;
1090 vc
->vt_mode
.acqsig
= 0;
1091 vc
->vt_mode
.frsig
= 0;
1092 put_pid(vc
->vt_pid
);
1095 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
1099 void vc_SAK(struct work_struct
*work
)
1102 container_of(work
, struct vc
, SAK_work
);
1104 struct tty_struct
*tty
;
1106 acquire_console_sem();
1111 * SAK should also work in all raw modes and reset
1118 release_console_sem();
1122 * Performs the back end of a vt switch
1124 static void complete_change_console(struct vc_data
*vc
)
1126 unsigned char old_vc_mode
;
1128 last_console
= fg_console
;
1131 * If we're switching, we could be going from KD_GRAPHICS to
1132 * KD_TEXT mode or vice versa, which means we need to blank or
1133 * unblank the screen later.
1135 old_vc_mode
= vc_cons
[fg_console
].d
->vc_mode
;
1139 * This can't appear below a successful kill_pid(). If it did,
1140 * then the *blank_screen operation could occur while X, having
1141 * received acqsig, is waking up on another processor. This
1142 * condition can lead to overlapping accesses to the VGA range
1143 * and the framebuffer (causing system lockups).
1145 * To account for this we duplicate this code below only if the
1146 * controlling process is gone and we've called reset_vc.
1148 if (old_vc_mode
!= vc
->vc_mode
) {
1149 if (vc
->vc_mode
== KD_TEXT
)
1150 do_unblank_screen(1);
1156 * If this new console is under process control, send it a signal
1157 * telling it that it has acquired. Also check if it has died and
1158 * clean up (similar to logic employed in change_console())
1160 if (vc
->vt_mode
.mode
== VT_PROCESS
) {
1162 * Send the signal as privileged - kill_pid() will
1163 * tell us if the process has gone or something else
1166 if (kill_pid(vc
->vt_pid
, vc
->vt_mode
.acqsig
, 1) != 0) {
1168 * The controlling process has died, so we revert back to
1169 * normal operation. In this case, we'll also change back
1170 * to KD_TEXT mode. I'm not sure if this is strictly correct
1171 * but it saves the agony when the X server dies and the screen
1172 * remains blanked due to KD_GRAPHICS! It would be nice to do
1173 * this outside of VT_PROCESS but there is no single process
1174 * to account for and tracking tty count may be undesirable.
1178 if (old_vc_mode
!= vc
->vc_mode
) {
1179 if (vc
->vc_mode
== KD_TEXT
)
1180 do_unblank_screen(1);
1188 * Wake anyone waiting for their VT to activate
1190 vt_wake_waitactive();
1195 * Performs the front-end of a vt switch
1197 void change_console(struct vc_data
*new_vc
)
1201 if (!new_vc
|| new_vc
->vc_num
== fg_console
|| vt_dont_switch
)
1205 * If this vt is in process mode, then we need to handshake with
1206 * that process before switching. Essentially, we store where that
1207 * vt wants to switch to and wait for it to tell us when it's done
1208 * (via VT_RELDISP ioctl).
1210 * We also check to see if the controlling process still exists.
1211 * If it doesn't, we reset this vt to auto mode and continue.
1212 * This is a cheap way to track process control. The worst thing
1213 * that can happen is: we send a signal to a process, it dies, and
1214 * the switch gets "lost" waiting for a response; hopefully, the
1215 * user will try again, we'll detect the process is gone (unless
1216 * the user waits just the right amount of time :-) and revert the
1217 * vt to auto control.
1219 vc
= vc_cons
[fg_console
].d
;
1220 if (vc
->vt_mode
.mode
== VT_PROCESS
) {
1222 * Send the signal as privileged - kill_pid() will
1223 * tell us if the process has gone or something else
1226 * We need to set vt_newvt *before* sending the signal or we
1229 vc
->vt_newvt
= new_vc
->vc_num
;
1230 if (kill_pid(vc
->vt_pid
, vc
->vt_mode
.relsig
, 1) == 0) {
1232 * It worked. Mark the vt to switch to and
1233 * return. The process needs to send us a
1234 * VT_RELDISP ioctl to complete the switch.
1240 * The controlling process has died, so we revert back to
1241 * normal operation. In this case, we'll also change back
1242 * to KD_TEXT mode. I'm not sure if this is strictly correct
1243 * but it saves the agony when the X server dies and the screen
1244 * remains blanked due to KD_GRAPHICS! It would be nice to do
1245 * this outside of VT_PROCESS but there is no single process
1246 * to account for and tracking tty count may be undesirable.
1251 * Fall through to normal (VT_AUTO) handling of the switch...
1256 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
1258 if (vc
->vc_mode
== KD_GRAPHICS
)
1261 complete_change_console(new_vc
);