All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: Nicolas Schier <nsc@kernel.org>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nam Cao <namcao@linutronix.de>, kernel test robot <lkp@intel.com>
Subject: Re: [PATCH RFC] kbuild: enable pipefail for commands where possible
Date: Wed, 14 Oct 2026 14:40:43 -0700	[thread overview]
Message-ID: <20261014214043.GA3380464@ax162> (raw)
In-Reply-To: <20261014-kbuild-error-propagation-v1-1-573adaa0a076@linutronix.de>

On Wed, Oct 14, 2026 at 10:30:30AM +0200, Thomas Weißschuh wrote:
> The exit status of a shell pipeline by default only depends on the exit
> status of its last command. If an earlier command fails this is silently
> ignored. In this case the build continues operating on intermediate
> state, potentially leading to confusing follow-up failures.
> 
> The 'pipefail' option can be used to exit the pipeline with an error as
> soon as a single of its command fails which 'set -e' will elevate to
> error exit of the whole command.
> 
> 'pipefail' has been only standardized in POSIX 2024, but it is supported
> by many shells anyways, including bash and dash. To avoid issues with
> shells not implementing it, ignore failures silently.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/oe-kbuild-all/202610131613.BpOi6VPp-lkp@intel.com/
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

This is probably the right thing to do but it makes me nervous. pipefail
is very easy to hold wrong mainly because of SIGPIPE:

  $ cat test.sh
  set -o pipefail

  yes | head -n +50

  $ bash test.sh
  ...

  $ echo $?
  141

and debugging that is unlikely to be obvious (but maybe it will because
the error would be 141).

> ---
>  scripts/Kbuild.include | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 8c311b997e24..1975d2739cdb 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -149,8 +149,11 @@ delete-on-interrupt = \
>  		$(foreach sig, HUP INT QUIT TERM PIPE, \
>  			trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);))
>  
> +# try to enable pipefail
> +try-pipefail = set -o pipefail || true 2>/dev/null
> +
>  # print and execute commands
> -cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:)
> +cmd = @$(if $(cmd_$(1)),$(try-pipefail); set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:)
>  
>  ###
>  # if_changed      - execute command if any prerequisite is newer than
> 
> ---
> base-commit: 27286bf096c51df05eec6664f18b945f8dd61c0e
> change-id: 20261013-kbuild-error-propagation-8ab5f649ff36
> 
> Best regards,
> --  
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 

-- 
Cheers,
Nathan

  reply	other threads:[~2026-10-14 21:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  8:30 [PATCH RFC] kbuild: enable pipefail for commands where possible Thomas Weißschuh
2026-10-14 21:40 ` Nathan Chancellor [this message]
2026-10-15 10:15   ` Thomas Weißschuh
2026-10-15  8:36 ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014214043.GA3380464@ax162 \
    --to=nathan@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=namcao@linutronix.de \
    --cc=nsc@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.