diff --git a/README/ReleaseNotes/v638/index.md b/README/ReleaseNotes/v638/index.md index 328ef46d9ff86..72fb6eba8d155 100644 --- a/README/ReleaseNotes/v638/index.md +++ b/README/ReleaseNotes/v638/index.md @@ -58,6 +58,7 @@ export CLING_LDSYSPATH=ROOT_LDSYSPATH export CLING_CPPSYSINCL=$(LC_ALL=C c++ -xc++ -E -v /dev/null 2>&1 | sed -n '/^.include/,${/^ \/.*++/{p}}' | tr '\n' ':' | tr ' ' ':') ``` This caching reduces sub-process creation during initialization and can be useful when multiple ROOT instances or binaries linked to ROOT are executed (less system-calls, cleaner debugging). +* It is now possible to read a user configuration file (in jeargon, a "rootrc file") at startup in a custom path instead of the one in the home directory, by specifying its full path with the `ROOTENV_USER_PATH` environment variable. ## I/O diff --git a/core/base/src/TEnv.cxx b/core/base/src/TEnv.cxx index 4744cf891ef50..b61ab566a0549 100644 --- a/core/base/src/TEnv.cxx +++ b/core/base/src/TEnv.cxx @@ -388,14 +388,20 @@ TString TEnvRec::ExpandValue(const char *value) //////////////////////////////////////////////////////////////////////////////// /// Create a resource table and read the (possibly) three resource files, -/// i.e.\ `$ROOTSYS/etc/system` (or `ROOTETCDIR/system`), -/// `$HOME/` and `$PWD/`. +/// i.e.\ `$ROOTSYS/etc/system` or `ROOTETCDIR/system` +/// (kEnvGlobal), `$HOME/` or (kEnvUser), and `$PWD/` (kEnvLocal). /// ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can /// read additional user defined resource files by creating additional TEnv /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of /// the `$HOME/` resource file will be skipped. This might be useful in /// case the home directory resides on an auto-mounted remote file system /// and one wants to avoid the file system from being mounted. +/// In case the environment variable ROOTENV_USER_PATH is specified, +/// and ROOTENV_NO_HOME is not set, then `$ROOTENV_USER_PATH/` +/// is considered instead of `$HOME/`. +/// If environment variables have to be avoided, a `rootlogon.C` script +/// can be created where where the environment can be set through an +/// invocation of TEnv::ReadFile. TEnv::TEnv(const char *name) { @@ -412,14 +418,23 @@ TEnv::TEnv(const char *name) char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname); ReadFile(s, kEnvGlobal); delete [] s; + if (!gSystem->Getenv("ROOTENV_NO_HOME")) { - s = gSystem->ConcatFileName(gSystem->HomeDirectory(), name); - ReadFile(s, kEnvUser); - delete [] s; - if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) + if (const auto rootrcPath = gSystem->Getenv("ROOTENV_USER_PATH")) { + s = gSystem->ConcatFileName(rootrcPath, name); + ReadFile(s, kEnvUser); + delete[] s; + } else { + s = gSystem->ConcatFileName(gSystem->HomeDirectory(), name); + ReadFile(s, kEnvUser); + delete[] s; + } + if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) { ReadFile(name, kEnvLocal); - } else + } + } else { ReadFile(name, kEnvLocal); + } } } diff --git a/roottest/root/core/CMakeLists.txt b/roottest/root/core/CMakeLists.txt index ac6c03e515830..09d6133e091c2 100644 --- a/roottest/root/core/CMakeLists.txt +++ b/roottest/root/core/CMakeLists.txt @@ -1,5 +1,9 @@ ROOTTEST_ADD_TESTDIRS() +ROOTTEST_ADD_TEST(customRootrcPath + MACRO customRootrcPath.C + ENVIRONMENT ROOTENV_USER_PATH=${CMAKE_CURRENT_SOURCE_DIR}/customrootc) + ROOTTEST_ADD_TEST(lifetime MACRO lifetime.C OUTREF lifetime.ref) diff --git a/roottest/root/core/customRootrcPath.C b/roottest/root/core/customRootrcPath.C new file mode 100644 index 0000000000000..0ffe184e9024c --- /dev/null +++ b/roottest/root/core/customRootrcPath.C @@ -0,0 +1,14 @@ +int customRootrcPath() +{ + + if (!gSystem->Getenv("ROOTENV_USER_PATH")) { + cerr << "Error: env variable 'ROOTENV_USER_PATH' cannot be found." << endl; + return 1; + } + + if (1 != gEnv->GetValue("customVal.customVal", (int)-1)) { + cerr << "Error: variable customVal is not 1" << endl; + return 2; + } + return 0; +} diff --git a/roottest/root/core/customrootc/.rootrc b/roottest/root/core/customrootc/.rootrc new file mode 100644 index 0000000000000..236c142b1ca53 --- /dev/null +++ b/roottest/root/core/customrootc/.rootrc @@ -0,0 +1 @@ +customVal.customVal: 1