All of lore.kernel.org
 help / color / mirror / Atom feed
From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: linux-media@vger.kernel.org
Cc: hverkuil-cisco@xs4all.nl,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>
Subject: [PATCH] v4l2-tracer: Fix libv4l2tracer.so loader
Date: Wed, 24 May 2023 17:20:45 -0700	[thread overview]
Message-ID: <20230525002045.82937-1-deborah.brouwer@collabora.com> (raw)

From: Nicolas Dufresne <nicolas.dufresne@collabora.com>

The code was still assuming libtools being use, so it didn't work
installed anymore. Also, it didn't work installed if the full
v4l2-tracer path was being passed.

Fix this by always trying next by libv4l2tracer.so loading (using stat()
to validate) and always fallback to the installed path otherwise.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
Hi - thanks to Nicolas for this patch.
I tested tracing and retracing on both installed and uninstalled
v4l2-tracer including with and without an absolute path and it
all works as expected.

Note that I've got three sets of v4l2-tracer patches outstanding now,
but they all still apply independently of each other:

Tuner patches:
https://lore.kernel.org/linux-media/cover.1684453027.git.deborah.brouwer@collabora.com/

Debug patches:
https://lore.kernel.org/linux-media/cover.1681245372.git.deborah.brouwer@collabora.com/

Thanks,
Deb

 utils/v4l2-tracer/v4l2-tracer.cpp | 33 +++++++++++++++++--------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/utils/v4l2-tracer/v4l2-tracer.cpp b/utils/v4l2-tracer/v4l2-tracer.cpp
index e3f002a9..7c3662be 100644
--- a/utils/v4l2-tracer/v4l2-tracer.cpp
+++ b/utils/v4l2-tracer/v4l2-tracer.cpp
@@ -5,6 +5,7 @@
 
 #include "retrace.h"
 #include <climits>
+#include <sys/stat.h>
 #include <sys/wait.h>
 #include <time.h>
 
@@ -295,24 +296,26 @@ int tracer(int argc, char *argv[], bool retrace)
 	fclose(trace_file);
 
 	/*
-	 * Preload the libv4l2tracer library. If the program is installed, load the library
-	 * from its installed location, otherwise load it locally. If it's loaded locally,
-	 * use ./configure --disable-dyn-libv4l.
+	 * Preload the libv4l2tracer library. The libv4l2tracer is looked up next to
+	 * the executable first in order to support uninstalled build.
 	 */
 	std::string libv4l2tracer_path;
 	std::string program = argv[0];
-	std::size_t idx = program.rfind("/v4l2-tracer");
-	if (idx != std::string::npos) {
-		libv4l2tracer_path = program.replace(program.begin() + idx + 1, program.end(), ".libs");
-		DIR *directory_pointer = opendir(libv4l2tracer_path.c_str());
-		if (directory_pointer == nullptr)
-			libv4l2tracer_path = program.replace(program.begin() + idx, program.end(), "./.libs");
-		else
-			closedir(directory_pointer);
-	} else {
-		libv4l2tracer_path = LIBTRACER_PATH;
-	}
-	libv4l2tracer_path += "/libv4l2tracer.so";
+	std::size_t idx = program.rfind("/");
+	struct stat sb;
+
+	if (idx == std::string::npos)
+		idx = 0;
+	else
+		idx++;
+
+	/* look for libv4l2tracer next to the executable */
+	libv4l2tracer_path = program.replace(program.begin() + idx, program.end(), "libv4l2tracer.so");
+
+	/* otherwise, use the installation path */
+	if (stat(libv4l2tracer_path.c_str(), &sb) == -1)
+		libv4l2tracer_path = std::string(LIBTRACER_PATH) + "/libv4l2tracer.so";
+
 	if (is_verbose())
 		fprintf(stderr, "Loading libv4l2tracer: %s\n", libv4l2tracer_path.c_str());
 	setenv("LD_PRELOAD", libv4l2tracer_path.c_str(), 0);
-- 
2.40.1


             reply	other threads:[~2023-05-25  0:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25  0:20 Deborah Brouwer [this message]
2023-05-25 16:45 ` [PATCH] v4l2-tracer: Fix libv4l2tracer.so loader Nicolas Dufresne
2023-05-25 17:02   ` Deborah Brouwer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230525002045.82937-1-deborah.brouwer@collabora.com \
    --to=deborah.brouwer@collabora.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.