{"id":1127,"url":"https://patchwork.libcamera.org/api/patches/1127/?format=json","web_url":"https://patchwork.libcamera.org/patch/1127/","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":"<20190429123826.31597-1-laurent.pinchart@ideasonboard.com>","date":"2019-04-29T12:38:26","name":"[libcamera-devel,v1.3,1/2] libcamera: Don't ignore the return value of read() and write()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"deaaf429f1017c71a5ac68dded786daff75a7ec3","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/1127/mbox/","series":[{"id":283,"url":"https://patchwork.libcamera.org/api/series/283/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=283","date":"2019-04-29T12:38:26","name":"[libcamera-devel,v1.3,1/2] libcamera: Don't ignore the return value of read() and write()","version":1,"mbox":"https://patchwork.libcamera.org/series/283/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1127/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1127/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 12AB860C46\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Apr 2019 14:38:41 +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 A3C942E7;\n\tMon, 29 Apr 2019 14:38:40 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1556541520;\n\tbh=XYakD+sHil3iLb6+9I3Ljr3M5TiffCPeEMiqL8bWbjI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Lo0Xjz6jWgBTfuarEZVubmjGPML1Sks7pSVtrFIBNXDzvud0ldGIGS8pQjaDVclhp\n\tOP3YgE+z8kVjYlUXnU1XsrirTA4FXUYJvzaJdC0VBv0i+dd19N6QaOz4hS6Adn0r2o\n\tf7TtSc+nfr1FsTD+bnOOll8KrblQp6V/DuZvuTdw=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1.3 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:38:41 -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 | 17 +++++++++++++++--\n test/event.cpp                          | 13 +++++++++++--\n 2 files changed, 26 insertions(+), 4 deletions(-)\n---\nWith real changes this time, sorry about the noise.","diff":"diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp\nindex 1f0f352a8e0a..0ff99fce47ab 100644\n--- a/src/libcamera/event_dispatcher_poll.cpp\n+++ b/src/libcamera/event_dispatcher_poll.cpp\n@@ -162,7 +162,14 @@ 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 != sizeof(value)) {\n+\t\tif (ret < 0)\n+\t\t\tret = -errno;\n+\t\tLOG(Event, Error)\n+\t\t\t<< \"Failed to interrupt event dispatcher (\"\n+\t\t\t<< ret << \")\";\n+\t}\n }\n \n short EventDispatcherPoll::EventNotifierSetPoll::events() const\n@@ -214,7 +221,13 @@ 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 != sizeof(value)) {\n+\t\tif (ret < 0)\n+\t\t\tret = -errno;\n+\t\tLOG(Event, Error)\n+\t\t\t<< \"Failed to process interrupt (\" << ret << \")\";\n+\t}\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.3","1/2"]}