From ddb61f915e939f05fb5f1f2cb1d563b1d7a5bc97 Mon Sep 17 00:00:00 2001 From: Kirill Chilikin Date: Thu, 16 Jun 2022 19:40:04 +0300 Subject: [PATCH 1/4] Check whether ROOTSYS is defined in rootcling_stage1. --- core/rootcling_stage1/src/rootcling_stage1.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/rootcling_stage1/src/rootcling_stage1.cxx b/core/rootcling_stage1/src/rootcling_stage1.cxx index 60ab481646c69..fc6331d4427e3 100644 --- a/core/rootcling_stage1/src/rootcling_stage1.cxx +++ b/core/rootcling_stage1/src/rootcling_stage1.cxx @@ -24,12 +24,22 @@ static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym; ROOT::Internal::RootCling::TROOTSYSSetter gROOTSYSSetter; static const char *GetIncludeDir() { - static std::string incdir = std::string(getenv("ROOTSYS")) + "/include"; + const char *rootsys = getenv("ROOTSYS"); + static std::string incdir; + if (rootsys != nullptr) + incdir = std::string(rootsys) + "/include"; + else + incdir = "/include"; return incdir.c_str(); } static const char *GetEtcDir() { - static std::string etcdir = std::string(getenv("ROOTSYS")) + "/etc"; + const char *rootsys = getenv("ROOTSYS"); + static std::string etcdir; + if (rootsys != nullptr) + etcdir = std::string(rootsys) + "/etc"; + else + etcdir = "/etc"; return etcdir.c_str(); } From c4b7c13a9cc5e605494af8fb28a9942749fb0e33 Mon Sep 17 00:00:00 2001 From: Kirill Chilikin Date: Fri, 17 Jun 2022 08:12:17 +0300 Subject: [PATCH 2/4] Get executable path at FreeBSD. --- core/dictgen/src/rootcling_impl.cxx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx index 1ab98203b90f0..9c969abeab46e 100644 --- a/core/dictgen/src/rootcling_impl.cxx +++ b/core/dictgen/src/rootcling_impl.cxx @@ -59,6 +59,10 @@ #include #endif +#if defined(__FreeBSD__) +#include +#include +#endif #include "cling/Interpreter/Interpreter.h" #include "cling/Interpreter/InterpreterCallbacks.h" @@ -205,6 +209,22 @@ const char *GetExePath() exepath = buf; } #endif +#if defined(__FreeBSD__) + int name[4]; + size_t len; + name[0] = CTL_KERN; + name[1] = KERN_PROC; + name[2] = KERN_PROC_PATHNAME; + name[3] = -1; + int ret = sysctl(name, 4, nullptr, &len, nullptr, 0); + if (ret == 0) { + char *buf = new char[len]; + ret = sysctl(name, 4, buf, &len, nullptr, 0); + if (ret == 0) + exepath = buf; + delete[] buf; + } +#endif #ifdef _WIN32 char *buf = new char[MAX_MODULE_NAME32 + 1]; ::GetModuleFileName(NULL, buf, MAX_MODULE_NAME32 + 1); @@ -471,7 +491,7 @@ void SetRootSys() #if !defined(_WIN32) char *ep = new char[PATH_MAX]; if (!realpath(exepath, ep)) { - fprintf(stderr, "rootcling: error getting realpath of rootcling!"); + fprintf(stderr, "rootcling: error getting realpath of rootcling!\n"); strlcpy(ep, exepath, PATH_MAX); } #else @@ -525,6 +545,8 @@ void SetRootSys() putenv(env); // intentionally not call delete [] env, while GLIBC keep use pointer delete [] ep; + } else { + fprintf(stderr, "rootcling: cannot set ROOTSYS because executable path is unknown.\n"); } } From 431cb07dfb11fcc9c73e46651f0d5913ffc3f14e Mon Sep 17 00:00:00 2001 From: Kirill Chilikin Date: Fri, 17 Jun 2022 18:38:23 +0300 Subject: [PATCH 3/4] Assert that ROOTSYS is set. --- core/rootcling_stage1/src/rootcling_stage1.cxx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/rootcling_stage1/src/rootcling_stage1.cxx b/core/rootcling_stage1/src/rootcling_stage1.cxx index fc6331d4427e3..76bf715a68b56 100644 --- a/core/rootcling_stage1/src/rootcling_stage1.cxx +++ b/core/rootcling_stage1/src/rootcling_stage1.cxx @@ -25,21 +25,17 @@ ROOT::Internal::RootCling::TROOTSYSSetter gROOTSYSSetter; static const char *GetIncludeDir() { const char *rootsys = getenv("ROOTSYS"); - static std::string incdir; - if (rootsys != nullptr) - incdir = std::string(rootsys) + "/include"; - else - incdir = "/include"; + // The environment variable ROOTSYS is expected to be set by SetRootSys(). + assert(rootsys != nullptr); + static std::string incdir = std::string(rootsys) + "/include"; return incdir.c_str(); } static const char *GetEtcDir() { const char *rootsys = getenv("ROOTSYS"); - static std::string etcdir; - if (rootsys != nullptr) - etcdir = std::string(rootsys) + "/etc"; - else - etcdir = "/etc"; + // The environment variable ROOTSYS is expected to be set by SetRootSys(). + assert(rootsys != nullptr); + static std::string etcdir = std::string(rootsys) + "/etc"; return etcdir.c_str(); } From 0103713a110283b3744834ba7ebbea9de170f25d Mon Sep 17 00:00:00 2001 From: Kirill Chilikin Date: Fri, 17 Jun 2022 23:10:22 +0300 Subject: [PATCH 4/4] Add missing include file. --- core/rootcling_stage1/src/rootcling_stage1.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/core/rootcling_stage1/src/rootcling_stage1.cxx b/core/rootcling_stage1/src/rootcling_stage1.cxx index 76bf715a68b56..10f77c44e74c0 100644 --- a/core/rootcling_stage1/src/rootcling_stage1.cxx +++ b/core/rootcling_stage1/src/rootcling_stage1.cxx @@ -11,6 +11,7 @@ #include "rootcling_impl.h" #include "RConfigure.h" #include +#include #include #include