vt_ioctl.c 31 KB

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