Re: [PATCH v3 1/4] Do not ignore errors from tar

Alyssa Ross
2025-09-17T11:48:38Z

[-- Attachment #1: Type: text/plain, Size: 2581 bytes --]

Demi Marie Obenour <demiobenour@gmail.com> writes:

> These would be ignored due to a missing -o pipefail in the shell script.
> As a result, listing nonexistent s6-rc-compile inputs would cause a
> broken image to be successfully built.
>
> Reported-by: Alyssa Ross <hi@alyssa.is>
> Link: https://spectrum-os.org/lists/archives/spectrum-devel/87segu879h.fsf@alyssa.is
> Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
> ---
> host/rootfs/Makefile | 4 ++--
> img/app/Makefile | 4 ++--
> vm/sys/net/Makefile | 4 ++--
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile
> index e96458dba06ae31129b115b2b649962f8d88187a..2288ae4d22ca817ba9fe8ebfc42326fe38b27c27 100644
> --- a/host/rootfs/Makefile
> +++ b/host/rootfs/Makefile
> @@ -169,8 +169,8 @@ build/etc/s6-rc: $(S6_RC_FILES)
> mkdir -p $$(dirname $@)
> rm -rf $@
>
> - dir=$$(mktemp -d) && \
> - tar -c $(S6_RC_FILES) | tar -C $$dir -x --strip-components 2 && \
> + set -uo pipefail; dir=$$(mktemp -d) || exit; \
> + { tar -c $(S6_RC_FILES) | tar -C $$dir -x --strip-components 2; } && \
> s6-rc-compile $@ $$dir; \
> exit=$$?; rm -r $$dir; exit $$exit
>

What do the additional { } do?

> diff --git a/img/app/Makefile b/img/app/Makefile
> index 9665a6b7158f2d8b183831202a4559ae06d53d16..73db07cc4c781d9c41cdf41a6214298aae8de58a 100644
> --- a/img/app/Makefile
> +++ b/img/app/Makefile
> @@ -117,8 +117,8 @@ build/etc/s6-rc: $(VM_S6_RC_FILES)
> mkdir -p $$(dirname $@)
> rm -rf $@
>
> - dir=$$(mktemp -d) && \
> - tar -c $(VM_S6_RC_FILES) | tar -C $$dir -x --strip-components 2 && \
> + set -uo pipefail; dir=$$(mktemp -d) || exit; \
> + { tar -c $(VM_S6_RC_FILES) | tar -C $$dir -x --strip-components 2; } && \
> s6-rc-compile $@ $$dir; \
> exit=$$?; rm -r $$dir; exit $$exit
>
> diff --git a/vm/sys/net/Makefile b/vm/sys/net/Makefile
> index 755b145175199aa97049dbd7feadc0e76230cf30..88ae20de79cd21b06263837f90310e8800b3d4e2 100644
> --- a/vm/sys/net/Makefile
> +++ b/vm/sys/net/Makefile
> @@ -82,8 +82,8 @@ build/etc/s6-rc: $(VM_S6_RC_FILES)
> mkdir -p $$(dirname $@)
> rm -rf $@
>
> - dir=$$(mktemp -d) && \
> - tar -c $(VM_S6_RC_FILES) | tar -C $$dir -x --strip-components 2 && \
> + set -uo pipefail; dir=$$(mktemp -d) || exit; \
> + { tar -c $(VM_S6_RC_FILES) | tar -C $$dir -x --strip-components 2; } && \
> s6-rc-compile $@ $$dir; \
> exit=$$?; rm -r $$dir; exit $$exit
>
>
> --
> 2.51.0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]