diff --git a/Cargo.lock b/Cargo.lock
index e8d6b18..2824a9f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 3
+[[package]]
+name = "addr2line"
+version = "0.21.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
+dependencies = [
+ "gimli",
+]
+
+[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
[[package]]
name = "aho-corasick"
version = "1.0.5"
@@ -11,16 +26,6 @@ dependencies = [
"memchr",
]
-[[package]]
-name = "async-attributes"
-version = "1.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5"
-dependencies = [
- "quote",
- "syn 1.0.109",
-]
-
[[package]]
name = "async-broadcast"
version = "0.5.1"
@@ -68,21 +73,6 @@ dependencies = [
"futures-lite",
]
-[[package]]
-name = "async-global-executor"
-version = "2.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776"
-dependencies = [
- "async-channel",
- "async-executor",
- "async-io",
- "async-lock",
- "blocking",
- "futures-lite",
- "once_cell",
-]
-
[[package]]
name = "async-io"
version = "1.13.0"
@@ -99,7 +89,7 @@ dependencies = [
"polling",
"rustix 0.37.23",
"slab",
- "socket2",
+ "socket2 0.4.9",
"waker-fn",
]
@@ -141,33 +131,6 @@ dependencies = [
"syn 2.0.33",
]
-[[package]]
-name = "async-std"
-version = "1.12.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d"
-dependencies = [
- "async-attributes",
- "async-channel",
- "async-global-executor",
- "async-io",
- "async-lock",
- "crossbeam-utils",
- "futures-channel",
- "futures-core",
- "futures-io",
- "futures-lite",
- "gloo-timers",
- "kv-log-macro",
- "log",
- "memchr",
- "once_cell",
- "pin-project-lite",
- "pin-utils",
- "slab",
- "wasm-bindgen-futures",
-]
-
[[package]]
name = "async-task"
version = "4.4.0"
@@ -197,6 +160,21 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+[[package]]
+name = "backtrace"
+version = "0.3.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
+dependencies = [
+ "addr2line",
+ "cc",
+ "cfg-if",
+ "libc",
+ "miniz_oxide",
+ "object",
+ "rustc-demangle",
+]
+
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -233,18 +211,18 @@ dependencies = [
"log",
]
-[[package]]
-name = "bumpalo"
-version = "3.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
-
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
+[[package]]
+name = "bytes"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
+
[[package]]
name = "cc"
version = "1.0.83"
@@ -393,15 +371,6 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
-[[package]]
-name = "futures-channel"
-version = "0.3.28"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
-dependencies = [
- "futures-core",
-]
-
[[package]]
name = "futures-core"
version = "0.3.28"
@@ -479,16 +448,10 @@ dependencies = [
]
[[package]]
-name = "gloo-timers"
-version = "0.2.6"
+name = "gimli"
+version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c"
-dependencies = [
- "futures-channel",
- "futures-core",
- "js-sys",
- "wasm-bindgen",
-]
+checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "hashbrown"
@@ -538,24 +501,6 @@ dependencies = [
"windows-sys",
]
-[[package]]
-name = "js-sys"
-version = "0.3.64"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
-dependencies = [
- "wasm-bindgen",
-]
-
-[[package]]
-name = "kv-log-macro"
-version = "1.0.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f"
-dependencies = [
- "log",
-]
-
[[package]]
name = "libc"
version = "0.2.148"
@@ -579,9 +524,6 @@ name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
-dependencies = [
- "value-bag",
-]
[[package]]
name = "memchr"
@@ -598,6 +540,26 @@ dependencies = [
"autocfg",
]
+[[package]]
+name = "miniz_oxide"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
+dependencies = [
+ "adler",
+]
+
+[[package]]
+name = "mio"
+version = "0.8.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
+dependencies = [
+ "libc",
+ "wasi",
+ "windows-sys",
+]
+
[[package]]
name = "nix"
version = "0.26.4"
@@ -610,6 +572,25 @@ dependencies = [
"memoffset",
]
+[[package]]
+name = "num_cpus"
+version = "1.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
+dependencies = [
+ "hermit-abi",
+ "libc",
+]
+
+[[package]]
+name = "object"
+version = "0.32.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "once_cell"
version = "1.18.0"
@@ -762,6 +743,12 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
+[[package]]
+name = "rustc-demangle"
+version = "0.1.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
+
[[package]]
name = "rustix"
version = "0.37.23"
@@ -869,6 +856,16 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "socket2"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
[[package]]
name = "static_assertions"
version = "1.1.0"
@@ -879,24 +876,13 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
name = "steamos-manager"
version = "0.1.0"
dependencies = [
- "async-std",
"dyn",
"serde",
- "subprocess",
+ "tokio",
"zbus",
"zbus_macros",
]
-[[package]]
-name = "subprocess"
-version = "0.2.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086"
-dependencies = [
- "libc",
- "winapi",
-]
-
[[package]]
name = "syn"
version = "1.0.109"
@@ -932,6 +918,36 @@ dependencies = [
"windows-sys",
]
+[[package]]
+name = "tokio"
+version = "1.33.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653"
+dependencies = [
+ "backtrace",
+ "bytes",
+ "libc",
+ "mio",
+ "num_cpus",
+ "pin-project-lite",
+ "signal-hook-registry",
+ "socket2 0.5.4",
+ "tokio-macros",
+ "tracing",
+ "windows-sys",
+]
+
+[[package]]
+name = "tokio-macros"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.33",
+]
+
[[package]]
name = "toml_datetime"
version = "0.6.3"
@@ -1003,12 +1019,6 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
-[[package]]
-name = "value-bag"
-version = "1.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d92ccd67fb88503048c01b59152a04effd0782d035a83a6d256ce6085f08f4a3"
-
[[package]]
name = "version_check"
version = "0.9.4"
@@ -1027,82 +1037,6 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
-[[package]]
-name = "wasm-bindgen"
-version = "0.2.87"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
-dependencies = [
- "cfg-if",
- "wasm-bindgen-macro",
-]
-
-[[package]]
-name = "wasm-bindgen-backend"
-version = "0.2.87"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
-dependencies = [
- "bumpalo",
- "log",
- "once_cell",
- "proc-macro2",
- "quote",
- "syn 2.0.33",
- "wasm-bindgen-shared",
-]
-
-[[package]]
-name = "wasm-bindgen-futures"
-version = "0.4.37"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
-dependencies = [
- "cfg-if",
- "js-sys",
- "wasm-bindgen",
- "web-sys",
-]
-
-[[package]]
-name = "wasm-bindgen-macro"
-version = "0.2.87"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
-dependencies = [
- "quote",
- "wasm-bindgen-macro-support",
-]
-
-[[package]]
-name = "wasm-bindgen-macro-support"
-version = "0.2.87"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.33",
- "wasm-bindgen-backend",
- "wasm-bindgen-shared",
-]
-
-[[package]]
-name = "wasm-bindgen-shared"
-version = "0.2.87"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
-
-[[package]]
-name = "web-sys"
-version = "0.3.64"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
-dependencies = [
- "js-sys",
- "wasm-bindgen",
-]
-
[[package]]
name = "winapi"
version = "0.3.9"
@@ -1242,6 +1176,7 @@ dependencies = [
"serde_repr",
"sha1",
"static_assertions",
+ "tokio",
"tracing",
"uds_windows",
"winapi",
diff --git a/Cargo.toml b/Cargo.toml
index 2de46bf..e9a671c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,9 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-async-std = { version = "1.12.0", features = ["attributes"] }
dyn = "0.0.0"
serde = { version = "1.0.188", features = ["derive"] }
-subprocess = "0.2.9"
-zbus = "3.14.1"
+tokio = { version = "1.33.0", features = ["fs", "process", "io-std", "rt-multi-thread", "macros"] }
+zbus = { version = "3.14.1", features = ["tokio"] }
zbus_macros = "3.14.1"
diff --git a/data/com.steampowered.SteamOSManager1.conf b/data/com.steampowered.SteamOSManager1.conf
new file mode 100644
index 0000000..d5e101f
--- /dev/null
+++ b/data/com.steampowered.SteamOSManager1.conf
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/com.steampowered.SteamOSManager1.service b/data/com.steampowered.SteamOSManager1.service
new file mode 100644
index 0000000..cc2db50
--- /dev/null
+++ b/data/com.steampowered.SteamOSManager1.service
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=com.steampowered.SteamOSManager1
+Exec=/usr/lib/steamos-manager
+User=root
+SystemdService=steamosmanager.service
diff --git a/data/steamosmanager.service b/data/steamosmanager.service
new file mode 100644
index 0000000..b10f3b3
--- /dev/null
+++ b/data/steamosmanager.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=SteamOS Manager Daemon
+
+[Service]
+Type=dbus
+BusName=com.steampowered.SteamOSManager1
+ExecStart=/usr/lib/steamos-manager
diff --git a/src/main.rs b/src/main.rs
index 81ac2f8..34b0c2b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,7 +27,7 @@ use zbus::{ConnectionBuilder, Result};
pub mod manager;
-#[async_std::main]
+#[tokio::main]
async fn main() -> Result<()>
{
// This daemon is responsible for creating a dbus api that steam client can use to do various OS
@@ -35,7 +35,7 @@ async fn main() -> Result<()>
let manager = manager::SMManager {};
- let _system_connection = ConnectionBuilder::session()?
+ let _system_connection = ConnectionBuilder::system()?
.name("com.steampowered.SteamOSManager1")?
.serve_at("/com/steampowered/SteamOSManager1", manager)?
.build()
diff --git a/src/manager.rs b/src/manager.rs
index d0ae714..a92c547 100644
--- a/src/manager.rs
+++ b/src/manager.rs
@@ -23,40 +23,43 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-use std::ffi::OsStr;
-use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError, Redirection};
+use std::{ffi::OsStr};
+use tokio::process::Command;
use zbus_macros::dbus_interface;
pub struct SMManager {
}
-fn script_exit_code(argv: &[impl AsRef]) -> Result {
+async fn script_exit_code(executable: &str, args: &[impl AsRef]) -> Result> {
// Run given script and return true on success
- let mut process = Popen::create(argv, PopenConfig::default())?;
- let exit_status = process.wait()?;
- Ok(exit_status == Exited(0))
+ let mut child = Command::new(executable)
+ .args(args)
+ .spawn()
+ .expect("Failed to spawn {executable}");
+ let status = child.wait().await?;
+ Ok(status.success())
}
-fn run_script(name: &str, argv: &[impl AsRef]) -> bool {
+async fn run_script(name: &str, executable: &str, args: &[impl AsRef]) -> 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(argv) {
+ match script_exit_code(executable, args).await {
Ok(value) => value,
- Err(err) => { println!("Error running {} {}", name, err); false }
+ Err(err) => { println!("Error running {} {}", name, err); false}
}
}
-fn script_output(argv: &[impl AsRef]) -> Result {
+async fn script_output(executable: &str, args: &[impl AsRef]) -> Result> {
// Run given command and return the output given
- let mut process = Popen::create(argv, PopenConfig {
- stdout: Redirection::Pipe,
- ..Default::default()
- })?;
- let (output, _err) = process.communicate(None)?;
- let _exit_status = process.wait()?;
- match output {
- Some(output_strings) => Ok(output_strings),
- None => Err(PopenError::LogicError("Error getting output"))
- }
+ let output = Command::new(executable)
+ .args(args).output();
+
+ let output = output.await?;
+
+ let s = match std::str::from_utf8(&output.stdout) {
+ Ok(v) => v,
+ Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
+ };
+ Ok(s.to_string())
}
#[dbus_interface(name = "com.steampowered.SteamOSManager1")]
@@ -70,32 +73,32 @@ impl SMManager {
async fn factory_reset(&self) -> bool {
// Run steamos factory reset script and return true on success
- run_script("factory reset", &["steamos-factory-reset-config"])
+ run_script("factory reset", "steamos-factory-reset-config", &[""]).await
}
async fn disable_wifi_power_management(&self) -> bool {
// Run polkit helper script and return true on success
- run_script("disable wifi power management", &["/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management"])
+ run_script("disable wifi power management", "/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management", &[""]).await
}
async fn enable_fan_control(&self, enable: bool) -> bool {
// Run what steamos-polkit-helpers/jupiter-fan-control does
if enable {
- run_script("enable fan control", &["systemctl", "start", "jupiter-fan-control.service"])
+ run_script("enable fan control", "systemcltl", &["start", "jupiter-fan-control-service"]).await
} else {
- run_script("disable fan control", &["systemctl", "stop", "jupiter-fan-control.service"])
+ run_script("disable fan control", "systemctl", &["stop", "jupiter-fan-control.service"]).await
}
}
async fn hardware_check_support(&self) -> bool {
// Run jupiter-check-support note this script does exit 1 for "Support: No" case
// so no need to parse output, etc.
- run_script("check hardware support", &["jupiter-check-support"])
+ run_script("check hardware support", "jupiter-check-support", &[""]).await
}
async fn read_als_calibration(&self) -> f32 {
// Run script to get calibration value
- let result = script_output(&["/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain"]);
+ let result = script_output("/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain", &[""]).await;
let mut value: f32 = -1.0;
match result {
Ok(as_string) => value = as_string.trim().parse().unwrap(),