diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-10-11 22:51:35 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-10-11 22:51:35 +0000 |
commit | 2c29389dc08c04273939555135de94e5ae0309c1 (patch) | |
tree | 82b0ab24274fd58c32bf0e21411dc5a16b5546a7 | |
parent | 04d78f8888c1a1fdf0f40fcaf533fccf23692ac8 (diff) | |
parent | b3407e31a0175b34b537a87d3c39661c9c1bcf8a (diff) | |
download | netd-android12-security-release.tar.gz |
Merge cherrypicks of ['googleplex-android-review.googlesource.com/24366176'] into security-aosp-sc-release.android-security-12.0.0_r59android-security-12.0.0_r58android-security-12.0.0_r57android-security-12.0.0_r56android-security-12.0.0_r55android-security-12.0.0_r54android12-security-release
Change-Id: I3caba2501e78c502ac32a5824b132db5f1bd3641
-rw-r--r-- | server/MDnsSdListener.cpp | 35 | ||||
-rw-r--r-- | server/MDnsSdListener.h | 4 |
2 files changed, 26 insertions, 13 deletions
diff --git a/server/MDnsSdListener.cpp b/server/MDnsSdListener.cpp index 42dcddf3..d551d37c 100644 --- a/server/MDnsSdListener.cpp +++ b/server/MDnsSdListener.cpp @@ -29,6 +29,7 @@ #include <sys/poll.h> #include <sys/socket.h> #include <sys/types.h> +#include <thread> #define LOG_TAG "MDnsDS" #define DBG 1 @@ -527,12 +528,18 @@ MDnsSdListener::Monitor::Monitor() { mPollSize = 10; socketpair(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, mCtrlSocketPair); - const int rval = ::android::netdutils::threadLaunch(this); - if (rval != 0) { - ALOGW("Error spawning monitor thread: %s (%d)", strerror(-rval), -rval); - } + mRescanThread = new std::thread(&Monitor::run, this); + if (!mRescanThread->joinable()) ALOGE("Unable to launch thread."); } +MDnsSdListener::Monitor::~Monitor() { + if (VDBG) ALOGD("Monitor recycling"); + close(mCtrlSocketPair[1]); // interrupt poll in MDnsSdListener::Monitor::run() and revent will + // be 17 = POLLIN | POLLHUP + mRescanThread->join(); + delete mRescanThread; + if (VDBG) ALOGD("Monitor recycled"); +} #define NAP_TIME 200 // 200 ms between polls static int wait_for_property(const char *name, const char *desired_value, int maxwait) { @@ -611,14 +618,18 @@ void MDnsSdListener::Monitor::run() { } } if (VDBG) ALOGD("controlSocket shows revent= %d", mPollFds[0].revents); - switch (mPollFds[0].revents) { - case POLLIN: { - char readBuf[2]; - read(mCtrlSocketPair[0], &readBuf, 1); - if (DBG) ALOGD("MDnsSdListener::Monitor got %c", readBuf[0]); - if (memcmp(RESCAN, readBuf, 1) == 0) { - pollCount = rescan(); - } + if (mPollFds[0].revents & POLLHUP) { + free(mPollFds); + free(mPollRefs); + if (VDBG) ALOGD("Monitor thread leaving."); + return; + } + if (mPollFds[0].revents == POLLIN) { + char readBuf[2]; + read(mCtrlSocketPair[0], &readBuf, 1); + if (DBG) ALOGD("MDnsSdListener::Monitor got %c", readBuf[0]); + if (memcmp(RESCAN, readBuf, 1) == 0) { + pollCount = rescan(); } } mPollFds[0].revents = 0; diff --git a/server/MDnsSdListener.h b/server/MDnsSdListener.h index 83cf23e3..196419b1 100644 --- a/server/MDnsSdListener.h +++ b/server/MDnsSdListener.h @@ -22,6 +22,7 @@ #include <sysutils/FrameworkListener.h> #include <mutex> #include <string> +#include <thread> #include "NetdCommand.h" @@ -71,7 +72,7 @@ private: class Monitor { public: Monitor(); - virtual ~Monitor() {} + ~Monitor(); DNSServiceRef *allocateServiceRef(int id, Context *c); void startMonitoring(int id); DNSServiceRef *lookupServiceRef(int id); @@ -102,6 +103,7 @@ private: int mPollSize; int mCtrlSocketPair[2]; std::mutex mMutex; + std::thread* mRescanThread; }; class Handler : public NetdCommand { |