summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinitard <solo@softwareag.com>2022-03-08 14:08:58 +0000
committerinitard <solo@softwareag.com>2022-03-10 12:48:37 +0000
commit30c6ec1478c050a75fa909c5320a9c6431b2c616 (patch)
tree397d72042f9e5fb352a8525a8ed094b96c56ed71
parentdd607148665cbaea265211f1442c7ec8e01cc604 (diff)
fixed /run path bug introduced by #939
- updated /run default configuration to use /run Signed-off-by: initard <solo@softwareag.com>
-rw-r--r--crates/common/flockfile/src/unix.rs17
-rw-r--r--crates/common/tedge_config/src/tedge_config.rs2
-rw-r--r--crates/core/tedge_agent/src/restart_operation_handler.rs6
3 files changed, 15 insertions, 10 deletions
diff --git a/crates/common/flockfile/src/unix.rs b/crates/common/flockfile/src/unix.rs
index fe2053a0..2efaa316 100644
--- a/crates/common/flockfile/src/unix.rs
+++ b/crates/common/flockfile/src/unix.rs
@@ -5,7 +5,9 @@ use std::{
os::unix::io::AsRawFd,
path::{Path, PathBuf},
};
-use tracing::{debug, error, warn};
+use tracing::{debug, error, info, warn};
+
+const LOCK_CHILD_DIRECTORY: &str = "lock/";
#[derive(thiserror::Error, Debug)]
pub enum FlockfileError {
@@ -40,9 +42,8 @@ impl Flockfile {
///
/// let _lockfile = match flockfile::Flockfile::new_lock("app")).unwrap();
///
- pub fn new_lock(lock_name: impl AsRef<Path>) -> Result<Flockfile, FlockfileError> {
- let path = Path::new("/run/lock").join(lock_name);
-
+ pub fn new_lock(path: impl AsRef<Path>) -> Result<Flockfile, FlockfileError> {
+ let path = PathBuf::new().join(path);
let file = match OpenOptions::new()
.create(true)
.read(true)
@@ -62,7 +63,7 @@ impl Flockfile {
}
};
- debug!(r#"Lockfile created "{:?}""#, &path);
+ info!(r#"Lockfile created {:?}"#, &path);
Ok(Flockfile {
handle: Some(file),
path,
@@ -109,7 +110,11 @@ pub fn check_another_instance_is_not_running(
app_name: &str,
run_dir: &PathBuf,
) -> Result<Flockfile, FlockfileError> {
- match Flockfile::new_lock(run_dir.join(format!("{}.lock", app_name))) {
+ match Flockfile::new_lock(
+ run_dir
+ .join(format!("{}{}.lock", LOCK_CHILD_DIRECTORY, app_name))
+ .as_path(),
+ ) {
Ok(file) => Ok(file),
Err(err) => {
return match &err {
diff --git a/crates/common/tedge_config/src/tedge_config.rs b/crates/common/tedge_config/src/tedge_config.rs
index f3567d28..0c403087 100644
--- a/crates/common/tedge_config/src/tedge_config.rs
+++ b/crates/common/tedge_config/src/tedge_config.rs
@@ -566,7 +566,7 @@ impl ConfigSettingAccessor<RunPathDefaultSetting> for TEdgeConfig {
.run
.dir_path
.clone()
- .unwrap_or_else(|| self.config_defaults.default_logs_path.clone()))
+ .unwrap_or_else(|| self.config_defaults.default_run_path.clone()))
}
fn update(
diff --git a/crates/core/tedge_agent/src/restart_operation_handler.rs b/crates/core/tedge_agent/src/restart_operation_handler.rs
index 0873c43d..ed1b46ab 100644
--- a/crates/core/tedge_agent/src/restart_operation_handler.rs
+++ b/crates/core/tedge_agent/src/restart_operation_handler.rs
@@ -46,8 +46,8 @@ pub mod restart_operation {
}
/// returns the datetime of `SLASH_RUN_PATH_TEDGE_AGENT_RESTART` "modified at".
- fn get_restart_file_datetime() -> Result<time::OffsetDateTime, AgentError> {
- let mut file = File::open(&SLASH_RUN_PATH_TEDGE_AGENT_RESTART)?;
+ fn get_restart_file_datetime(run_dir: &PathBuf) -> Result<time::OffsetDateTime, AgentError> {
+ let mut file = File::open(&run_dir.join(SLASH_RUN_PATH_TEDGE_AGENT_RESTART))?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
@@ -108,7 +108,7 @@ pub mod restart_operation {
}
let system_reboot_dt = get_system_uptime()?;
- let tedge_restart_file_dt = get_restart_file_datetime()?;
+ let tedge_restart_file_dt = get_restart_file_datetime(&run_dir)?;
Ok(system_reboot_dt > tedge_restart_file_dt)
}