From 69c5c4c45bd4f1575ae8bdba13795297be7deb8c Mon Sep 17 00:00:00 2001 From: JP Abgrall Date: Fri, 18 Feb 2011 14:16:59 -0800 Subject: Fix adb hang when subprocess dies early. * Handling of the subprocess and its FD. This fixes http://b/3400254 "Many bugreports getting hung at the end in monkey" - Start up a service thread that waits on the subprocess to terminate, then closes the FD associated with it. - Have the event handler select() with a timeout so that it can detect the closed FD. Select() with no timeout does not return when an FD is closed. - Have the event handler force a read on the closed FD to trigger the close sequence. - Migrate the "shell:blabla" handling to "#if !ADB_HOST" sections. * Fix the race around OOM adjusting. - Do it in the child before exec() instead of the in the parent as the child could already have started or not (no /proc/pid/... yet). * Allow for multi-threaded D() invocations to not clobber each other. - Allow locks across object files. - Add lock within D() * Add some missing close(fd) calls - Match similar existing practices near dup2() * Add extra D() invocations related to FD handling. * Warn about using debugging as stderr/stdout is used for protocol. Change-Id: Ie5c4a5e6bfbe3f22201adf5f9a205d32e069bf9d Signed-off-by: JP Abgrall --- adb/mutex_list.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'adb/mutex_list.h') diff --git a/adb/mutex_list.h b/adb/mutex_list.h index eebe0df..83f3e42 100644 --- a/adb/mutex_list.h +++ b/adb/mutex_list.h @@ -1,4 +1,6 @@ /* the list of mutexes used by addb */ +#ifndef __MUTEX_LIST_H +#define __MUTEX_LIST_H #ifndef ADB_MUTEX #error ADB_MUTEX not defined when including this file #endif @@ -11,4 +13,14 @@ ADB_MUTEX(local_transports_lock) #endif ADB_MUTEX(usb_lock) +// Sadly logging to /data/adb/adb-... is not thread safe. +// After modifying adb.h::D() to count invocations: +// DEBUG(jpa):0:Handling main() +// DEBUG(jpa):1:[ usb_init - starting thread ] +// (Oopsies, no :2:, and matching message is also gone.) +// DEBUG(jpa):3:[ usb_thread - opening device ] +// DEBUG(jpa):4:jdwp control socket started (10) +ADB_MUTEX(D_lock) + #undef ADB_MUTEX +#endif -- cgit v1.1