SHARE
TWEET

Untitled

a guest Feb 11th, 2011 154 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* chvt.c - change virtual terminal for [k]freebsd
  2.    Copyright (C) 2009 Werner Koch
  3.  
  4.    This file is free software; as a special exception the author gives
  5.    unlimited permission to copy and/or distribute it, with or without
  6.    modifications, as long as this notice is preserved.
  7.  
  8.    This file is distributed in the hope that it will be useful, but
  9.    WITHOUT ANY WARRANTY, to the extent permitted by law; without even
  10.    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11.    PURPOSE.  */
  12.  
  13. #include <sys/consio.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/types.h>
  16.  
  17. #include <err.h>
  18. #include <errno.h>
  19. #include <fcntl.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. int
  25. main(int argc, char *argv[])
  26. {
  27.         int fd, screen;
  28.  
  29.         if (argc < 1 || argc > 2) {
  30.                 fprintf(stderr, "usage: %s [VT number] [</dev/ttyvN]\n", argv[0]);
  31.                 return 1;
  32.         }
  33.  
  34.         if ((fd = open("/dev/console", O_WRONLY, 0)) < 0)
  35.                 fd = fileno(stdin);
  36.  
  37.         if (argc == 1) {
  38.                 if (ioctl(fd, VT_GETACTIVE, &screen))
  39.                         err(errno, "VT_GETACTIVE failed");
  40.                 warnx("active VT = %d", screen);
  41.                 return 0;
  42.         }
  43.  
  44.         sscanf(argv[1], "%d", &screen);
  45.         if (screen < 1) {
  46.                 warnx("invalid VT = %d", screen);
  47.                 return 1;
  48.         }
  49.  
  50.         if (ioctl(fd, VT_ACTIVATE, screen))
  51.                 err(errno, "VT_ACTIVATE failed");
  52.  
  53.         return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top