aboutsummaryrefslogtreecommitdiffstats
path: root/vtchs.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-10-19 20:06:26 +0200
committerMattias Andrée <maandree@kth.se>2017-10-19 20:06:26 +0200
commite06ed443542d3fbd8a070e08d275db10bec9d353 (patch)
tree62776742bcb8b5aec1d28d604092bc750f0414c6 /vtchs.c
parentm build system fix (diff)
downloadvtchs-e06ed443542d3fbd8a070e08d275db10bec9d353.tar.gz
vtchs-e06ed443542d3fbd8a070e08d275db10bec9d353.tar.bz2
vtchs-e06ed443542d3fbd8a070e08d275db10bec9d353.tar.xz
Rewrite and relicense
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'vtchs.c')
-rw-r--r--vtchs.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/vtchs.c b/vtchs.c
new file mode 100644
index 0000000..b2e67e0
--- /dev/null
+++ b/vtchs.c
@@ -0,0 +1,45 @@
+/* See LICENSE file for copyright and license details. */
+#include <linux/vt.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stropts.h>
+#include <unistd.h>
+
+#define VT(OP, ARG) vt(OP, ARG, #OP)
+
+static char *argv0;
+
+static void
+vt(int op, void *arg, const char *opstr)
+{
+ if (ioctl(STDIN_FILENO, op, arg) == -1) {
+ fprintf(stderr, "%s: ioctl <stdin> %s: %s\n", argv0, opstr, strerror(errno));
+ exit(1);
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct vt_event e;
+ struct vt_stat s;
+
+ argv0 = *argv++, argc--;
+ if (argc != (*argv && !strcmp(*argv, "=="))) {
+ fprintf(stderr, "usage: %s\n", argv0);
+ exit(1);
+ }
+
+ VT(VT_GETSTATE, &s);
+ printf("%u\n", s.v_active);
+
+ e.event = VT_EVENT_SWITCH;
+ for (;;) {
+ VT(VT_WAITEVENT, &e);
+ printf("%u\n", e.newev);
+ }
+
+ return 0;
+}