Skip to content

Commit

Permalink
Fix build break due to POLLRDHUP not existing on Mac
Browse files Browse the repository at this point in the history
Summary: fixes hhvm/homebrew-hhvm#110

Reviewed By: fredemmott

Differential Revision: D10240660

fbshipit-source-id: bf9527b7e9246bb8d0adbe29965a9a69c183b636
  • Loading branch information
ebluestein authored and hhvm-bot committed Oct 8, 2018
1 parent 7d06ea4 commit d180c0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
11 changes: 7 additions & 4 deletions hphp/runtime/ext/vsdebug/socket_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void SocketTransport::shutdownSocket(int sockFd, int abortFd) {
return;
}

int eventMask = POLLIN | POLLERR | POLLHUP | POLLRDHUP;
int eventMask = POLLIN | POLLERR | POLLHUP | g_platformPollFlags;
constexpr int abortIdx = 0;
constexpr int readIdx = 1;

Expand All @@ -453,8 +453,7 @@ void SocketTransport::shutdownSocket(int sockFd, int abortFd) {
fds[abortIdx].revents != 0 ||
fds[readIdx].revents & POLLERR ||
fds[readIdx].revents & POLLHUP ||
fds[readIdx].revents & POLLRDHUP
) {
fds[readIdx].revents & g_platformPollFlags) {

break;
} else if (fds[readIdx].revents & POLLIN) {
Expand Down Expand Up @@ -499,7 +498,7 @@ void SocketTransport::waitForConnection(
// fds[0] will contain the read end of our "abort" pipe. Another thread will
// write data to tihs pipe to signal it's time for this worker to stop
// blocking in poll() and terminate.
int eventMask = POLLIN | POLLERR | POLLHUP | POLLRDHUP;
int eventMask = POLLIN | POLLERR | POLLHUP | g_platformPollFlags;
fds[0].fd = abortFd;
fds[0].events = eventMask;

Expand Down Expand Up @@ -591,6 +590,7 @@ void SocketTransport::waitForConnection(
}

bool SocketTransport::validatePeerCreds(int newFd, ClientInfo& info) {
#ifdef SO_PEERCRED
struct ucred ucred = {0};
socklen_t len = sizeof(ucred);

Expand Down Expand Up @@ -656,6 +656,9 @@ bool SocketTransport::validatePeerCreds(int newFd, ClientInfo& info) {
info.clientUser = std::string(pw.pw_name);
info.clientPid = ucred.pid;
return pw.pw_name != nullptr && strlen(pw.pw_name) > 0;
#else
return true;
#endif
}

}
Expand Down
11 changes: 7 additions & 4 deletions hphp/runtime/ext/vsdebug/transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ void DebugTransport::processOutgoingMessages() {

pollFds[abortIdx] = {0};
pollFds[abortIdx].fd = m_abortPipeFd[0];
pollFds[abortIdx].events = POLLIN | POLLERR | POLLHUP | POLLRDHUP;
pollFds[abortIdx].events =
POLLIN | POLLERR | POLLHUP | g_platformPollFlags;

pollFds[transportIdx] = {0};
pollFds[transportIdx].fd = fd;
pollFds[transportIdx].events = POLLOUT | POLLERR | POLLHUP | POLLRDHUP;
pollFds[transportIdx].events =
POLLOUT | POLLERR | POLLHUP | g_platformPollFlags;

while (true) {
std::list<std::string> messagesToSend;
Expand Down Expand Up @@ -256,7 +258,7 @@ void DebugTransport::processOutgoingMessages() {
} else {
// TransportFD hangup or error.
assert((pollFds[transportIdx].revents &
(POLLERR | POLLHUP | POLLRDHUP)) != 0);
(POLLERR | POLLHUP | g_platformPollFlags)) != 0);
VSDebugLogger::Log(
VSDebugLogger::LogLevelInfo,
"Transport write thread: error event on fd."
Expand Down Expand Up @@ -287,7 +289,8 @@ void DebugTransport::processIncomingMessages() {
// Wait for data to be available, or a termination event to occur.
constexpr int abortIdx = 0;
constexpr int transportIdx = 1;
int eventMask = POLLIN | POLLERR | POLLHUP | POLLRDHUP;

int eventMask = POLLIN | POLLERR | POLLHUP | g_platformPollFlags;
struct pollfd pollFds[2];
memset(pollFds, 0, sizeof(pollFds));
pollFds[abortIdx].fd = m_abortPipeFd[0];
Expand Down
6 changes: 6 additions & 0 deletions hphp/runtime/ext/vsdebug/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ struct DebugTransport {
static constexpr char* OutputLevelStdout = "stdout";
static constexpr char* OutputLevelStderr = "stderr";

#ifdef POLLRDHUP // Linux-only
static constexpr int g_platformPollFlags = POLLRDHUP;
#else
static constexpr int g_platformPollFlags = 0;
#endif

protected:

const std::string wrapOutgoingMessage(
Expand Down

0 comments on commit d180c0d

Please sign in to comment.