diff options
author | Benoit Goby <benoit@android.com> | 2011-02-01 18:57:41 -0800 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-02-03 15:26:45 -0500 |
commit | 3b4a0c81c4f2af46e6075f1150dcde55d436c7a6 (patch) | |
tree | 2f785ec4dda4ad1ca5ed5f5682bb8e18b68688f0 /adb | |
parent | eb5df470e6e0402006030b76315f06bcb4f17882 (diff) | |
download | system_core-3b4a0c81c4f2af46e6075f1150dcde55d436c7a6.zip system_core-3b4a0c81c4f2af46e6075f1150dcde55d436c7a6.tar.gz system_core-3b4a0c81c4f2af46e6075f1150dcde55d436c7a6.tar.bz2 |
Fix adb leaking file descriptors to forked processes
accept() creates a new file descriptor that should be closed on exec so
that forked processes don't keep a fd opened on the socket.
This also fixes b/3297070 where adb hangs after running adb on the
target.
Change-Id: I8df511289e5549ae49b4824c9dfb71a3bf85eae8
Diffstat (limited to 'adb')
-rw-r--r-- | adb/adb.c | 2 | ||||
-rw-r--r-- | adb/jdwp_service.c | 1 | ||||
-rw-r--r-- | adb/services.c | 1 | ||||
-rw-r--r-- | adb/sysdeps.h | 8 |
4 files changed, 11 insertions, 1 deletions
@@ -682,9 +682,11 @@ void start_device_log(void) dup2(fd, 1); dup2(fd, 2); fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid()); + adb_close(fd); fd = unix_open("/dev/null", O_RDONLY); dup2(fd, 0); + adb_close(fd); } #endif diff --git a/adb/jdwp_service.c b/adb/jdwp_service.c index 296f718..cd62b55 100644 --- a/adb/jdwp_service.c +++ b/adb/jdwp_service.c @@ -499,6 +499,7 @@ jdwp_control_init( JdwpControl* control, /* only wait for incoming connections */ fdevent_add(control->fde, FDE_READ); + close_on_exec(s); D("jdwp control socket started (%d)\n", control->listen_socket); return 0; diff --git a/adb/services.c b/adb/services.c index 487c7d3..c22ce17 100644 --- a/adb/services.c +++ b/adb/services.c @@ -309,6 +309,7 @@ static int create_subprocess(const char *cmd, const char *arg0, const char *arg1 dup2(pts, 1); dup2(pts, 2); + adb_close(pts); adb_close(ptm); execl(cmd, cmd, arg0, arg1, NULL); diff --git a/adb/sysdeps.h b/adb/sysdeps.h index 6372649..74f4ed1 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -387,7 +387,13 @@ static __inline__ int adb_creat(const char* path, int mode) static __inline__ int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrlen) { - return accept( serverfd, addr, addrlen ); + int fd; + + fd = accept(serverfd, addr, addrlen); + if (fd >= 0) + close_on_exec(fd); + + return fd; } #undef accept |