diff --git a/debuggerd/client/debuggerd_client.cpp b/debuggerd/client/debuggerd_client.cpp index c357fd6d6..cb7cbbe0f 100644 --- a/debuggerd/client/debuggerd_client.cpp +++ b/debuggerd/client/debuggerd_client.cpp @@ -28,7 +28,9 @@ #include #include +#include #include +#include #include #include @@ -117,6 +119,20 @@ bool debuggerd_trigger_dump(pid_t pid, DebuggerdDumpType dump_type, unsigned int return false; } + std::string pipe_size_str; + int pipe_buffer_size = 1024 * 1024; + if (android::base::ReadFileToString("/proc/sys/fs/pipe-max-size", &pipe_size_str)) { + pipe_size_str = android::base::Trim(pipe_size_str); + + if (!android::base::ParseInt(pipe_size_str.c_str(), &pipe_buffer_size, 0)) { + LOG(FATAL) << "failed to parse pipe max size '" << pipe_size_str << "'"; + } + } + + if (fcntl(pipe_read.get(), F_SETPIPE_SZ, pipe_buffer_size) != pipe_buffer_size) { + PLOG(ERROR) << "failed to set pipe buffer size"; + } + if (send_fd(set_timeout(sockfd), &req, sizeof(req), std::move(pipe_write)) != sizeof(req)) { PLOG(ERROR) << "libdebuggerd_client: failed to send output fd to tombstoned"; return false; diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp index cc7824219..558bc721a 100644 --- a/debuggerd/crash_dump.cpp +++ b/debuggerd/crash_dump.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include "backtrace.h" @@ -99,8 +100,9 @@ static bool ptrace_seize_thread(int pid_proc_fd, pid_t tid, std::string* error) return true; } -static bool activity_manager_notify(int pid, int signal, const std::string& amfd_data) { - android::base::unique_fd amfd(socket_local_client("/data/system/ndebugsocket", ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM)); +static bool activity_manager_notify(pid_t pid, int signal, const std::string& amfd_data) { + android::base::unique_fd amfd(socket_local_client( + "/data/system/ndebugsocket", ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM)); if (amfd.get() == -1) { PLOG(ERROR) << "unable to connect to activity manager"; return false; @@ -207,9 +209,14 @@ int main(int argc, char** argv) { action.sa_handler = signal_handler; debuggerd_register_handlers(&action); + sigset_t mask; + sigemptyset(&mask); + if (sigprocmask(SIG_SETMASK, &mask, nullptr) != 0) { + PLOG(FATAL) << "failed to set signal mask"; + } + if (argc != 4) { LOG(FATAL) << "Wrong number of args: " << argc << " (expected 4)"; - return 1; } pid_t main_tid; @@ -264,7 +271,7 @@ int main(int argc, char** argv) { } // Die if we take too long. - alarm(20); + alarm(2); std::string attach_error; @@ -408,7 +415,10 @@ int main(int argc, char** argv) { } if (fatal_signal) { - activity_manager_notify(target, signo, amfd_data); + // Don't try to notify ActivityManager if it just crashed, or we might hang until timeout. + if (target_info.name != "system_server" || target_info.uid != AID_SYSTEM) { + activity_manager_notify(target, signo, amfd_data); + } } // Close stdout before we notify tombstoned of completion. diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index 8c00b76a0..9008b95ac 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -119,6 +119,8 @@ static void tombstoned_intercept(pid_t target_pid, unique_fd* intercept_fd, uniq FAIL() << "failed to set pipe size: " << strerror(errno); } + ASSERT_GE(pipe_buffer_size, 1024 * 1024); + if (send_fd(intercept_fd->get(), &req, sizeof(req), std::move(output_pipe_write)) != sizeof(req)) { FAIL() << "failed to send output fd to tombstoned: " << strerror(errno); }