From cab81646f6e56233d89928b149b9f9bd734270dd Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 7 Jul 2024 10:57:17 -0400 Subject: [PATCH 1/2] remove useless grep in quiet refresh In commit da77c23984bfd3a9ef3a3630ed5eac5393005a0a, getuto "made quiet mode more quiet". It did this by piping the output of some gpg calls to a grep pipe, that filtered out any "expected warnings" in the form of no user IDs emitted by keys.openpgp.org, while mostly leaning on gpg --quiet to be quiet. In commit 15fcac948421cf6022a5652d40fbe966dc9aad44, getuto added -q to grep, with the note "Also, use grep -q to honour --quiet". This meant that grep was instructed to emit zero output if at all possible, and is intended to use for scripts that want to check the return code of grep to see whether matches were found. (getuto does NOT check this.) Given this is incorrect use of grep, we instead just redirect all stdout and stderr to /dev/null. It is semantically identical to what we already do, but with one less fork+exec and the intent is far clearer. --- getuto | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/getuto b/getuto index ae51b34..c98a9df 100755 --- a/getuto +++ b/getuto @@ -83,10 +83,6 @@ getuto_refresh() { else [[ -n ${QUIET} ]] || einfo "gnupg keyring for package signatures already up-to-date." fi - - # If we got here, everything is fine. Empty a silly string to keep the grep happy - # on the output of getuto_refresh. - [[ -n ${QUIET} ]] && echo OK || true } @@ -196,7 +192,7 @@ else export LC_ALL=C.UTF8 if [[ -n ${QUIET} ]] ; then - getuto_refresh |& grep -qv ": no user ID" + getuto_refresh >/dev/null 2>&1 else getuto_refresh fi From 66ad5bee788115ca5384aab6becd38dcee8af457 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 7 Jul 2024 11:18:04 -0400 Subject: [PATCH 2/2] fix getuto emitting informative messages regarding what it is doing quiet mode silences all output, as made more obvious by the previous change. This isn't really appropriate for einfo status messages, though, even if it is fine for gpg output itself. Redirect our einfos to a temporary fd so we can capture them and preserve them. Fixes portage being entirely silent about the fact that it is running the trust helper, leading to people thinking portage itself is hanging forever if getuto itself has issues. --- getuto | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/getuto b/getuto index c98a9df..7855d04 100755 --- a/getuto +++ b/getuto @@ -64,7 +64,7 @@ getuto_refresh() { fi if (( ${NOW} - ${DAY} >= ${LST} )) ; then - einfo "Updating gnupg keyring for package signatures" + einfo "Updating gnupg keyring for package signatures" >&3 # Always re-import the system keys because it might be our only source of updates # for e.g. revocations, renewals, etc if we're on a firewalled machine. @@ -81,7 +81,7 @@ getuto_refresh() { touch ${LASTRUNFILE} else - [[ -n ${QUIET} ]] || einfo "gnupg keyring for package signatures already up-to-date." + [[ -n ${QUIET} ]] || einfo "gnupg keyring for package signatures already up-to-date." >&3 fi } @@ -191,11 +191,13 @@ else # We want to be able to filter error messages export LC_ALL=C.UTF8 - if [[ -n ${QUIET} ]] ; then - getuto_refresh >/dev/null 2>&1 - else - getuto_refresh - fi + { + if [[ -n ${QUIET} ]] ; then + getuto_refresh >/dev/null 2>&1 + else + getuto_refresh + fi + } 3>&1 fi # Make sure the trustdb is world-readable (again).