{"id":1126,"url":"https://patchwork.libcamera.org/api/patches/1126/?format=json","web_url":"https://patchwork.libcamera.org/patch/1126/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190429122813.31256-1-laurent.pinchart@ideasonboard.com>","date":"2019-04-29T12:28:13","name":"[libcamera-devel,v1.1,1/2] libcamera: Don't ignore the return value of read() and write()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9693cc463a88c9654a419ab016b1a9e46167051e","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1126/mbox/","series":[{"id":282,"url":"https://patchwork.libcamera.org/api/series/282/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=282","date":"2019-04-29T12:28:13","name":"[libcamera-devel,v1.1,1/2] libcamera: Don't ignore the return value of read() and write()","version":1,"mbox":"https://patchwork.libcamera.org/series/282/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1126/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1126/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 71FDC60C46\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Apr 2019 14:28:29 +0200 (CEST)","from pendragon.station (net-37-182-44-227.cust.vodafonedsl.it\n\t[37.182.44.227])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D1AE22E7;\n\tMon, 29 Apr 2019 14:28:28 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1556540909;\n\tbh=Qs5KrlcLhb4GGbojzVTl/BSKYa6ODXg4N5cdaUBjW/E=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=n7u8WARXvIA8BZIJ2Y5FsHKtXs6Jd0e1yvEM+LahWmnw/MlPDQYnCuO6DJJ8LYY9g\n\thDY5vCIswxcOf4ww/yZP/naDuiMYUf5IP1QQGcJFHt63c0t6RZrlFS9tR5NoYK8JrF\n\tNjEAYKm6oxDy6sR3tQ4F8to7nDoiIzSCY6lFfp2U=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1.1 1/2] libcamera: Don't ignore the\n\treturn value of read() and write()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 29 Apr 2019 12:28:29 -0000"},"content":"The glibc read() and write() functions are defined with the\n__warn_unused_result__ attribute when using FORTIFY_SOURCE. Don't ignore\ntheir return value.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/event_dispatcher_poll.cpp |  8 ++++++--\n test/event.cpp                          | 13 +++++++++++--\n 2 files changed, 17 insertions(+), 4 deletions(-)","diff":"diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp\nindex 1f0f352a8e0a..2621b7d96b1e 100644\n--- a/src/libcamera/event_dispatcher_poll.cpp\n+++ b/src/libcamera/event_dispatcher_poll.cpp\n@@ -162,7 +162,9 @@ void EventDispatcherPoll::processEvents()\n void EventDispatcherPoll::interrupt()\n {\n \tuint64_t value = 1;\n-\twrite(eventfd_, &value, sizeof(value));\n+\tssize_t ret = write(eventfd_, &value, sizeof(value));\n+\tif (ret < 0)\n+\t\tLOG(Event, Error) << \"Failed to interrupt event dispatcher\";\n }\n \n short EventDispatcherPoll::EventNotifierSetPoll::events() const\n@@ -214,7 +216,9 @@ void EventDispatcherPoll::processInterrupt(const struct pollfd &pfd)\n \t\treturn;\n \n \tuint64_t value;\n-\tread(eventfd_, &value, sizeof(value));\n+\tssize_t ret = read(eventfd_, &value, sizeof(value));\n+\tif (ret < 0)\n+\t\tLOG(Event, Error) << \"Failed to process interrupt\";\n }\n \n void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pollfds)\ndiff --git a/test/event.cpp b/test/event.cpp\nindex 52bc0c7e77f5..9bd876153a18 100644\n--- a/test/event.cpp\n+++ b/test/event.cpp\n@@ -38,6 +38,7 @@ protected:\n \t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n \t\tstd::string data(\"H2G2\");\n \t\tTimer timeout;\n+\t\tssize_t ret;\n \n \t\tEventNotifier readNotifier(pipefd_[0], EventNotifier::Read);\n \t\treadNotifier.activated.connect(this, &EventTest::readReady);\n@@ -46,7 +47,11 @@ protected:\n \t\tmemset(data_, 0, sizeof(data_));\n \t\tsize_ = 0;\n \n-\t\twrite(pipefd_[1], data.data(), data.size());\n+\t\tret = write(pipefd_[1], data.data(), data.size());\n+\t\tif (ret < 0) {\n+\t\t\tcout << \"Pipe write failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n \n \t\ttimeout.start(100);\n \t\tdispatcher->processEvents();\n@@ -73,7 +78,11 @@ protected:\n \t\tnotified_ = false;\n \t\treadNotifier.setEnabled(false);\n \n-\t\twrite(pipefd_[1], data.data(), data.size());\n+\t\tret = write(pipefd_[1], data.data(), data.size());\n+\t\tif (ret < 0) {\n+\t\t\tcout << \"Pipe write failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n \n \t\ttimeout.start(100);\n \t\tdispatcher->processEvents();\n","prefixes":["libcamera-devel","v1.1","1/2"]}