Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix openat relative paths + detours to support ls #139

Closed
wants to merge 13 commits into from

Conversation

infiniteregrets
Copy link
Contributor

Closes #120

@infiniteregrets infiniteregrets changed the title [WIP] Fix openat relative paths Jun 10, 2022
@infiniteregrets infiniteregrets marked this pull request as draft June 10, 2022 21:09
mirrord-protocol/src/codec.rs Outdated Show resolved Hide resolved
@@ -21,7 +21,7 @@ use crate::{error::AgentError, runtime::get_container_pid, sniffer::DEFAULT_RUNT
// `HashMap<_, RemoteFile`>, where `RemoteFile` is a struct that holds both the `File` + `PathBuf`.
#[derive(Debug, Default)]
pub struct FileManager {
pub open_files: HashMap<i32, File>,
pub open_files: HashMap<i32, (File, PathBuf)>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest changing this tuple into a RemoteFile struct:

struct RemoteFile {
    inner: std::fs::File,
    path: PathBuf,
}

And then you could implement many of the file functions in a similar fashion to Rust's std (or just keep the current implementation of FileManager and we do something better later).

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@meowjesty meowjesty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving some initial comments.

@@ -21,7 +21,7 @@ use crate::{error::AgentError, runtime::get_container_pid, sniffer::DEFAULT_RUNT
// `HashMap<_, RemoteFile`>, where `RemoteFile` is a struct that holds both the `File` + `PathBuf`.
#[derive(Debug, Default)]
pub struct FileManager {
pub open_files: HashMap<i32, File>,
pub open_files: HashMap<i32, (File, PathBuf)>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest changing this tuple into a RemoteFile struct:

struct RemoteFile {
    inner: std::fs::File,
    path: PathBuf,
}

And then you could implement many of the file functions in a similar fashion to Rust's std (or just keep the current implementation of FileManager and we do something better later).

Ok(CloseFileResponse { result: 0 })
}

pub(crate) fn opendir(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this distinction? Shouldn't opendir be the same as open? Have you checked how Rust implements this?

})
}

pub(crate) fn readdir(&mut self, fd: i32) -> Result<ReadDirResponse, ResponseError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, isn't a directory just a special case of a file?


// Are we managing the relative part?
if let Some(remote_fd) = remote_fd {
if path.is_absolute() || fd == AT_FDCWD {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs on this handling are a bit confusing to me, but shouldn't these be handled differently?

absolute path, it ignores the fd argument

AT_FDCWD in the fd parameter, the current working directory is used


let local_dir_fd = unsafe {
let local_dir_fd = libc::shm_open(
fake_local_dir_name.as_ptr(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause the *mut DIR to be reported as not a directory. You can check for this on the sample side by looking at the file metadata (Rust has an is_dir method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants