summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAva Hahn <a.hahn@f5.com>2024-05-03 17:52:47 -0700
committeravahahn <110854134+avahahn@users.noreply.github.com>2024-05-08 13:30:08 -0700
commitcb03d31e02741b87fc3a3aa379bf8f1849442ae2 (patch)
tree142671ad3019a029647f8d715381f81090ad692c
parent787980db2e4cdc39c6195584e54661841e542a47 (diff)
downloadunit-cb03d31e02741b87fc3a3aa379bf8f1849442ae2.tar.gz
unit-cb03d31e02741b87fc3a3aa379bf8f1849442ae2.tar.bz2
tools/unitctl: Update host_path() to account for OSX special behaviour
Signed-off-by: Ava Hahn <a.hahn@f5.com>
-rw-r--r--tools/unitctl/unit-client-rs/src/unitd_docker.rs39
-rw-r--r--tools/unitctl/unit-client-rs/src/unitd_process.rs2
2 files changed, 32 insertions, 9 deletions
diff --git a/tools/unitctl/unit-client-rs/src/unitd_docker.rs b/tools/unitctl/unit-client-rs/src/unitd_docker.rs
index 2b51ddd3..4c86c870 100644
--- a/tools/unitctl/unit-client-rs/src/unitd_docker.rs
+++ b/tools/unitctl/unit-client-rs/src/unitd_docker.rs
@@ -166,7 +166,6 @@ impl UnitdContainer {
pub fn host_path(&self, container_path: String) -> String {
let cp = PathBuf::from(container_path);
-
// get only possible mount points
// sort to deepest mountpoint first
// assumed deepest possible mount point takes precedence
@@ -180,14 +179,26 @@ impl UnitdContainer {
// either return translated path or original prefixed with "container"
if keys.len() > 0 {
- self.mounts[&keys[0]]
+ let mut matches = self.mounts[&keys[0]]
.clone()
- .join(
- cp.as_path()
- .strip_prefix(keys[0].clone())
- .expect("error checking path prefix"),
- )
- .to_string_lossy()
+ .join(cp.as_path()
+ .strip_prefix(keys[0].clone())
+ .expect("error checking path prefix"));
+ /* Observed on M1 Mac that Docker on OSX
+ * adds a bunch of garbage to the mount path
+ * converting it into a useless directory
+ * that doesnt actually exist
+ */
+ if cfg!(target_os = "macos") {
+ let mut abs = PathBuf::from("/");
+ let m = matches.strip_prefix("/host_mnt/private")
+ .unwrap_or(matches.strip_prefix("/host_mnt")
+ .unwrap_or(matches.as_path()));
+ // make it absolute again
+ abs.push(m);
+ matches = abs;
+ }
+ matches.to_string_lossy()
.to_string()
} else {
format!("<container>:{}", cp.display())
@@ -361,6 +372,8 @@ mod tests {
mounts.insert("/root/mid/child".into(), "/3".into());
mounts.insert("/mid/child".into(), "/4".into());
mounts.insert("/child".into(), "/5".into());
+ mounts.insert("/var".into(), "/host_mnt/private/6".into());
+ mounts.insert("/var/var".into(), "/host_mnt/7".into());
let ctr = UnitdContainer {
container_id: None,
@@ -379,6 +392,16 @@ mod tests {
"<container>:/path/to/conf".to_string(),
ctr.host_path("/path/to/conf".to_string())
);
+ if cfg!(target_os = "macos") {
+ assert_eq!(
+ "/6/test".to_string(),
+ ctr.host_path("/var/test".to_string())
+ );
+ assert_eq!(
+ "/7/test".to_string(),
+ ctr.host_path("/var/var/test".to_string())
+ );
+ }
}
#[test]
diff --git a/tools/unitctl/unit-client-rs/src/unitd_process.rs b/tools/unitctl/unit-client-rs/src/unitd_process.rs
index 848f31bc..47ffcb5d 100644
--- a/tools/unitctl/unit-client-rs/src/unitd_process.rs
+++ b/tools/unitctl/unit-client-rs/src/unitd_process.rs
@@ -63,7 +63,7 @@ impl UnitdProcess {
.filter(|p| {
#[cfg(target_os = "linux")]
if pid_is_dockerized(p.0.as_u32().into()) {
- false
+ return false;
}
let parent_pid = p.1.parent();
match parent_pid {