From patchwork Wed Mar 18 00:10:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3149 Return-Path: Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B59A60422 for ; Wed, 18 Mar 2020 01:10:41 +0100 (CET) Received: by mail-pg1-x52f.google.com with SMTP id t24so12632084pgj.7 for ; Tue, 17 Mar 2020 17:10:40 -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=BjxbadyKnvQeZHEaUc82NkDXvLsV4Hay+RsBUzZq6Qo=; b=Z2BKoqP7R5XWm/i3L+ikIAFHAnNKM5NcRt60DNewG+oMBwXwXvhLuXpP7EgSTcZXdf uEnNKR91yytAhpwyOlNWJacOeVd6jhjXRla/npdWtgvb/6azS+HRvHBjhaVzzP1/hc77 DU1ko9uTdPKv4CV/2Wpz8VKPniGaI5M+P/lV2ufAAjq7qJ5/ONqpOqAE4D0uhY7cRTmD 8Zcn1lhXPzqeClDvRFN8S1dj+ZcgOu3ED9PK8mvI+QC1MV+4Ga0MCxfaxB2ZEG56rbce lVqdXWijBKIWB/XjiONU8DcyyID/wVz69nb0f2cDx48F8BxWfa6Vs21k4ifddj6jYIZo V0xg== 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=BjxbadyKnvQeZHEaUc82NkDXvLsV4Hay+RsBUzZq6Qo=; b=AumD6RHRh4GWfzbEdDPEqhOruQNscdg0k/AV/fjxKwkG7r8876SSY9ti0rHD4wReVq yNJhDV7hBXT5+1AFEn1/g7Mz+L4AnazUGyZQUDGj5EV5Pj+Jp3P56ce00N5QBRndgMM0 wsOS8A0vUvdE6AdqGFgcrrLSxs6NdsjelS+PfzvVDr9cy2yMjHb2jZG8ZBCtQBryvQvF xvbYBG9sGaixMcqNDymTbOVhm9jTg+Evwud/N0YFaQSf+RZaFrSKQJkH4TSg5oRkmPgH OxolOHhO/zL+E03Mzz6WIhCnb+d/R1/SCiLaSlZOUXuUm/E4kmHxCtu+ld2MEV72qYWk Vr8g== X-Gm-Message-State: ANhLgQ2hJvqHAtoLiA3D6AVajnZ1mNdxCZ4QQkDLWNW8/AjbiFn53oAK 7fuXje0iUL1tb84OAeiPjc07vQ== X-Google-Smtp-Source: ADFU+vttXeM+ZtwCSD6dQ7vfRvGDEd9XYh54QG2uriSW4DnliprzfwW14hExWHh6BfNoILBfHjlevw== X-Received: by 2002:a62:1c08:: with SMTP id c8mr1483363pfc.80.1584490239623; Tue, 17 Mar 2020 17:10:39 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id gv7sm460563pjb.16.2020.03.17.17.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2020 17:10:39 -0700 (PDT) From: Kaaira Gupta To: kieran.bingham@ideasonboard.com, libcamera-devel@lists.libcamera.org, Helen Koike , Vaishali Thakkar Cc: Kaaira Gupta Date: Wed, 18 Mar 2020 05:40:06 +0530 Message-Id: <20200318001009.32512-4-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318001009.32512-1-kgupta@es.iitr.ac.in> References: <20200318001009.32512-1-kgupta@es.iitr.ac.in> Subject: [libcamera-devel] [PATCH LIBCAMERA v2 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 00:10:41 -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/utils.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index f566e88..1f6ec60 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include /** * \file utils.h @@ -310,6 +313,51 @@ 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() +{ + /* 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; +} + +/** + * \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 */