aboutsummaryrefslogtreecommitdiffstats
path: root/sleeping-getty.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-12-10 23:55:26 +0100
committerMattias Andrée <maandree@kth.se>2017-12-10 23:55:26 +0100
commitf7f87b788bdfdaed3e69b60fd9ce9d2c17b06e0a (patch)
tree5ee68c7907baf8666d5d585ae491129ffcfdb6e5 /sleeping-getty.c
parentupdate news and makefile (diff)
downloadsleeping-getty-6bffb9d5a572c06dcb49a23607851059f3d9ba6a.tar.gz
sleeping-getty-6bffb9d5a572c06dcb49a23607851059f3d9ba6a.tar.bz2
sleeping-getty-6bffb9d5a572c06dcb49a23607851059f3d9ba6a.tar.xz
Simplify and cahgne license1.1
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'sleeping-getty.c')
-rw-r--r--sleeping-getty.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/sleeping-getty.c b/sleeping-getty.c
new file mode 100644
index 0000000..25e95a9
--- /dev/null
+++ b/sleeping-getty.c
@@ -0,0 +1,48 @@
+/* See LICENSE file for copyright and license details. */
+#include <linux/vt.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stropts.h>
+#include <unistd.h>
+
+static char *argv0;
+
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: %s vtno getty-command [arguments] ...\n", argv0);
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct vt_stat state;
+ long int tmp;
+ int tty;
+ char *end;
+
+ argv0 = argv[0];
+ if (argc < 3)
+ usage();
+
+ if (!isdigit(argv[1][0]))
+ usage();
+ errno = 0;
+ tmp = strtol(argv[1], &end, 10);
+ if (errno || *end || tmp < 0 || tmp > INT_MAX)
+ usage();
+ tty = (int)tmp;
+
+ if (!ioctl(STDIN_FILENO, (long)VT_GETSTATE, &state))
+ if (state.v_active != tty)
+ ioctl(STDIN_FILENO, (long)VT_WAITACTIVE, tty);
+
+ execvp(argv[2], &argv[2]);
+ fprintf(stderr, "%s: execvp %s: %s\n", argv0, argv[2], strerror(errno));
+ return 1;
+}