mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
agent: replace if let Err
with or_else
Fixes #934 Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
parent
6ffa8283f0
commit
a3c64e5ce5
@ -487,23 +487,26 @@ fn do_init_child(cwfd: RawFd) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log_child!(cfd_log, "join namespace {:?}", s);
|
log_child!(cfd_log, "join namespace {:?}", s);
|
||||||
if let Err(e) = sched::setns(fd, s) {
|
sched::setns(fd, s).or_else(|e| {
|
||||||
if s == CloneFlags::CLONE_NEWUSER {
|
if s == CloneFlags::CLONE_NEWUSER {
|
||||||
if e.as_errno().unwrap() != Errno::EINVAL {
|
if e.as_errno().unwrap() != Errno::EINVAL {
|
||||||
check!(
|
check!(
|
||||||
write_sync(cwfd, SYNC_FAILED, format!("{:?}", e).as_str()),
|
write_sync(cwfd, SYNC_FAILED, format!("{:?}", e).as_str()),
|
||||||
"write_sync for CLONE_NEWUSER"
|
"write_sync for CLONE_NEWUSER"
|
||||||
);
|
);
|
||||||
return Err(e.into());
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
check!(
|
check!(
|
||||||
write_sync(cwfd, SYNC_FAILED, format!("{:?}", e).as_str()),
|
write_sync(cwfd, SYNC_FAILED, format!("{:?}", e).as_str()),
|
||||||
"write_sync for sched::setns"
|
"write_sync for sched::setns"
|
||||||
);
|
);
|
||||||
return Err(e.into());
|
Err(e)
|
||||||
}
|
}
|
||||||
}
|
})?;
|
||||||
|
|
||||||
unistd::close(fd)?;
|
unistd::close(fd)?;
|
||||||
|
|
||||||
if s == CloneFlags::CLONE_NEWUSER {
|
if s == CloneFlags::CLONE_NEWUSER {
|
||||||
|
@ -479,15 +479,18 @@ fn mount_to_rootfs(logger: &Logger, m: &INIT_MOUNT) -> Result<()> {
|
|||||||
|
|
||||||
fs::create_dir_all(Path::new(m.dest)).context("could not create directory")?;
|
fs::create_dir_all(Path::new(m.dest)).context("could not create directory")?;
|
||||||
|
|
||||||
if let Err(err) = bare_mount.mount() {
|
bare_mount.mount().or_else(|e| {
|
||||||
if m.src != "dev" {
|
if m.src != "dev" {
|
||||||
return Err(err.into());
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
error!(
|
error!(
|
||||||
logger,
|
logger,
|
||||||
"Could not mount filesystem from {} to {}", m.src, m.dest
|
"Could not mount filesystem from {} to {}", m.src, m.dest
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1610,11 +1610,13 @@ fn do_copy_file(req: &CopyFileRequest) -> Result<()> {
|
|||||||
PathBuf::from("/")
|
PathBuf::from("/")
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = fs::create_dir_all(dir.to_str().unwrap()) {
|
fs::create_dir_all(dir.to_str().unwrap()).or_else(|e| {
|
||||||
if e.kind() != std::io::ErrorKind::AlreadyExists {
|
if e.kind() != std::io::ErrorKind::AlreadyExists {
|
||||||
return Err(e.into());
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
|
||||||
std::fs::set_permissions(
|
std::fs::set_permissions(
|
||||||
dir.to_str().unwrap(),
|
dir.to_str().unwrap(),
|
||||||
|
Loading…
Reference in New Issue
Block a user