From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 46B3C158137 for ; Sat, 10 Jun 2023 04:22:05 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 87945E0933; Sat, 10 Jun 2023 04:22:04 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 69DB1E0933 for ; Sat, 10 Jun 2023 04:22:04 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6FD06335D6F for ; Sat, 10 Jun 2023 04:22:03 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0B85DA87 for ; Sat, 10 Jun 2023 04:22:02 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1686344047.9ed12f2dbbd47a621839a4ba3183669f8ec5806c.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: ecma48-cpr.c X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 9ed12f2dbbd47a621839a4ba3183669f8ec5806c X-VCS-Branch: master Date: Sat, 10 Jun 2023 04:22:02 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: fcdf17a5-8a7c-458d-b6f6-f740ac5c844c X-Archives-Hash: 29600bb71418b8d344fcfb37bbdedf4f commit: 9ed12f2dbbd47a621839a4ba3183669f8ec5806c Author: Kerin Millar plushkava net> AuthorDate: Fri Jun 9 20:49:49 2023 +0000 Commit: Sam James gentoo org> CommitDate: Fri Jun 9 20:54:07 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=9ed12f2d Have ecma48-cpr flush the terminal's input queue There is no guarantee that the input queue is empty at the time that ecma48-cpr is executed. If the terminal has input waiting, not only will ecma48-cpr potentially fail but it will pollute the input queue. Work around this by flushing the input queue entirely. I'm not especially pleased by this approach but I can see no other option, short of giving up on the idea of using the CPR sequence at all. Signed-off-by: Kerin Millar plushkava.net> ecma48-cpr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ecma48-cpr.c b/ecma48-cpr.c index 9aef182..144c4ea 100644 --- a/ecma48-cpr.c +++ b/ecma48-cpr.c @@ -95,6 +95,8 @@ main(void) { */ if (tcsetattr(STDIN_FILENO, TCSANOW, &new_tty) != 0) { die("failed to modify the terminal settings"); + } else if (tcflush(STDIN_FILENO, TCIFLUSH) != 0) { + die("failed to flush the terminal's input queue"); } else if (fprintf(tty, "\033[6n") != 4) { die("failed to write the CPR sequence to the terminal"); } else if (fclose(tty) != 0) {