Conversation
'pgrep -f apt|aptd|unattended-upgrade' matched the pattern anywhere in any process's full command line. That catches unrelated processes whose arguments happen to contain "apt", and -- because the pattern is itself an argument to the sudo/pkill pair this function spawns -- the function could match and signal its own helpers. Anchor the alternation at the start of the command line with an optional /usr/bin or /usr/sbin prefix and a word boundary at the end, and stop the responsible systemd units first, which is what actually schedules these jobs. Also replace the unbounded 'while pgrep' with a bounded 20-iteration loop so an unkillable process degrades to a warning instead of hanging the script, silence the pgrep PID output, and make $unwanted local. Verified the new pattern matches 'apt-get update', '/usr/bin/apt-get install', 'aptd' and 'unattended-upgrade --download-only' while rejecting its own pkill command line, gnome-terminal-server and snapd. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change is small, locally scoped, and directly addresses the stated failure modes (false matches and unbounded looping) with clear, bounded behavior.
Pull request overview
This PR tightens and hardens the kill_apt_inhibitors helper in setup to avoid accidental self-matches / false positives when detecting and terminating background apt-related processes that can hold the dpkg lock during installation steps.
Changes:
- Stops the relevant systemd units (e.g.,
unattended-upgrades,apt-daily*,packagekit) before attempting process-based termination. - Replaces the unanchored
pgrep/pkill -fpattern with an anchored regex to avoid matching unrelated processes and the script’s own helper commands. - Bounds the kill loop to 20 iterations (~10s) and silences
pgrep/pkilloutput, emitting a warning if processes remain.
File summaries
| File | Description |
|---|---|
setup |
Refines apt-inhibitor shutdown logic (systemd-first, safer regex matching, bounded retry loop) to prevent lock-related hangs and false-positive kills. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
'pgrep -f apt|aptd|unattended-upgrade' matched the pattern anywhere in
any process's full command line. That catches unrelated processes whose
arguments happen to contain "apt", and -- because the pattern is itself
an argument to the sudo/pkill pair this function spawns -- the function
could match and signal its own helpers.
Anchor the alternation at the start of the command line with an
optional /usr/bin or /usr/sbin prefix and a word boundary at the end,
and stop the responsible systemd units first, which is what actually
schedules these jobs.
Also replace the unbounded 'while pgrep' with a bounded 20-iteration
loop so an unkillable process degrades to a warning instead of hanging
the script, silence the pgrep PID output, and make $unwanted local.
Verified the new pattern matches 'apt-get update',
'/usr/bin/apt-get install', 'aptd' and 'unattended-upgrade --download-only'
while rejecting its own pkill command line, gnome-terminal-server and snapd.
🤖 Generated with Claude Code