diff options
author | Jorge E. Moreira <jemoreira@google.com> | 2019-05-17 13:57:04 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-05-22 20:57:00 -0700 |
commit | 9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4 (patch) | |
tree | 46523fb853222732a0b476b9370e2afe433d3b3d /devices/src/serial.rs | |
parent | 3007ff3cf408f9e6a2e0731a4fa7d6f8f65dfa47 (diff) | |
download | crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.tar crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.tar.gz crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.tar.bz2 crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.tar.lz crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.tar.xz crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.tar.zst crosvm-9c9e0e71bd0ecf770fca66320a4b3b8a0b329bd4.zip |
crosvm: Implement the file type for serial ports
BUG=chromium:953983 Change-Id: I0c1dc6216ebfdb61db85d3d9665f88f7231d99c8 Reviewed-on: https://chromium-review.googlesource.com/1618281 Commit-Ready: Jorge Moreira Broche <jemoreira@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'devices/src/serial.rs')
-rw-r--r-- | devices/src/serial.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/devices/src/serial.rs b/devices/src/serial.rs index 4d12512..1fa7b61 100644 --- a/devices/src/serial.rs +++ b/devices/src/serial.rs @@ -4,6 +4,7 @@ use std::collections::VecDeque; use std::fmt::{self, Display}; +use std::fs::File; use std::io::{self, stdout}; use std::path::PathBuf; use std::str::FromStr; @@ -51,6 +52,8 @@ const DEFAULT_BAUD_DIVISOR: u16 = 12; // 9600 bps pub enum Error { CloneEventFd(sys_util::Error), InvalidSerialType(String), + PathRequired, + FileError(std::io::Error), Unimplemented(SerialType), } @@ -62,7 +65,9 @@ impl Display for Error { #[sorted] match self { CloneEventFd(e) => write!(f, "unable to clone an EventFd: {}", e), + FileError(e) => write!(f, "Unable to open/create file: {}", e), InvalidSerialType(e) => write!(f, "invalid serial type: {}", e), + PathRequired => write!(f, "serial device type file requires a path"), Unimplemented(e) => write!(f, "serial device type {} not implemented", e.to_string()), } } @@ -71,7 +76,7 @@ impl Display for Error { /// Enum for possible type of serial devices #[derive(Debug)] pub enum SerialType { - File, // NOT IMPLEMENTED + File, Stdout, Sink, Syslog, @@ -136,7 +141,13 @@ impl SerialParameters { syslog::Facility::Daemon, )), )), - SerialType::File => Err(Error::Unimplemented(SerialType::File)), + SerialType::File => match &self.path { + None => Err(Error::PathRequired), + Some(path) => Ok(Serial::new_out( + evt_fd.try_clone().map_err(Error::CloneEventFd)?, + Box::new(File::create(path.as_path()).map_err(|e| Error::FileError(e))?), + )), + }, SerialType::UnixSocket => Err(Error::Unimplemented(SerialType::UnixSocket)), } } |