-
Notifications
You must be signed in to change notification settings - Fork 100
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
Conversation
@@ -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)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change?
There was a problem hiding this comment.
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).
There was a problem hiding this 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)>, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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).
Closes #120