vt_ioctl.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  863. vc = vc_cons[i].d;
  864. if (vc) {
  865. vc->vc_resize_user = 1;
  866. vc_lock_resize(vc_cons[i].d, cc, ll);
  867. }
  868. }
  869. }
  870. break;
  871. }
  872. case VT_RESIZEX:
  873. {
  874. struct vt_consize __user *vtconsize = up;
  875. ushort ll,cc,vlin,clin,vcol,ccol;
  876. if (!perm)
  877. goto eperm;
  878. if (!access_ok(VERIFY_READ, vtconsize,
  879. sizeof(struct vt_consize))) {
  880. ret = -EFAULT;
  881. break;
  882. }
  883. /* FIXME: Should check the copies properly */
  884. __get_user(ll, &vtconsize->v_rows);
  885. __get_user(cc, &vtconsize->v_cols);
  886. __get_user(vlin, &vtconsize->v_vlin);
  887. __get_user(clin, &vtconsize->v_clin);
  888. __get_user(vcol, &vtconsize->v_vcol);
  889. __get_user(ccol, &vtconsize->v_ccol);
  890. vlin = vlin ? vlin : vc->vc_scan_lines;
  891. if (clin) {
  892. if (ll) {
  893. if (ll != vlin/clin) {
  894. /* Parameters don't add up */
  895. ret = -EINVAL;
  896. break;
  897. }
  898. } else
  899. ll = vlin/clin;
  900. }
  901. if (vcol && ccol) {
  902. if (cc) {
  903. if (cc != vcol/ccol) {
  904. ret = -EINVAL;
  905. break;
  906. }
  907. } else
  908. cc = vcol/ccol;
  909. }
  910. if (clin > 32) {
  911. ret = -EINVAL;
  912. break;
  913. }
  914. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  915. if (!vc_cons[i].d)
  916. continue;
  917. acquire_console_sem();
  918. if (vlin)
  919. vc_cons[i].d->vc_scan_lines = vlin;
  920. if (clin)
  921. vc_cons[i].d->vc_font.height = clin;
  922. vc_cons[i].d->vc_resize_user = 1;
  923. vc_resize(vc_cons[i].d, cc, ll);
  924. release_console_sem();
  925. }
  926. break;
  927. }
  928. case PIO_FONT: {
  929. if (!perm)
  930. goto eperm;
  931. op.op = KD_FONT_OP_SET;
  932. op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
  933. op.width = 8;
  934. op.height = 0;
  935. op.charcount = 256;
  936. op.data = up;
  937. ret = con_font_op(vc_cons[fg_console].d, &op);
  938. break;
  939. }
  940. case GIO_FONT: {
  941. op.op = KD_FONT_OP_GET;
  942. op.flags = KD_FONT_FLAG_OLD;
  943. op.width = 8;
  944. op.height = 32;
  945. op.charcount = 256;
  946. op.data = up;
  947. ret = con_font_op(vc_cons[fg_console].d, &op);
  948. break;
  949. }
  950. case PIO_CMAP:
  951. if (!perm)
  952. ret = -EPERM;
  953. else
  954. ret = con_set_cmap(up);
  955. break;
  956. case GIO_CMAP:
  957. ret = con_get_cmap(up);
  958. break;
  959. case PIO_FONTX:
  960. case GIO_FONTX:
  961. ret = do_fontx_ioctl(cmd, up, perm, &op);
  962. break;
  963. case PIO_FONTRESET:
  964. {
  965. if (!perm)
  966. goto eperm;
  967. #ifdef BROKEN_GRAPHICS_PROGRAMS
  968. /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
  969. font is not saved. */
  970. ret = -ENOSYS;
  971. break;
  972. #else
  973. {
  974. op.op = KD_FONT_OP_SET_DEFAULT;
  975. op.data = NULL;
  976. ret = con_font_op(vc_cons[fg_console].d, &op);
  977. if (ret)
  978. break;
  979. con_set_default_unimap(vc_cons[fg_console].d);
  980. break;
  981. }
  982. #endif
  983. }
  984. case KDFONTOP: {
  985. if (copy_from_user(&op, up, sizeof(op))) {
  986. ret = -EFAULT;
  987. break;
  988. }
  989. if (!perm && op.op != KD_FONT_OP_GET)
  990. goto eperm;
  991. ret = con_font_op(vc, &op);
  992. if (ret)
  993. break;
  994. if (copy_to_user(up, &op, sizeof(op)))
  995. ret = -EFAULT;
  996. break;
  997. }
  998. case PIO_SCRNMAP:
  999. if (!perm)
  1000. ret = -EPERM;
  1001. else
  1002. ret = con_set_trans_old(up);
  1003. break;
  1004. case GIO_SCRNMAP:
  1005. ret = con_get_trans_old(up);
  1006. break;
  1007. case PIO_UNISCRNMAP:
  1008. if (!perm)
  1009. ret = -EPERM;
  1010. else
  1011. ret = con_set_trans_new(up);
  1012. break;
  1013. case GIO_UNISCRNMAP:
  1014. ret = con_get_trans_new(up);
  1015. break;
  1016. case PIO_UNIMAPCLR:
  1017. { struct unimapinit ui;
  1018. if (!perm)
  1019. goto eperm;
  1020. ret = copy_from_user(&ui, up, sizeof(struct unimapinit));
  1021. if (!ret)
  1022. con_clear_unimap(vc, &ui);
  1023. break;
  1024. }
  1025. case PIO_UNIMAP:
  1026. case GIO_UNIMAP:
  1027. ret = do_unimap_ioctl(cmd, up, perm, vc);
  1028. break;
  1029. case VT_LOCKSWITCH:
  1030. if (!capable(CAP_SYS_TTY_CONFIG))
  1031. goto eperm;
  1032. vt_dont_switch = 1;
  1033. break;
  1034. case VT_UNLOCKSWITCH:
  1035. if (!capable(CAP_SYS_TTY_CONFIG))
  1036. goto eperm;
  1037. vt_dont_switch = 0;
  1038. break;
  1039. case VT_GETHIFONTMASK:
  1040. ret = put_user(vc->vc_hi_font_mask,
  1041. (unsigned short __user *)arg);
  1042. break;
  1043. default:
  1044. ret = -ENOIOCTLCMD;
  1045. }
  1046. out:
  1047. unlock_kernel();
  1048. return ret;
  1049. eperm:
  1050. ret = -EPERM;
  1051. goto out;
  1052. }
  1053. /*
  1054. * Sometimes we want to wait until a particular VT has been activated. We
  1055. * do it in a very simple manner. Everybody waits on a single queue and
  1056. * get woken up at once. Those that are satisfied go on with their business,
  1057. * while those not ready go back to sleep. Seems overkill to add a wait
  1058. * to each vt just for this - usually this does nothing!
  1059. */
  1060. static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue);
  1061. /*
  1062. * Sleeps until a vt is activated, or the task is interrupted. Returns
  1063. * 0 if activation, -EINTR if interrupted by a signal handler.
  1064. */
  1065. int vt_waitactive(int vt)
  1066. {
  1067. int retval;
  1068. DECLARE_WAITQUEUE(wait, current);
  1069. add_wait_queue(&vt_activate_queue, &wait);
  1070. for (;;) {
  1071. retval = 0;
  1072. /*
  1073. * Synchronize with redraw_screen(). By acquiring the console
  1074. * semaphore we make sure that the console switch is completed
  1075. * before we return. If we didn't wait for the semaphore, we
  1076. * could return at a point where fg_console has already been
  1077. * updated, but the console switch hasn't been completed.
  1078. */
  1079. acquire_console_sem();
  1080. set_current_state(TASK_INTERRUPTIBLE);
  1081. if (vt == fg_console) {
  1082. release_console_sem();
  1083. break;
  1084. }
  1085. release_console_sem();
  1086. retval = -ERESTARTNOHAND;
  1087. if (signal_pending(current))
  1088. break;
  1089. schedule();
  1090. }
  1091. remove_wait_queue(&vt_activate_queue, &wait);
  1092. __set_current_state(TASK_RUNNING);
  1093. return retval;
  1094. }
  1095. #define vt_wake_waitactive() wake_up(&vt_activate_queue)
  1096. void reset_vc(struct vc_data *vc)
  1097. {
  1098. vc->vc_mode = KD_TEXT;
  1099. kbd_table[vc->vc_num].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
  1100. vc->vt_mode.mode = VT_AUTO;
  1101. vc->vt_mode.waitv = 0;
  1102. vc->vt_mode.relsig = 0;
  1103. vc->vt_mode.acqsig = 0;
  1104. vc->vt_mode.frsig = 0;
  1105. put_pid(vc->vt_pid);
  1106. vc->vt_pid = NULL;
  1107. vc->vt_newvt = -1;
  1108. if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
  1109. reset_palette(vc);
  1110. }
  1111. void vc_SAK(struct work_struct *work)
  1112. {
  1113. struct vc *vc_con =
  1114. container_of(work, struct vc, SAK_work);
  1115. struct vc_data *vc;
  1116. struct tty_struct *tty;
  1117. acquire_console_sem();
  1118. vc = vc_con->d;
  1119. if (vc) {
  1120. tty = vc->vc_tty;
  1121. /*
  1122. * SAK should also work in all raw modes and reset
  1123. * them properly.
  1124. */
  1125. if (tty)
  1126. __do_SAK(tty);
  1127. reset_vc(vc);
  1128. }
  1129. release_console_sem();
  1130. }
  1131. /*
  1132. * Performs the back end of a vt switch
  1133. */
  1134. static void complete_change_console(struct vc_data *vc)
  1135. {
  1136. unsigned char old_vc_mode;
  1137. last_console = fg_console;
  1138. /*
  1139. * If we're switching, we could be going from KD_GRAPHICS to
  1140. * KD_TEXT mode or vice versa, which means we need to blank or
  1141. * unblank the screen later.
  1142. */
  1143. old_vc_mode = vc_cons[fg_console].d->vc_mode;
  1144. switch_screen(vc);
  1145. /*
  1146. * This can't appear below a successful kill_pid(). If it did,
  1147. * then the *blank_screen operation could occur while X, having
  1148. * received acqsig, is waking up on another processor. This
  1149. * condition can lead to overlapping accesses to the VGA range
  1150. * and the framebuffer (causing system lockups).
  1151. *
  1152. * To account for this we duplicate this code below only if the
  1153. * controlling process is gone and we've called reset_vc.
  1154. */
  1155. if (old_vc_mode != vc->vc_mode) {
  1156. if (vc->vc_mode == KD_TEXT)
  1157. do_unblank_screen(1);
  1158. else
  1159. do_blank_screen(1);
  1160. }
  1161. /*
  1162. * If this new console is under process control, send it a signal
  1163. * telling it that it has acquired. Also check if it has died and
  1164. * clean up (similar to logic employed in change_console())
  1165. */
  1166. if (vc->vt_mode.mode == VT_PROCESS) {
  1167. /*
  1168. * Send the signal as privileged - kill_pid() will
  1169. * tell us if the process has gone or something else
  1170. * is awry
  1171. */
  1172. if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
  1173. /*
  1174. * The controlling process has died, so we revert back to
  1175. * normal operation. In this case, we'll also change back
  1176. * to KD_TEXT mode. I'm not sure if this is strictly correct
  1177. * but it saves the agony when the X server dies and the screen
  1178. * remains blanked due to KD_GRAPHICS! It would be nice to do
  1179. * this outside of VT_PROCESS but there is no single process
  1180. * to account for and tracking tty count may be undesirable.
  1181. */
  1182. reset_vc(vc);
  1183. if (old_vc_mode != vc->vc_mode) {
  1184. if (vc->vc_mode == KD_TEXT)
  1185. do_unblank_screen(1);
  1186. else
  1187. do_blank_screen(1);
  1188. }
  1189. }
  1190. }
  1191. /*
  1192. * Wake anyone waiting for their VT to activate
  1193. */
  1194. vt_wake_waitactive();
  1195. return;
  1196. }
  1197. /*
  1198. * Performs the front-end of a vt switch
  1199. */
  1200. void change_console(struct vc_data *new_vc)
  1201. {
  1202. struct vc_data *vc;
  1203. if (!new_vc || new_vc->vc_num == fg_console || vt_dont_switch)
  1204. return;
  1205. /*
  1206. * If this vt is in process mode, then we need to handshake with
  1207. * that process before switching. Essentially, we store where that
  1208. * vt wants to switch to and wait for it to tell us when it's done
  1209. * (via VT_RELDISP ioctl).
  1210. *
  1211. * We also check to see if the controlling process still exists.
  1212. * If it doesn't, we reset this vt to auto mode and continue.
  1213. * This is a cheap way to track process control. The worst thing
  1214. * that can happen is: we send a signal to a process, it dies, and
  1215. * the switch gets "lost" waiting for a response; hopefully, the
  1216. * user will try again, we'll detect the process is gone (unless
  1217. * the user waits just the right amount of time :-) and revert the
  1218. * vt to auto control.
  1219. */
  1220. vc = vc_cons[fg_console].d;
  1221. if (vc->vt_mode.mode == VT_PROCESS) {
  1222. /*
  1223. * Send the signal as privileged - kill_pid() will
  1224. * tell us if the process has gone or something else
  1225. * is awry.
  1226. *
  1227. * We need to set vt_newvt *before* sending the signal or we
  1228. * have a race.
  1229. */
  1230. vc->vt_newvt = new_vc->vc_num;
  1231. if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
  1232. /*
  1233. * It worked. Mark the vt to switch to and
  1234. * return. The process needs to send us a
  1235. * VT_RELDISP ioctl to complete the switch.
  1236. */
  1237. return;
  1238. }
  1239. /*
  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.
  1247. */
  1248. reset_vc(vc);
  1249. /*
  1250. * Fall through to normal (VT_AUTO) handling of the switch...
  1251. */
  1252. }
  1253. /*
  1254. * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
  1255. */
  1256. if (vc->vc_mode == KD_GRAPHICS)
  1257. return;
  1258. complete_change_console(new_vc);
  1259. }