Patch Detail
Show a patch.
GET /api/1.1/patches/14883/?format=api
{ "id": 14883, "url": "https://patchwork.libcamera.org/api/1.1/patches/14883/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14883/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20211130102736.1768-1-laurent.pinchart@ideasonboard.com>", "date": "2021-11-30T10:27:36", "name": "[libcamera-devel,v4.1,07/22] libcamera: base: file_descriptor: Return UniqueFD from dup()", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a388d182c02786200a9661a725785d905b7919d6", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14883/mbox/", "series": [ { "id": 2781, "url": "https://patchwork.libcamera.org/api/1.1/series/2781/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2781", "date": "2021-11-30T10:27:16", "name": null, "version": 1, "mbox": "https://patchwork.libcamera.org/series/2781/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14883/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14883/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A0E2ABF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 10:28:05 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5783E605B4;\n\tTue, 30 Nov 2021 11:28:05 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D1A9160230\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 11:28:03 +0100 (CET)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6F7732A5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 11:28:03 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"d65vqPik\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638268083;\n\tbh=YSFQHGBQvSj8ibJm0RrAidBpqucwCNeGQQw1uH3Hscc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=d65vqPik1HZiYxEuesc3WkHlDDrjfKHazKwiOyCls4MLsjg6a3VOj+OEVV93gRi4s\n\tc2MLhusngs4LwZunDVN1dEtwo+IBW66FciKwZkynsE8/96xiVYdAX5HeG04pycCae/\n\tPyuEZwBKy6yEimcsXANkHd1WlV3MaffiCZM9H+EU=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 30 Nov 2021 12:27:36 +0200", "Message-Id": "<20211130102736.1768-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20211130033820.18235-8-laurent.pinchart@ideasonboard.com>", "References": "<20211130033820.18235-8-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4.1 07/22] libcamera: base:\n\tfile_descriptor: Return UniqueFD from dup()", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The dup() function returns a duplicate of the file descriptor. Wrapping\nit in a FileDescriptor isn't wrong as such, but it prevents from using\nit in contexts where a UniqueFD is needed. As the duplicate is\nguaranteed to have a single owner when created, return it as a UniqueFD\ninstead. A FileDescriptor can easily be created from the UniqueFD if\ndesired.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nChanges since v4:\n\n- Store ::dup() return value directly in UniqueFD\n---\n include/libcamera/base/file_descriptor.h | 2 +-\n src/libcamera/base/file_descriptor.cpp | 22 ++++++++++++++--------\n 2 files changed, 15 insertions(+), 9 deletions(-)", "diff": "diff --git a/include/libcamera/base/file_descriptor.h b/include/libcamera/base/file_descriptor.h\nindex 74292eba04f5..12a43f95d414 100644\n--- a/include/libcamera/base/file_descriptor.h\n+++ b/include/libcamera/base/file_descriptor.h\n@@ -28,7 +28,7 @@ public:\n \n \tbool isValid() const { return fd_ != nullptr; }\n \tint fd() const { return fd_ ? fd_->fd() : -1; }\n-\tFileDescriptor dup() const;\n+\tUniqueFD dup() const;\n \n private:\n \tclass Descriptor\ndiff --git a/src/libcamera/base/file_descriptor.cpp b/src/libcamera/base/file_descriptor.cpp\nindex da696b2501cd..8e181abc44bb 100644\n--- a/src/libcamera/base/file_descriptor.cpp\n+++ b/src/libcamera/base/file_descriptor.cpp\n@@ -222,17 +222,23 @@ FileDescriptor &FileDescriptor::operator=(FileDescriptor &&other)\n * \\brief Duplicate a FileDescriptor\n *\n * Duplicating a FileDescriptor creates a duplicate of the wrapped file\n- * descriptor and returns a new FileDescriptor instance that wraps the\n- * duplicate. The fd() function of the original and duplicate instances will\n- * return different values. The duplicate instance will not be affected by\n- * destruction of the original instance or its copies.\n+ * descriptor and returns a UniqueFD that owns the duplicate. The fd() function\n+ * of the original and the get() function of the duplicate will return different\n+ * values. The duplicate instance will not be affected by destruction of the\n+ * original instance or its copies.\n *\n- * \\return A new FileDescriptor instance wrapping a duplicate of the original\n- * file descriptor\n+ * \\return A UniqueFD owning a duplicate of the original file descriptor\n */\n-FileDescriptor FileDescriptor::dup() const\n+UniqueFD FileDescriptor::dup() const\n {\n-\treturn FileDescriptor(fd());\n+\tUniqueFD dupFd(::dup(fd()));\n+\tif (!dupFd.isValid()) {\n+\t\tint ret = -errno;\n+\t\tLOG(FileDescriptor, Error)\n+\t\t\t<< \"Failed to dup() fd: \" << strerror(-ret);\n+\t}\n+\n+\treturn dupFd;\n }\n \n FileDescriptor::Descriptor::Descriptor(int fd, bool duplicate)\n", "prefixes": [ "libcamera-devel", "v4.1", "07/22" ] }