diff --git a/hostd/src/machine.rs b/hostd/src/machine.rs index 1e49c89..b249576 100644 --- a/hostd/src/machine.rs +++ b/hostd/src/machine.rs @@ -1,13 +1,12 @@ use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext}; use schemars::JsonSchema; use serde::Serialize; +use std::sync::{Arc, Mutex}; use trace_request::trace_request; use systemd_ipc::addrs::SYSTEMD_HOSTNAME; use systemd_ipc::io_systemd_hostname::{self, VarlinkClientInterface}; -use std::sync::Arc; - use crate::context::ControllerContext; /// Version and build information @@ -25,19 +24,19 @@ struct MachineInfo { pub async fn describe( rqctx: RequestContext<Arc<ControllerContext>>, ) -> Result<HttpResponseOk<MachineInfo>, HttpError> { - // Connect to systemd.Hostname - // Make it tokio task blocking - tokio::task::block_in_place(move || { + let machine_info = tokio::task::spawn_blocking(move || { + // Connect to systemd.Hostname let conn = varlink::Connection::with_address(SYSTEMD_HOSTNAME).unwrap(); let mut sd = io_systemd_hostname::VarlinkClient::new(conn); + let machine_id = sd.describe().call().unwrap().MachineID; - - tracing::info_span!("Hello, span hostd!"); - - tracing::info!(monotonic_counter.version_calls = 1); - - let machine_info = MachineInfo { machine_id }; - - Ok(HttpResponseOk(machine_info)) + MachineInfo { machine_id } }) + .await + .unwrap(); + + tracing::info_span!("Hello, span hostd!"); + + tracing::info!(monotonic_counter.version_calls = 1); + Ok(HttpResponseOk(machine_info)) }