Repository navigation
install-phone: a second install with the same work directory stops, instead of replacing the first one's images - #798
Conversation
The image copy and the other staged files have fixed names in --work (root.img, root.simg, firstboot.conf, authorized_keys, boot-update.conf, ramdisk/), and every install uses the same default work directory. With two installs waiting at "Type the phone's codename", the second had replaced the first one's files, so confirming the first flashed the second owner's firstboot.conf while it said it set up the first owner; and either one's exit removed the other's files. An install or a dry run now holds an exclusive flock until it exits, taken before it reads the ramdisk or writes in the work directory, and a second one with the same work directory stops there, before the phone: "another install is using the work directory DIR: let it finish, or give this one its own with --work DIR". The lock file is beside the resolved work directory, .NAME.install.lock in its parent (as make-bundle's lock is beside the bundles), so two spellings of one directory lock one file and the directory still ends empty. It is kept after the run, since unlinking it could let two runs lock different inodes. The work directory's parent must be writable: if the lock file can't be created there, the install stops with a message naming it. A lock that can't be taken for any other reason (a file system without flock) stops the install too, with "can't lock the work directory DIR", rather than going ahead unlocked. The kernel drops the lock with the run's last process, so an install killed outright keeps none out. The lock is python3's fcntl, as derekross#682's is: the bundle ships the installer alone. --verify-only takes no part and still runs beside an install, so derekross#682's sweep is unchanged. tests/install-phone: a second install with the same --work, and one through a symlink to it, is refused within a time bound, before it writes in --work or reads the ramdisk (a mktemp and an lz4 that note their calls are never run) and before any question, and sends the phone nothing; the waiting install's staged files are unchanged and it flashes its own owner; --verify-only passes beside it; after a SIGKILL of a waiting install (and its child) the next one installs; the work directory ends empty with the lock beside it; an unwritable parent is refused; and a python3 stand-in whose flock on the lock fails refuses the install before any question, staging write or fastboot call. It fails on main's tool at "a second install with the same --work is refused". tests/install-phone-initramfs: derekross#682's case ran two full installs in one --work, which this forbids. Its killed run is now a --verify-only held in its lz4 by a stand-in and killed with SIGKILL; every assertion keeps its meaning, and the suite still fails without the exclusive check, with the shared lock let go after marking, without the mark check (also with the run's own directory spared), without the mark, and with a blocking exclusive lock. Tested: tools/pr-check, tests/install-phone, tests/install-phone-initramfs, tests/install-guided, tests/all. Not tested: a phone; a network-mounted home; a real file system that rejects flock (the failure is simulated in the test). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you, @only21mil. The scenario in your description is a nasty one (the first owner's install flashing the second owner's answers while telling the first it set them up), and the fix is the right size. I checked the order: the lock is the first thing that writes in I also checked it against the guided installer's new keep-awake hold (#814), which landed after you branched. That hold starts after install-phone has finished and runs from the guided installer itself, so the two don't meet, and One behaviour change I want to note, not change: a |
What and why
An AI agent found this reading the code. An install stages the image copy and the owner's files under fixed names in
--work(root.simg,firstboot.conf, ...), one default directory for every run. With two installs waiting at "Type the phone's codename", the second replaces the first's files: confirming the first flashes the second owner'sfirstboot.confwhile saying it set up the first owner.Following #682's lock, an install or dry run holds an exclusive
flockfrom before it reads the ramdisk or writes in the work directory until it exits. A second one with the same work directory stops there, before the phone, and says to let the first finish or give it its own--work DIR.--verify-onlytakes no part, so #682's sweep is unchanged. The lock file is.NAME.install.lockin the resolved work directory's parent (as make-bundle's since #664), so--workstill ends empty. Its parent must be writable; a lock that can't be taken (a file system withoutflock) also stops the install. The kernel drops the lock, so an install killed outright keeps none out.An AI agent made both runs (details block). Before, on main 12258d9, before the fix was written: alice's run says it set up alice; its image holds
USERNAME=bob. After, on 84791fc: bob's run is refused; alice's image holds alice.Regression test in
tests/install-phone(a stand-in, not the reproduction): a second install, also through a symlink, is refused before it writes in--work, reads the ramdisk or asks anything, and sends the phone nothing;--verify-onlypasses beside it; a SIGKILLed install keeps none out. On main's tool it fails at "a second install with the same --work is refused". Details covertests/install-phone-initramfs.Device and build
uname -r): not applicableChecks (no phone needed)
An AI agent ran these on 84791fc, on an x86_64 desktop running Ubuntu 26.04.
tools/pr-check origin/mainpassestests/allpassestests/packagespasses (or the packages I touched: ...): not run, no package changedversionbumped, and the new version is in the commit subject: no package changedCo-Authored-By:orAssisted-by:trailer, never aSigned-off-by:On the phone
userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)tools/phone-smokereportNot applicable: a laptop-side installer change; nothing on the phone changes.
tests/install-phone-initramfs: the killed run of #682's case is now a--verify-onlyheld in itslz4by a stand-in and killed with SIGKILL; every other step and assertion is as it was, and #699's quiet job handling stays. On 84791fc the agent checked that the suite still fails without the exclusive check, with the shared lock let go after marking, without the mark check (also with the run's own directory spared), without the mark, and with a blocking exclusive lock.84791fc is based on main 1a28cf3. The same steps give bob on main 6649b76 and alice on local merge d6e0910a; that merge is clean.
Setup: an x86_64 desktop running Ubuntu 26.04. An AI agent ran the real
tools/install-phoneintests/install-phone's fixture, only fastboot faked, in bwrap with the checkout at /mnt, on a fixture built fresh for each commit. The agent's script prints only the==> Preparing,==> Done,==> The files,user:anderror:lines, without colour codes, and only the USERNAME line of the image fastboot got for userdata.Steps: alice's and bob's installs on one
--work→ a--verify-onlybeside them → confirm alice's → read USERNAME → SIGKILL dave's at the codename → erin's install → read USERNAMEBefore,
12258d91(main, before the fix was written):After,
84791fc7:Links: the regression test,
tests/install-phoneat 84791fc; #682, whose lock this follows.Not shown (no one, agent or person, tested these):
flock(the failure is simulated in the offline test)Generated with Claude Opus 5.5 in T3 Code Nightly