From patchwork Wed Mar 18 11:58:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3165 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E3A860419 for ; Wed, 18 Mar 2020 12:59:24 +0100 (CET) Received: by mail-pf1-x435.google.com with SMTP id 2so13766006pfg.12 for ; Wed, 18 Mar 2020 04:59:24 -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=mKogFjsmRN3byaPv0b/6ZZyVMnNZ8tddAXwdndhLKH0=; b=u14CwDODjdreSOhe+S5/2Iw7Bmqq2rKc5MIYmg9FelM4Fu9ILp6bjecor/qEKS8vAR Ob1KJA9vQcYf1np6Wx/SJldcGqfW4isTpKQSX/p+whyHmW7Gc73xzbY0UGSx1w9gcljo WBGNhyIWjbHE5+nuntatv8o7gzETDZ+P0rgY2xumuXiwn0oA9LdMlaTHDM1SrSFASDVs XFxalksr4KpORQCG84/6S+pJnNyRKHnbMS67hpirVmUxacVLdOH9ZEmAinFUBja3fdsm 2COrutuQyUI5MWEodUCB7A8aYKEXdMQF5KnfzgiCoTX0UAIrEZ/IqLL7T5nlQt5vsNgE CFQQ== 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=mKogFjsmRN3byaPv0b/6ZZyVMnNZ8tddAXwdndhLKH0=; b=jqDOiJbhfQ8sPnIOoWKG1hkIzNmxIg8QQ3BIUVlvtc4W9h9zeNPbQOC3bmyvStIFHc 263hmGt2t5jgDTHlf542CHWDF8xb/GbQPek7NPJJuhqZrcYd++JMR8PdNbXAcuLbG2xd EJ4mH4RCojR0UZ13YmGeZMsEZqBgLWhrzIaqOKsRV8QLlY1P0ctzsZvijuUHwqaMswEd SDpAdJAhB/bukwjNqApDmV0bRulrsVKFv8Aa8JQHsJcFyCXKcoj9QlXtYkbyEPPgcYLt +9fPS1drFPZUY7WV0qqQasJI7Jd1SbHRz5iAehJ7cC1qH7L0XvtjSx1CzRBgMARmWww5 50fw== X-Gm-Message-State: ANhLgQ0Nx0wK9CpS2paDA6M3WAgujfrC6SCt0fop3NUd2TC68z41I94a OpPMZu1aYAM6GXS0QP5Or+EHuQ== X-Google-Smtp-Source: ADFU+vuC/5vEGkQqxzRm7VlMppCyPeDQR+8AmrOh7WcL3kRqbA/0+VtT6yHbgX+wa/f62TvAczpcxQ== X-Received: by 2002:a62:1cf:: with SMTP id 198mr4062245pfb.246.1584532762859; Wed, 18 Mar 2020 04:59:22 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id i11sm2378818pje.30.2020.03.18.04.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 04:59:22 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Vaishali Thakkar , kieran.bingham@ideasonboard.com, libcamera-devel@lists.libcamera.org Cc: Kaaira Gupta Date: Wed, 18 Mar 2020 17:28:43 +0530 Message-Id: <20200318115846.7975-4-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318115846.7975-1-kgupta@es.iitr.ac.in> References: <20200318115846.7975-1-kgupta@es.iitr.ac.in> Subject: [libcamera-devel] [PATCH LIBCAMERA v3 3/6] libcamera: utils: add Libcamera installed & path 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: Wed, 18 Mar 2020 11:59:24 -0000 Add a global functions 'isLibcameraInstalled' to check if libcamera is installed or not, and another global function 'libcameraPath' to return the path of libcamera.so in utils. Signed-off-by: Kaaira Gupta --- src/libcamera/include/utils.h | 4 +++ src/libcamera/utils.cpp | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 9405977..bc96e79 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -143,6 +143,10 @@ private: details::StringSplitter split(const std::string &str, const std::string &delim); +bool isLibcameraInstalled(); + +std::string libcameraPath(); + } /* namespace utils */ } /* namespace libcamera */ diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index f566e88..aeaf163 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -12,12 +12,18 @@ #include #include #include +#include +#include +#include /** * \file utils.h * \brief Miscellaneous utility functions */ +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */ +extern ElfW(Dyn) _DYNAMIC[]; + namespace libcamera { namespace utils { @@ -310,6 +316,48 @@ details::StringSplitter split(const std::string &str, const std::string &delim) return details::StringSplitter(str, delim); } +/** + * \brief Checks if Libcamera is installed or not + * + * Utilises the build_rpath dynamic tag which is stripped out by meson at + * install time to determine at runtime if the library currently executing + * has been installed or not. + * + * \return A bool stating if libcamera is installed or not + */ +bool isLibcameraInstalled() +{ + /* + * 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; +} + +/** + * \brief Identifies libcamera path + * + * Identifies the location by finding the path of the active libcamera.so itself. + * + * \return A string stating the path. + */ +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 utils */ } /* namespace libcamera */