mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-06 06:30:27 -04:00
Run cargo fmt
This commit is contained in:
parent
5afe7222ca
commit
7217b0c2b1
1 changed files with 84 additions and 81 deletions
165
src/manager.rs
165
src/manager.rs
|
@ -23,9 +23,9 @@
|
|||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
use std::{ fs, ffi::OsStr, fmt };
|
||||
use std::{ffi::OsStr, fmt, fs};
|
||||
use tokio::{fs::File, io::AsyncWriteExt, process::Command};
|
||||
use zbus::{ interface, zvariant::Fd };
|
||||
use zbus::{interface, zvariant::Fd};
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
|
@ -36,16 +36,13 @@ enum WifiDebugMode {
|
|||
|
||||
impl TryFrom<u32> for WifiDebugMode {
|
||||
type Error = &'static str;
|
||||
fn try_from(v: u32) -> Result<Self, Self::Error>
|
||||
{
|
||||
fn try_from(v: u32) -> Result<Self, Self::Error> {
|
||||
match v {
|
||||
x if x == WifiDebugMode::Off as u32 => Ok(WifiDebugMode::Off),
|
||||
x if x == WifiDebugMode::On as u32 => Ok(WifiDebugMode::On),
|
||||
_ => { Err("No enum match for value {v}") },
|
||||
_ => Err("No enum match for value {v}"),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl fmt::Display for WifiDebugMode {
|
||||
|
@ -64,10 +61,8 @@ pub struct SMManager {
|
|||
should_trace: bool,
|
||||
}
|
||||
|
||||
impl SMManager
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
impl SMManager {
|
||||
pub fn new() -> Self {
|
||||
SMManager {
|
||||
wifi_debug_mode: WifiDebugMode::Off,
|
||||
should_trace: is_galileo().unwrap(),
|
||||
|
@ -75,17 +70,13 @@ impl SMManager
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for SMManager
|
||||
{
|
||||
fn default() -> Self
|
||||
{
|
||||
impl Default for SMManager {
|
||||
fn default() -> Self {
|
||||
SMManager::new()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const OVERRIDE_CONTENTS: &str =
|
||||
"[Service]
|
||||
const OVERRIDE_CONTENTS: &str = "[Service]
|
||||
ExecStart=
|
||||
ExecStart=/usr/lib/iwd/iwd -d
|
||||
";
|
||||
|
@ -99,8 +90,7 @@ const MIN_BUFFER_SIZE: u32 = 100;
|
|||
const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name";
|
||||
const GALILEO_NAME: &str = "Galileo";
|
||||
|
||||
fn is_galileo() -> std::io::Result<bool>
|
||||
{
|
||||
fn is_galileo() -> std::io::Result<bool> {
|
||||
let mut board_name = fs::read_to_string(BOARD_NAME_PATH)?;
|
||||
board_name = board_name.trim().to_string();
|
||||
|
||||
|
@ -108,19 +98,18 @@ fn is_galileo() -> std::io::Result<bool>
|
|||
Ok(matches)
|
||||
}
|
||||
|
||||
async fn script_exit_code(
|
||||
executable: &str,
|
||||
args: &[impl AsRef<OsStr>],
|
||||
) -> std::io::Result<bool> {
|
||||
async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> std::io::Result<bool> {
|
||||
// Run given script and return true on success
|
||||
let mut child = Command::new(executable)
|
||||
.args(args)
|
||||
.spawn()?;
|
||||
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>]) -> std::io::Result<bool> {
|
||||
async fn run_script(
|
||||
name: &str,
|
||||
executable: &str,
|
||||
args: &[impl AsRef<OsStr>],
|
||||
) -> std::io::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
|
||||
match script_exit_code(executable, args).await {
|
||||
|
@ -148,9 +137,8 @@ async fn script_output(
|
|||
Ok(s.to_string())
|
||||
}
|
||||
|
||||
async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error>
|
||||
{
|
||||
// Copy override.conf file into place or out of place depending
|
||||
async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> {
|
||||
// Copy override.conf file into place or out of place depending
|
||||
// on install value
|
||||
|
||||
if want_override {
|
||||
|
@ -165,8 +153,7 @@ async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error>
|
|||
}
|
||||
}
|
||||
|
||||
async fn restart_iwd() -> std::io::Result<bool>
|
||||
{
|
||||
async fn restart_iwd() -> std::io::Result<bool> {
|
||||
// First reload systemd since we modified the config most likely
|
||||
// othorwise we wouldn't be restarting iwd.
|
||||
match run_script("reload systemd", "systemctl", &["daemon-reload"]).await {
|
||||
|
@ -179,7 +166,7 @@ async fn restart_iwd() -> std::io::Result<bool>
|
|||
println!("restart_iwd: reload systemd failed somehow");
|
||||
Ok(false)
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("restart_iwd: reload systemd got an error {message}");
|
||||
Err(message)
|
||||
|
@ -187,8 +174,7 @@ async fn restart_iwd() -> std::io::Result<bool>
|
|||
}
|
||||
}
|
||||
|
||||
async fn stop_tracing(should_trace: bool) -> std::io::Result<bool>
|
||||
{
|
||||
async fn stop_tracing(should_trace: bool) -> std::io::Result<bool> {
|
||||
if !should_trace {
|
||||
return Ok(true);
|
||||
}
|
||||
|
@ -196,18 +182,27 @@ async fn stop_tracing(should_trace: bool) -> std::io::Result<bool>
|
|||
// Stop tracing and extract ring buffer to disk for capture
|
||||
run_script("stop tracing", "trace-cmd", &["stop"]).await?;
|
||||
// stop tracing worked
|
||||
run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await
|
||||
run_script(
|
||||
"extract traces",
|
||||
"trace-cmd",
|
||||
&["extract", "-o", OUTPUT_FILE],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn start_tracing(buffer_size:u32, should_trace: bool) -> std::io::Result<bool>
|
||||
{
|
||||
async fn start_tracing(buffer_size: u32, should_trace: bool) -> std::io::Result<bool> {
|
||||
if !should_trace {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// Start tracing
|
||||
let size_str = format!("{}", buffer_size);
|
||||
run_script("start tracing", "trace-cmd", &["start", "-e", "ath11k_wmi_diag", "-b", &size_str]).await
|
||||
run_script(
|
||||
"start tracing",
|
||||
"trace-cmd",
|
||||
&["start", "-e", "ath11k_wmi_diag", "-b", &size_str],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1")]
|
||||
|
@ -221,8 +216,8 @@ impl SMManager {
|
|||
async fn factory_reset(&self) -> bool {
|
||||
// Run steamos factory reset script and return true on success
|
||||
match run_script("factory reset", "steamos-factory-reset-config", &[""]).await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,9 +228,10 @@ impl SMManager {
|
|||
"/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management",
|
||||
&[""],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,9 +243,10 @@ impl SMManager {
|
|||
"systemcltl",
|
||||
&["start", "jupiter-fan-control-service"],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
} else {
|
||||
match run_script(
|
||||
|
@ -257,9 +254,10 @@ impl SMManager {
|
|||
"systemctl",
|
||||
&["stop", "jupiter-fan-control.service"],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,8 +266,8 @@ impl SMManager {
|
|||
// Run jupiter-check-support note this script does exit 1 for "Support: No" case
|
||||
// so no need to parse output, etc.
|
||||
match run_script("check hardware support", "jupiter-check-support", &[""]).await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,9 +295,10 @@ impl SMManager {
|
|||
"/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate",
|
||||
&["--auto"],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,9 +310,10 @@ impl SMManager {
|
|||
"/usr/bin/steamos-polkit-helpers/jupiter-dock-updater",
|
||||
&[""],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,9 +325,10 @@ impl SMManager {
|
|||
"/usr/bin/steamos-polkit-helpers/steamos-trim-devices",
|
||||
&[""],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,9 +340,10 @@ impl SMManager {
|
|||
"/usr/bin/steamos-polkit-helpers/steamos-format-sdcard",
|
||||
&[""],
|
||||
)
|
||||
.await {
|
||||
Ok(value) => { value },
|
||||
Err(_) => { false }
|
||||
.await
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,9 +477,7 @@ impl SMManager {
|
|||
}
|
||||
}
|
||||
|
||||
async fn get_als_integration_time_file_descriptor(
|
||||
&self,
|
||||
) -> Result<Fd, zbus::fdo::Error> {
|
||||
async fn get_als_integration_time_file_descriptor(&self) -> Result<Fd, zbus::fdo::Error> {
|
||||
// Get the file descriptor for the als integration time sysfs path
|
||||
// /sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time
|
||||
// Return -1 on error
|
||||
|
@ -520,33 +520,36 @@ impl SMManager {
|
|||
self.wifi_debug_mode = WifiDebugMode::Off;
|
||||
} else {
|
||||
// restart_iwd failed
|
||||
println!("restart_iwd failed somehow, check log above");
|
||||
println!(
|
||||
"restart_iwd failed somehow, check log above"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("restart_iwd got an error {message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("setup_iwd_config false got an error somehow {message}");
|
||||
println!(
|
||||
"setup_iwd_config false got an error somehow {message}"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("stop_tracing command failed somehow, bailing");
|
||||
return false;
|
||||
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("stop_tracing command had an error {message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(WifiDebugMode::On) => {
|
||||
// If mode is 1 enable wifi debug mode
|
||||
if buffer_size < MIN_BUFFER_SIZE {
|
||||
|
@ -570,7 +573,7 @@ impl SMManager {
|
|||
println!("start_tracing failed somehow");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("start_tracing got an error {message}");
|
||||
return false;
|
||||
|
@ -580,24 +583,24 @@ impl SMManager {
|
|||
println!("restart_iwd failed somehow");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("restart_iwd got an error {message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(message) => {
|
||||
println!("setup_iwd_config true got an error somehow {message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(_) => {
|
||||
// Invalid mode requested, more coming later, but add this catch-all for now
|
||||
println!("Invalid wifi debug mode {mode} requested");
|
||||
println!("Invalid wifi debug mode {mode} requested");
|
||||
return false;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue