From patchwork Mon Apr 29 12:38:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1127 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 12AB860C46 for ; Mon, 29 Apr 2019 14:38:41 +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 A3C942E7; Mon, 29 Apr 2019 14:38:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1556541520; bh=XYakD+sHil3iLb6+9I3Ljr3M5TiffCPeEMiqL8bWbjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lo0Xjz6jWgBTfuarEZVubmjGPML1Sks7pSVtrFIBNXDzvud0ldGIGS8pQjaDVclhp OP3YgE+z8kVjYlUXnU1XsrirTA4FXUYJvzaJdC0VBv0i+dd19N6QaOz4hS6Adn0r2o f7TtSc+nfr1FsTD+bnOOll8KrblQp6V/DuZvuTdw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Apr 2019 15:38:26 +0300 Message-Id: <20190429123826.31597-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.3 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:38:41 -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 Reviewed-by: Kieran Bingham --- src/libcamera/event_dispatcher_poll.cpp | 17 +++++++++++++++-- test/event.cpp | 13 +++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) --- With real changes this time, sorry about the noise. diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index 1f0f352a8e0a..0ff99fce47ab 100644 --- a/src/libcamera/event_dispatcher_poll.cpp +++ b/src/libcamera/event_dispatcher_poll.cpp @@ -162,7 +162,14 @@ 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 != sizeof(value)) { + if (ret < 0) + ret = -errno; + LOG(Event, Error) + << "Failed to interrupt event dispatcher (" + << ret << ")"; + } } short EventDispatcherPoll::EventNotifierSetPoll::events() const @@ -214,7 +221,13 @@ 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 != sizeof(value)) { + if (ret < 0) + ret = -errno; + LOG(Event, Error) + << "Failed to process interrupt (" << ret << ")"; + } } 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();