From eff0680c139338170d0821ad19d7ab1ad2e8811b Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Fri, 20 Sep 2019 11:19:38 -0700 Subject: [PATCH] linux: silence logs on client disconnect When all Crashpad clients have closed their crash handling sockets, the handler's recvmsg() returns 0 and doesn't include any credentials. Silence error logs for this normally occurring case. Change-Id: I56acf3b38c8e95a9bbaa9bff04e0a6859a194e66 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1816286 Reviewed-by: Mark Mentovai Commit-Queue: Joshua Peraza --- util/linux/socket.cc | 12 ++++++------ util/linux/socket.h | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) 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,