Merge "Most accept/accept4 calls in system/core don't actually want the remote address."
This commit is contained in:
commit
299d64144b
5 changed files with 11 additions and 34 deletions
|
|
@ -254,10 +254,7 @@ TEST_F(LocalSocketTest, close_socket_in_CLOSE_WAIT_state) {
|
||||||
ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(ClientThreadFunc), nullptr,
|
ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(ClientThreadFunc), nullptr,
|
||||||
&client_thread));
|
&client_thread));
|
||||||
|
|
||||||
struct sockaddr addr;
|
int accept_fd = adb_socket_accept(listen_fd, nullptr, nullptr);
|
||||||
socklen_t alen;
|
|
||||||
alen = sizeof(addr);
|
|
||||||
int accept_fd = adb_socket_accept(listen_fd, &addr, &alen);
|
|
||||||
ASSERT_GE(accept_fd, 0);
|
ASSERT_GE(accept_fd, 0);
|
||||||
CloseRdHupSocketArg arg;
|
CloseRdHupSocketArg arg;
|
||||||
arg.socket_fd = accept_fd;
|
arg.socket_fd = accept_fd;
|
||||||
|
|
|
||||||
|
|
@ -821,12 +821,8 @@ static int do_server() {
|
||||||
ALOGI("debuggerd: starting\n");
|
ALOGI("debuggerd: starting\n");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
sockaddr_storage ss;
|
|
||||||
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
|
|
||||||
socklen_t alen = sizeof(ss);
|
|
||||||
|
|
||||||
ALOGV("waiting for connection\n");
|
ALOGV("waiting for connection\n");
|
||||||
int fd = accept4(s, addrp, &alen, SOCK_CLOEXEC | SOCK_NONBLOCK);
|
int fd = accept4(s, nullptr, nullptr, SOCK_CLOEXEC | SOCK_NONBLOCK);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
ALOGE("accept failed: %s\n", strerror(errno));
|
ALOGE("accept failed: %s\n", strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -227,32 +227,29 @@ int property_set(const char* name, const char* value) {
|
||||||
static void handle_property_set_fd()
|
static void handle_property_set_fd()
|
||||||
{
|
{
|
||||||
prop_msg msg;
|
prop_msg msg;
|
||||||
int s;
|
|
||||||
int r;
|
int r;
|
||||||
struct ucred cr;
|
|
||||||
struct sockaddr_un addr;
|
|
||||||
socklen_t addr_size = sizeof(addr);
|
|
||||||
socklen_t cr_size = sizeof(cr);
|
|
||||||
char * source_ctx = NULL;
|
char * source_ctx = NULL;
|
||||||
struct pollfd ufds[1];
|
|
||||||
const int timeout_ms = 2 * 1000; /* Default 2 sec timeout for caller to send property. */
|
|
||||||
int nr;
|
|
||||||
|
|
||||||
if ((s = accept(property_set_fd, (struct sockaddr *) &addr, &addr_size)) < 0) {
|
int s = accept(property_set_fd, nullptr, nullptr);
|
||||||
|
if (s == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check socket options here */
|
/* Check socket options here */
|
||||||
|
struct ucred cr;
|
||||||
|
socklen_t cr_size = sizeof(cr);
|
||||||
if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &cr_size) < 0) {
|
if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &cr_size) < 0) {
|
||||||
close(s);
|
close(s);
|
||||||
PLOG(ERROR) << "Unable to receive socket options";
|
PLOG(ERROR) << "Unable to receive socket options";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr int timeout_ms = 2 * 1000; /* Default 2 sec timeout for caller to send property. */
|
||||||
|
struct pollfd ufds[1];
|
||||||
ufds[0].fd = s;
|
ufds[0].fd = s;
|
||||||
ufds[0].events = POLLIN;
|
ufds[0].events = POLLIN;
|
||||||
ufds[0].revents = 0;
|
ufds[0].revents = 0;
|
||||||
nr = TEMP_FAILURE_RETRY(poll(ufds, 1, timeout_ms));
|
int nr = TEMP_FAILURE_RETRY(poll(ufds, 1, timeout_ms));
|
||||||
if (nr == 0) {
|
if (nr == 0) {
|
||||||
LOG(ERROR) << "sys_prop: timeout waiting for uid " << cr.uid << " to send property message.";
|
LOG(ERROR) << "sys_prop: timeout waiting for uid " << cr.uid << " to send property message.";
|
||||||
close(s);
|
close(s);
|
||||||
|
|
|
||||||
|
|
@ -199,16 +199,7 @@ void SocketListener::runListener() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (mListen && FD_ISSET(mSock, &read_fds)) {
|
if (mListen && FD_ISSET(mSock, &read_fds)) {
|
||||||
sockaddr_storage ss;
|
int c = TEMP_FAILURE_RETRY(accept4(mSock, nullptr, nullptr, SOCK_CLOEXEC));
|
||||||
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
|
|
||||||
socklen_t alen;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
do {
|
|
||||||
alen = sizeof(ss);
|
|
||||||
c = accept4(mSock, addrp, &alen, SOCK_CLOEXEC);
|
|
||||||
SLOGV("%s got %d from accept", mSocketName, c);
|
|
||||||
} while (c < 0 && errno == EINTR);
|
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
SLOGE("accept failed (%s)", strerror(errno));
|
SLOGE("accept failed (%s)", strerror(errno));
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
|
||||||
|
|
@ -410,9 +410,6 @@ static void ctrl_data_handler(uint32_t events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ctrl_connect_handler(uint32_t events __unused) {
|
static void ctrl_connect_handler(uint32_t events __unused) {
|
||||||
struct sockaddr_storage ss;
|
|
||||||
struct sockaddr *addrp = (struct sockaddr *)&ss;
|
|
||||||
socklen_t alen;
|
|
||||||
struct epoll_event epev;
|
struct epoll_event epev;
|
||||||
|
|
||||||
if (ctrl_dfd >= 0) {
|
if (ctrl_dfd >= 0) {
|
||||||
|
|
@ -420,8 +417,7 @@ static void ctrl_connect_handler(uint32_t events __unused) {
|
||||||
ctrl_dfd_reopened = 1;
|
ctrl_dfd_reopened = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
alen = sizeof(ss);
|
ctrl_dfd = accept(ctrl_lfd, NULL, NULL);
|
||||||
ctrl_dfd = accept(ctrl_lfd, addrp, &alen);
|
|
||||||
|
|
||||||
if (ctrl_dfd < 0) {
|
if (ctrl_dfd < 0) {
|
||||||
ALOGE("lmkd control socket accept failed; errno=%d", errno);
|
ALOGE("lmkd control socket accept failed; errno=%d", errno);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue