From cef3558006302ae6a3eda7d43ac1b7bec75b2f7e Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 19 May 2020 00:36:39 -0700 Subject: [PATCH] arch: serial: open file outputs for append When opening the same output file for two serial devices (earlycon and console), the output would be overwritten by the later device. Change the file creation to use append mode so that the output file contains all of the logs from both devices instead of overwriting it. Tested with: crosvm run \ --serial hardware=serial,type=file,console=false,earlycon=true,path=test.log \ --serial hardware=virtio-console,type=file,console=true,stdin=true,path=test.log \ vm_kernel BUG=None TEST=see above - verify log contains earlycon and console output Change-Id: I14dab9eaf56dbb0ae410215324b20b34fea723ae Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2208712 Reviewed-by: Dylan Reid Reviewed-by: Zach Reizner Tested-by: kokoro Commit-Queue: Daniel Verkamp --- arch/src/serial.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/src/serial.rs b/arch/src/serial.rs index f24f4bc467..b817cfdceb 100644 --- a/arch/src/serial.rs +++ b/arch/src/serial.rs @@ -4,7 +4,7 @@ use std::collections::BTreeMap; use std::fmt::{self, Display}; -use std::fs::File; +use std::fs::{File, OpenOptions}; use std::io::{self, stdin, stdout}; use std::os::unix::io::{AsRawFd, RawFd}; use std::path::PathBuf; @@ -170,7 +170,11 @@ impl SerialParameters { } SerialType::File => match &self.path { Some(path) => { - let file = File::create(path.as_path()).map_err(Error::FileError)?; + let file = OpenOptions::new() + .append(true) + .create(true) + .open(path.as_path()) + .map_err(Error::FileError)?; keep_fds.push(file.as_raw_fd()); Some(Box::new(file)) }