Skip to content

fix(init): propagate lxc-autostart exit status in lxc-containers - #4709

Open
SudhanshuMatrix wants to merge 1 commit into
lxc:mainfrom
SudhanshuMatrix:fix/autostart-exit-code
Open

SudhanshuMatrix wants to merge 1 commit into
lxc:mainfrom
SudhanshuMatrix:fix/autostart-exit-code

Conversation

@SudhanshuMatrix

Copy link
Copy Markdown

Description

This PR addresses an issue where the lxc-containers helper script masks the exit status of the lxc-autostart command and always returns 0 upon starting.

Since systemd (via lxc.service), SysVinit, and OpenRC utilize this script to initialize and autostart containers, the service manager would report that the unit successfully started even when container autostarting partially or completely failed. As a consequence, failures during startup went unnoticed by monitoring tools and administrators relying on service exit status.

Fixes #4661

Changes

  • Updated the start) case block in config/init/common/lxc-containers.in.
  • Cached the exit code of lxc-autostart to a local variable res (using res=$?).
  • Executed the transient lock file cleanup command rm -f "$lockdir"/lxc.
  • Explicitly called exit $res to return the original exit status of lxc-autostart back to the invoking init wrapper.

Technical Context & Impact

  • Lock File Semantics: The lock file /var/lock/subsys/lxc (or /var/lock/lxc) acts as a transient lock to prevent concurrent container startup runs. Removing it at the end of the start block is a necessary cleanup step regardless of success or failure. By caching $? first, we prevent rm from overwriting the exit code.
  • Portability: This solution is fully POSIX compliant and uses standard syntax that works across different shells (such as dash, bash, or generic sh).
  • Init Systems Affected:
    • Systemd (Type=oneshot service lxc.service using lxc-containers start)
    • SysVinit (delegates to lxc-containers start)
    • OpenRC (delegates to lxc-containers start)

Verification & Testing

  • Built/configured the build tree utilizing Meson. Verified that macro expansion correctly generates build/config/init/common/lxc-containers.
  • Manually verified that the script correctly returns non-zero values on failures of lxc-autostart and 0 on successful runs.
  • Verified that lock file cleanup continues to run properly.

The start section in lxc-containers was executing 'rm -f' immediately after 'lxc-autostart'. This masked the exit status of the autostart action, causing the script to always return 0.
By saving the exit status to a variable before removing the lock file, we ensure the correct exit code is propagated to the service manager (e.g. systemd or OpenRC).

Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com>
@SudhanshuMatrix
SudhanshuMatrix force-pushed the fix/autostart-exit-code branch from 061ee2b to 900f3b8 Compare July 13, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

config/init/common/lxc-containers.in: bogus startup

1 participant