fix(ensure-shutdown): apply timeout default under nounset#369
Open
maybebyte wants to merge 1 commit into
Open
Conversation
The script runs under 'set -o nounset'. When no config file assigns
ENSURE_SHUTDOWN_TIMEOUT, the bare "${ENSURE_SHUTDOWN_TIMEOUT}" in the
fallback guard raises an unbound-variable error and aborts before the
guard can apply the default, so ExecStart never starts the shutdown
monitor. Add the ':-' default in the -z test so the guard runs and
falls back to 30. The sibling emerg-shutdown wrapper avoids this by
pre-initializing its config variables before sourcing.
Contributor
Author
|
AI assisted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ensure-shutdown's built-inENSURE_SHUTDOWN_TIMEOUTfallback is unreachable underset -o nounset. When no config file assigns the variable, the guard aborts the script instead of defaulting to 30, so the forced-shutdown watchdog (ExecStart) never starts.Changes
[ -z "${ENSURE_SHUTDOWN_TIMEOUT}" ]with no:-default. Undernounset, expanding the unset variable raisesunbound variableand exits before the=30fallback can run. Add the:-default (${ENSURE_SHUTDOWN_TIMEOUT:-}) so the guard evaluates and applies the default. Theis_whole_numbercall on the next line is unchanged — it is only reached when the variable is set.Testing
bash -non the patched script — OK.set -o nounset, variable unset: pre-fix[ -z "${VAR}" ]→VAR: unbound variable, exit 127, fallback never runs; post-fix[ -z "${VAR:-}" ]→ prints the fallback branch, exit 0.Notes for reviewers
etc/security-misc/emerg-shutdown/30_security_misc.confsetsENSURE_SHUTDOWN_TIMEOUT=30, so this only bites a config that no longer assigns it (e.g. an admin edits the conffile trusting the script's advertised default). The siblingemerg-shutdownwrapper avoids the same trap by pre-initializing its config variables before sourcing.