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

Remove unnecessary chdir #2780

Merged
merged 7 commits into from
May 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions crates/libcontainer/src/container/container_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ impl Container {
err
})?;
if let Some(hooks) = config.hooks.as_ref() {
let original_dir = env::current_dir().map_err(|err| {
tracing::error!("failed to get current directory: {}", err);
LibcontainerError::Other(format!("failed to get current directory: {}", err))
})?;

unistd::chdir(self.root.as_os_str()).map_err(|err| {
tracing::error!("failed to change directory to container root: {}", err);
LibcontainerError::OtherSyscall(err)
})?;

// While prestart is marked as deprecated in the OCI spec, the docker and integration test still
// uses it.
#[allow(deprecated)]
Expand All @@ -69,11 +59,6 @@ impl Container {

err
})?;

unistd::chdir(original_dir.as_path()).map_err(|err| {
tracing::error!("failed to change directory to container root: {}", err);
LibcontainerError::OtherSyscall(err)
})?;
}

let mut notify_socket = NotifySocket::new(self.root.join(NOTIFY_FILE));
Expand All @@ -88,10 +73,25 @@ impl Container {
// Run post start hooks. It runs after the container process is started.
// It is called in the runtime namespace.
if let Some(hooks) = config.hooks.as_ref() {
let original_dir = env::current_dir().map_err(|err| {
tracing::error!("failed to get current directory: {}", err);
LibcontainerError::Other(format!("failed to get current directory: {}", err))
})?;

unistd::chdir(self.root.as_os_str()).map_err(|err| {
jprendes marked this conversation as resolved.
Show resolved Hide resolved
tracing::error!("failed to change directory to container root: {}", err);
LibcontainerError::OtherSyscall(err)
})?;

hooks::run_hooks(hooks.poststart().as_ref(), Some(self)).map_err(|err| {
tracing::error!("failed to run post start hooks: {}", err);
err
})?;

unistd::chdir(original_dir.as_path()).map_err(|err| {
tracing::error!("failed to change directory to container root: {}", err);
LibcontainerError::OtherSyscall(err)
})?;
}

Ok(())
Expand Down