From 07d5fff29ce96f3456cf74d740b56a46c5cba507 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 28 Dec 2021 23:29:51 +0200 Subject: v4l2: v4l2_camera_file: Store file description 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 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/v4l2/v4l2_camera_file.cpp') diff --git a/src/v4l2/v4l2_camera_file.cpp b/src/v4l2/v4l2_camera_file.cpp index a07679b5..0a41587c 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_; +} -- cgit v1.2.1