main: only remove the API socket after a clean run

The API socket path was removed unconditionally when the process
exited, including on a failed start. On a failed start where another
running instance already held the path, that deleted the live
instance's socket.

Remove the socket only when start_vmm returned Ok, meaning this process
owned and bound it. A stale socket left by a crash is cleaned up under
the lock by the next start, so dropping the unconditional removal does
not leak sockets, and a failed start no longer clobbers a socket owned
by another instance.

Signed-off-by: Max Makarov <maxpain@linux.com>
Assisted-by: Claude:claude-opus-4-8 [Claude Code]
This commit is contained in:
Max Makarov
2026-06-03 13:11:56 +00:00
committed by Rob Bradford
parent 0a08f6551a
commit 81f9cd068f

View File

@@ -902,8 +902,14 @@ fn main() {
let vmm_result = start_vmm(&cmd_arguments, &api_socket_path, api_socket_fd);
if let Some(ref p) = api_socket_path {
let _ = std::fs::remove_file(p);
// Remove the socket only when we actually ran (Ok): a failed start may mean
// another instance already holds the path, and removing it would clobber
// that live socket. A stale socket left by a crash is cleared under the lock
// on the next start.
if vmm_result.is_ok()
&& let Some(ref api_socket_path) = api_socket_path
{
let _ = std::fs::remove_file(api_socket_path);
}
let exit_code = match vmm_result {