From patchwork Mon Apr 29 12:28:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1126 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71FDC60C46 for ; Mon, 29 Apr 2019 14:28:29 +0200 (CEST) Received: from pendragon.station (net-37-182-44-227.cust.vodafonedsl.it [37.182.44.227]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D1AE22E7; Mon, 29 Apr 2019 14:28:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1556540909; bh=Qs5KrlcLhb4GGbojzVTl/BSKYa6ODXg4N5cdaUBjW/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n7u8WARXvIA8BZIJ2Y5FsHKtXs6Jd0e1yvEM+LahWmnw/MlPDQYnCuO6DJJ8LYY9g hDY5vCIswxcOf4ww/yZP/naDuiMYUf5IP1QQGcJFHt63c0t6RZrlFS9tR5NoYK8JrF NjEAYKm6oxDy6sR3tQ4F8to7nDoiIzSCY6lFfp2U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Apr 2019 15:28:13 +0300 Message-Id: <20190429122813.31256-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190428231238.30547-1-laurent.pinchart@ideasonboard.com> References: <20190428231238.30547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1.1 1/2] libcamera: Don't ignore the return value of read() and write() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Apr 2019 12:28:29 -0000 The glibc read() and write() functions are defined with the __warn_unused_result__ attribute when using FORTIFY_SOURCE. Don't ignore their return value. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/event_dispatcher_poll.cpp | 8 ++++++-- test/event.cpp | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index 1f0f352a8e0a..2621b7d96b1e 100644 --- a/src/libcamera/event_dispatcher_poll.cpp +++ b/src/libcamera/event_dispatcher_poll.cpp @@ -162,7 +162,9 @@ void EventDispatcherPoll::processEvents() void EventDispatcherPoll::interrupt() { uint64_t value = 1; - write(eventfd_, &value, sizeof(value)); + ssize_t ret = write(eventfd_, &value, sizeof(value)); + if (ret < 0) + LOG(Event, Error) << "Failed to interrupt event dispatcher"; } short EventDispatcherPoll::EventNotifierSetPoll::events() const @@ -214,7 +216,9 @@ void EventDispatcherPoll::processInterrupt(const struct pollfd &pfd) return; uint64_t value; - read(eventfd_, &value, sizeof(value)); + ssize_t ret = read(eventfd_, &value, sizeof(value)); + if (ret < 0) + LOG(Event, Error) << "Failed to process interrupt"; } void EventDispatcherPoll::processNotifiers(const std::vector &pollfds) diff --git a/test/event.cpp b/test/event.cpp index 52bc0c7e77f5..9bd876153a18 100644 --- a/test/event.cpp +++ b/test/event.cpp @@ -38,6 +38,7 @@ protected: EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); std::string data("H2G2"); Timer timeout; + ssize_t ret; EventNotifier readNotifier(pipefd_[0], EventNotifier::Read); readNotifier.activated.connect(this, &EventTest::readReady); @@ -46,7 +47,11 @@ protected: memset(data_, 0, sizeof(data_)); size_ = 0; - write(pipefd_[1], data.data(), data.size()); + ret = write(pipefd_[1], data.data(), data.size()); + if (ret < 0) { + cout << "Pipe write failed" << endl; + return TestFail; + } timeout.start(100); dispatcher->processEvents(); @@ -73,7 +78,11 @@ protected: notified_ = false; readNotifier.setEnabled(false); - write(pipefd_[1], data.data(), data.size()); + ret = write(pipefd_[1], data.data(), data.size()); + if (ret < 0) { + cout << "Pipe write failed" << endl; + return TestFail; + } timeout.start(100); dispatcher->processEvents();