SHARE
TWEET

Untitled

a guest May 11th, 2012 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <fcntl.h>
  5.  
  6. #include <sys/ioctl.h>
  7. #include <sys/vt.h>
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.     int fd;
  12.  
  13.     unsigned char vtnum;
  14.     bool vtlock;
  15.    
  16.     if (argc < 3) {
  17.         fprintf(stderr, "Usage: vt_set_lock <vtnum> <lock>\n"
  18.                         "       (use numeric int/bool values)\n");
  19.         exit(EXIT_FAILURE);
  20.     }
  21.  
  22.     fd = open("/dev/tty0", O_RDWR);
  23.     if (fd < 0) {
  24.         perror("/dev/tty");
  25.         exit(EXIT_FAILURE);
  26.     }
  27.  
  28.     vtnum = *argv[1]-'0';
  29.     vtlock = !!(*argv[2]-'0');
  30.  
  31.     /* switch */
  32.     if (ioctl(fd, VT_UNLOCKSWITCH, 1) < 0) {
  33.         perror("VT_UNLOCKSWITCH");
  34.         exit(EXIT_FAILURE);
  35.     }
  36.     if (ioctl(fd, VT_ACTIVATE, vtnum) < 0) {
  37.         perror("VT_ACTIVATE");
  38.         exit(EXIT_FAILURE);
  39.     }
  40.  
  41.     /* lock */
  42.     if (vtlock) {
  43.         if (ioctl(fd, VT_LOCKSWITCH, 1) < 0) {
  44.             perror("VT_LOCKSWITCH");
  45.             exit(EXIT_FAILURE);
  46.         }
  47.     } else {
  48.         if (ioctl(fd, VT_UNLOCKSWITCH, 1) < 0) {
  49.             perror("VT_UNLOCKSWITCH");
  50.             exit(EXIT_FAILURE);
  51.         }
  52.     }
  53.  
  54.     return 0;
  55. }
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