From 4abdeee073aecd2130e82f301ceff03dbd27fd72 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 13 May 2016 18:16:43 -0700 Subject: [PATCH] adb: replace failing exits in adbd with abort(). This makes it possible to get a core dump from adbd when it decides to exit. Bug: http://b/28347842 Change-Id: I4cfe5f273f62b2c32e61232d3c39881ecdd6b582 --- adb/adb.cpp | 29 +++++++++++++++++++++-------- adb/shell_service.cpp | 6 +++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/adb/adb.cpp b/adb/adb.cpp index 11e9c6863..3f14f1aca 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -65,21 +65,34 @@ std::string adb_version() { void fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(stderr, "error: "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + char buf[1024]; + vsnprintf(buf, sizeof(buf), fmt, ap); + +#if ADB_HOST + fprintf(stderr, "error: %s\n", buf); +#else + LOG(ERROR) << "error: " << buf; +#endif + va_end(ap); - exit(-1); + abort(); } void fatal_errno(const char* fmt, ...) { + int err = errno; va_list ap; va_start(ap, fmt); - fprintf(stderr, "error: %s: ", strerror(errno)); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + char buf[1024]; + vsnprintf(buf, sizeof(buf), fmt, ap); + +#if ADB_HOST + fprintf(stderr, "error: %s: %s\n", buf, strerror(err)); +#else + LOG(ERROR) << "error: " << buf << ": " << strerror(err); +#endif + va_end(ap); - exit(-1); + abort(); } apacket* get_apacket(void) diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp index 3eeed34b2..374b4683b 100644 --- a/adb/shell_service.cpp +++ b/adb/shell_service.cpp @@ -412,7 +412,7 @@ int Subprocess::OpenPtyChildFd(const char* pts_name, ScopedFd* error_sfd) { for (const char* message : messages) { WriteFdExactly(error_sfd->fd(), message); } - exit(-1); + abort(); } if (make_pty_raw_) { @@ -421,7 +421,7 @@ int Subprocess::OpenPtyChildFd(const char* pts_name, ScopedFd* error_sfd) { int saved_errno = errno; WriteFdExactly(error_sfd->fd(), "tcgetattr failed: "); WriteFdExactly(error_sfd->fd(), strerror(saved_errno)); - exit(-1); + abort(); } cfmakeraw(&tattr); @@ -429,7 +429,7 @@ int Subprocess::OpenPtyChildFd(const char* pts_name, ScopedFd* error_sfd) { int saved_errno = errno; WriteFdExactly(error_sfd->fd(), "tcsetattr failed: "); WriteFdExactly(error_sfd->fd(), strerror(saved_errno)); - exit(-1); + abort(); } }