Skip to content

multi-arch-test-build: grep version output even on non-zero exit#112

Merged
dangowrt merged 1 commit into
openwrt:mainfrom
dangowrt:multi-arch-test-build-version-grep-on-error
May 12, 2026
Merged

multi-arch-test-build: grep version output even on non-zero exit#112
dangowrt merged 1 commit into
openwrt:mainfrom
dangowrt:multi-arch-test-build-version-grep-on-error

Conversation

@dangowrt

@dangowrt dangowrt commented May 9, 2026

Copy link
Copy Markdown
Member

The version probe in check_exec() runs each candidate flag through:

output=$(timeout --kill-after=5s 10s "$check_file" "$flag" 2>&1) || continue

if echo "$output" | grep -F "$PKG_VERSION"; then
    status_pass "Version check ($check_file)"
    return 0
fi

The 2>&1 is there precisely so the help/usage blob a tool dumps when given an unrecognized flag — which often contains the version — gets captured and grepped. But the || continue throws that captured output away whenever the command exits non-zero, so the grep never gets to see it.

unbound-host is a clean example. It has no flag in the probe list that exits 0:

root@BPI-R4:~# unbound-host --version
unbound-host: unrecognized option: -
Usage:    unbound-host [-C configfile] [-vdhr46] [-c class] [-t type]
                     [-y key] [-f keyfile] [-F namedkeyfile] hostname
  Queries the DNS for information.
  ...
Version 1.24.2
BSD licensed, see LICENSE in source package for details.
Report bugs to unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues

Version 1.24.2 matches $PKG_VERSION exactly and is sitting in the captured $output, but the non-zero exit means || continue fires before grep runs. Every flag in the loop hits the same fate — even -h, which unbound-host treats identically to any other "unknown" option and exits non-zero on. The result is a spurious:

unbound-host: [warn] Version check (/usr/sbin/unbound-host)
unbound-host: No executables in the package provided version 1.24.2
unbound-host: Generic tests failed

The fix: switch the errexit-suppressor to || true so the grep below decides whether the version was found, instead of pre-filtering on exit status. set -o errexit (line 6) is still satisfied; set -o pipefail is explicitly off, so the subsequent if echo … | grep … is unaffected.

Many tools (e.g. unbound-host) print their version as part of a usage
blob that is dumped on stderr when an unrecognized flag is given, and
exit non-zero. The 2>&1 in the version probe captures that text, but
the trailing `|| continue` discarded it before grep could see it,
producing spurious "No executables in the package provided version"
failures.

unbound-host has no flag that returns 0 from the probe loop -- every
candidate flag (including -h) errors out -- so the test never matched
even though "Version 1.24.2" was sitting right there in the captured
output.

Switch the suppressor to `|| true` so set -o errexit stays satisfied
while letting the grep below decide whether the version was found.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

Warning

Some formality checks failed.

Consider (re)reading submissions guidelines.

Failed checks

Issues marked with an ❌ are failing checks.

Commit c35cfe6

  • 🔶 Commit subject length: recommended max 60, required max 80 characters

For more details, see the full job log.

Something broken? Consider providing feedback.

@GeorgeSapkin

GeorgeSapkin commented May 9, 2026

Copy link
Copy Markdown
Member

I only tested that check_exec part locally for unbound-host and it seems to pass with these changes.

For some reason I thought timeout only passes the error code with --preserve-status.

@danielfdickinson

Copy link
Copy Markdown

This apparently causes problems for executable scripts that are an OpenWrt add-on to a package: See openwrt/packages#29390 (comment)

https://github.com/openwrt/packages/actions/runs/25605546906/job/75183164135?pr=29390#step:17:5157

openwrt/packages#29390 (comment)

@BKPepe

BKPepe commented May 11, 2026

Copy link
Copy Markdown
Member

This can be merged, right?

@danielfdickinson

Copy link
Copy Markdown

The issues in my comment above were probably caused by something else, so from my point of view, yes.

@BKPepe

BKPepe commented May 11, 2026

Copy link
Copy Markdown
Member

@dangowrt Can you please merge your PR? :)

@dangowrt dangowrt merged commit b352985 into openwrt:main May 12, 2026
3 checks passed
@dangowrt dangowrt deleted the multi-arch-test-build-version-grep-on-error branch May 12, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants