[hackers] [ubase] Add vtallow(1) to enable or disable VT switch || sin
commit 4269d523e2c5cc65c89e5340a55febe72c3d3f49
Author: sin <sin_AT_2f30.org>
Date: Fri Dec 5 15:04:37 2014 +0000
Add vtallow(1) to enable or disable VT switch
diff --git a/Makefile b/Makefile
index 9f070bf..a640f50 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -82,6 +82,7 @@ BIN = \
umount \
unshare \
uptime \
+ vtallow \
watch \
who
diff --git a/vtallow.c b/vtallow.c
new file mode 100644
index 0000000..03d67a5
--- /dev/null
+++ b/vtallow.c
_AT_@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "util.h"
+
+#define CONSOLE "/dev/console"
+
+#define VT_LOCKSWITCH 0x560B /* disallow vt switching */
+#define VT_UNLOCKSWITCH 0x560C /* allow vt switching */
+
+static void
+usage(void)
+{
+ eprintf("usage: vtallow n|y\n");
+}
+
+int
+main(int argc, char *argv[])
+{
+ int fd;
+ int allow;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc != 1)
+ usage();
+
+ if (!strcmp(argv[0], "y"))
+ allow = 1;
+ else if (!strcmp(argv[0], "n"))
+ allow = 0;
+ else
+ usage();
+
+ if ((fd = open(CONSOLE, O_WRONLY)) < 0)
+ eprintf("open %s:", CONSOLE);
+ if (ioctl(fd, allow ? VT_UNLOCKSWITCH : VT_LOCKSWITCH) < 0)
+ eprintf("cannot %s VT switch:",
+ allow ? "enable" : "disable");
+ close(fd);
+ return 0;
+}
Received on Fri Dec 05 2014 - 16:16:45 CET
This archive was generated by hypermail 2.3.0
: Fri Dec 05 2014 - 16:24:08 CET