diff options
| author | JP Abgrall <jpa@google.com> | 2011-02-18 14:16:59 -0800 |
|---|---|---|
| committer | JP Abgrall <jpa@google.com> | 2011-02-18 14:16:59 -0800 |
| commit | 69c5c4c45bd4f1575ae8bdba13795297be7deb8c (patch) | |
| tree | 1d46a9a6e66433fbae7342206be0d040408354a6 /adb/adb.h | |
| parent | 53df0b6393979e7f35ab271683429aa1ea1230cd (diff) | |
| download | system_core-69c5c4c45bd4f1575ae8bdba13795297be7deb8c.tar.gz system_core-69c5c4c45bd4f1575ae8bdba13795297be7deb8c.tar.bz2 system_core-69c5c4c45bd4f1575ae8bdba13795297be7deb8c.zip | |
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 <jpa@google.com>
Diffstat (limited to 'adb/adb.h')
| -rw-r--r-- | adb/adb.h | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -123,7 +123,7 @@ struct asocket { /* socket-type-specific extradata */ void *extra; - /* A socket is bound to atransport */ + /* A socket is bound to atransport */ atransport *transport; }; @@ -344,20 +344,50 @@ typedef enum { #if ADB_TRACE - int adb_trace_mask; +// TODO(jpa): remove this after fixing fprintf() multithreading issue { +// Can't include sysdeps.h, because framebuffer_service.c wants a different +// close() than what sysdeps overrides when linking adbd. +// Assume Linux. +#ifndef _ADB_SYSDEPS_H +#include <pthread.h> +typedef pthread_mutex_t adb_mutex_t; +#define ADB_MUTEX(x) extern adb_mutex_t x; +#include "mutex_list.h" +#endif + +// } + + extern int adb_trace_mask; + extern unsigned char adb_trace_output_count; void adb_trace_init(void); # define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0) /* you must define TRACE_TAG before using this macro */ - #define D(...) \ +# define D(...) \ + do { \ + if (ADB_TRACING) { \ + adb_mutex_lock(&D_lock); \ + fprintf(stderr, "%s::%s():", \ + __FILE__, __FUNCTION__); \ + fprintf(stderr, __VA_ARGS__ ); \ + fflush(stderr); \ + adb_mutex_unlock(&D_lock); \ + } \ + } while (0) +# define DR(...) \ do { \ - if (ADB_TRACING) \ + if (ADB_TRACING) { \ + adb_mutex_lock(&D_lock); \ fprintf(stderr, __VA_ARGS__ ); \ + fflush(stderr); \ + adb_mutex_unlock(&D_lock); \ + } \ } while (0) #else # define D(...) ((void)0) +# define DR(...) ((void)0) # define ADB_TRACING 0 #endif |
