Fix minor compos_key_cmd problems
- Occasionally, when the VM crashes early on, I've seen crashes where
we call getline with a null FILE*. Defend against this.
- We were always opening the instance image read-only, which prevented
it being updated, e.g. with info about the loaded APEXes.
Test: Exercise various compos_key_cmd incantations
Change-Id: I09c71dada254d2db426742c0d8175bfebc08125f
diff --git a/compos/compos_key_cmd/compos_key_cmd.cpp b/compos/compos_key_cmd/compos_key_cmd.cpp
index c2699ab..560eb09 100644
--- a/compos/compos_key_cmd/compos_key_cmd.cpp
+++ b/compos/compos_key_cmd/compos_key_cmd.cpp
@@ -101,6 +101,10 @@
void copyToLog(unique_fd&& fd) {
FILE* source = Fdopen(std::move(fd), "r");
+ if (source == nullptr) {
+ LOG(INFO) << "Can't log VM output";
+ return;
+ }
size_t size = 0;
char* line = nullptr;
@@ -237,7 +241,7 @@
}
ScopedFileDescriptor instanceFd(
- TEMP_FAILURE_RETRY(open(mInstanceImageFile.c_str(), O_RDONLY | O_CLOEXEC)));
+ TEMP_FAILURE_RETRY(open(mInstanceImageFile.c_str(), O_RDWR | O_CLOEXEC)));
if (instanceFd.get() == -1) {
return ErrnoError() << "Failed to open instance image file";
}