Skip to content

fix(lib): maybe_reload_networkd must not fail EXIT trap when EC2_IF_INITIAL_SETUP is unset#145

Open
mjnowen wants to merge 2 commits intoamazonlinux:mainfrom
mjnowen:patch-4
Open

fix(lib): maybe_reload_networkd must not fail EXIT trap when EC2_IF_INITIAL_SETUP is unset#145
mjnowen wants to merge 2 commits intoamazonlinux:mainfrom
mjnowen:patch-4

Conversation

@mjnowen
Copy link
Copy Markdown
Contributor

@mjnowen mjnowen commented Mar 25, 2026

refresh-policy-routes@.service (oneshot) often exited 1 after a successful run because maybe_reload_networkd returned non-zero from the EXIT trap when no networkctl reload was required and EC2_IF_INITIAL_SETUP was unset.

Before

journalctl -u 'refresh-policy-routes@ens5.service' -o cat
Got IMDSv2 token for interface ens5 from http://169.254.169.254/latest via ens5
refresh-policy-routes@ens5.service: Main process exited, code=exited, status=1/FAILURE
refresh-policy-routes@ens5.service: Failed with result 'exit-code'.
Failed to start refresh-policy-routes@ens5.service - Refresh policy routes for ens5.

After

Got IMDSv2 token for interface ens5 from http://169.254.169.254/latest via ens5
refresh-policy-routes@ens5.service: Deactivated successfully.
Finished refresh-policy-routes@ens5.service - Refresh policy routes for ens5.

Change

In maybe_reload_networkd, replace:

[ -v EC2_IF_INITIAL_SETUP ] && debug "No networkd reload needed"

with an if [ -v EC2_IF_INITIAL_SETUP ]; then debug ...; fi so the else branch does not end on a failing [ when the variable is unset.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

… needed

maybe_reload_networkd runs under an EXIT trap with set -e. The branch that skips networkctl reload used `[ -v EC2_IF_INITIAL_SETUP ] && debug ...`. When EC2_IF_INITIAL_SETUP is unset (typical refresh runs), the test fails with status 1, the trap returns non-zero, and systemd reports failure even though setup-policy-routes completed successfully.
Addressed review: applied the same fix as in amazonlinux#144’s intent everywhere [ -v EC2_IF_INITIAL_SETUP ] && debug appears in lib/lib.sh (get_meta, maybe_reload_networkd else branch, and the EXIT trap in register_networkd_reloader) so none of these return non-zero when the variable is unset under set -e.
@joeysk2012
Copy link
Copy Markdown
Contributor

Looks good.

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.

2 participants