Skip to content

Commit

Permalink
Contract error could be named better (#4081)
Browse files Browse the repository at this point in the history
While looking through sled-agent I noticed the contract(3contract) calls
were returning a `ZoneEnter` error. It seems to make more sense to
rename that error `ContractFailure` and introduce a new log line where
the `zone_enter()` call actually occurs.
  • Loading branch information
papertigers authored Sep 13, 2023
1 parent 951651a commit b966d8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions illumos-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub enum ExecutionError {
#[error("{0}")]
CommandFailure(Box<CommandFailureInfo>),

#[error("Failed to enter zone: {err}")]
ZoneEnter { err: std::io::Error },
#[error("Failed to manipulate process contract: {err}")]
ContractFailure { err: std::io::Error },

#[error("Zone is not running")]
NotRunning,
Expand Down
14 changes: 11 additions & 3 deletions illumos-utils/src/running_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ mod zenter {
let fd = unsafe { libc::open(path.as_ptr(), libc::O_RDWR) };
if fd < 0 {
let err = std::io::Error::last_os_error();
return Err(crate::ExecutionError::ZoneEnter { err });
return Err(crate::ExecutionError::ContractFailure { err });
}

// Initialize the contract template.
Expand All @@ -372,7 +372,7 @@ mod zenter {
|| unsafe { ct_tmpl_activate(fd) } != 0
{
let err = std::io::Error::last_os_error();
return Err(crate::ExecutionError::ZoneEnter { err });
return Err(crate::ExecutionError::ContractFailure { err });
}
Ok(Self { fd })
}
Expand Down Expand Up @@ -440,6 +440,8 @@ impl RunningZone {
})?);
let tmpl = std::sync::Arc::clone(&template);
let mut command = std::process::Command::new(crate::PFEXEC);
let logger = self.inner.log.clone();
let zone = self.name().to_string();
command.env_clear();
unsafe {
command.pre_exec(move || {
Expand All @@ -452,7 +454,13 @@ impl RunningZone {
if zenter::zone_enter(id) == 0 {
Ok(())
} else {
Err(std::io::Error::last_os_error())
let err = std::io::Error::last_os_error();
error!(
logger,
"failed to enter zone: {}", &err;
"zone" => &zone,
);
Err(err)
}
});
}
Expand Down

0 comments on commit b966d8b

Please sign in to comment.