morpheus-base

morpheus base system
git clone git://git.2f30.org/morpheus-base.git
Log | Files | Refs

vtallow.c (899B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/types.h>
      3 #include <sys/stat.h>
      4 #include <sys/ioctl.h>
      5 
      6 #include <fcntl.h>
      7 #include <stdio.h>
      8 #include <string.h>
      9 #include <unistd.h>
     10 
     11 #include "util.h"
     12 
     13 #define CONSOLE "/dev/console"
     14 
     15 #define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
     16 #define VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
     17 
     18 static void
     19 usage(void)
     20 {
     21 	eprintf("usage: vtallow n | y\n");
     22 }
     23 
     24 int
     25 main(int argc, char *argv[])
     26 {
     27 	int fd;
     28 	int allow;
     29 
     30 	ARGBEGIN {
     31 	default:
     32 		usage();
     33 	} ARGEND;
     34 
     35 	if (argc != 1)
     36 		usage();
     37 
     38 	if (!strcmp(argv[0], "y"))
     39 		allow = 1;
     40 	else if (!strcmp(argv[0], "n"))
     41 		allow = 0;
     42 	else
     43 		usage();
     44 
     45 	if ((fd = open(CONSOLE, O_WRONLY)) < 0)
     46 		eprintf("open %s:", CONSOLE);
     47 	if (ioctl(fd, allow ? VT_UNLOCKSWITCH : VT_LOCKSWITCH) < 0)
     48 		eprintf("cannot %s VT switch:",
     49 			allow ? "unlock" : "lock");
     50 	close(fd);
     51 	return 0;
     52 }