mirror of
https://github.com/containers/youki
synced 2024-06-10 16:56:17 +02:00
fix the notify listener
This commit is contained in:
parent
33ab221467
commit
27bbccd240
|
@ -43,8 +43,8 @@ pub(super) struct ContainerBuilderImpl {
|
|||
pub console_socket: Option<FileDescriptor>,
|
||||
/// Options for rootless containers
|
||||
pub rootless: Option<Rootless>,
|
||||
/// Socket to communicate container start
|
||||
pub notify_socket: NotifyListener,
|
||||
/// Path to the Unix Domain Socket to communicate container start
|
||||
pub notify_path: PathBuf,
|
||||
/// Container state
|
||||
pub container: Option<Container>,
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ impl ContainerBuilderImpl {
|
|||
self.syscall.clone(),
|
||||
self.rootfs.clone(),
|
||||
self.console_socket.clone(),
|
||||
self.container_dir.clone(),
|
||||
self.notify_path.clone(),
|
||||
&mut child,
|
||||
) {
|
||||
log::debug!("failed to run container_init: {:?}", error);
|
||||
|
@ -209,14 +209,14 @@ fn container_init(
|
|||
command: LinuxSyscall,
|
||||
rootfs: PathBuf,
|
||||
console_socket: Option<FileDescriptor>,
|
||||
container_dir: PathBuf,
|
||||
notify_name: PathBuf,
|
||||
child: &mut child::ChildProcess,
|
||||
) -> Result<()> {
|
||||
let linux = spec.linux.as_ref().unwrap();
|
||||
let namespaces: Namespaces = linux.namespaces.clone().into();
|
||||
// need to create the notify socket before we pivot root, since the unix
|
||||
// domain socket used here is outside of the rootfs of container
|
||||
let mut notify_socket: NotifyListener = NotifyListener::new(&container_dir)?;
|
||||
let mut notify_socket: NotifyListener = NotifyListener::new(¬ify_name)?;
|
||||
let proc = &spec.process;
|
||||
|
||||
// if Out-of-memory score adjustment is set in specification. set the score
|
||||
|
|
|
@ -45,12 +45,11 @@ impl InitContainerBuilder {
|
|||
let container_dir = self.create_container_dir()?;
|
||||
let spec = self.load_and_safeguard_spec(&container_dir)?;
|
||||
|
||||
unistd::chdir(&*container_dir)?;
|
||||
let container_state = self
|
||||
.create_container_state(&container_dir)?
|
||||
.set_systemd(self.use_systemd);
|
||||
|
||||
let notify_socket: NotifyListener = NotifyListener::new(NOTIFY_FILE)?;
|
||||
let notify_path = container_dir.join(NOTIFY_FILE);
|
||||
// convert path of root file system of the container to absolute path
|
||||
let rootfs = fs::canonicalize(&spec.root.path)?;
|
||||
|
||||
|
@ -79,7 +78,7 @@ impl InitContainerBuilder {
|
|||
spec,
|
||||
rootfs,
|
||||
rootless,
|
||||
notify_socket,
|
||||
notify_path,
|
||||
container: Some(container_state),
|
||||
};
|
||||
|
||||
|
|
|
@ -95,8 +95,7 @@ impl TenantContainerBuilder {
|
|||
self.adapt_spec_for_tenant(&mut spec, &container)?;
|
||||
log::debug!("{:#?}", spec);
|
||||
|
||||
unistd::chdir(&*container_dir)?;
|
||||
let (notify_listener, notify_path) = Self::setup_notify_listener(&container_dir)?;
|
||||
let notify_path = Self::setup_notify_listener(&container_dir)?;
|
||||
// convert path of root file system of the container to absolute path
|
||||
let rootfs = fs::canonicalize(&spec.root.path)?;
|
||||
|
||||
|
@ -118,7 +117,7 @@ impl TenantContainerBuilder {
|
|||
spec,
|
||||
rootfs,
|
||||
rootless,
|
||||
notify_socket: notify_listener,
|
||||
notify_path: notify_path.clone(),
|
||||
container: None,
|
||||
};
|
||||
|
||||
|
@ -287,12 +286,11 @@ impl TenantContainerBuilder {
|
|||
false
|
||||
}
|
||||
|
||||
fn setup_notify_listener(container_dir: &Path) -> Result<(NotifyListener, PathBuf)> {
|
||||
fn setup_notify_listener(container_dir: &Path) -> Result<PathBuf> {
|
||||
let notify_name = Self::generate_name(&container_dir, TENANT_NOTIFY);
|
||||
let socket_path = container_dir.join(¬ify_name);
|
||||
let notify_listener: NotifyListener = NotifyListener::new(¬ify_name)?;
|
||||
|
||||
Ok((notify_listener, socket_path))
|
||||
Ok(socket_path)
|
||||
}
|
||||
|
||||
fn setup_tty_socket(&self, container_dir: &Path) -> Result<Option<FileDescriptor>> {
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::env;
|
|||
use std::io::prelude::*;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use nix::unistd::{self, close};
|
||||
|
@ -14,7 +14,7 @@ pub struct NotifyListener {
|
|||
}
|
||||
|
||||
impl NotifyListener {
|
||||
pub fn new(socket_name: &str) -> Result<Self> {
|
||||
pub fn new(socket_name: &Path) -> Result<Self> {
|
||||
let stream = UnixListener::bind(socket_name)?;
|
||||
Ok(Self { socket: stream })
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue