"GOT", but the "O" is a cute, smiling sun Index | Thread

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: ensure stdin is a tty
To:
Game of Trees <gameoftrees@openbsd.org>
Date:
Sat, 3 Sep 2022 23:24:47 +1000

Download raw body.

This was discussed a while back on IRC to handle such things like:

  $ tog < /dev/null

ok?

diff refs/heads/main refs/heads/fix/tty
commit - 58381f7013ee220415b44aaf36c549b2f1cd2937
commit + 1859edcc64e667da877c42b8e0575cedcb812ee6
blob - d3fe18a13136b64b9e9ba153ae5a2deda0482b9c
blob + 05c7f2e05a60fb8224d0514b4c65008eb24facb7
--- tog/tog.c
+++ tog/tog.c
@@ -8471,6 +8471,11 @@ main(int argc, char *argv[])
 	};
 	char *diff_algo_str = NULL;
 
+	if (!isatty(STDIN_FILENO)) {
+		fprintf(stderr, "%s: tty required\n", getprogname());
+		return GOT_ERR_IO;
+	}
+
 	setlocale(LC_CTYPE, "");
 
 	while ((ch = getopt_long(argc, argv, "+hV", longopts, NULL)) != -1) {

-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68