From 1f7ae9d4e38096180c56a4fcc04759f10f117b2d Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 10 May 2019 11:37:34 -0700 Subject: [PATCH] adbd: don't abort on EOF on functionfs control fd. Also, improve the logging in the cases where we do abort. Bug: http://b/131867920 Test: treehugger Change-Id: If8ec9f4614ce146e6dbd21cc77587ea81658199b (cherry picked from commit 2916e148d9c333be253533968f407b73ebc017c2) --- adb/daemon/usb.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index 3b29ab5fc..0fc4512c0 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -295,9 +295,15 @@ struct UsbFfsConnection : public Connection { } struct usb_functionfs_event event; - if (TEMP_FAILURE_RETRY(adb_read(control_fd_.get(), &event, sizeof(event))) != - sizeof(event)) { + rc = TEMP_FAILURE_RETRY(adb_read(control_fd_.get(), &event, sizeof(event))); + if (rc == -1) { PLOG(FATAL) << "failed to read functionfs event"; + } else if (rc == 0) { + LOG(WARNING) << "hit EOF on functionfs control fd"; + break; + } else if (rc != sizeof(event)) { + LOG(FATAL) << "read functionfs event of unexpected size, expected " + << sizeof(event) << ", got " << rc; } LOG(INFO) << "USB event: "