user: Add user-running manager prototype

This commit is contained in:
Vicki Pfau 2024-04-23 19:37:55 -07:00
parent ac823a845b
commit 24d740d178
3 changed files with 60 additions and 2 deletions

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*/
use anyhow::{anyhow, Result};
use anyhow::{anyhow, ensure, Result};
use tokio::signal::unix::{signal, Signal, SignalKind};
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
@ -58,6 +58,11 @@ impl Daemon {
}
pub async fn run(&mut self) -> Result<()> {
ensure!(
!self.services.is_empty(),
"Can't run a daemon with no services attached."
);
let mut res = tokio::select! {
e = self.services.join_next() => match e.unwrap() {
Ok(Ok(())) => Ok(()),

View file

@ -24,6 +24,7 @@ mod process;
mod root;
mod sls;
mod systemd;
mod user;
mod wifi;
#[cfg(test)]
@ -157,7 +158,7 @@ pub async fn main() -> Result<()> {
if args.root {
root::daemon().await
} else {
todo!();
user::daemon().await
}
}

52
src/user.rs Normal file
View file

@ -0,0 +1,52 @@
/*
* Copyright © 2023 Collabora Ltd.
* Copyright © 2024 Valve Software
*
* SPDX-License-Identifier: MIT
*/
use anyhow::{bail, Result};
use tracing::error;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, Registry};
use zbus::connection::Connection;
use zbus::ConnectionBuilder;
use crate::daemon::Daemon;
async fn create_connection() -> Result<Connection> {
let connection = ConnectionBuilder::session()?
.name("com.steampowered.SteamOSManager1")?
.build()
.await?;
Ok(connection)
}
pub async fn daemon() -> Result<()> {
// This daemon is responsible for creating a dbus api that steam client can use to do various OS
// level things. It implements com.steampowered.SteamOSManager1.Manager interface
let stdout_log = fmt::layer();
let subscriber = Registry::default().with(stdout_log);
let system = match Connection::system().await {
Ok(c) => c,
Err(e) => {
let _guard = tracing::subscriber::set_default(subscriber);
error!("Error connecting to DBus: {}", e);
bail!(e);
}
};
let session = match create_connection().await {
Ok(c) => c,
Err(e) => {
let _guard = tracing::subscriber::set_default(subscriber);
error!("Error connecting to DBus: {}", e);
bail!(e);
}
};
let mut daemon = Daemon::new(subscriber, system.clone()).await?;
daemon.run().await
}