summaryrefslogtreecommitdiffstats
path: root/adb/backup_service.c
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2011-06-21 15:59:25 -0700
committerChristopher Tate <ctate@google.com>2011-06-21 16:05:17 -0700
commit10f129ca8eb266f46393e981484e60521f9011df (patch)
treeb7fc047bc23a4f9f37601c3ddffba6667dd9da92 /adb/backup_service.c
parent5b811fa5dd00288954f15209a56aea03d5e4a004 (diff)
downloadsystem_core-10f129ca8eb266f46393e981484e60521f9011df.zip
system_core-10f129ca8eb266f46393e981484e60521f9011df.tar.gz
system_core-10f129ca8eb266f46393e981484e60521f9011df.tar.bz2
Fix hang after end of backup
The buggy behavior was that the 'adb backup ....' host command line invocation would hang forever, even after the backup finished and the forked device-side subprocess had been reaped. The reason for this is that the device adbd end of the socketpair used to send the data back from the forked subprocess was still stuck readable even after the remote end of it had been closed. With this patch, the thread whose job it is to waitpid() in order to harvest the forked child process also closes the local (adbd) end of the socketpair. This makes the fdevent logic notice that the socket is dead, at which point it cleans up everything including the communication back to the host. Change-Id: I90e7e4e5db36c5a6f7363708b29a6d2c56d1250e
Diffstat (limited to 'adb/backup_service.c')
-rw-r--r--adb/backup_service.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/adb/backup_service.c b/adb/backup_service.c
index 4f0c8ac..669ff86 100644
--- a/adb/backup_service.c
+++ b/adb/backup_service.c
@@ -22,6 +22,11 @@
#define TRACE_TAG TRACE_ADB
#include "adb.h"
+typedef struct {
+ pid_t pid;
+ int fd;
+} backup_harvest_params;
+
// socketpair but do *not* mark as close_on_exec
static int backup_socketpair(int sv[2]) {
int rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv );
@@ -31,11 +36,14 @@ static int backup_socketpair(int sv[2]) {
return 0;
}
-static void* backup_child_waiter(void* pid_cookie) {
+// harvest the child process then close the read end of the socketpair
+static void* backup_child_waiter(void* args) {
int status;
+ backup_harvest_params* params = (backup_harvest_params*) args;
- waitpid((pid_t) pid_cookie, &status, 0);
- D("harvested backup/restore child, status=%d\n", status);
+ waitpid(params->pid, &status, 0);
+ adb_close(params->fd);
+ free(params);
return NULL;
}
@@ -124,14 +132,19 @@ int backup_service(BackupOperation op, char* args) {
exit(-1);
} else {
adb_thread_t t;
+ backup_harvest_params* params;
// parent, i.e. adbd -- close the sending half of the socket
D("fork() returned pid %d\n", pid);
adb_close(s[1]);
// spin a thread to harvest the child process
- if (adb_thread_create(&t, backup_child_waiter, (void*)pid)) {
+ params = (backup_harvest_params*) malloc(sizeof(backup_harvest_params));
+ params->pid = pid;
+ params->fd = s[0];
+ if (adb_thread_create(&t, backup_child_waiter, params)) {
adb_close(s[0]);
+ free(params);
D("Unable to create child harvester\n");
return -1;
}