vt_ioctl.c 31 KB

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