diff options
author | Chia-chi Yeh <chiachi@android.com> | 2011-08-22 13:05:42 -0700 |
---|---|---|
committer | Chia-chi Yeh <chiachi@android.com> | 2011-08-22 13:05:42 -0700 |
commit | 3724e61c7fb7a792d36c4dbec826e06b1aabd039 (patch) | |
tree | 637189e4b606acda86d34ec2ecc3bc6b9c05987c | |
parent | 2871f2f1bd4e22a5ac3a3d2b2c4fe0d581c3aa74 (diff) | |
download | ipsec-tools-ics-factoryrom-2-release.tar.gz |
ipsec-tools: update control protocol.android-sdk-adt_r16.0.1android-cts-4.0_r1android-4.0.2_r1android-4.0.1_r1.2android-4.0.1_r1.1android-4.0.1_r1ics-mr0-releaseics-mr0ics-factoryrom-2-release
Now closing the control socket becomes a signal of termination.
Thus it is no longer closed after getting the arguments.
Change-Id: Ie042c97e0c50c949a7627b782d21edb872672de4
-rw-r--r-- | main.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -57,21 +57,22 @@ static int android_get_control_and_arguments(int *argc, char ***argv) exit(1); } close(i); + fcntl(control, F_SETFD, FD_CLOEXEC); args[0] = (*argv)[0]; for (i = 1; i < 32; ++i) { unsigned char bytes[2]; - int length = recv(control, &bytes[0], 1, 0); - - if (!length) { - break; - } else if (length != 1 || recv(control, &bytes[1], 1, 0) != 1) { + if (recv(control, &bytes[0], 1, 0) != 1 || + recv(control, &bytes[1], 1, 0) != 1) { do_plog(LLV_ERROR, "Cannot get argument length"); exit(1); } else { + int length = bytes[0] << 8 | bytes[1]; int offset = 0; - length = bytes[0] << 8 | bytes[1]; + if (length == 0xFFFF) { + break; + } args[i] = malloc(length + 1); while (offset < length) { int n = recv(control, &args[i][offset], length - offset, 0); @@ -142,6 +143,7 @@ int main(int argc, char **argv) int control = android_get_control_and_arguments(&argc, &argv); if (control != -1) { pname = "%p"; + monitor_fd(control, NULL, NULL, 0); } #endif @@ -156,7 +158,7 @@ int main(int argc, char **argv) setup(argc, argv); #ifdef ANDROID_CHANGES - close(control); + shutdown(control, SHUT_WR); setuid(AID_VPN); #endif @@ -168,7 +170,7 @@ int main(int argc, char **argv) int i; for (i = 0; i < monitor_count; ++i) { if (pollfds[i].revents & POLLHUP) { - do_plog(LLV_ERROR, "fd %d is closed\n", pollfds[i].fd); + do_plog(LLV_ERROR, "Connection is closed\n", pollfds[i].fd); exit(1); } if (pollfds[i].revents & POLLIN) { @@ -191,7 +193,7 @@ void monitor_fd(int fd, int (*callback)(void *, int), void *ctx, int priority) monitors[monitor_count].callback = callback; monitors[monitor_count].ctx = ctx; pollfds[monitor_count].fd = fd; - pollfds[monitor_count].events = POLLIN; + pollfds[monitor_count].events = callback ? POLLIN : 0; ++monitor_count; } |