From 8dcdb57dafd554e801de97012e7d0ef6ec63a5ac Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 23 Oct 2015 15:03:31 -0700 Subject: [PATCH] adb: Mask SIGTTIN so that I/O works when backgrounded. SIGTTIN gets sent to the process when we attempt to read from stdin when we're in the background, which stops the process by default. Mask the signal so that the read returns -1 with errno set to EIO, instead. Change-Id: I4ae626b0670c05a1a05165539b9eed709e83d536 --- adb/commandline.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/adb/commandline.cpp b/adb/commandline.cpp index bc5ba38a0..a915a3359 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -39,6 +39,7 @@ #include #if !defined(_WIN32) +#include #include #include #endif @@ -440,6 +441,14 @@ static void* stdin_read_thread(void* x) { adb_thread_setname("stdin reader"); +#ifndef __WIN32 + // Mask SIGTTIN in case we're in a backgrounded process + sigset_t sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGTTIN); + pthread_sigmask(SIG_BLOCK, &sigset, nullptr); +#endif + char raw_buffer[1024]; char* buffer_ptr = raw_buffer; size_t buffer_size = sizeof(raw_buffer);