Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion core/dictgen/src/rootcling_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
#include <unistd.h>
#endif

#if defined(__FreeBSD__)
#include <sys/sysctl.h>
#include <sys/types.h>
#endif

#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/InterpreterCallbacks.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}

Expand Down
11 changes: 9 additions & 2 deletions core/rootcling_stage1/src/rootcling_stage1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "rootcling_impl.h"
#include "RConfigure.h"
#include <ROOT/RConfig.hxx>
#include <cassert>
#include <cstdlib>
#include <string>

Expand All @@ -24,12 +25,18 @@ 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");
Copy link
Copy Markdown
Member

@Axel-Naumann Axel-Naumann Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we instead assert that ROOTSYS is set at this point? This is rootcling_stage1.cxx - ROOTSYS must have been set by rootcling itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that it is a better idea since the variable should always be defined. As requested, the assertion is added together with a comment pointing to the place of definition.

// 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() {
static std::string etcdir = std::string(getenv("ROOTSYS")) + "/etc";
const char *rootsys = getenv("ROOTSYS");
// 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();
}

Expand Down