diff --git a/util/linux/socket.cc b/util/linux/socket.cc index 68efd570..f56eacf6 100644 --- a/util/linux/socket.cc +++ b/util/linux/socket.cc @@ -168,17 +168,17 @@ bool UnixCredentialSocket::RecvMsg(int fd, return false; } + // Credentials are missing from the message either when the recv socket wasn't + // configured with SO_PASSCRED or when all sending sockets have been closed. + // In the latter case, res == 0. This case is also indistinguishable from an + // empty message sent to a recv socket which hasn't set SO_PASSCRED. if (!local_creds) { - LOG(ERROR) << "missing credentials"; + LOG_IF(ERROR, res != 0) << "missing credentials"; return false; } - // res == 0 may also indicate that the sending socket disconnected, but in - // that case, the message will also have missing or invalid credentials. if (static_cast(res) != buf_size) { - if (res != 0 || (local_creds && local_creds->pid != 0)) { - LOG(ERROR) << "incorrect payload size " << res; - } + LOG(ERROR) << "incorrect payload size " << res; return false; } diff --git a/util/linux/socket.h b/util/linux/socket.h index c02a6c30..85860f7b 100644 --- a/util/linux/socket.h +++ b/util/linux/socket.h @@ -76,7 +76,11 @@ class UnixCredentialSocket { //! \param[out] creds The credentials of the sender. //! \param[out] fds The recieved file descriptors. Optional. If `nullptr`, all //! received file descriptors will be closed. - //! \return `true` on success. Otherwise, `false`, with a message logged. + //! \return `true` on success. Otherwise, `false`, with a message logged. No + //! message will be logged if the message was detected to be an EOF + //! condition triggered by all clients disconnecting. This case is + //! indistinguishable from misuses of this interface that haven't set + //! `SO_PASSCRED` on \a fd. static bool RecvMsg(int fd, void* buf, size_t buf_size,