diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-11-06 23:50:23 -0500 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-11-06 23:50:23 -0500 |
commit | 4a21921acf313c65e10bfffda6dd1a14f45a9c48 (patch) | |
tree | 0164eee05a517fc69744fab4a316c1fa9e069a13 | |
download | termvader-4a21921acf313c65e10bfffda6dd1a14f45a9c48.tar.xz termvader-4a21921acf313c65e10bfffda6dd1a14f45a9c48.zip |
Initial commit.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | termvader.c | 31 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..32cd0f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +CFLAGS = -O2 -march=native -std=c99 +termvader: diff --git a/termvader.c b/termvader.c new file mode 100644 index 0000000..474fe39 --- /dev/null +++ b/termvader.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fprintf(stderr, "Usage: %s /dev/tty[0-9]+ COMMANDS ...\n", argv[0]); + fprintf(stderr, "You can obtain the tty device from a particular terminal via the 'tty' command.\n"); + fprintf(stderr, "Please note, you may have to run this program as root.\n"); + return 1; + } + int ttyfd; + if ((ttyfd = open(argv[1], O_WRONLY)) == -1) { + perror("open"); + return errno; + } + for (char *c = argv[2]; *c; ++c) { + if (ioctl(ttyfd, TIOCSTI, c) == -1) { + perror("ioctl"); + return errno; + } + } + if (ioctl(ttyfd, TIOCSTI, "\n") == -1) { + perror("ioctl"); + return errno; + } + return 0; +} |