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 <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2020-05-19 00:36:39 -07:00 committed by Commit Bot
parent ec9a99146e
commit cef3558006

View file

@ -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))
}