fixed a jail image convertion bug, and docker, I hate you to allow empty string as working dir

This commit is contained in:
(null)
2023-07-26 00:48:01 -04:00
parent b60c9eea7d
commit cb376b93fd
3 changed files with 25 additions and 9 deletions

View File

@@ -250,7 +250,13 @@ impl ProcessRunner {
.jail(&jail);
if let Some(work_dir) = &exec.work_dir {
cmd.jwork_dir(work_dir);
// god damn it Docker
if !work_dir.is_empty() {
let path = std::path::Path::new(&work_dir);
if path.is_absolute() {
cmd.jwork_dir(work_dir);
}
}
}
let devnull = std::path::PathBuf::from("/dev/null");
let spawn_info_result = match &exec.output_mode {
@@ -569,7 +575,7 @@ impl ProcessRunner {
self.container.main_started_notify.notify_waiters();
}
}
Err(error) => error!("cannot spawn {id}: {error:#?}"),
Err(error) => error!("cannot spawn {id}: {process:#?} {error:#?}"),
}
}

View File

@@ -308,13 +308,20 @@ impl JailConfig {
}
pub fn from_json(value: serde_json::Value) -> Option<JailImage> {
serde_json::from_value::<JailImage>(value.clone())
.ok()
.or_else(|| {
serde_json::from_value::<OciConfig>(value)
.ok()
.and_then(Self::from_oci)
})
let maybe_converted = serde_json::from_value::<JailImage>(value.clone()).ok()?;
// .expect(&format!("unknown format: {value}"));
if maybe_converted
.clone()
.oci_config
.config
.and_then(|c| c.xc_extension)
.is_none()
{
let ociconfig = serde_json::from_value::<OciConfig>(value).ok()?;
Self::from_oci(ociconfig)
} else {
Some(maybe_converted)
}
}
pub fn from_oci(config: OciConfig) -> Option<JailImage> {

View File

@@ -200,6 +200,9 @@ pub async fn pull_image(
});
let jail_image = JailConfig::from_json(config).ok_or(PullImageError::ConfigConvertFail)?;
eprintln!("jail_image: {jail_image:#?}");
_ = emitter.use_try(|state| {
state.jail_image = Some(jail_image.clone());
Ok(())