-
Notifications
You must be signed in to change notification settings - Fork 0
/
termfix.c
47 lines (40 loc) · 1.07 KB
/
termfix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Terminal fixer, based on
* https://gist.github.com/joerick/9e2d244f456c2431619e7063eda62e1d
*
* Restore a terminal messed up by a semi-graphical application such as a
* SDL framebuffer app not cleaning up after itself.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <linux/kd.h>
#include <linux/keyboard.h>
int main(int argc, char** argv) {
char* path = "/dev/tty";
if (argc == 2) {
path = argv[1];
} else if (argc > 2) {
printf("usage: termfix [/path/to/tty]\n");
return 1;
}
int fd = open(path, O_RDWR, 0);
if (fd < 0) {
perror("unable to open tty");
return 1;
}
if (ioctl(fd, VT_UNLOCKSWITCH, 1) < 0) {
perror("warn: ioctl VT_UNLOCKSWITCH failed");
}
if (ioctl(fd, KDSETMODE, KD_TEXT) < 0) {
perror("warn: ioctl KDSETMODE failed");
}
if (ioctl(fd, KDSKBMODE, K_XLATE) < 0) {
perror("warn: ioctl KBSKBMODE failed");
}
return 0;
}