Dragonball: Fix the problem about stdio console

Let stdout stream connect to the com1_device,

Fixes: #5083

Signed-off-by: qiliangfan <fanqiliang@mail.nankai.edu.cn>
This commit is contained in:
qiliangfan 2022-09-02 17:39:00 +08:00 committed by qiliangfan
parent b5786361e9
commit 7622452f4b
2 changed files with 21 additions and 7 deletions

View File

@ -74,11 +74,20 @@ impl ConsoleManager {
/// Create a console backend device by using stdio streams. /// Create a console backend device by using stdio streams.
pub fn create_stdio_console(&mut self, device: Arc<Mutex<SerialDevice>>) -> Result<()> { pub fn create_stdio_console(&mut self, device: Arc<Mutex<SerialDevice>>) -> Result<()> {
device
.lock()
.unwrap()
.set_output_stream(Some(Box::new(std::io::stdout())));
let stdin_handle = std::io::stdin(); let stdin_handle = std::io::stdin();
stdin_handle stdin_handle
.lock() .lock()
.set_raw_mode() .set_raw_mode()
.map_err(|e| DeviceMgrError::ConsoleManager(ConsoleManagerError::StdinHandle(e)))?; .map_err(|e| DeviceMgrError::ConsoleManager(ConsoleManagerError::StdinHandle(e)))?;
stdin_handle
.lock()
.set_non_block(true)
.map_err(ConsoleManagerError::StdinHandle)
.map_err(DeviceMgrError::ConsoleManager)?;
let handler = ConsoleEpollHandler::new(device, Some(stdin_handle), None, &self.logger); let handler = ConsoleEpollHandler::new(device, Some(stdin_handle), None, &self.logger);
self.subscriber_id = Some(self.epoll_mgr.add_subscriber(Box::new(handler))); self.subscriber_id = Some(self.epoll_mgr.add_subscriber(Box::new(handler)));

View File

@ -591,14 +591,19 @@ impl DeviceManager {
.map_err(|_| StartMicroVmError::EventFd)?; .map_err(|_| StartMicroVmError::EventFd)?;
info!(self.logger, "init console path: {:?}", com1_sock_path); info!(self.logger, "init console path: {:?}", com1_sock_path);
if let Some(path) = com1_sock_path {
if let Some(legacy_manager) = self.legacy_manager.as_ref() { if let Some(legacy_manager) = self.legacy_manager.as_ref() {
if let Some(path) = com1_sock_path {
// Currently, the `com1_sock_path` "stdio" is only reserved for creating the stdio console
if path != "stdio" {
let com1 = legacy_manager.get_com1_serial(); let com1 = legacy_manager.get_com1_serial();
self.con_manager self.con_manager
.create_socket_console(com1, path) .create_socket_console(com1, path)
.map_err(StartMicroVmError::DeviceManager)?; .map_err(StartMicroVmError::DeviceManager)?;
return Ok(());
} }
} else if let Some(legacy_manager) = self.legacy_manager.as_ref() { }
let com1 = legacy_manager.get_com1_serial(); let com1 = legacy_manager.get_com1_serial();
self.con_manager self.con_manager
.create_stdio_console(com1) .create_stdio_console(com1)