summary refs log tree commit diff
path: root/host/start-vm/start-vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'host/start-vm/start-vm.rs')
-rw-r--r--host/start-vm/start-vm.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/host/start-vm/start-vm.rs b/host/start-vm/start-vm.rs
index 4790841..df1ce0a 100644
--- a/host/start-vm/start-vm.rs
+++ b/host/start-vm/start-vm.rs
@@ -1,28 +1,40 @@
 // SPDX-License-Identifier: EUPL-1.2+
-// SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+// SPDX-FileCopyrightText: 2022-2023 Alyssa Ross <hi@alyssa.is>
 
 use std::env::current_dir;
 use std::os::unix::prelude::*;
 use std::path::Path;
 use std::process::exit;
 
-use start_vm::{prog_name, vm_command};
+use start_vm::{create_api_socket, notify_readiness, prog_name, vm_command};
 
 const CONFIG_ROOT: &str = "/ext/svc/data";
 
-fn run() -> String {
+/// # Safety
+///
+/// Calls [`notify_readiness`], so can only be called once.
+unsafe fn run() -> String {
     let dir = match current_dir().map_err(|e| format!("getting current directory: {}", e)) {
         Ok(dir) => dir,
         Err(e) => return e,
     };
 
-    match vm_command(dir, Path::new(CONFIG_ROOT)) {
+    let api_socket = match create_api_socket() {
+        Ok(api_socket) => api_socket,
+        Err(e) => return e,
+    };
+
+    if let Err(e) = notify_readiness() {
+        return e;
+    }
+
+    match vm_command(dir, Path::new(CONFIG_ROOT), api_socket.into_raw_fd()) {
         Ok(mut command) => format!("failed to exec: {}", command.exec()),
         Err(e) => e,
     }
 }
 
 fn main() {
-    eprintln!("{}: {}", prog_name(), run());
+    eprintln!("{}: {}", prog_name(), unsafe { run() });
     exit(1);
 }