From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 finch.gentoo.org (Postfix) with ESMTPS id 1F75715820D for ; Tue, 22 Jul 2025 22:31:34 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id CC1BC340F2B for ; Tue, 22 Jul 2025 22:31:03 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id C2FCB11055E; Tue, 22 Jul 2025 22:31:02 +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) server-digest SHA256) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id B7B0811055E for ; Tue, 22 Jul 2025 22:31:02 +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) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 68A5F340FD9 for ; Tue, 22 Jul 2025 22:31:02 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D241C3293 for ; Tue, 22 Jul 2025 22:31:00 +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: <1753223452.9f354763d2cd8ef0f3390aee1dfd46a571c5d4f1.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/isolated-functions.sh X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 9f354763d2cd8ef0f3390aee1dfd46a571c5d4f1 X-VCS-Branch: master Date: Tue, 22 Jul 2025 22:31:00 +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: 78aba287-0017-4ed3-a63c-9ab9fdf18e48 X-Archives-Hash: 26397fe714be88a2ecb2d76d48e0fa22 commit: 9f354763d2cd8ef0f3390aee1dfd46a571c5d4f1 Author: Kerin Millar plushkava net> AuthorDate: Sun Jul 20 05:14:02 2025 +0000 Commit: Sam James gentoo org> CommitDate: Tue Jul 22 22:30:52 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=9f354763 isolated-functions.sh: don't open/close/dup file descriptors so frequently As regards the die() function, refrain from duplicating file descriptor #2 to file descriptor #1 for each invocation of the functions whose names comprise the value of the 'EBUILD_DEATH_HOOKS' variable, twice. Instead, duplicate once and maintain the state of file descriptor #1 for the duration of the containing loop. As regards the __elog_base() function, refrain from duplicating file descriptor #2 to file descriptor #1 twice in the course of printing the banner message. Instead, do so only once. Further, refrain from opening and closing a log file for each and every line that is destined to it. Instead, open the file once and keep it open for the duration of the containing loop. As regards the eqawarn(), eerror(), einfo(), ewarn() and elog() functions, refrain from duplicating file descriptor #2 to file descriptor #1 for each and every line that is to be printed. Instead, duplicate once and maintain the state of file descriptor #1 for the duration of the containing loop. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/isolated-functions.sh | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh index 0c83e5d963..23348b918c 100644 --- a/bin/isolated-functions.sh +++ b/bin/isolated-functions.sh @@ -182,8 +182,8 @@ die() { then local x for x in ${EBUILD_DEATH_HOOKS}; do - ${x} "$@" >&2 1>&2 - done + ${x} "$@" + done >&2 > "${PORTAGE_BUILDDIR}/.die_hooks" fi @@ -234,8 +234,8 @@ __elog_base() { if [[ ${EBUILD_PHASE} == depend && -z ${__PORTAGE_ELOG_BANNER_OUTPUT} ]]; then # in depend phase, we want to output a banner indicating which # package emitted the message - echo >&2 - echo "Messages for package ${PORTAGE_COLOR_INFO}${CATEGORY}/${PF}::${PORTAGE_REPO_NAME}${PORTAGE_COLOR_NORMAL}:" >&2 + printf >&2 '\nMessages for package %s%s%s:\n' \ + "${PORTAGE_COLOR_INFO}" "${CATEGORY}/${PF}::${PORTAGE_REPO_NAME}" "${PORTAGE_COLOR_NORMAL}" __PORTAGE_ELOG_BANNER_OUTPUT=1 fi [[ -z "${1}" || -z "${T}" || ! -d "${T}/logging" ]] && return 1 @@ -250,9 +250,8 @@ __elog_base() { ;; esac echo -e "$@" | while read -r ; do - echo "${messagetype} ${REPLY}" >> \ - "${T}/logging/${EBUILD_PHASE:-other}" - done + echo "${messagetype} ${REPLY}" + done >> "${T}/logging/${EBUILD_PHASE:-other}" return 0 } @@ -260,8 +259,8 @@ eqawarn() { __elog_base QA "$*" [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2 echo -e "$@" | while read -r ; do - echo " ${PORTAGE_COLOR_QAWARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2 - done + echo " ${PORTAGE_COLOR_QAWARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" + done >&2 LAST_E_CMD="eqawarn" return 0 } @@ -270,8 +269,8 @@ elog() { __elog_base LOG "$*" [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2 echo -e "$@" | while read -r ; do - echo " ${PORTAGE_COLOR_LOG}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2 - done + echo " ${PORTAGE_COLOR_LOG}*${PORTAGE_COLOR_NORMAL} ${REPLY}" + done >&2 LAST_E_CMD="elog" return 0 } @@ -280,8 +279,8 @@ einfo() { __elog_base INFO "$*" [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2 echo -e "$@" | while read -r ; do - echo " ${PORTAGE_COLOR_INFO}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2 - done + echo " ${PORTAGE_COLOR_INFO}*${PORTAGE_COLOR_NORMAL} ${REPLY}" + done >&2 LAST_E_CMD="einfo" return 0 } @@ -298,8 +297,8 @@ ewarn() { __elog_base WARN "$*" [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2 echo -e "$@" | while read -r ; do - echo " ${PORTAGE_COLOR_WARN}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2 - done + echo " ${PORTAGE_COLOR_WARN}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" + done >&2 LAST_E_CMD="ewarn" return 0 } @@ -308,8 +307,8 @@ eerror() { __elog_base ERROR "$*" [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2 echo -e "$@" | while read -r ; do - echo " ${PORTAGE_COLOR_ERR}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2 - done + echo " ${PORTAGE_COLOR_ERR}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" + done >&2 LAST_E_CMD="eerror" return 0 }