termfix.c 689 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <sys/ioctl.h>
  2. #include <errno.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <linux/vt.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <linux/kd.h>
  10. #include <linux/keyboard.h>
  11. int main(int argc, char** argv) {
  12. if (argc != 2) {
  13. printf("usage: termfix /dev/ttyX\n");
  14. return 2;
  15. }
  16. int fd = open(argv[1], O_RDWR, 0);
  17. int res = ioctl(fd, VT_UNLOCKSWITCH, 1);
  18. if (res != 0) {
  19. perror("ioctl VT_UNLOCKSWITCH failed");
  20. return 3;
  21. }
  22. ioctl(fd, KDSETMODE, KD_TEXT);
  23. if (res != 0) {
  24. perror("ioctl KDSETMODE failed");
  25. return 3;
  26. }
  27. printf("Success\n");
  28. return res;
  29. }