]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/char/vt_ioctl.c
pcmcia/cm4000: fix lock imbalance
[net-next-2.6.git] / drivers / char / vt_ioctl.c
CommitLineData
1da177e4
LT
1/*
2 * linux/drivers/char/vt_ioctl.c
3 *
4 * Copyright (C) 1992 obz under the linux copyright
5 *
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
11 */
12
1da177e4
LT
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>
19#include <linux/kd.h>
20#include <linux/vt.h>
21#include <linux/string.h>
22#include <linux/slab.h>
23#include <linux/major.h>
24#include <linux/fs.h>
25#include <linux/console.h>
04c71976 26#include <linux/consolemap.h>
7ed20e1a 27#include <linux/signal.h>
bcc8ca09 28#include <linux/timex.h>
1da177e4
LT
29
30#include <asm/io.h>
31#include <asm/uaccess.h>
32
33#include <linux/kbd_kern.h>
34#include <linux/vt_kern.h>
35#include <linux/kbd_diacr.h>
36#include <linux/selection.h>
37
b257bc05 38char vt_dont_switch;
1da177e4
LT
39extern struct tty_driver *console_driver;
40
41#define VT_IS_IN_USE(i) (console_driver->ttys[i] && console_driver->ttys[i]->count)
42#define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || vc_cons[i].d == sel_cons)
43
44/*
45 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
46 * experimentation and study of X386 SYSV handling.
47 *
48 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
49 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
50 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
51 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
52 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
53 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
54 * to the current console is done by the main ioctl code.
55 */
56
57#ifdef CONFIG_X86
58#include <linux/syscalls.h>
59#endif
60
61static void complete_change_console(struct vc_data *vc);
62
63/*
64 * these are the valid i/o ports we're allowed to change. they map all the
65 * video ports
66 */
67#define GPFIRST 0x3b4
68#define GPLAST 0x3df
69#define GPNUM (GPLAST - GPFIRST + 1)
70
71#define i (tmp.kb_index)
72#define s (tmp.kb_table)
73#define v (tmp.kb_value)
74static inline int
75do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_struct *kbd)
76{
77 struct kbentry tmp;
78 ushort *key_map, val, ov;
79
80 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
81 return -EFAULT;
82
e3f17f0f
MT
83 if (!capable(CAP_SYS_TTY_CONFIG))
84 perm = 0;
85
1da177e4
LT
86 switch (cmd) {
87 case KDGKBENT:
88 key_map = key_maps[s];
89 if (key_map) {
90 val = U(key_map[i]);
91 if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES)
92 val = K_HOLE;
93 } else
94 val = (i ? K_HOLE : K_NOSUCHMAP);
95 return put_user(val, &user_kbe->kb_value);
96 case KDSKBENT:
97 if (!perm)
98 return -EPERM;
99 if (!i && v == K_NOSUCHMAP) {
ca9bda00 100 /* deallocate map */
1da177e4
LT
101 key_map = key_maps[s];
102 if (s && key_map) {
103 key_maps[s] = NULL;
104 if (key_map[0] == U(K_ALLOCATED)) {
105 kfree(key_map);
106 keymap_count--;
107 }
108 }
109 break;
110 }
111
112 if (KTYP(v) < NR_TYPES) {
113 if (KVAL(v) > max_vals[KTYP(v)])
114 return -EINVAL;
115 } else
116 if (kbd->kbdmode != VC_UNICODE)
117 return -EINVAL;
118
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 */
122 if (!i)
123 break;
124#endif
125
126 if (!(key_map = key_maps[s])) {
127 int j;
128
129 if (keymap_count >= MAX_NR_OF_USER_KEYMAPS &&
130 !capable(CAP_SYS_RESOURCE))
131 return -EPERM;
132
5cbded58 133 key_map = kmalloc(sizeof(plain_map),
1da177e4
LT
134 GFP_KERNEL);
135 if (!key_map)
136 return -ENOMEM;
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);
141 keymap_count++;
142 }
143 ov = U(key_map[i]);
144 if (v == ov)
145 break; /* nothing to do */
146 /*
147 * Attention Key.
148 */
149 if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN))
150 return -EPERM;
151 key_map[i] = U(v);
152 if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT))
153 compute_shiftstate();
154 break;
155 }
156 return 0;
157}
158#undef i
159#undef s
160#undef v
161
162static inline int
163do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, int perm)
164{
165 struct kbkeycode tmp;
166 int kc = 0;
167
168 if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode)))
169 return -EFAULT;
170 switch (cmd) {
171 case KDGETKEYCODE:
172 kc = getkeycode(tmp.scancode);
173 if (kc >= 0)
174 kc = put_user(kc, &user_kbkc->keycode);
175 break;
176 case KDSETKEYCODE:
177 if (!perm)
178 return -EPERM;
179 kc = setkeycode(tmp.scancode, tmp.keycode);
180 break;
181 }
182 return kc;
183}
184
185static inline int
186do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
187{
188 struct kbsentry *kbs;
189 char *p;
190 u_char *q;
191 u_char __user *up;
192 int sz;
193 int delta;
194 char *first_free, *fj, *fnw;
195 int i, j, k;
196 int ret;
197
0b360adb 198 if (!capable(CAP_SYS_TTY_CONFIG))
e3f17f0f 199 perm = 0;
0b360adb 200
1da177e4
LT
201 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
202 if (!kbs) {
203 ret = -ENOMEM;
204 goto reterr;
205 }
206
207 /* we mostly copy too much here (512bytes), but who cares ;) */
208 if (copy_from_user(kbs, user_kdgkb, sizeof(struct kbsentry))) {
209 ret = -EFAULT;
210 goto reterr;
211 }
212 kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
213 i = kbs->kb_func;
214
215 switch (cmd) {
216 case KDGKBSENT:
217 sz = sizeof(kbs->kb_string) - 1; /* sz should have been
218 a struct member */
219 up = user_kdgkb->kb_string;
220 p = func_table[i];
221 if(p)
222 for ( ; *p && sz; p++, sz--)
223 if (put_user(*p, up++)) {
224 ret = -EFAULT;
225 goto reterr;
226 }
227 if (put_user('\0', up)) {
228 ret = -EFAULT;
229 goto reterr;
230 }
231 kfree(kbs);
232 return ((p && *p) ? -EOVERFLOW : 0);
233 case KDSKBSENT:
234 if (!perm) {
235 ret = -EPERM;
236 goto reterr;
237 }
238
239 q = func_table[i];
240 first_free = funcbufptr + (funcbufsize - funcbufleft);
241 for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
242 ;
243 if (j < MAX_NR_FUNC)
244 fj = func_table[j];
245 else
246 fj = first_free;
247
248 delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string);
249 if (delta <= funcbufleft) { /* it fits in current buf */
250 if (j < MAX_NR_FUNC) {
251 memmove(fj + delta, fj, first_free - fj);
252 for (k = j; k < MAX_NR_FUNC; k++)
253 if (func_table[k])
254 func_table[k] += delta;
255 }
256 if (!q)
257 func_table[i] = fj;
258 funcbufleft -= delta;
259 } else { /* allocate a larger buffer */
260 sz = 256;
261 while (sz < funcbufsize - funcbufleft + delta)
262 sz <<= 1;
5cbded58 263 fnw = kmalloc(sz, GFP_KERNEL);
1da177e4
LT
264 if(!fnw) {
265 ret = -ENOMEM;
266 goto reterr;
267 }
268
269 if (!q)
270 func_table[i] = fj;
271 if (fj > funcbufptr)
272 memmove(fnw, funcbufptr, fj - funcbufptr);
273 for (k = 0; k < j; k++)
274 if (func_table[k])
275 func_table[k] = fnw + (func_table[k] - funcbufptr);
276
277 if (first_free > fj) {
278 memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj);
279 for (k = j; k < MAX_NR_FUNC; k++)
280 if (func_table[k])
281 func_table[k] = fnw + (func_table[k] - funcbufptr) + delta;
282 }
283 if (funcbufptr != func_buf)
284 kfree(funcbufptr);
285 funcbufptr = fnw;
286 funcbufleft = funcbufleft - delta + sz - funcbufsize;
287 funcbufsize = sz;
288 }
289 strcpy(func_table[i], kbs->kb_string);
290 break;
291 }
292 ret = 0;
293reterr:
294 kfree(kbs);
295 return ret;
296}
297
298static inline int
299do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op)
300{
301 struct consolefontdesc cfdarg;
302 int i;
303
304 if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc)))
305 return -EFAULT;
306
307 switch (cmd) {
308 case PIO_FONTX:
309 if (!perm)
310 return -EPERM;
311 op->op = KD_FONT_OP_SET;
312 op->flags = KD_FONT_FLAG_OLD;
313 op->width = 8;
314 op->height = cfdarg.charheight;
315 op->charcount = cfdarg.charcount;
316 op->data = cfdarg.chardata;
317 return con_font_op(vc_cons[fg_console].d, op);
318 case GIO_FONTX: {
319 op->op = KD_FONT_OP_GET;
320 op->flags = KD_FONT_FLAG_OLD;
321 op->width = 8;
322 op->height = cfdarg.charheight;
323 op->charcount = cfdarg.charcount;
324 op->data = cfdarg.chardata;
325 i = con_font_op(vc_cons[fg_console].d, op);
326 if (i)
327 return i;
328 cfdarg.charheight = op->height;
329 cfdarg.charcount = op->charcount;
330 if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc)))
331 return -EFAULT;
332 return 0;
333 }
334 }
335 return -EINVAL;
336}
337
338static inline int
339do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_data *vc)
340{
341 struct unimapdesc tmp;
342
343 if (copy_from_user(&tmp, user_ud, sizeof tmp))
344 return -EFAULT;
345 if (tmp.entries)
346 if (!access_ok(VERIFY_WRITE, tmp.entries,
347 tmp.entry_ct*sizeof(struct unipair)))
348 return -EFAULT;
349 switch (cmd) {
350 case PIO_UNIMAP:
351 if (!perm)
352 return -EPERM;
353 return con_set_unimap(vc, tmp.entry_ct, tmp.entries);
354 case GIO_UNIMAP:
355 if (!perm && fg_console != vc->vc_num)
356 return -EPERM;
357 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp.entries);
358 }
359 return 0;
360}
361
362/*
363 * We handle the console-specific ioctl's here. We allow the
364 * capability to modify any console, not just the fg_console.
365 */
366int vt_ioctl(struct tty_struct *tty, struct file * file,
367 unsigned int cmd, unsigned long arg)
368{
c9f19e96 369 struct vc_data *vc = tty->driver_data;
1da177e4
LT
370 struct console_font_op op; /* used in multiple places here */
371 struct kbd_struct * kbd;
372 unsigned int console;
373 unsigned char ucval;
374 void __user *up = (void __user *)arg;
375 int i, perm;
9cc3c22b
AC
376 int ret = 0;
377
1da177e4
LT
378 console = vc->vc_num;
379
9cc3c22b
AC
380 lock_kernel();
381
382 if (!vc_cons_allocated(console)) { /* impossible? */
383 ret = -ENOIOCTLCMD;
384 goto out;
385 }
386
1da177e4
LT
387
388 /*
389 * To have permissions to do most of the vt ioctls, we either have
390 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
391 */
392 perm = 0;
393 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
394 perm = 1;
395
396 kbd = kbd_table + console;
397 switch (cmd) {
e6885107
AC
398 case TIOCLINUX:
399 return tioclinux(tty, arg);
1da177e4
LT
400 case KIOCSOUND:
401 if (!perm)
9cc3c22b 402 goto eperm;
fab89223
AC
403 /* FIXME: This is an old broken API but we need to keep it
404 supported and somehow separate the historic advertised
405 tick rate from any real one */
1da177e4 406 if (arg)
bcc8ca09 407 arg = CLOCK_TICK_RATE / arg;
1da177e4 408 kd_mksound(arg, 0);
9cc3c22b 409 break;
1da177e4
LT
410
411 case KDMKTONE:
412 if (!perm)
9cc3c22b 413 goto eperm;
1da177e4
LT
414 {
415 unsigned int ticks, count;
416
417 /*
418 * Generate the tone for the appropriate number of ticks.
419 * If the time is zero, turn off sound ourselves.
420 */
421 ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
422 count = ticks ? (arg & 0xffff) : 0;
fab89223
AC
423 /* FIXME: This is an old broken API but we need to keep it
424 supported and somehow separate the historic advertised
425 tick rate from any real one */
1da177e4 426 if (count)
bcc8ca09 427 count = CLOCK_TICK_RATE / count;
1da177e4 428 kd_mksound(count, ticks);
9cc3c22b 429 break;
1da177e4
LT
430 }
431
432 case KDGKBTYPE:
433 /*
434 * this is naive.
435 */
436 ucval = KB_101;
437 goto setchar;
438
439 /*
440 * These cannot be implemented on any machine that implements
441 * ioperm() in user level (such as Alpha PCs) or not at all.
442 *
443 * XXX: you should never use these, just call ioperm directly..
444 */
445#ifdef CONFIG_X86
446 case KDADDIO:
447 case KDDELIO:
448 /*
449 * KDADDIO and KDDELIO may be able to add ports beyond what
450 * we reject here, but to be safe...
451 */
9cc3c22b
AC
452 if (arg < GPFIRST || arg > GPLAST) {
453 ret = -EINVAL;
454 break;
455 }
456 ret = sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
457 break;
1da177e4
LT
458
459 case KDENABIO:
460 case KDDISABIO:
9cc3c22b 461 ret = sys_ioperm(GPFIRST, GPNUM,
1da177e4 462 (cmd == KDENABIO)) ? -ENXIO : 0;
9cc3c22b 463 break;
1da177e4
LT
464#endif
465
466 /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
467
468 case KDKBDREP:
469 {
470 struct kbd_repeat kbrep;
1da177e4
LT
471
472 if (!capable(CAP_SYS_TTY_CONFIG))
9cc3c22b 473 goto eperm;
1da177e4 474
9cc3c22b
AC
475 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) {
476 ret = -EFAULT;
477 break;
478 }
479 ret = kbd_rate(&kbrep);
480 if (ret)
481 break;
1da177e4 482 if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat)))
9cc3c22b
AC
483 ret = -EFAULT;
484 break;
1da177e4
LT
485 }
486
487 case KDSETMODE:
488 /*
489 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
490 * doesn't do a whole lot. i'm not sure if it should do any
491 * restoration of modes or what...
492 *
493 * XXX It should at least call into the driver, fbdev's definitely
494 * need to restore their engine state. --BenH
495 */
496 if (!perm)
9cc3c22b 497 goto eperm;
1da177e4
LT
498 switch (arg) {
499 case KD_GRAPHICS:
500 break;
501 case KD_TEXT0:
502 case KD_TEXT1:
503 arg = KD_TEXT;
504 case KD_TEXT:
505 break;
506 default:
9cc3c22b
AC
507 ret = -EINVAL;
508 goto out;
1da177e4
LT
509 }
510 if (vc->vc_mode == (unsigned char) arg)
9cc3c22b 511 break;
1da177e4
LT
512 vc->vc_mode = (unsigned char) arg;
513 if (console != fg_console)
9cc3c22b 514 break;
1da177e4
LT
515 /*
516 * explicitly blank/unblank the screen if switching modes
517 */
518 acquire_console_sem();
519 if (arg == KD_TEXT)
520 do_unblank_screen(1);
521 else
522 do_blank_screen(1);
523 release_console_sem();
9cc3c22b 524 break;
1da177e4
LT
525
526 case KDGETMODE:
527 ucval = vc->vc_mode;
528 goto setint;
529
530 case KDMAPDISP:
531 case KDUNMAPDISP:
532 /*
533 * these work like a combination of mmap and KDENABIO.
534 * this could be easily finished.
535 */
9cc3c22b
AC
536 ret = -EINVAL;
537 break;
1da177e4
LT
538
539 case KDSKBMODE:
540 if (!perm)
9cc3c22b 541 goto eperm;
1da177e4
LT
542 switch(arg) {
543 case K_RAW:
544 kbd->kbdmode = VC_RAW;
545 break;
546 case K_MEDIUMRAW:
547 kbd->kbdmode = VC_MEDIUMRAW;
548 break;
549 case K_XLATE:
550 kbd->kbdmode = VC_XLATE;
551 compute_shiftstate();
552 break;
553 case K_UNICODE:
554 kbd->kbdmode = VC_UNICODE;
555 compute_shiftstate();
556 break;
557 default:
9cc3c22b
AC
558 ret = -EINVAL;
559 goto out;
1da177e4
LT
560 }
561 tty_ldisc_flush(tty);
9cc3c22b 562 break;
1da177e4
LT
563
564 case KDGKBMODE:
565 ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW :
566 (kbd->kbdmode == VC_MEDIUMRAW) ? K_MEDIUMRAW :
567 (kbd->kbdmode == VC_UNICODE) ? K_UNICODE :
568 K_XLATE);
569 goto setint;
570
571 /* this could be folded into KDSKBMODE, but for compatibility
572 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
573 case KDSKBMETA:
574 switch(arg) {
575 case K_METABIT:
576 clr_vc_kbd_mode(kbd, VC_META);
577 break;
578 case K_ESCPREFIX:
579 set_vc_kbd_mode(kbd, VC_META);
580 break;
581 default:
9cc3c22b 582 ret = -EINVAL;
1da177e4 583 }
9cc3c22b 584 break;
1da177e4
LT
585
586 case KDGKBMETA:
587 ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT);
588 setint:
9cc3c22b
AC
589 ret = put_user(ucval, (int __user *)arg);
590 break;
1da177e4
LT
591
592 case KDGETKEYCODE:
593 case KDSETKEYCODE:
594 if(!capable(CAP_SYS_TTY_CONFIG))
9cc3c22b
AC
595 perm = 0;
596 ret = do_kbkeycode_ioctl(cmd, up, perm);
597 break;
1da177e4
LT
598
599 case KDGKBENT:
600 case KDSKBENT:
9cc3c22b
AC
601 ret = do_kdsk_ioctl(cmd, up, perm, kbd);
602 break;
1da177e4
LT
603
604 case KDGKBSENT:
605 case KDSKBSENT:
9cc3c22b
AC
606 ret = do_kdgkb_ioctl(cmd, up, perm);
607 break;
1da177e4
LT
608
609 case KDGKBDIACR:
610 {
611 struct kbdiacrs __user *a = up;
04c71976
ST
612 struct kbdiacr diacr;
613 int i;
1da177e4 614
9cc3c22b
AC
615 if (put_user(accent_table_size, &a->kb_cnt)) {
616 ret = -EFAULT;
617 break;
618 }
04c71976
ST
619 for (i = 0; i < accent_table_size; i++) {
620 diacr.diacr = conv_uni_to_8bit(accent_table[i].diacr);
621 diacr.base = conv_uni_to_8bit(accent_table[i].base);
622 diacr.result = conv_uni_to_8bit(accent_table[i].result);
9cc3c22b
AC
623 if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) {
624 ret = -EFAULT;
625 break;
626 }
04c71976 627 }
9cc3c22b 628 break;
04c71976
ST
629 }
630 case KDGKBDIACRUC:
631 {
632 struct kbdiacrsuc __user *a = up;
633
634 if (put_user(accent_table_size, &a->kb_cnt))
9cc3c22b
AC
635 ret = -EFAULT;
636 else if (copy_to_user(a->kbdiacruc, accent_table,
637 accent_table_size*sizeof(struct kbdiacruc)))
638 ret = -EFAULT;
639 break;
1da177e4
LT
640 }
641
642 case KDSKBDIACR:
643 {
644 struct kbdiacrs __user *a = up;
04c71976
ST
645 struct kbdiacr diacr;
646 unsigned int ct;
647 int i;
648
649 if (!perm)
9cc3c22b
AC
650 goto eperm;
651 if (get_user(ct,&a->kb_cnt)) {
652 ret = -EFAULT;
653 break;
654 }
655 if (ct >= MAX_DIACR) {
656 ret = -EINVAL;
657 break;
658 }
04c71976
ST
659 accent_table_size = ct;
660 for (i = 0; i < ct; i++) {
9cc3c22b
AC
661 if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) {
662 ret = -EFAULT;
663 break;
664 }
04c71976
ST
665 accent_table[i].diacr = conv_8bit_to_uni(diacr.diacr);
666 accent_table[i].base = conv_8bit_to_uni(diacr.base);
667 accent_table[i].result = conv_8bit_to_uni(diacr.result);
668 }
9cc3c22b 669 break;
04c71976
ST
670 }
671
672 case KDSKBDIACRUC:
673 {
674 struct kbdiacrsuc __user *a = up;
1da177e4
LT
675 unsigned int ct;
676
677 if (!perm)
9cc3c22b
AC
678 goto eperm;
679 if (get_user(ct,&a->kb_cnt)) {
680 ret = -EFAULT;
681 break;
682 }
683 if (ct >= MAX_DIACR) {
684 ret = -EINVAL;
685 break;
686 }
1da177e4 687 accent_table_size = ct;
04c71976 688 if (copy_from_user(accent_table, a->kbdiacruc, ct*sizeof(struct kbdiacruc)))
9cc3c22b
AC
689 ret = -EFAULT;
690 break;
1da177e4
LT
691 }
692
693 /* the ioctls below read/set the flags usually shown in the leds */
694 /* don't use them - they will go away without warning */
695 case KDGKBLED:
696 ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4);
697 goto setchar;
698
699 case KDSKBLED:
700 if (!perm)
9cc3c22b
AC
701 goto eperm;
702 if (arg & ~0x77) {
703 ret = -EINVAL;
704 break;
705 }
1da177e4
LT
706 kbd->ledflagstate = (arg & 7);
707 kbd->default_ledflagstate = ((arg >> 4) & 7);
708 set_leds();
9cc3c22b 709 break;
1da177e4
LT
710
711 /* the ioctls below only set the lights, not the functions */
712 /* for those, see KDGKBLED and KDSKBLED above */
713 case KDGETLED:
714 ucval = getledstate();
715 setchar:
9cc3c22b
AC
716 ret = put_user(ucval, (char __user *)arg);
717 break;
1da177e4
LT
718
719 case KDSETLED:
720 if (!perm)
9cc3c22b 721 goto eperm;
1da177e4 722 setledstate(kbd, arg);
9cc3c22b 723 break;
1da177e4
LT
724
725 /*
726 * A process can indicate its willingness to accept signals
727 * generated by pressing an appropriate key combination.
728 * Thus, one can have a daemon that e.g. spawns a new console
729 * upon a keypress and then changes to it.
730 * See also the kbrequest field of inittab(5).
731 */
732 case KDSIGACCEPT:
733 {
1da177e4 734 if (!perm || !capable(CAP_KILL))
9cc3c22b 735 goto eperm;
7ed20e1a 736 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
9cc3c22b
AC
737 ret = -EINVAL;
738 else {
739 spin_lock_irq(&vt_spawn_con.lock);
740 put_pid(vt_spawn_con.pid);
741 vt_spawn_con.pid = get_pid(task_pid(current));
742 vt_spawn_con.sig = arg;
743 spin_unlock_irq(&vt_spawn_con.lock);
744 }
745 break;
1da177e4
LT
746 }
747
748 case VT_SETMODE:
749 {
750 struct vt_mode tmp;
751
752 if (!perm)
9cc3c22b
AC
753 goto eperm;
754 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) {
755 ret = -EFAULT;
756 goto out;
757 }
758 if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) {
759 ret = -EINVAL;
760 goto out;
761 }
1da177e4
LT
762 acquire_console_sem();
763 vc->vt_mode = tmp;
764 /* the frsig is ignored, so we set it to 0 */
765 vc->vt_mode.frsig = 0;
8b6312f4
EB
766 put_pid(vc->vt_pid);
767 vc->vt_pid = get_pid(task_pid(current));
1da177e4
LT
768 /* no switch is required -- saw@shade.msu.ru */
769 vc->vt_newvt = -1;
770 release_console_sem();
9cc3c22b 771 break;
1da177e4
LT
772 }
773
774 case VT_GETMODE:
775 {
776 struct vt_mode tmp;
777 int rc;
778
779 acquire_console_sem();
780 memcpy(&tmp, &vc->vt_mode, sizeof(struct vt_mode));
781 release_console_sem();
782
783 rc = copy_to_user(up, &tmp, sizeof(struct vt_mode));
9cc3c22b
AC
784 if (rc)
785 ret = -EFAULT;
786 break;
1da177e4
LT
787 }
788
789 /*
790 * Returns global vt state. Note that VT 0 is always open, since
791 * it's an alias for the current VT, and people can't use it here.
792 * We cannot return state for more than 16 VTs, since v_state is short.
793 */
794 case VT_GETSTATE:
795 {
796 struct vt_stat __user *vtstat = up;
797 unsigned short state, mask;
798
799 if (put_user(fg_console + 1, &vtstat->v_active))
9cc3c22b
AC
800 ret = -EFAULT;
801 else {
802 state = 1; /* /dev/tty0 is always open */
803 for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask;
804 ++i, mask <<= 1)
805 if (VT_IS_IN_USE(i))
806 state |= mask;
807 ret = put_user(state, &vtstat->v_state);
808 }
809 break;
1da177e4
LT
810 }
811
812 /*
813 * Returns the first available (non-opened) console.
814 */
815 case VT_OPENQRY:
816 for (i = 0; i < MAX_NR_CONSOLES; ++i)
817 if (! VT_IS_IN_USE(i))
818 break;
819 ucval = i < MAX_NR_CONSOLES ? (i+1) : -1;
820 goto setint;
821
822 /*
823 * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
824 * with num >= 1 (switches to vt 0, our console, are not allowed, just
825 * to preserve sanity).
826 */
827 case VT_ACTIVATE:
828 if (!perm)
9cc3c22b 829 goto eperm;
1da177e4 830 if (arg == 0 || arg > MAX_NR_CONSOLES)
9cc3c22b
AC
831 ret = -ENXIO;
832 else {
833 arg--;
834 acquire_console_sem();
835 ret = vc_allocate(arg);
836 release_console_sem();
837 if (ret)
838 break;
839 set_console(arg);
840 }
841 break;
1da177e4
LT
842
843 /*
844 * wait until the specified VT has been activated
845 */
846 case VT_WAITACTIVE:
847 if (!perm)
9cc3c22b 848 goto eperm;
1da177e4 849 if (arg == 0 || arg > MAX_NR_CONSOLES)
9cc3c22b
AC
850 ret = -ENXIO;
851 else
852 ret = vt_waitactive(arg - 1);
853 break;
1da177e4
LT
854
855 /*
856 * If a vt is under process control, the kernel will not switch to it
857 * immediately, but postpone the operation until the process calls this
858 * ioctl, allowing the switch to complete.
859 *
860 * According to the X sources this is the behavior:
861 * 0: pending switch-from not OK
862 * 1: pending switch-from OK
863 * 2: completed switch-to OK
864 */
865 case VT_RELDISP:
866 if (!perm)
9cc3c22b 867 goto eperm;
1da177e4 868
9cc3c22b
AC
869 if (vc->vt_mode.mode != VT_PROCESS) {
870 ret = -EINVAL;
871 break;
872 }
1da177e4
LT
873 /*
874 * Switching-from response
875 */
8792f961 876 acquire_console_sem();
1da177e4
LT
877 if (vc->vt_newvt >= 0) {
878 if (arg == 0)
879 /*
880 * Switch disallowed, so forget we were trying
881 * to do it.
882 */
883 vc->vt_newvt = -1;
884
885 else {
886 /*
887 * The current vt has been released, so
888 * complete the switch.
889 */
890 int newvt;
1da177e4
LT
891 newvt = vc->vt_newvt;
892 vc->vt_newvt = -1;
9cc3c22b
AC
893 ret = vc_allocate(newvt);
894 if (ret) {
1da177e4 895 release_console_sem();
9cc3c22b 896 break;
1da177e4
LT
897 }
898 /*
899 * When we actually do the console switch,
900 * make sure we are atomic with respect to
901 * other console switches..
902 */
903 complete_change_console(vc_cons[newvt].d);
1da177e4 904 }
9cc3c22b
AC
905 } else {
906 /*
907 * Switched-to response
908 */
1da177e4
LT
909 /*
910 * If it's just an ACK, ignore it
911 */
9cc3c22b
AC
912 if (arg != VT_ACKACQ)
913 ret = -EINVAL;
1da177e4 914 }
8792f961 915 release_console_sem();
9cc3c22b 916 break;
1da177e4
LT
917
918 /*
919 * Disallocate memory associated to VT (but leave VT1)
920 */
921 case VT_DISALLOCATE:
9cc3c22b
AC
922 if (arg > MAX_NR_CONSOLES) {
923 ret = -ENXIO;
924 break;
925 }
1da177e4 926 if (arg == 0) {
ca9bda00 927 /* deallocate all unused consoles, but leave 0 */
1da177e4
LT
928 acquire_console_sem();
929 for (i=1; i<MAX_NR_CONSOLES; i++)
930 if (! VT_BUSY(i))
ca9bda00 931 vc_deallocate(i);
1da177e4
LT
932 release_console_sem();
933 } else {
ca9bda00 934 /* deallocate a single console, if possible */
1da177e4
LT
935 arg--;
936 if (VT_BUSY(arg))
9cc3c22b
AC
937 ret = -EBUSY;
938 else if (arg) { /* leave 0 */
1da177e4 939 acquire_console_sem();
ca9bda00 940 vc_deallocate(arg);
1da177e4
LT
941 release_console_sem();
942 }
943 }
9cc3c22b 944 break;
1da177e4
LT
945
946 case VT_RESIZE:
947 {
948 struct vt_sizes __user *vtsizes = up;
e400b6ec
AD
949 struct vc_data *vc;
950
1da177e4
LT
951 ushort ll,cc;
952 if (!perm)
9cc3c22b 953 goto eperm;
1da177e4
LT
954 if (get_user(ll, &vtsizes->v_rows) ||
955 get_user(cc, &vtsizes->v_cols))
9cc3c22b
AC
956 ret = -EFAULT;
957 else {
8c9a9dd0 958 acquire_console_sem();
9cc3c22b
AC
959 for (i = 0; i < MAX_NR_CONSOLES; i++) {
960 vc = vc_cons[i].d;
e400b6ec 961
9cc3c22b
AC
962 if (vc) {
963 vc->vc_resize_user = 1;
8c9a9dd0 964 vc_resize(vc_cons[i].d, cc, ll);
9cc3c22b 965 }
e400b6ec 966 }
8c9a9dd0 967 release_console_sem();
e400b6ec 968 }
9cc3c22b 969 break;
1da177e4
LT
970 }
971
972 case VT_RESIZEX:
973 {
974 struct vt_consize __user *vtconsize = up;
975 ushort ll,cc,vlin,clin,vcol,ccol;
976 if (!perm)
9cc3c22b 977 goto eperm;
1da177e4 978 if (!access_ok(VERIFY_READ, vtconsize,
9cc3c22b
AC
979 sizeof(struct vt_consize))) {
980 ret = -EFAULT;
981 break;
982 }
983 /* FIXME: Should check the copies properly */
1da177e4
LT
984 __get_user(ll, &vtconsize->v_rows);
985 __get_user(cc, &vtconsize->v_cols);
986 __get_user(vlin, &vtconsize->v_vlin);
987 __get_user(clin, &vtconsize->v_clin);
988 __get_user(vcol, &vtconsize->v_vcol);
989 __get_user(ccol, &vtconsize->v_ccol);
990 vlin = vlin ? vlin : vc->vc_scan_lines;
991 if (clin) {
992 if (ll) {
9cc3c22b
AC
993 if (ll != vlin/clin) {
994 /* Parameters don't add up */
995 ret = -EINVAL;
996 break;
997 }
1da177e4
LT
998 } else
999 ll = vlin/clin;
1000 }
1001 if (vcol && ccol) {
1002 if (cc) {
9cc3c22b
AC
1003 if (cc != vcol/ccol) {
1004 ret = -EINVAL;
1005 break;
1006 }
1da177e4
LT
1007 } else
1008 cc = vcol/ccol;
1009 }
1010
9cc3c22b
AC
1011 if (clin > 32) {
1012 ret = -EINVAL;
1013 break;
1014 }
1da177e4
LT
1015
1016 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1017 if (!vc_cons[i].d)
1018 continue;
1019 acquire_console_sem();
1020 if (vlin)
1021 vc_cons[i].d->vc_scan_lines = vlin;
1022 if (clin)
1023 vc_cons[i].d->vc_font.height = clin;
e400b6ec 1024 vc_cons[i].d->vc_resize_user = 1;
1da177e4
LT
1025 vc_resize(vc_cons[i].d, cc, ll);
1026 release_console_sem();
1027 }
9cc3c22b 1028 break;
1da177e4
LT
1029 }
1030
1031 case PIO_FONT: {
1032 if (!perm)
9cc3c22b 1033 goto eperm;
1da177e4
LT
1034 op.op = KD_FONT_OP_SET;
1035 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
1036 op.width = 8;
1037 op.height = 0;
1038 op.charcount = 256;
1039 op.data = up;
9cc3c22b
AC
1040 ret = con_font_op(vc_cons[fg_console].d, &op);
1041 break;
1da177e4
LT
1042 }
1043
1044 case GIO_FONT: {
1045 op.op = KD_FONT_OP_GET;
1046 op.flags = KD_FONT_FLAG_OLD;
1047 op.width = 8;
1048 op.height = 32;
1049 op.charcount = 256;
1050 op.data = up;
9cc3c22b
AC
1051 ret = con_font_op(vc_cons[fg_console].d, &op);
1052 break;
1da177e4
LT
1053 }
1054
1055 case PIO_CMAP:
1056 if (!perm)
9cc3c22b
AC
1057 ret = -EPERM;
1058 else
1059 ret = con_set_cmap(up);
1060 break;
1da177e4
LT
1061
1062 case GIO_CMAP:
9cc3c22b
AC
1063 ret = con_get_cmap(up);
1064 break;
1da177e4
LT
1065
1066 case PIO_FONTX:
1067 case GIO_FONTX:
9cc3c22b
AC
1068 ret = do_fontx_ioctl(cmd, up, perm, &op);
1069 break;
1da177e4
LT
1070
1071 case PIO_FONTRESET:
1072 {
1073 if (!perm)
9cc3c22b 1074 goto eperm;
1da177e4
LT
1075
1076#ifdef BROKEN_GRAPHICS_PROGRAMS
1077 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
1078 font is not saved. */
9cc3c22b
AC
1079 ret = -ENOSYS;
1080 break;
1da177e4
LT
1081#else
1082 {
1083 op.op = KD_FONT_OP_SET_DEFAULT;
1084 op.data = NULL;
9cc3c22b
AC
1085 ret = con_font_op(vc_cons[fg_console].d, &op);
1086 if (ret)
1087 break;
1da177e4 1088 con_set_default_unimap(vc_cons[fg_console].d);
9cc3c22b 1089 break;
1da177e4
LT
1090 }
1091#endif
1092 }
1093
1094 case KDFONTOP: {
9cc3c22b
AC
1095 if (copy_from_user(&op, up, sizeof(op))) {
1096 ret = -EFAULT;
1097 break;
1098 }
1da177e4 1099 if (!perm && op.op != KD_FONT_OP_GET)
9cc3c22b
AC
1100 goto eperm;
1101 ret = con_font_op(vc, &op);
1102 if (ret)
1103 break;
1da177e4 1104 if (copy_to_user(up, &op, sizeof(op)))
9cc3c22b
AC
1105 ret = -EFAULT;
1106 break;
1da177e4
LT
1107 }
1108
1109 case PIO_SCRNMAP:
1110 if (!perm)
9cc3c22b
AC
1111 ret = -EPERM;
1112 else
1113 ret = con_set_trans_old(up);
1114 break;
1da177e4
LT
1115
1116 case GIO_SCRNMAP:
9cc3c22b
AC
1117 ret = con_get_trans_old(up);
1118 break;
1da177e4
LT
1119
1120 case PIO_UNISCRNMAP:
1121 if (!perm)
9cc3c22b
AC
1122 ret = -EPERM;
1123 else
1124 ret = con_set_trans_new(up);
1125 break;
1da177e4
LT
1126
1127 case GIO_UNISCRNMAP:
9cc3c22b
AC
1128 ret = con_get_trans_new(up);
1129 break;
1da177e4
LT
1130
1131 case PIO_UNIMAPCLR:
1132 { struct unimapinit ui;
1133 if (!perm)
9cc3c22b
AC
1134 goto eperm;
1135 ret = copy_from_user(&ui, up, sizeof(struct unimapinit));
1136 if (!ret)
1137 con_clear_unimap(vc, &ui);
1138 break;
1da177e4
LT
1139 }
1140
1141 case PIO_UNIMAP:
1142 case GIO_UNIMAP:
9cc3c22b
AC
1143 ret = do_unimap_ioctl(cmd, up, perm, vc);
1144 break;
1da177e4
LT
1145
1146 case VT_LOCKSWITCH:
1147 if (!capable(CAP_SYS_TTY_CONFIG))
9cc3c22b 1148 goto eperm;
1da177e4 1149 vt_dont_switch = 1;
9cc3c22b 1150 break;
1da177e4
LT
1151 case VT_UNLOCKSWITCH:
1152 if (!capable(CAP_SYS_TTY_CONFIG))
9cc3c22b 1153 goto eperm;
1da177e4 1154 vt_dont_switch = 0;
9cc3c22b 1155 break;
533475d3 1156 case VT_GETHIFONTMASK:
9cc3c22b
AC
1157 ret = put_user(vc->vc_hi_font_mask,
1158 (unsigned short __user *)arg);
1159 break;
1da177e4 1160 default:
9cc3c22b 1161 ret = -ENOIOCTLCMD;
1da177e4 1162 }
9cc3c22b
AC
1163out:
1164 unlock_kernel();
1165 return ret;
1166eperm:
1167 ret = -EPERM;
1168 goto out;
1da177e4
LT
1169}
1170
1171/*
1172 * Sometimes we want to wait until a particular VT has been activated. We
1173 * do it in a very simple manner. Everybody waits on a single queue and
1174 * get woken up at once. Those that are satisfied go on with their business,
1175 * while those not ready go back to sleep. Seems overkill to add a wait
1176 * to each vt just for this - usually this does nothing!
1177 */
1178static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue);
1179
1180/*
1181 * Sleeps until a vt is activated, or the task is interrupted. Returns
70cb9793 1182 * 0 if activation, -EINTR if interrupted by a signal handler.
1da177e4
LT
1183 */
1184int vt_waitactive(int vt)
1185{
1186 int retval;
1187 DECLARE_WAITQUEUE(wait, current);
1188
1189 add_wait_queue(&vt_activate_queue, &wait);
1190 for (;;) {
1da177e4 1191 retval = 0;
f991519c
MJ
1192
1193 /*
1194 * Synchronize with redraw_screen(). By acquiring the console
1195 * semaphore we make sure that the console switch is completed
1196 * before we return. If we didn't wait for the semaphore, we
1197 * could return at a point where fg_console has already been
1198 * updated, but the console switch hasn't been completed.
1199 */
1200 acquire_console_sem();
1201 set_current_state(TASK_INTERRUPTIBLE);
1202 if (vt == fg_console) {
1203 release_console_sem();
1da177e4 1204 break;
f991519c
MJ
1205 }
1206 release_console_sem();
70cb9793 1207 retval = -ERESTARTNOHAND;
1da177e4
LT
1208 if (signal_pending(current))
1209 break;
1210 schedule();
1211 }
1212 remove_wait_queue(&vt_activate_queue, &wait);
cc0a8fbb 1213 __set_current_state(TASK_RUNNING);
1da177e4
LT
1214 return retval;
1215}
1216
1217#define vt_wake_waitactive() wake_up(&vt_activate_queue)
1218
1219void reset_vc(struct vc_data *vc)
1220{
1221 vc->vc_mode = KD_TEXT;
2e8ecb9d 1222 kbd_table[vc->vc_num].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
1da177e4
LT
1223 vc->vt_mode.mode = VT_AUTO;
1224 vc->vt_mode.waitv = 0;
1225 vc->vt_mode.relsig = 0;
1226 vc->vt_mode.acqsig = 0;
1227 vc->vt_mode.frsig = 0;
8b6312f4
EB
1228 put_pid(vc->vt_pid);
1229 vc->vt_pid = NULL;
1da177e4
LT
1230 vc->vt_newvt = -1;
1231 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
1232 reset_palette(vc);
1233}
1234
8b6312f4
EB
1235void vc_SAK(struct work_struct *work)
1236{
1237 struct vc *vc_con =
1238 container_of(work, struct vc, SAK_work);
1239 struct vc_data *vc;
1240 struct tty_struct *tty;
1241
1242 acquire_console_sem();
1243 vc = vc_con->d;
1244 if (vc) {
1245 tty = vc->vc_tty;
1246 /*
1247 * SAK should also work in all raw modes and reset
1248 * them properly.
1249 */
1250 if (tty)
1251 __do_SAK(tty);
1252 reset_vc(vc);
1253 }
1254 release_console_sem();
1255}
1256
1da177e4
LT
1257/*
1258 * Performs the back end of a vt switch
1259 */
1260static void complete_change_console(struct vc_data *vc)
1261{
1262 unsigned char old_vc_mode;
1263
1264 last_console = fg_console;
1265
1266 /*
1267 * If we're switching, we could be going from KD_GRAPHICS to
1268 * KD_TEXT mode or vice versa, which means we need to blank or
1269 * unblank the screen later.
1270 */
1271 old_vc_mode = vc_cons[fg_console].d->vc_mode;
1272 switch_screen(vc);
1273
1274 /*
3dfcaf16 1275 * This can't appear below a successful kill_pid(). If it did,
1da177e4
LT
1276 * then the *blank_screen operation could occur while X, having
1277 * received acqsig, is waking up on another processor. This
1278 * condition can lead to overlapping accesses to the VGA range
1279 * and the framebuffer (causing system lockups).
1280 *
1281 * To account for this we duplicate this code below only if the
1282 * controlling process is gone and we've called reset_vc.
1283 */
1284 if (old_vc_mode != vc->vc_mode) {
1285 if (vc->vc_mode == KD_TEXT)
1286 do_unblank_screen(1);
1287 else
1288 do_blank_screen(1);
1289 }
1290
1291 /*
1292 * If this new console is under process control, send it a signal
1293 * telling it that it has acquired. Also check if it has died and
1294 * clean up (similar to logic employed in change_console())
1295 */
1296 if (vc->vt_mode.mode == VT_PROCESS) {
1297 /*
3dfcaf16 1298 * Send the signal as privileged - kill_pid() will
1da177e4
LT
1299 * tell us if the process has gone or something else
1300 * is awry
1301 */
bde0d2c9 1302 if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
1da177e4
LT
1303 /*
1304 * The controlling process has died, so we revert back to
1305 * normal operation. In this case, we'll also change back
1306 * to KD_TEXT mode. I'm not sure if this is strictly correct
1307 * but it saves the agony when the X server dies and the screen
1308 * remains blanked due to KD_GRAPHICS! It would be nice to do
1309 * this outside of VT_PROCESS but there is no single process
1310 * to account for and tracking tty count may be undesirable.
1311 */
1312 reset_vc(vc);
1313
1314 if (old_vc_mode != vc->vc_mode) {
1315 if (vc->vc_mode == KD_TEXT)
1316 do_unblank_screen(1);
1317 else
1318 do_blank_screen(1);
1319 }
1320 }
1321 }
1322
1323 /*
1324 * Wake anyone waiting for their VT to activate
1325 */
1326 vt_wake_waitactive();
1327 return;
1328}
1329
1330/*
1331 * Performs the front-end of a vt switch
1332 */
1333void change_console(struct vc_data *new_vc)
1334{
1335 struct vc_data *vc;
1336
1337 if (!new_vc || new_vc->vc_num == fg_console || vt_dont_switch)
1338 return;
1339
1340 /*
1341 * If this vt is in process mode, then we need to handshake with
1342 * that process before switching. Essentially, we store where that
1343 * vt wants to switch to and wait for it to tell us when it's done
1344 * (via VT_RELDISP ioctl).
1345 *
1346 * We also check to see if the controlling process still exists.
1347 * If it doesn't, we reset this vt to auto mode and continue.
1348 * This is a cheap way to track process control. The worst thing
1349 * that can happen is: we send a signal to a process, it dies, and
1350 * the switch gets "lost" waiting for a response; hopefully, the
1351 * user will try again, we'll detect the process is gone (unless
1352 * the user waits just the right amount of time :-) and revert the
1353 * vt to auto control.
1354 */
1355 vc = vc_cons[fg_console].d;
1356 if (vc->vt_mode.mode == VT_PROCESS) {
1357 /*
3dfcaf16 1358 * Send the signal as privileged - kill_pid() will
1da177e4 1359 * tell us if the process has gone or something else
a64314e6
JL
1360 * is awry.
1361 *
1362 * We need to set vt_newvt *before* sending the signal or we
1363 * have a race.
1da177e4 1364 */
a64314e6 1365 vc->vt_newvt = new_vc->vc_num;
bde0d2c9 1366 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
1da177e4
LT
1367 /*
1368 * It worked. Mark the vt to switch to and
1369 * return. The process needs to send us a
1370 * VT_RELDISP ioctl to complete the switch.
1371 */
1da177e4
LT
1372 return;
1373 }
1374
1375 /*
1376 * The controlling process has died, so we revert back to
1377 * normal operation. In this case, we'll also change back
1378 * to KD_TEXT mode. I'm not sure if this is strictly correct
1379 * but it saves the agony when the X server dies and the screen
1380 * remains blanked due to KD_GRAPHICS! It would be nice to do
1381 * this outside of VT_PROCESS but there is no single process
1382 * to account for and tracking tty count may be undesirable.
1383 */
1384 reset_vc(vc);
1385
1386 /*
1387 * Fall through to normal (VT_AUTO) handling of the switch...
1388 */
1389 }
1390
1391 /*
1392 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
1393 */
1394 if (vc->vc_mode == KD_GRAPHICS)
1395 return;
1396
1397 complete_change_console(new_vc);
1398}