Skip to content

One install or uninstall at a time; the USB stick no longer offers the NEMESIS install - #478

Open
VysseCodes wants to merge 3 commits into
release/2.0from
fix/install-lock
Open

VysseCodes wants to merge 3 commits into
release/2.0from
fix/install-lock

Conversation

@VysseCodes

@VysseCodes VysseCodes commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

install.sh and uninstall.sh had no lock, and the USB stick carried two ways into the same install:

  • ota_package.tar: Engineering Mode → USB Copy → DSP → Update OTA runs troubleShooter, which runs install.sh.
  • NEMESIS.data (type=install): on a unit with NEMESIS, plugging the stick in makes NEMESIS offer the same package, whose postinstall.sh runs install.sh too.

Both can run at once, each remounting /system and swapping app_process. The app, adb and NEMESIS packages call these scripts as well.

Change

  • lib.sh install_lock, called by install.sh and uninstall.sh right after the root check, before anything changes:
    • a folder on tmpfs, /dev/.hmgapi-install, with the holder's pid; given back when the script exits;
    • held by a running install.sh / uninstall.sh / troubleShooter: refused with "another HMG-API install or uninstall is running (pid N). Nothing was changed: wait for it to finish.";
    • a holder that's gone (cut off, or that pid is now another process) is taken over, and tmpfs means a power cut never blocks the next boot.
    • NEMESIS's list-only sync (HMGAPI_NEMESIS_SYNC=1) never reaches uninstall.sh, so install.sh's own nemesis-sync isn't refused by its lock.
  • The USB stick (tools/mkinstallers.sh) no longer has NEMESIS.data or HMGAPI/install/hmgapi.zip. The README's route B says HMG-API isn't installed alongside NEMESIS (no pointer to the NEMESIS download).

Part of 2.0 (#468, section 2).

Tested

Off-car only:

  • install/common/test.sh: new checks for the lock (taken and given back; refused while another install runs, its lock left alone; taken over from a holder that's gone or whose pid is another process)
  • install/common/install-test.sh (262), install/common/orders-test.sh, install/usb/test.sh (60, with new checks: no NEMESIS.data, no NEMESIS package, the DSP entry and payload there)
  • core/runtime/scriptcheck-test.sh

install/common/test.sh under dash fails the same way on release/2.0 without this change.

Not on a car yet. To check on one: an install while another runs is refused; an install after a power cut mid-install isn't.

…e NEMESIS install

The stick carried both ota_package.tar (Engineering Mode's DSP OTA) and a
NEMESIS.data of type install, so on a unit with NEMESIS both could run the
same install.sh at once, each swapping app_process, and install.sh had no lock.

install.sh and uninstall.sh take a lock first (lib.sh install_lock): a folder
on tmpfs (/dev/.hmgapi-install), so a run cut off by a power loss never blocks
the next boot, with the holder's pid; a holder that's gone is taken over. While
it's held they refuse and change nothing. The stick no longer has NEMESIS.data
or the NEMESIS package; the README points NEMESIS owners to route A or the
NEMESIS download.

Tested off-car only: install/common/test.sh (lock taken, refused while another
install runs, taken over from a holder that's gone), install-test.sh (262),
orders-test.sh, install/usb/test.sh (60).
@VysseCodes
VysseCodes requested a review from a team as a code owner December 1, 2026 22:27
…load

HMG-API isn't installed alongside NEMESIS (2.0), so the stick's route B says
so instead of pointing at hmgapi-<v>-nemesis.zip.
@zpoon

zpoon commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Small race: the pid is written after mkdir, so a second install arriving in between sees an empty pid, treats the lock as stale, removes it, and both run. Suggest: when the pid is empty, wait a second and read it again before taking over (or write the pid in a temp dir and rename the dir into place). fast-macos is red because the stale-holder check reads /proc; skip that case where /proc is missing.

…t fix

A second install arriving between the first one's mkdir and its pid write saw
an empty pid, took the lock over, and both ran (review). An empty pid is now
read again after a second before the lock counts as left behind. The test's
skip path (no /proc, macOS) never made the lock folder before writing a pid
into it, which ended the suite under set -e.

Tested off-car: install/common/test.sh (new check: a lock taken a moment ago
with no pid yet is refused; it fails without the fix), in sh and bash.

@AwsomeFox AwsomeFox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The macOS test fix in 6abb939 works: install/common/test.sh passes here on macOS at that commit.

On the lock itself:

  • grep -e is new on the unit. No script that runs on the head unit uses grep -e today. If the unit's grep doesn't take it, the stale-holder check errors, every lock looks stale, and the lock quietly does nothing. One plain grep -q install.sh covers it: it also matches uninstall.sh, and the holder is never troubleShooter, which doesn't take the lock.
  • Taking over still isn't atomic. The read-again in 6abb939 covers a holder that hasn't written its pid yet. Two runs that both find a stale lock can still both go ahead: A removes it and makes its own, then B's rm -rf removes A's fresh lock and B makes its own. The window is small. Taking over by rename closes it, since only one mv "$INSTALL_LOCK" "$INSTALL_LOCK.stale.$$" wins.
  • A mkdir that fails for another reason refuses every install. If /dev can't be written from some caller's context, every install says "another HMG-API install or uninstall just started". That message misleads. When the folder doesn't exist after a failed mkdir, say the lock couldn't be taken. Not checked on a car, as the PR says.
  • README B says "This build has no way to install on a unit with NEMESIS yet". But tools/mkinstallers.sh still builds hmgapi-<v>-nemesis.zip, and with #480 that download still updates units that already have HMG-API. Say that, or drop the download for 2.0.

Checked and fine:

  • A NEMESIS sync inside a locked install never reaches a second install.sh or uninstall.sh, because both NEMESIS hooks exit at once on HMGAPI_NEMESIS_SYNC=1.
  • No other trap ... EXIT replaces the lock's.

This branch has not been deployed

No deployments
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.

3 participants