summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-08-03 09:46:29 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-08-16 11:58:23 +0200
commit9e6f96addf5ace5716f3a94dce95937921fa8f51 (patch)
treec5e187c9b2ad28a0e0ce71903a3022a5396e6b03
parentd7863fc8c154135d95f99da81a0e4e8f30e0a8d2 (diff)
Make systemd watchdog backend only build for linux
This patch ensures that the systemd watchdog backend is only used when building for linux. Right now, there is no other watchdog implementation. Thus, there is a "dummy_watchdog" module introduced that does nothing. This might be removed and replaced by something specific, if we ever build thin-edge.io for other targets, such as Apple, FreeBSD or others. Suggested-by: Albin Suresh <albin.suresh@softwareag.com> Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--crates/core/tedge_watchdog/src/dummy_watchdog.rs3
-rw-r--r--crates/core/tedge_watchdog/src/error.rs4
-rw-r--r--crates/core/tedge_watchdog/src/main.rs13
3 files changed, 19 insertions, 1 deletions
diff --git a/crates/core/tedge_watchdog/src/dummy_watchdog.rs b/crates/core/tedge_watchdog/src/dummy_watchdog.rs
new file mode 100644
index 00000000..f701ffbe
--- /dev/null
+++ b/crates/core/tedge_watchdog/src/dummy_watchdog.rs
@@ -0,0 +1,3 @@
+pub async fn start_watchdog(_config_dir: PathBuf) -> Result<(), anyhow::Error> {
+ anyhow::Error::from(crate::error::WatchdogError::WatchdogNotAvailable)
+}
diff --git a/crates/core/tedge_watchdog/src/error.rs b/crates/core/tedge_watchdog/src/error.rs
index f9763798..27a9a1ed 100644
--- a/crates/core/tedge_watchdog/src/error.rs
+++ b/crates/core/tedge_watchdog/src/error.rs
@@ -4,6 +4,10 @@ use tedge_config::{ConfigSettingError, TEdgeConfigError};
#[derive(Debug, thiserror::Error)]
pub enum WatchdogError {
+ #[cfg(not(target_os = "linux"))]
+ #[error("The watchdog is not available on this platform")]
+ WatchdogNotAvailable,
+
#[error("Fail to run `{cmd}`: {from}")]
CommandExecError { cmd: String, from: std::io::Error },
diff --git a/crates/core/tedge_watchdog/src/main.rs b/crates/core/tedge_watchdog/src/main.rs
index e4478b2f..8f0c2b4b 100644
--- a/crates/core/tedge_watchdog/src/main.rs
+++ b/crates/core/tedge_watchdog/src/main.rs
@@ -3,7 +3,18 @@ use std::path::PathBuf;
use tedge_config::DEFAULT_TEDGE_CONFIG_PATH;
mod error;
+
+// on linux, we use systemd
+#[cfg(target_os = "linux")]
mod systemd_watchdog;
+#[cfg(target_os = "linux")]
+use systemd_watchdog as watchdog;
+
+// on non-linux, we do nothing for now
+#[cfg(not(target_os = "linux"))]
+mod dummy_watchdog;
+#[cfg(not(target_os = "linux"))]
+use dummy_watchdog as watchdog;
#[derive(Debug, clap::Parser)]
#[clap(
@@ -31,5 +42,5 @@ async fn main() -> Result<(), anyhow::Error> {
let watchdog_opt = WatchdogOpt::parse();
tedge_utils::logging::initialise_tracing_subscriber(watchdog_opt.debug);
- systemd_watchdog::start_watchdog(watchdog_opt.config_dir).await
+ watchdog::start_watchdog(watchdog_opt.config_dir).await
}