mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 09:22:26 -04:00
process: Split out from manager
This commit is contained in:
parent
128c5ee36a
commit
0d90859841
3 changed files with 40 additions and 27 deletions
|
@ -23,6 +23,7 @@ use crate::sls::{LogLayer, LogReceiver};
|
||||||
mod ds_inhibit;
|
mod ds_inhibit;
|
||||||
mod hardware;
|
mod hardware;
|
||||||
mod manager;
|
mod manager;
|
||||||
|
mod process;
|
||||||
mod sls;
|
mod sls;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
use std::{ffi::OsStr, fmt};
|
use std::fmt;
|
||||||
use tokio::{fs, fs::File, io::AsyncWriteExt, process::Command};
|
use tokio::{fs, fs::File, io::AsyncWriteExt};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
use zbus::{interface, zvariant::Fd};
|
use zbus::{interface, zvariant::Fd};
|
||||||
|
|
||||||
use crate::hardware::{variant, HardwareVariant};
|
use crate::hardware::{variant, HardwareVariant};
|
||||||
|
use crate::process::{run_script, script_output};
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
|
@ -78,31 +79,6 @@ const GPU_CLOCKS_PATH: &str = "/sys/class/drm/card0/device/pp_od_clk_voltage";
|
||||||
const SYSTEMCTL_PATH: &str = "/usr/bin/systemctl";
|
const SYSTEMCTL_PATH: &str = "/usr/bin/systemctl";
|
||||||
const TRACE_CMD_PATH: &str = "/usr/bin/trace-cmd";
|
const TRACE_CMD_PATH: &str = "/usr/bin/trace-cmd";
|
||||||
|
|
||||||
async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool> {
|
|
||||||
// Run given script and return true on success
|
|
||||||
let mut child = Command::new(executable).args(args).spawn()?;
|
|
||||||
let status = child.wait().await?;
|
|
||||||
Ok(status.success())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_script(name: &str, executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool> {
|
|
||||||
// Run given script to get exit code and return true on success.
|
|
||||||
// Return false on failure, but also print an error if needed
|
|
||||||
script_exit_code(executable, args)
|
|
||||||
.await
|
|
||||||
.inspect_err(|message| warn!("Error running {name} {message}"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn script_output(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<String> {
|
|
||||||
// Run given command and return the output given
|
|
||||||
let output = Command::new(executable).args(args).output();
|
|
||||||
|
|
||||||
let output = output.await?;
|
|
||||||
|
|
||||||
let s = std::str::from_utf8(&output.stdout)?;
|
|
||||||
Ok(s.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> {
|
async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> {
|
||||||
// Copy override.conf file into place or out of place depending
|
// Copy override.conf file into place or out of place depending
|
||||||
// on install value
|
// on install value
|
||||||
|
|
36
src/process.rs
Normal file
36
src/process.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Collabora Ltd.
|
||||||
|
* Copyright © 2024 Valve Software
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use tokio::process::Command;
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
|
pub async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool> {
|
||||||
|
// Run given script and return true on success
|
||||||
|
let mut child = Command::new(executable).args(args).spawn()?;
|
||||||
|
let status = child.wait().await?;
|
||||||
|
Ok(status.success())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_script(name: &str, executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool> {
|
||||||
|
// Run given script to get exit code and return true on success.
|
||||||
|
// Return false on failure, but also print an error if needed
|
||||||
|
script_exit_code(executable, args)
|
||||||
|
.await
|
||||||
|
.inspect_err(|message| warn!("Error running {name} {message}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn script_output(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<String> {
|
||||||
|
// Run given command and return the output given
|
||||||
|
let output = Command::new(executable).args(args).output();
|
||||||
|
|
||||||
|
let output = output.await?;
|
||||||
|
|
||||||
|
let s = std::str::from_utf8(&output.stdout)?;
|
||||||
|
Ok(s.to_string())
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue