Commit Diff


commit - 9cbac887301ab85a09a6e123f9963b76f60514e1
commit + 906c73f69f5ab088561e8f1378c27d852a022e37
blob - a411c9ed187b845c6ae5b24e656b8f43e9515a72
blob + ce6df683d22ae7ee7dcf845076a046795faad31d
--- tog/tog.c
+++ tog/tog.c
@@ -4186,6 +4186,7 @@ static const struct got_error *
 init_mock_term(const char *test_script_path)
 {
 	const struct got_error	*err = NULL;
+	int in;
 
 	if (test_script_path == NULL || *test_script_path == '\0')
 		return got_error_msg(GOT_ERR_IO, "TOG_TEST_SCRIPT not defined");
@@ -4200,13 +4201,19 @@ init_mock_term(const char *test_script_path)
 	/* test mode, we don't want any output */
 	tog_io.cout = fopen("/dev/null", "w+");
 	if (tog_io.cout == NULL) {
-		err = got_error_from_errno("fopen: /dev/null");
+		err = got_error_from_errno2("fopen", "/dev/null");
 		goto done;
 	}
 
-	tog_io.cin = fopen("/dev/tty", "r+");
+	in = dup(fileno(tog_io.cout));
+	if (in == -1) {
+		err = got_error_from_errno("dup");
+		goto done;
+	}
+	tog_io.cin = fdopen(in, "r");
 	if (tog_io.cin == NULL) {
-		err = got_error_from_errno("fopen: /dev/tty");
+		err = got_error_from_errno("fdopen");
+		close(in);
 		goto done;
 	}