diff options
| author | JP Abgrall <jpa@google.com> | 2011-03-16 15:57:42 -0700 |
|---|---|---|
| committer | JP Abgrall <jpa@google.com> | 2011-03-28 14:12:22 -0700 |
| commit | 408fa57864c01113deaa213e5c1848a9c594ae92 (patch) | |
| tree | d7bd9d8bee63f2feb03cd3397784436e4f8f00f0 /adb/adb.h | |
| parent | cdae7a1df8f118404689b656003f4313b62987f2 (diff) | |
| download | system_core-408fa57864c01113deaa213e5c1848a9c594ae92.tar.gz system_core-408fa57864c01113deaa213e5c1848a9c594ae92.tar.bz2 system_core-408fa57864c01113deaa213e5c1848a9c594ae92.zip | |
adb: fix subprocess exit handling, oom adjust fixes, extra debugging.
* Add support for correctly handling subprocess termination in shell service (b/3400254 b/3482112 b/2249397)
- have a waitpid() track the subprocess, then notify the fdevent via a socket
- force an eof on the pty master in fdevent's new subproc handler.
- modify fdevent to force-read the pty after an exit.
* Migrate the "shell:blabla" handling to "#if !ADB_HOST" sections, where it
belongs.
* 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()
- Make sure sysdesp init (mutex init also) is called early.
* 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.
* Fix some errno handling and make D() correctly handle it.
* Add new adb trace_mask: services.
* Make fdevent_loop's handle BADFDs more gracefully (could occur some subproc closed its pts explicitely).
* Remove obsolete commandline args reported in help. (b/3509092)
Change-Id: I928287fdf4f1a86777e22ce105f9581685f46e35
Diffstat (limited to 'adb/adb.h')
| -rw-r--r-- | adb/adb.h | 47 |
1 files changed, 33 insertions, 14 deletions
@@ -19,6 +19,8 @@ #include <limits.h> +#include "transport.h" /* readx(), writex() */ + #define MAX_PAYLOAD 4096 #define A_SYNC 0x434e5953 @@ -315,13 +317,6 @@ void put_apacket(apacket *p); int check_header(apacket *p); int check_data(apacket *p); -/* convenience wrappers around read/write that will retry on -** EINTR and/or short read/write. Returns 0 on success, -1 -** on error or EOF. -*/ -int readx(int fd, void *ptr, size_t len); -int writex(int fd, const void *ptr, size_t len); - /* define ADB_TRACE to 1 to enable tracing support, or 0 to disable it */ #define ADB_TRACE 1 @@ -331,33 +326,56 @@ int writex(int fd, const void *ptr, size_t len); * the adb_trace_init() function implemented in adb.c */ typedef enum { - TRACE_ADB = 0, + TRACE_ADB = 0, /* 0x001 */ TRACE_SOCKETS, TRACE_PACKETS, TRACE_TRANSPORT, - TRACE_RWX, + TRACE_RWX, /* 0x010 */ TRACE_USB, TRACE_SYNC, TRACE_SYSDEPS, - TRACE_JDWP, + TRACE_JDWP, /* 0x100 */ + TRACE_SERVICES, } AdbTrace; #if ADB_TRACE - int adb_trace_mask; - + 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) { \ + int save_errno = errno; \ + adb_mutex_lock(&D_lock); \ + fprintf(stderr, "%s::%s():", \ + __FILE__, __FUNCTION__); \ + errno = save_errno; \ + fprintf(stderr, __VA_ARGS__ ); \ + fflush(stderr); \ + adb_mutex_unlock(&D_lock); \ + errno = save_errno; \ + } \ + } while (0) +# define DR(...) \ do { \ - if (ADB_TRACING) \ + if (ADB_TRACING) { \ + int save_errno = errno; \ + adb_mutex_lock(&D_lock); \ + errno = save_errno; \ fprintf(stderr, __VA_ARGS__ ); \ + fflush(stderr); \ + adb_mutex_unlock(&D_lock); \ + errno = save_errno; \ + } \ } while (0) #else # define D(...) ((void)0) +# define DR(...) ((void)0) # define ADB_TRACING 0 #endif @@ -413,6 +431,7 @@ int connection_state(atransport *t); #define CS_NOPERM 5 /* Insufficient permissions to communicate with the device */ extern int HOST; +extern int SHELL_EXIT_NOTIFY_FD; #define CHUNK_SIZE (64*1024) |
