summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBao Haojun <baohaojun@gmail.com>2014-05-14 21:03:48 +0800
committerBao Haojun <baohaojun@gmail.com>2014-05-14 21:45:11 +0800
commitcdb1b1b84daa528d078379a7f343177b94e5976e (patch)
tree254bd0b0b2667f1096adef3195c8fd167a9f7a97
parent32e4479d5535887d03625b43b7e3574b458dfc8d (diff)
downloadsystem_core-cdb1b1b84daa528d078379a7f343177b94e5976e.zip
system_core-cdb1b1b84daa528d078379a7f343177b94e5976e.tar.gz
system_core-cdb1b1b84daa528d078379a7f343177b94e5976e.tar.bz2
Fix deadlocks.
1. Close pipe fds[1] as soon as possible. Otherwise it may block when reading from fds[0] even though the child process has exited early and closed its copy of fds[1]. 2. Waitpid after pipe is closed. Otherwise the screencap child process may block while writing fds[1], because the fds[0] is not closed yet. If we close fds[0] first, then the screencap child process will die because of SIGPIPE, and waitpid will return correctly. Change-Id: I433c95a5ba2eb3045727fc39a49fd9557fb1a1d1 Signed-off-by: Bao Haojun <baohaojun@gmail.com>
-rw-r--r--adb/framebuffer_service.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c
index fa7fd98..e42dcbf 100644
--- a/adb/framebuffer_service.c
+++ b/adb/framebuffer_service.c
@@ -76,6 +76,7 @@ void framebuffer_service(int fd, void *cookie)
exit(1);
}
+ close(fds[1]);
fd_screencap = fds[0];
/* read w, h & format */
@@ -173,10 +174,9 @@ void framebuffer_service(int fd, void *cookie)
}
done:
- TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));
-
close(fds[0]);
- close(fds[1]);
+
+ TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));
pipefail:
close(fd);
}