mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 09:22:26 -04:00
Add some error checking to run_script and println! on errors.
TODO: Maybe log to journal instead, but maybe not needed depending how this daemon gets executed.
This commit is contained in:
parent
a10db120e6
commit
96b42d1338
1 changed files with 19 additions and 16 deletions
|
@ -24,21 +24,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use subprocess::{ExitStatus::Exited, Popen, PopenConfig, Redirection};
|
use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError};
|
||||||
use zbus_macros::dbus_interface;
|
use zbus_macros::dbus_interface;
|
||||||
pub struct SMManager {
|
pub struct SMManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_script(argv: &[impl AsRef<OsStr>]) -> bool {
|
fn script_exit_code(argv: &[impl AsRef<OsStr>]) -> Result<bool, PopenError> {
|
||||||
// Run given script and return true on success
|
// Run given script and return true on success
|
||||||
let mut process = Popen::create(argv, PopenConfig {
|
let mut process = Popen::create(argv, PopenConfig::default())?;
|
||||||
stdout: Redirection::Pipe, ..Default::default()
|
let exit_status = process.wait()?;
|
||||||
}).unwrap();
|
Ok(exit_status == Exited(0))
|
||||||
let (_out, _err) = process.communicate(None).unwrap();
|
}
|
||||||
if let Some(exit_status) = process.poll() {
|
|
||||||
exit_status == Exited(0)
|
fn run_script(name: &str, argv: &[impl AsRef<OsStr>]) -> bool {
|
||||||
} else {
|
// Run given script to get exit code and return true on success.
|
||||||
false
|
// Return false on failure, but also print an error if needed
|
||||||
|
match script_exit_code(argv) {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(err) => { println!("Error running {} {}", name, err); false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,27 +56,27 @@ impl SMManager {
|
||||||
|
|
||||||
async fn factory_reset(&self) -> bool {
|
async fn factory_reset(&self) -> bool {
|
||||||
// Run steamos factory reset script and return true on success
|
// Run steamos factory reset script and return true on success
|
||||||
run_script(&["steamos-factory-reset-config"])
|
run_script("factory reset", &["steamos-factory-reset-config"])
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn disable_wifi_power_management(&self) -> bool {
|
async fn disable_wifi_power_management(&self) -> bool {
|
||||||
// Run what steamos-polkit-helpers/steamos-disable-wifi-power-management does
|
// Run polkit helper script and return true on success
|
||||||
run_script(&["iwconfig", "wlan0", "power", "off"])
|
run_script("disable wifi power management", &["/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management"])
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn enable_fan_control(&self, enable: bool) -> bool {
|
async fn enable_fan_control(&self, enable: bool) -> bool {
|
||||||
// Run what steamos-polkit-helpers/jupiter-fan-control does
|
// Run what steamos-polkit-helpers/jupiter-fan-control does
|
||||||
if enable {
|
if enable {
|
||||||
run_script(&["systemctl", "start", "jupiter-fan-control.service"])
|
run_script("enable fan control", &["systemctl", "start", "jupiter-fan-control.service"])
|
||||||
} else {
|
} else {
|
||||||
run_script(&["systemctl", "stop", "jupiter-fan-control.service"])
|
run_script("disable fan control", &["systemctl", "stop", "jupiter-fan-control.service"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn hardware_check_support(&self) -> bool {
|
async fn hardware_check_support(&self) -> bool {
|
||||||
// Run jupiter-check-support note this script does exit 1 for "Support: No" case
|
// Run jupiter-check-support note this script does exit 1 for "Support: No" case
|
||||||
// so no need to parse output, etc.
|
// so no need to parse output, etc.
|
||||||
run_script(&["jupiter-check-support"])
|
run_script("check hardware support", &["jupiter-check-support"])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A version property.
|
/// A version property.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue