mirror of
https://github.com/storytold/figcraft.git
synced 2026-12-04 19:41:51 -05:00
fc98db023d
Comments, board stickies and live sessions are signed with `Prefs.user_name`, which nothing ever filled, so every install signs as "You" until somebody types a name. A desktop start with a settings folder now asks the machine what the account is called - first and last name, or display name, on Windows; the GECOS name of the passwd entry that our uid names on Linux and the BSDs; `/usr/bin/id -F` on macOS; the logon name wherever none of those exist - and puts it through `pref.userName`, the command the Preferences field uses, so it is trimmed, cleaned of control characters and capped at 64 characters the same way, renames you in a live session at once, marks no document dirty and adds no undo step. It asks only while the stored name is still the placeholder: a name typed in Preferences always wins. A run with no settings folder, and one started for an agent (`--control`, the control port), never asks, so what those runs save and show stays the same on every machine. Both lookups that go through the machine's directory services are bounded by 2 s and run off the start-up thread: macOS's `id` child is killed and waited for at the deadline rather than left behind for the next start to add to, and the Windows Runtime call cannot be interrupted by anyone, so its deadline is a wait. The wait is a helper of its own (`wait_with_deadline`) so that path can be tested at all: no unit test can make Directory Services unresponsive, so it is handed a `sleep` child and checks that the deadline ends the wait and that the child is left reaped, not as a zombie (`kill -0` finds no such process afterwards). On Windows the account is `User::GetDefault()` first - the account this process runs as - falling back to `FindAllAsync()` only when that errors and only if it names exactly one user, so a machine with two signed-in accounts gets no guess. The passwd entry is matched by our uid alone, the logon name never being a key into the file: an account from a directory service has no line in it under its uid *or* its name, so a match by name can only ever land on somebody else's local entry (CodeRabbit's finding here, autocraft-bot's on the DeckCraft sibling). A record the file itself comments out - a line beginning `#`, which `getpwuid` skips - is not an account: a commented-out `#ada:x:1000:...` would otherwise answer for uid 1000 and outrank the live entry below it (CodeRabbit, again on the DeckCraft sibling). `/usr/bin/id` runs by absolute path: a GNU coreutils `id` earlier in `PATH` has no `-F`. The uid is the one the kernel gives for this process, `rustix::process::getuid` (`rustix` already in the build, this adding only its `process` module, as a unix-only target dependency), rather than who owns `/proc/self`, which proc(5) assigns to root for a non-dumpable process, or the environment's logon name, which can say anything; the web and agent runs never reach this file at all. Only the GECOS half before the first comma is decoded, so a Latin-1 in the office field cannot cost the name; a GECOS full name with nothing in it that any cleaning could keep - empty, blanks, control characters - is refused as no name at all, so the logon name has its turn rather than one stray control character in the field leaving "You" (CodeRabbit's finding on the DeckCraft sibling, taken here before it arrived); and the deadline test spawns `sleep` itself, so the process it checks is the process the wait kills. `docs/collab-protocol.md` records that clearing the name is not a lasting choice: the next desktop start refills it from the account, so it stays cleared only for that run.