Skip to content

apt: anchor the inhibitor pattern and bound the kill loop - #17

Open
presto8 wants to merge 1 commit into
mainfrom
fix/apt-inhibitor-pattern
Open

presto8 wants to merge 1 commit into
mainfrom
fix/apt-inhibitor-pattern

Conversation

@presto8

@presto8 presto8 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

'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

'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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 -f pattern 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/pkill output, 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.

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