mirror of
https://github.com/jamesstringer90/appsandbox.git
synced 2026-10-19 01:31:28 -05:00
The macOS guest agent ran ssh_deploy_key inline on its single command socket. On a cold first boot the find_primary_user lookup (getpwent/OpenDirectory) can take several seconds, during which the agent could not service heartbeats or replies and the host would tear the connection down -- the key deploy reported as failed even though it eventually succeeded. Run the deploy on a detached worker thread (spawn_deploy_key) so the accept loop keeps responding. send_line takes a mutex so a worker's reply can't interleave its bytes with the loop's writes on the shared socket, and a connection generation counter (g_conn_gen, bumped on every connection start/end) lets a worker tell its connection is gone -- and the fd possibly reused by a new client -- and suppress a stale write via send_line_gen. deploy_ssh_key now returns failure (reports ssh_key_failed) when the chown of authorized_keys fails instead of falsely reporting success.