From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75111C77B7A for ; Thu, 25 May 2023 17:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbjEYRCl (ORCPT ); Thu, 25 May 2023 13:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233274AbjEYRCk (ORCPT ); Thu, 25 May 2023 13:02:40 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B1DF194 for ; Thu, 25 May 2023 10:02:39 -0700 (PDT) Received: from localhost (node-1w7jr9st5p2esmclet71ntnwp.ipv6.telus.net [IPv6:2001:569:beb1:1500:6f9d:3a5c:4d25:e949]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dbrouwer) by madras.collabora.co.uk (Postfix) with ESMTPSA id 76D8A6606E7B; Thu, 25 May 2023 18:02:37 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1685034157; bh=qZq5asB1QLjxEVKS4qEuxmKTzHO+/CWHiQ+58+giOjs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mtXlAw1WNl77m/O72b5Fe8oDzLEjRd/W19Buq3OLK3H+gCDJHusmAkl/0nhZCLrzB Vc/D95Jt6KTh9KcdMy6ssDnjadTUlCDh0RjFBE1evDtmtktzAgeA2znIUutEO0YCfr OOdrLW+K41s1EbK4Vx1q2uS44YzRELj07RCENr1IXLjQKOIXeOLvcRl7za/olY46UA iXaCyYKOVjAqBEOaDnlVBU2oEzgTCqE3LHSrx2ZMR4GlXIvctMB2MzyBIoScsgNsfr i/+oHc5Y0Cw9Udc7MSHQzerEBGNXAhU+Rw2uIhipBa11sMIsb4vEZyLccPxJ4S2j1A LoxvlIC8ePOMw== Date: Thu, 25 May 2023 10:02:31 -0700 From: Deborah Brouwer To: Nicolas Dufresne Cc: linux-media@vger.kernel.org, hverkuil-cisco@xs4all.nl Subject: Re: [PATCH] v4l2-tracer: Fix libv4l2tracer.so loader Message-ID: References: <20230525002045.82937-1-deborah.brouwer@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Thu, May 25, 2023 at 12:45:28PM -0400, Nicolas Dufresne wrote: > Thanks Deborah, > > Le mercredi 24 mai 2023 à 17:20 -0700, Deborah Brouwer a écrit : > > From: Nicolas Dufresne > > > > 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 > > Mind adding you Singed-off-by ? Actually Hans already applied your patch (thanks!) but will do it next time. > > > --- > > 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 > > +#include > > #include > > #include > > > > @@ -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); >