From patchwork Tue Mar 17 17:31:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3143 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 442B962923 for ; Tue, 17 Mar 2020 18:32:35 +0100 (CET) Received: by mail-pf1-x430.google.com with SMTP id b72so12311996pfb.11 for ; Tue, 17 Mar 2020 10:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KrtPCqHQs+csT3TD5XmQcU1mNeju6IYSHxiln/8Vwk4=; b=TdJqvbXM27ujr7k1ASvreKqZOX9AzLts1tC+kqO4ZyCPc+4nXRUieMaGCTb77Vlmtd xhneuenxLyj5oq6aVU3LI9WIXbrZC0donelQs04S2c6g8islZGNW5sSXAHqQ6R6A34Ge hOhBfvDlT9GV0MqMrGjAmDHJiarg9g1kilmSQehugpipnpD9LXFgrxxLBrV/OKXnid10 9rRpizF3z8pg25kfuS2b+6M0DFIZnImewPWWTg3+dYdO++mGaaX2EbPPHv9aEwbGyOII Eh9kV3xBfvR42pwuc+LRYOdxy53E+hrMLWEOfGM0k/KE+WZufhIKBP3RX4mr8/3UqrlV Tz/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KrtPCqHQs+csT3TD5XmQcU1mNeju6IYSHxiln/8Vwk4=; b=ZhxN57t4f0/1qQzstmaKbZG2y0TrAeJOLnFbAKItcPceOCEaI9wLKd1dl/qWGsdCOa jwg0HVfA/4S4BUr316pAvtj0SXwU/9tY+bCdlsQuJIHP91IC0cZcLG1fMJXnpiRTuAmc VmB3bvVWuTMOwcvVU4YdSMvgzCfjGZHERugiZLHoVL9QQ28DstnAzJ8R6oTRjsx7BkR8 2kRCJUCTrsvOLEEi6zr43iAC1aYXU7c45aH5FRgPv7wvMI0NG+mudim4zMiStu6pc3Rj pdlaM7pGDNvMAoKUM8yQa+EWFbOel/fk6WzCg/D2ZW2WfcK/UM8G3eYoN0cFSA66/pjH 3qEg== X-Gm-Message-State: ANhLgQ3hwYMI3z/eszrSOMIwqfCTjYtPITQiF2vu71OLUXMigkB7Os0l qx8DPi1pdlZVMse9PRl/tqqCnw== X-Google-Smtp-Source: ADFU+vtatYKgzKXA9N9n1e9rVBE+LWqO3viayzgUZHX0P/kHU6PwWxcX0lyINDwok+SJjun/AC5dag== X-Received: by 2002:a63:4cc:: with SMTP id 195mr290250pge.93.1584466353853; Tue, 17 Mar 2020 10:32:33 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id v1sm52049pjy.35.2020.03.17.10.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2020 10:32:33 -0700 (PDT) From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, kieran.bingham@ideasonboard.com, Helen Koike , Vaishali Thakkar Cc: Kaaira Gupta Date: Tue, 17 Mar 2020 23:01:44 +0530 Message-Id: <20200317173145.18226-4-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200317173145.18226-1-kgupta@es.iitr.ac.in> References: <20200317173145.18226-1-kgupta@es.iitr.ac.in> Subject: [libcamera-devel] [PATCH LIBCAMERA 3/4] libcamera: ipa_proxy: search for proxy in build tree 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: , X-List-Received-Date: Tue, 17 Mar 2020 17:32:35 -0000 When libcamera is build and tested before installing, it will be unable to locate the path to proxy files,or previously installed files in the system path may be incorrect to load. Hence, when libcamera is not installed and running from a build tree, identify the location of that tree by finding the path of active libcamera.so, and from that point add the relative path to the proxy file. Signed-off-by: Kaaira Gupta --- src/libcamera/ipa_proxy.cpp | 54 +++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp index 363d034..d7c32a1 100644 --- a/src/libcamera/ipa_proxy.cpp +++ b/src/libcamera/ipa_proxy.cpp @@ -9,7 +9,9 @@ #include #include - +#include +#include +#include #include "log.h" #include "utils.h" @@ -20,6 +22,35 @@ * \brief IPA Proxy */ +static bool isLibcameraInstalled() +{ + /* musl doesn't declare _DYNAMIC in link.h, declare it manually. */ + extern ElfW(Dyn) _DYNAMIC[]; + + /* + * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on + * install. + */ + for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) { + if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH) + return false; + } + + return true; +} + +static std::string libcameraPath() +{ + Dl_info info; + + /* Look up our own symbol. */ + int ret = dladdr(reinterpret_cast(libcameraPath), &info); + if (ret == 0) + return nullptr; + + return info.dli_fname; +} + namespace libcamera { LOG_DEFINE_CATEGORY(IPAProxy) @@ -89,10 +120,23 @@ std::string IPAProxy::resolvePath(const std::string &file) const } } - /*Try finding the exec target from the install directory.*/ - std::string proxyPath = std::string(IPA_PROXY_DIR) + proxyFile; - if (!access(proxyPath.c_str(), X_OK)) - return proxyPath; + /* + *When libcamera is used before it is installed, load proxies from the + *same build directory as the libcamera directory itself. This requires + *identifying the path of the libcamera.so, and referencing a relative + *path for the proxies from that point. + */ + if (!isLibcameraInstalled()){ + std::string ipaProxyDir = utils::dirname(libcameraPath()) + "/../../proxy"; + + LOG(IPAProxy, Info) + << "libcamera is not installed. Adding '" + << ipaProxyDir << "' to the Proxy search path"; + + std::string proxyPath = ipaProxyDir + proxyFile; + if (!access(proxyPath.c_str(), X_OK)) + return proxyPath; + } return std::string(); }