From patchwork Tue Dec 28 21:59:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15228 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C200CC3258 for ; Tue, 28 Dec 2021 22:00:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 067056091C; Tue, 28 Dec 2021 23:00:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="K8yBROvq"; dkim-atps=neutral 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 50F6C608E9 for ; Tue, 28 Dec 2021 22:59:58 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E93413E7 for ; Tue, 28 Dec 2021 22:59:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728798; bh=zvuQC9WPq43vhHmWWlaS9LD1cwEdf0G0itcmYG0Tgx8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K8yBROvqnq9lyBqeAX07B8lWfx4aYjAiqf7rdVX0fRbuaCjHBq9bkCQT555Q2HzxL 0KuGQ74bKUgopOgKZo646FbZ280bppSJy5vgczmB5pRq74JcyeJDNV9gfU3KhntZ8I dcREbPIfobOXO1WW/8Ihq8OCC3EMJu1DgxIx65GM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:48 +0200 Message-Id: <20211228215951.32396-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/5] v4l2: v4l2_camera_file: Store file description X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create a string that describe the file from the path and file descriptor. This will be used in log messages to clearly identify which file an operation is related to. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_camera_file.cpp | 28 +++++++++++++++++++++++++++- src/v4l2/v4l2_camera_file.h | 8 +++++++- src/v4l2/v4l2_compat_manager.cpp | 4 +++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/v4l2/v4l2_camera_file.cpp b/src/v4l2/v4l2_camera_file.cpp index a07679b587ce..0a41587ca90b 100644 --- a/src/v4l2/v4l2_camera_file.cpp +++ b/src/v4l2/v4l2_camera_file.cpp @@ -7,20 +7,46 @@ #include "v4l2_camera_file.h" +#include +#include +#include + #include #include "v4l2_camera_proxy.h" using namespace libcamera; -V4L2CameraFile::V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy) +V4L2CameraFile::V4L2CameraFile(int dirfd, const char *path, int efd, + bool nonBlocking, V4L2CameraProxy *proxy) : proxy_(proxy), nonBlocking_(nonBlocking), efd_(efd), priority_(V4L2_PRIORITY_DEFAULT) { proxy_->open(this); + + if (path[0] != '/') { + if (dirfd == AT_FDCWD) { + char *cwd = getcwd(nullptr, 0); + if (cwd) { + description_ = std::string(cwd) + "/"; + free(cwd); + } else { + description_ = std::string("(unreachable)/"); + } + } else { + description_ = "(dirfd:" + std::to_string(dirfd) + ")/"; + } + } + + description_ += std::string(path) + " (fd:" + std::to_string(efd) + ")"; } V4L2CameraFile::~V4L2CameraFile() { proxy_->close(this); } + +const std::string &V4L2CameraFile::description() const +{ + return description_; +} diff --git a/src/v4l2/v4l2_camera_file.h b/src/v4l2/v4l2_camera_file.h index 6c4cb5d89dbf..1a7b6a63ae95 100644 --- a/src/v4l2/v4l2_camera_file.h +++ b/src/v4l2/v4l2_camera_file.h @@ -7,6 +7,8 @@ #pragma once +#include + #include class V4L2CameraProxy; @@ -14,7 +16,8 @@ class V4L2CameraProxy; class V4L2CameraFile { public: - V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy); + V4L2CameraFile(int dirfd, const char *path, int efd, bool nonBlocking, + V4L2CameraProxy *proxy); ~V4L2CameraFile(); V4L2CameraProxy *proxy() const { return proxy_; } @@ -25,9 +28,12 @@ public: enum v4l2_priority priority() const { return priority_; } void setPriority(enum v4l2_priority priority) { priority_ = priority; } + const std::string &description() const; + private: V4L2CameraProxy *proxy_; + std::string description_; bool nonBlocking_; int efd_; enum v4l2_priority priority_; diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index c64cdb862489..585046e97e4b 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -156,7 +156,9 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod return efd; V4L2CameraProxy *proxy = proxies_[ret].get(); - files_.emplace(efd, std::make_shared(efd, oflag & O_NONBLOCK, proxy)); + files_.emplace(efd, std::make_shared(dirfd, path, efd, + oflag & O_NONBLOCK, + proxy)); LOG(V4L2Compat, Debug) << "Opened " << path << " -> fd " << efd; return efd;