Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 97ee109b authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Fix bogus error checking on unique_fd

The expression "!fd" calls the implicit conversion to int, but comparing
the raw fd against 0 does not work, since open() and other POSIX calls
returning a file descriptor use -1 to signal an error.

Test: m libnetd_resolv
Test: sync, then atest resolver_integration_test
Change-Id: I876fe64a5507a0863151b6807990fdfa72e2973e
parent a32c8c1d
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -449,16 +449,18 @@ bool DnsTlsSocket::query(uint16_t id, const Slice query) {
}

void DnsTlsSocket::requestLoopShutdown() {
    if (mEventFd != -1) {
        // Write a negative number to the eventfd.  This triggers an immediate shutdown.
        incrementEventFd(INT64_MIN);
    }
}

bool DnsTlsSocket::incrementEventFd(const int64_t count) {
    if (!mEventFd) {
        ALOGV("eventfd is not initialized");
    if (mEventFd == -1) {
        ALOGE("eventfd is not initialized");
        return false;
    }
    int written = write(mEventFd.get(), &count, sizeof(count));
    ssize_t written = write(mEventFd.get(), &count, sizeof(count));
    if (written != sizeof(count)) {
        ALOGE("Failed to increment eventfd by %" PRId64, count);
        return false;