vt_ioctl.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  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 = 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 TIOCLINUX:
  358. return tioclinux(tty, arg);
  359. case KIOCSOUND:
  360. if (!perm)
  361. goto eperm;
  362. if (arg)
  363. arg = CLOCK_TICK_RATE / arg;
  364. kd_mksound(arg, 0);
  365. break;
  366. case KDMKTONE:
  367. if (!perm)
  368. goto eperm;
  369. {
  370. unsigned int ticks, count;
  371. /*
  372. * Generate the tone for the appropriate number of ticks.
  373. * If the time is zero, turn off sound ourselves.
  374. */
  375. ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
  376. count = ticks ? (arg & 0xffff) : 0;
  377. if (count)
  378. count = CLOCK_TICK_RATE / count;
  379. kd_mksound(count, ticks);
  380. break;
  381. }
  382. case KDGKBTYPE:
  383. /*
  384. * this is naive.
  385. */
  386. ucval = KB_101;
  387. goto setchar;
  388. /*
  389. * These cannot be implemented on any machine that implements
  390. * ioperm() in user level (such as Alpha PCs) or not at all.
  391. *
  392. * XXX: you should never use these, just call ioperm directly..
  393. */
  394. #ifdef CONFIG_X86
  395. case KDADDIO:
  396. case KDDELIO:
  397. /*
  398. * KDADDIO and KDDELIO may be able to add ports beyond what
  399. * we reject here, but to be safe...
  400. */
  401. if (arg < GPFIRST || arg > GPLAST) {
  402. ret = -EINVAL;
  403. break;
  404. }
  405. ret = sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
  406. break;
  407. case KDENABIO:
  408. case KDDISABIO:
  409. ret = sys_ioperm(GPFIRST, GPNUM,
  410. (cmd == KDENABIO)) ? -ENXIO : 0;
  411. break;
  412. #endif
  413. /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
  414. case KDKBDREP:
  415. {
  416. struct kbd_repeat kbrep;
  417. if (!capable(CAP_SYS_TTY_CONFIG))
  418. goto eperm;
  419. if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) {
  420. ret = -EFAULT;
  421. break;
  422. }
  423. ret = kbd_rate(&kbrep);
  424. if (ret)
  425. break;
  426. if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat)))
  427. ret = -EFAULT;
  428. break;
  429. }
  430. case KDSETMODE:
  431. /*
  432. * currently, setting the mode from KD_TEXT to KD_GRAPHICS
  433. * doesn't do a whole lot. i'm not sure if it should do any
  434. * restoration of modes or what...
  435. *
  436. * XXX It should at least call into the driver, fbdev's definitely
  437. * need to restore their engine state. --BenH
  438. */
  439. if (!perm)
  440. goto eperm;
  441. switch (arg) {
  442. case KD_GRAPHICS:
  443. break;
  444. case KD_TEXT0:
  445. case KD_TEXT1:
  446. arg = KD_TEXT;
  447. case KD_TEXT:
  448. break;
  449. default:
  450. ret = -EINVAL;
  451. goto out;
  452. }
  453. if (vc->vc_mode == (unsigned char) arg)
  454. break;
  455. vc->vc_mode = (unsigned char) arg;
  456. if (console != fg_console)
  457. break;
  458. /*
  459. * explicitly blank/unblank the screen if switching modes
  460. */
  461. acquire_console_sem();
  462. if (arg == KD_TEXT)
  463. do_unblank_screen(1);
  464. else
  465. do_blank_screen(1);
  466. release_console_sem();
  467. break;
  468. case KDGETMODE:
  469. ucval = vc->vc_mode;
  470. goto setint;
  471. case KDMAPDISP:
  472. case KDUNMAPDISP:
  473. /*
  474. * these work like a combination of mmap and KDENABIO.
  475. * this could be easily finished.
  476. */
  477. ret = -EINVAL;
  478. break;
  479. case KDSKBMODE:
  480. if (!perm)
  481. goto eperm;
  482. switch(arg) {
  483. case K_RAW:
  484. kbd->kbdmode = VC_RAW;
  485. break;
  486. case K_MEDIUMRAW:
  487. kbd->kbdmode = VC_MEDIUMRAW;
  488. break;
  489. case K_XLATE:
  490. kbd->kbdmode = VC_XLATE;
  491. compute_shiftstate();
  492. break;
  493. case K_UNICODE:
  494. kbd->kbdmode = VC_UNICODE;
  495. compute_shiftstate();
  496. break;
  497. default:
  498. ret = -EINVAL;
  499. goto out;
  500. }
  501. tty_ldisc_flush(tty);
  502. break;
  503. case KDGKBMODE:
  504. ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW :
  505. (kbd->kbdmode == VC_MEDIUMRAW) ? K_MEDIUMRAW :
  506. (kbd->kbdmode == VC_UNICODE) ? K_UNICODE :
  507. K_XLATE);
  508. goto setint;
  509. /* this could be folded into KDSKBMODE, but for compatibility
  510. reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
  511. case KDSKBMETA:
  512. switch(arg) {
  513. case K_METABIT:
  514. clr_vc_kbd_mode(kbd, VC_META);
  515. break;
  516. case K_ESCPREFIX:
  517. set_vc_kbd_mode(kbd, VC_META);
  518. break;
  519. default:
  520. ret = -EINVAL;
  521. }
  522. break;
  523. case KDGKBMETA:
  524. ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT);
  525. setint:
  526. ret = put_user(ucval, (int __user *)arg);
  527. break;
  528. case KDGETKEYCODE:
  529. case KDSETKEYCODE:
  530. if(!capable(CAP_SYS_TTY_CONFIG))
  531. perm = 0;
  532. ret = do_kbkeycode_ioctl(cmd, up, perm);
  533. break;
  534. case KDGKBENT:
  535. case KDSKBENT:
  536. ret = do_kdsk_ioctl(cmd, up, perm, kbd);
  537. break;
  538. case KDGKBSENT:
  539. case KDSKBSENT:
  540. ret = do_kdgkb_ioctl(cmd, up, perm);
  541. break;
  542. case KDGKBDIACR:
  543. {
  544. struct kbdiacrs __user *a = up;
  545. struct kbdiacr diacr;
  546. int i;
  547. if (put_user(accent_table_size, &a->kb_cnt)) {
  548. ret = -EFAULT;
  549. break;
  550. }
  551. for (i = 0; i < accent_table_size; i++) {
  552. diacr.diacr = conv_uni_to_8bit(accent_table[i].diacr);
  553. diacr.base = conv_uni_to_8bit(accent_table[i].base);
  554. diacr.result = conv_uni_to_8bit(accent_table[i].result);
  555. if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) {
  556. ret = -EFAULT;
  557. break;
  558. }
  559. }
  560. break;
  561. }
  562. case KDGKBDIACRUC:
  563. {
  564. struct kbdiacrsuc __user *a = up;
  565. if (put_user(accent_table_size, &a->kb_cnt))
  566. ret = -EFAULT;
  567. else if (copy_to_user(a->kbdiacruc, accent_table,
  568. accent_table_size*sizeof(struct kbdiacruc)))
  569. ret = -EFAULT;
  570. break;
  571. }
  572. case KDSKBDIACR:
  573. {
  574. struct kbdiacrs __user *a = up;
  575. struct kbdiacr diacr;
  576. unsigned int ct;
  577. int i;
  578. if (!perm)
  579. goto eperm;
  580. if (get_user(ct,&a->kb_cnt)) {
  581. ret = -EFAULT;
  582. break;
  583. }
  584. if (ct >= MAX_DIACR) {
  585. ret = -EINVAL;
  586. break;
  587. }
  588. accent_table_size = ct;
  589. for (i = 0; i < ct; i++) {
  590. if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) {
  591. ret = -EFAULT;
  592. break;
  593. }
  594. accent_table[i].diacr = conv_8bit_to_uni(diacr.diacr);
  595. accent_table[i].base = conv_8bit_to_uni(diacr.base);
  596. accent_table[i].result = conv_8bit_to_uni(diacr.result);
  597. }
  598. break;
  599. }
  600. case KDSKBDIACRUC:
  601. {
  602. struct kbdiacrsuc __user *a = up;
  603. unsigned int ct;
  604. if (!perm)
  605. goto eperm;
  606. if (get_user(ct,&a->kb_cnt)) {
  607. ret = -EFAULT;
  608. break;
  609. }
  610. if (ct >= MAX_DIACR) {
  611. ret = -EINVAL;
  612. break;
  613. }
  614. accent_table_size = ct;
  615. if (copy_from_user(accent_table, a->kbdiacruc, ct*sizeof(struct kbdiacruc)))
  616. ret = -EFAULT;
  617. break;
  618. }
  619. /* the ioctls below read/set the flags usually shown in the leds */
  620. /* don't use them - they will go away without warning */
  621. case KDGKBLED:
  622. ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4);
  623. goto setchar;
  624. case KDSKBLED:
  625. if (!perm)
  626. goto eperm;
  627. if (arg & ~0x77) {
  628. ret = -EINVAL;
  629. break;
  630. }
  631. kbd->ledflagstate = (arg & 7);
  632. kbd->default_ledflagstate = ((arg >> 4) & 7);
  633. set_leds();
  634. break;
  635. /* the ioctls below only set the lights, not the functions */
  636. /* for those, see KDGKBLED and KDSKBLED above */
  637. case KDGETLED:
  638. ucval = getledstate();
  639. setchar:
  640. ret = put_user(ucval, (char __user *)arg);
  641. break;
  642. case KDSETLED:
  643. if (!perm)
  644. goto eperm;
  645. setledstate(kbd, arg);
  646. break;
  647. /*
  648. * A process can indicate its willingness to accept signals
  649. * generated by pressing an appropriate key combination.
  650. * Thus, one can have a daemon that e.g. spawns a new console
  651. * upon a keypress and then changes to it.
  652. * See also the kbrequest field of inittab(5).
  653. */
  654. case KDSIGACCEPT:
  655. {
  656. if (!perm || !capable(CAP_KILL))
  657. goto eperm;
  658. if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
  659. ret = -EINVAL;
  660. else {
  661. spin_lock_irq(&vt_spawn_con.lock);
  662. put_pid(vt_spawn_con.pid);
  663. vt_spawn_con.pid = get_pid(task_pid(current));
  664. vt_spawn_con.sig = arg;
  665. spin_unlock_irq(&vt_spawn_con.lock);
  666. }
  667. break;
  668. }
  669. case VT_SETMODE:
  670. {
  671. struct vt_mode tmp;
  672. if (!perm)
  673. goto eperm;
  674. if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) {
  675. ret = -EFAULT;
  676. goto out;
  677. }
  678. if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) {
  679. ret = -EINVAL;
  680. goto out;
  681. }
  682. acquire_console_sem();
  683. vc->vt_mode = tmp;
  684. /* the frsig is ignored, so we set it to 0 */
  685. vc->vt_mode.frsig = 0;
  686. put_pid(vc->vt_pid);
  687. vc->vt_pid = get_pid(task_pid(current));
  688. /* no switch is required -- saw@shade.msu.ru */
  689. vc->vt_newvt = -1;
  690. release_console_sem();
  691. break;
  692. }
  693. case VT_GETMODE:
  694. {
  695. struct vt_mode tmp;
  696. int rc;
  697. acquire_console_sem();
  698. memcpy(&tmp, &vc->vt_mode, sizeof(struct vt_mode));
  699. release_console_sem();
  700. rc = copy_to_user(up, &tmp, sizeof(struct vt_mode));
  701. if (rc)
  702. ret = -EFAULT;
  703. break;
  704. }
  705. /*
  706. * Returns global vt state. Note that VT 0 is always open, since
  707. * it's an alias for the current VT, and people can't use it here.
  708. * We cannot return state for more than 16 VTs, since v_state is short.
  709. */
  710. case VT_GETSTATE:
  711. {
  712. struct vt_stat __user *vtstat = up;
  713. unsigned short state, mask;
  714. if (put_user(fg_console + 1, &vtstat->v_active))
  715. ret = -EFAULT;
  716. else {
  717. state = 1; /* /dev/tty0 is always open */
  718. for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask;
  719. ++i, mask <<= 1)
  720. if (VT_IS_IN_USE(i))
  721. state |= mask;
  722. ret = put_user(state, &vtstat->v_state);
  723. }
  724. break;
  725. }
  726. /*
  727. * Returns the first available (non-opened) console.
  728. */
  729. case VT_OPENQRY:
  730. for (i = 0; i < MAX_NR_CONSOLES; ++i)
  731. if (! VT_IS_IN_USE(i))
  732. break;
  733. ucval = i < MAX_NR_CONSOLES ? (i+1) : -1;
  734. goto setint;
  735. /*
  736. * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
  737. * with num >= 1 (switches to vt 0, our console, are not allowed, just
  738. * to preserve sanity).
  739. */
  740. case VT_ACTIVATE:
  741. if (!perm)
  742. goto eperm;
  743. if (arg == 0 || arg > MAX_NR_CONSOLES)
  744. ret = -ENXIO;
  745. else {
  746. arg--;
  747. acquire_console_sem();
  748. ret = vc_allocate(arg);
  749. release_console_sem();
  750. if (ret)
  751. break;
  752. set_console(arg);
  753. }
  754. break;
  755. /*
  756. * wait until the specified VT has been activated
  757. */
  758. case VT_WAITACTIVE:
  759. if (!perm)
  760. goto eperm;
  761. if (arg == 0 || arg > MAX_NR_CONSOLES)
  762. ret = -ENXIO;
  763. else
  764. ret = vt_waitactive(arg - 1);
  765. break;
  766. /*
  767. * If a vt is under process control, the kernel will not switch to it
  768. * immediately, but postpone the operation until the process calls this
  769. * ioctl, allowing the switch to complete.
  770. *
  771. * According to the X sources this is the behavior:
  772. * 0: pending switch-from not OK
  773. * 1: pending switch-from OK
  774. * 2: completed switch-to OK
  775. */
  776. case VT_RELDISP:
  777. if (!perm)
  778. goto eperm;
  779. if (vc->vt_mode.mode != VT_PROCESS) {
  780. ret = -EINVAL;
  781. break;
  782. }
  783. /*
  784. * Switching-from response
  785. */
  786. acquire_console_sem();
  787. if (vc->vt_newvt >= 0) {
  788. if (arg == 0)
  789. /*
  790. * Switch disallowed, so forget we were trying
  791. * to do it.
  792. */
  793. vc->vt_newvt = -1;
  794. else {
  795. /*
  796. * The current vt has been released, so
  797. * complete the switch.
  798. */
  799. int newvt;
  800. newvt = vc->vt_newvt;
  801. vc->vt_newvt = -1;
  802. ret = vc_allocate(newvt);
  803. if (ret) {
  804. release_console_sem();
  805. break;
  806. }
  807. /*
  808. * When we actually do the console switch,
  809. * make sure we are atomic with respect to
  810. * other console switches..
  811. */
  812. complete_change_console(vc_cons[newvt].d);
  813. }
  814. } else {
  815. /*
  816. * Switched-to response
  817. */
  818. /*
  819. * If it's just an ACK, ignore it
  820. */
  821. if (arg != VT_ACKACQ)
  822. ret = -EINVAL;
  823. }
  824. release_console_sem();
  825. break;
  826. /*
  827. * Disallocate memory associated to VT (but leave VT1)
  828. */
  829. case VT_DISALLOCATE:
  830. if (arg > MAX_NR_CONSOLES) {
  831. ret = -ENXIO;
  832. break;
  833. }
  834. if (arg == 0) {
  835. /* deallocate all unused consoles, but leave 0 */
  836. acquire_console_sem();
  837. for (i=1; i<MAX_NR_CONSOLES; i++)
  838. if (! VT_BUSY(i))
  839. vc_deallocate(i);
  840. release_console_sem();
  841. } else {
  842. /* deallocate a single console, if possible */
  843. arg--;
  844. if (VT_BUSY(arg))
  845. ret = -EBUSY;
  846. else if (arg) { /* leave 0 */
  847. acquire_console_sem();
  848. vc_deallocate(arg);
  849. release_console_sem();
  850. }
  851. }
  852. break;
  853. case VT_RESIZE:
  854. {
  855. struct vt_sizes __user *vtsizes = up;
  856. struct vc_data *vc;
  857. ushort ll,cc;
  858. if (!perm)
  859. goto eperm;
  860. if (get_user(ll, &vtsizes->v_rows) ||
  861. get_user(cc, &vtsizes->v_cols))
  862. ret = -EFAULT;
  863. else {
  864. acquire_console_sem();
  865. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  866. vc = vc_cons[i].d;
  867. if (vc) {
  868. vc->vc_resize_user = 1;
  869. vc_resize(vc_cons[i].d, cc, ll);
  870. }
  871. }
  872. release_console_sem();
  873. }
  874. break;
  875. }
  876. case VT_RESIZEX:
  877. {
  878. struct vt_consize __user *vtconsize = up;
  879. ushort ll,cc,vlin,clin,vcol,ccol;
  880. if (!perm)
  881. goto eperm;
  882. if (!access_ok(VERIFY_READ, vtconsize,
  883. sizeof(struct vt_consize))) {
  884. ret = -EFAULT;
  885. break;
  886. }
  887. /* FIXME: Should check the copies properly */
  888. __get_user(ll, &vtconsize->v_rows);
  889. __get_user(cc, &vtconsize->v_cols);
  890. __get_user(vlin, &vtconsize->v_vlin);
  891. __get_user(clin, &vtconsize->v_clin);
  892. __get_user(vcol, &vtconsize->v_vcol);
  893. __get_user(ccol, &vtconsize->v_ccol);
  894. vlin = vlin ? vlin : vc->vc_scan_lines;
  895. if (clin) {
  896. if (ll) {
  897. if (ll != vlin/clin) {
  898. /* Parameters don't add up */
  899. ret = -EINVAL;
  900. break;
  901. }
  902. } else
  903. ll = vlin/clin;
  904. }
  905. if (vcol && ccol) {
  906. if (cc) {
  907. if (cc != vcol/ccol) {
  908. ret = -EINVAL;
  909. break;
  910. }
  911. } else
  912. cc = vcol/ccol;
  913. }
  914. if (clin > 32) {
  915. ret = -EINVAL;
  916. break;
  917. }
  918. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  919. if (!vc_cons[i].d)
  920. continue;
  921. acquire_console_sem();
  922. if (vlin)
  923. vc_cons[i].d->vc_scan_lines = vlin;
  924. if (clin)
  925. vc_cons[i].d->vc_font.height = clin;
  926. vc_cons[i].d->vc_resize_user = 1;
  927. vc_resize(vc_cons[i].d, cc, ll);
  928. release_console_sem();
  929. }
  930. break;
  931. }
  932. case PIO_FONT: {
  933. if (!perm)
  934. goto eperm;
  935. op.op = KD_FONT_OP_SET;
  936. op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
  937. op.width = 8;
  938. op.height = 0;
  939. op.charcount = 256;
  940. op.data = up;
  941. ret = con_font_op(vc_cons[fg_console].d, &op);
  942. break;
  943. }
  944. case GIO_FONT: {
  945. op.op = KD_FONT_OP_GET;
  946. op.flags = KD_FONT_FLAG_OLD;
  947. op.width = 8;
  948. op.height = 32;
  949. op.charcount = 256;
  950. op.data = up;
  951. ret = con_font_op(vc_cons[fg_console].d, &op);
  952. break;
  953. }
  954. case PIO_CMAP:
  955. if (!perm)
  956. ret = -EPERM;
  957. else
  958. ret = con_set_cmap(up);
  959. break;
  960. case GIO_CMAP:
  961. ret = con_get_cmap(up);
  962. break;
  963. case PIO_FONTX:
  964. case GIO_FONTX:
  965. ret = do_fontx_ioctl(cmd, up, perm, &op);
  966. break;
  967. case PIO_FONTRESET:
  968. {
  969. if (!perm)
  970. goto eperm;
  971. #ifdef BROKEN_GRAPHICS_PROGRAMS
  972. /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
  973. font is not saved. */
  974. ret = -ENOSYS;
  975. break;
  976. #else
  977. {
  978. op.op = KD_FONT_OP_SET_DEFAULT;
  979. op.data = NULL;
  980. ret = con_font_op(vc_cons[fg_console].d, &op);
  981. if (ret)
  982. break;
  983. con_set_default_unimap(vc_cons[fg_console].d);
  984. break;
  985. }
  986. #endif
  987. }
  988. case KDFONTOP: {
  989. if (copy_from_user(&op, up, sizeof(op))) {
  990. ret = -EFAULT;
  991. break;
  992. }
  993. if (!perm && op.op != KD_FONT_OP_GET)
  994. goto eperm;
  995. ret = con_font_op(vc, &op);
  996. if (ret)
  997. break;
  998. if (copy_to_user(up, &op, sizeof(op)))
  999. ret = -EFAULT;
  1000. break;
  1001. }
  1002. case PIO_SCRNMAP:
  1003. if (!perm)
  1004. ret = -EPERM;
  1005. else
  1006. ret = con_set_trans_old(up);
  1007. break;
  1008. case GIO_SCRNMAP:
  1009. ret = con_get_trans_old(up);
  1010. break;
  1011. case PIO_UNISCRNMAP:
  1012. if (!perm)
  1013. ret = -EPERM;
  1014. else
  1015. ret = con_set_trans_new(up);
  1016. break;
  1017. case GIO_UNISCRNMAP:
  1018. ret = con_get_trans_new(up);
  1019. break;
  1020. case PIO_UNIMAPCLR:
  1021. { struct unimapinit ui;
  1022. if (!perm)
  1023. goto eperm;
  1024. ret = copy_from_user(&ui, up, sizeof(struct unimapinit));
  1025. if (!ret)
  1026. con_clear_unimap(vc, &ui);
  1027. break;
  1028. }
  1029. case PIO_UNIMAP:
  1030. case GIO_UNIMAP:
  1031. ret = do_unimap_ioctl(cmd, up, perm, vc);
  1032. break;
  1033. case VT_LOCKSWITCH:
  1034. if (!capable(CAP_SYS_TTY_CONFIG))
  1035. goto eperm;
  1036. vt_dont_switch = 1;
  1037. break;
  1038. case VT_UNLOCKSWITCH:
  1039. if (!capable(CAP_SYS_TTY_CONFIG))
  1040. goto eperm;
  1041. vt_dont_switch = 0;
  1042. break;
  1043. case VT_GETHIFONTMASK:
  1044. ret = put_user(vc->vc_hi_font_mask,
  1045. (unsigned short __user *)arg);
  1046. break;
  1047. default:
  1048. ret = -ENOIOCTLCMD;
  1049. }
  1050. out:
  1051. unlock_kernel();
  1052. return ret;
  1053. eperm:
  1054. ret = -EPERM;
  1055. goto out;
  1056. }
  1057. /*
  1058. * Sometimes we want to wait until a particular VT has been activated. We
  1059. * do it in a very simple manner. Everybody waits on a single queue and
  1060. * get woken up at once. Those that are satisfied go on with their business,
  1061. * while those not ready go back to sleep. Seems overkill to add a wait
  1062. * to each vt just for this - usually this does nothing!
  1063. */
  1064. static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue);
  1065. /*
  1066. * Sleeps until a vt is activated, or the task is interrupted. Returns
  1067. * 0 if activation, -EINTR if interrupted by a signal handler.
  1068. */
  1069. int vt_waitactive(int vt)
  1070. {
  1071. int retval;
  1072. DECLARE_WAITQUEUE(wait, current);
  1073. add_wait_queue(&vt_activate_queue, &wait);
  1074. for (;;) {
  1075. retval = 0;
  1076. /*
  1077. * Synchronize with redraw_screen(). By acquiring the console
  1078. * semaphore we make sure that the console switch is completed
  1079. * before we return. If we didn't wait for the semaphore, we
  1080. * could return at a point where fg_console has already been
  1081. * updated, but the console switch hasn't been completed.
  1082. */
  1083. acquire_console_sem();
  1084. set_current_state(TASK_INTERRUPTIBLE);
  1085. if (vt == fg_console) {
  1086. release_console_sem();
  1087. break;
  1088. }
  1089. release_console_sem();
  1090. retval = -ERESTARTNOHAND;
  1091. if (signal_pending(current))
  1092. break;
  1093. schedule();
  1094. }
  1095. remove_wait_queue(&vt_activate_queue, &wait);
  1096. __set_current_state(TASK_RUNNING);
  1097. return retval;
  1098. }
  1099. #define vt_wake_waitactive() wake_up(&vt_activate_queue)
  1100. void reset_vc(struct vc_data *vc)
  1101. {
  1102. vc->vc_mode = KD_TEXT;
  1103. kbd_table[vc->vc_num].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
  1104. vc->vt_mode.mode = VT_AUTO;
  1105. vc->vt_mode.waitv = 0;
  1106. vc->vt_mode.relsig = 0;
  1107. vc->vt_mode.acqsig = 0;
  1108. vc->vt_mode.frsig = 0;
  1109. put_pid(vc->vt_pid);
  1110. vc->vt_pid = NULL;
  1111. vc->vt_newvt = -1;
  1112. if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
  1113. reset_palette(vc);
  1114. }
  1115. void vc_SAK(struct work_struct *work)
  1116. {
  1117. struct vc *vc_con =
  1118. container_of(work, struct vc, SAK_work);
  1119. struct vc_data *vc;
  1120. struct tty_struct *tty;
  1121. acquire_console_sem();
  1122. vc = vc_con->d;
  1123. if (vc) {
  1124. tty = vc->vc_tty;
  1125. /*
  1126. * SAK should also work in all raw modes and reset
  1127. * them properly.
  1128. */
  1129. if (tty)
  1130. __do_SAK(tty);
  1131. reset_vc(vc);
  1132. }
  1133. release_console_sem();
  1134. }
  1135. /*
  1136. * Performs the back end of a vt switch
  1137. */
  1138. static void complete_change_console(struct vc_data *vc)
  1139. {
  1140. unsigned char old_vc_mode;
  1141. last_console = fg_console;
  1142. /*
  1143. * If we're switching, we could be going from KD_GRAPHICS to
  1144. * KD_TEXT mode or vice versa, which means we need to blank or
  1145. * unblank the screen later.
  1146. */
  1147. old_vc_mode = vc_cons[fg_console].d->vc_mode;
  1148. switch_screen(vc);
  1149. /*
  1150. * This can't appear below a successful kill_pid(). If it did,
  1151. * then the *blank_screen operation could occur while X, having
  1152. * received acqsig, is waking up on another processor. This
  1153. * condition can lead to overlapping accesses to the VGA range
  1154. * and the framebuffer (causing system lockups).
  1155. *
  1156. * To account for this we duplicate this code below only if the
  1157. * controlling process is gone and we've called reset_vc.
  1158. */
  1159. if (old_vc_mode != vc->vc_mode) {
  1160. if (vc->vc_mode == KD_TEXT)
  1161. do_unblank_screen(1);
  1162. else
  1163. do_blank_screen(1);
  1164. }
  1165. /*
  1166. * If this new console is under process control, send it a signal
  1167. * telling it that it has acquired. Also check if it has died and
  1168. * clean up (similar to logic employed in change_console())
  1169. */
  1170. if (vc->vt_mode.mode == VT_PROCESS) {
  1171. /*
  1172. * Send the signal as privileged - kill_pid() will
  1173. * tell us if the process has gone or something else
  1174. * is awry
  1175. */
  1176. if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
  1177. /*
  1178. * The controlling process has died, so we revert back to
  1179. * normal operation. In this case, we'll also change back
  1180. * to KD_TEXT mode. I'm not sure if this is strictly correct
  1181. * but it saves the agony when the X server dies and the screen
  1182. * remains blanked due to KD_GRAPHICS! It would be nice to do
  1183. * this outside of VT_PROCESS but there is no single process
  1184. * to account for and tracking tty count may be undesirable.
  1185. */
  1186. reset_vc(vc);
  1187. if (old_vc_mode != vc->vc_mode) {
  1188. if (vc->vc_mode == KD_TEXT)
  1189. do_unblank_screen(1);
  1190. else
  1191. do_blank_screen(1);
  1192. }
  1193. }
  1194. }
  1195. /*
  1196. * Wake anyone waiting for their VT to activate
  1197. */
  1198. vt_wake_waitactive();
  1199. return;
  1200. }
  1201. /*
  1202. * Performs the front-end of a vt switch
  1203. */
  1204. void change_console(struct vc_data *new_vc)
  1205. {
  1206. struct vc_data *vc;
  1207. if (!new_vc || new_vc->vc_num == fg_console || vt_dont_switch)
  1208. return;
  1209. /*
  1210. * If this vt is in process mode, then we need to handshake with
  1211. * that process before switching. Essentially, we store where that
  1212. * vt wants to switch to and wait for it to tell us when it's done
  1213. * (via VT_RELDISP ioctl).
  1214. *
  1215. * We also check to see if the controlling process still exists.
  1216. * If it doesn't, we reset this vt to auto mode and continue.
  1217. * This is a cheap way to track process control. The worst thing
  1218. * that can happen is: we send a signal to a process, it dies, and
  1219. * the switch gets "lost" waiting for a response; hopefully, the
  1220. * user will try again, we'll detect the process is gone (unless
  1221. * the user waits just the right amount of time :-) and revert the
  1222. * vt to auto control.
  1223. */
  1224. vc = vc_cons[fg_console].d;
  1225. if (vc->vt_mode.mode == VT_PROCESS) {
  1226. /*
  1227. * Send the signal as privileged - kill_pid() will
  1228. * tell us if the process has gone or something else
  1229. * is awry.
  1230. *
  1231. * We need to set vt_newvt *before* sending the signal or we
  1232. * have a race.
  1233. */
  1234. vc->vt_newvt = new_vc->vc_num;
  1235. if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
  1236. /*
  1237. * It worked. Mark the vt to switch to and
  1238. * return. The process needs to send us a
  1239. * VT_RELDISP ioctl to complete the switch.
  1240. */
  1241. return;
  1242. }
  1243. /*
  1244. * The controlling process has died, so we revert back to
  1245. * normal operation. In this case, we'll also change back
  1246. * to KD_TEXT mode. I'm not sure if this is strictly correct
  1247. * but it saves the agony when the X server dies and the screen
  1248. * remains blanked due to KD_GRAPHICS! It would be nice to do
  1249. * this outside of VT_PROCESS but there is no single process
  1250. * to account for and tracking tty count may be undesirable.
  1251. */
  1252. reset_vc(vc);
  1253. /*
  1254. * Fall through to normal (VT_AUTO) handling of the switch...
  1255. */
  1256. }
  1257. /*
  1258. * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
  1259. */
  1260. if (vc->vc_mode == KD_GRAPHICS)
  1261. return;
  1262. complete_change_console(new_vc);
  1263. }