View Issue Details

IDProjectCategoryView StatusLast Update
0002210OpenFOAMBugpublic2016-08-23 21:07
Reporterroenby Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version14.04
Summary0002210: foamCleanPath does not clean PATH and LD_LIBRARY_PATH properly
DescriptionI have of-2.2.0 and of-4.0 installed alongside. I load them with the usual aliases of220 and of40 which source OpenFOAM-XX/etc/bashrc. When I first type of220 and then of40 afterwards in the same terminal, the cleaning of old paths does not seem to succeed. This is seen if I do echo $PATH and echo $LD_LIBRARY, where I still see a lot of paths containing "2.2.0".
Steps To Reproduce1. Open a terminal and type of220.
2. Type of40
3. For Do echo $LD_LIBRARY_PATH, which for me gives:

/home/dhi/OpenFOAM/ThirdParty-4.0/platforms/linux64Gcc/gperftools-svn/lib:/home/dhi/OpenFOAM/ThirdParty-4.0/platforms/linux64Gcc/ParaView-5.0.1/lib/paraview-5.0:/home/dhi/OpenFOAM/OpenFOAM-4.0/platforms/linux64GccDPInt32Opt/lib/openmpi-system:/home/dhi/OpenFOAM/ThirdParty-4.0/platforms/linux64GccDPInt32/lib/openmpi-system:/home/dhi/OpenFOAM/ThirdParty-2.2.0/platforms/linux64Gcc/openmpi-1.6.3/lib/openmpi/lib:/home/jro/OpenFOAM/jro-4.0/platforms/linux64GccDPInt32Opt/lib:/home/dhi/OpenFOAM/site/4.0/platforms/linux64GccDPInt32Opt/lib:/home/dhi/OpenFOAM/OpenFOAM-4.0/platforms/linux64GccDPInt32Opt/lib:/home/dhi/OpenFOAM/ThirdParty-4.0/platforms/linux64GccDPInt32/lib:/home/dhi/OpenFOAM/OpenFOAM-4.0/platforms/linux64GccDPInt32Opt/lib/dummy:/home/dhi/Projects/BCBW_11812036/2.2.0/platforms/linux64GccDPOpt/lib

The thing to note here is the path /home/dhi/OpenFOAM/ThirdParty-2.2.0/platforms/linux64Gcc/openmpi-1.6.3/lib/openmpi/lib.

This happens even though foamCleanPath is given $WM_THIRD_PARTY_DIR as a wildcard in the etc/bashrc. Maybe this is related to the note in the header of foamCleanPath that: "false matches possible if a wildcard contains '.' (sed regex)"?
Additional InformationAnother small thing:

If I do echo $PATH, I get

/home/dhi/OpenFOAM/ThirdParty-4.0/platforms/linux64Gcc/gperftools-svn/bin:/home/dhi/OpenFOAM/ThirdParty-4.0/platforms/linux64Gcc/ParaView-5.0.1/bin:/home/jro/OpenFOAM/jro-4.0/platforms/linux64GccDPInt32Opt/bin:/home/dhi/OpenFOAM/site/4.0/platforms/linux64GccDPInt32Opt/bin:/home/dhi/OpenFOAM/OpenFOAM-4.0/platforms/linux64GccDPInt32Opt/bin:/home/dhi/OpenFOAM/OpenFOAM-4.0/bin:/home/dhi/OpenFOAM/OpenFOAM-4.0/wmake:/home/dhi/Projects/BCBW_11812036/2.2.0/platforms/linux64GccDPOpt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/thinlinc/bin

Here we note the path:

/home/dhi/Projects/BCBW_11812036/2.2.0/platforms/linux64GccDPOpt/bin

This is actually my $FOAM_USER_APPBIN because we do not follow the convention that $WM_PROJECT_USER_DIR should be $HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION. I would therefore suggest that $FOAM_USER_APPBIN and $FOAM_USER_LIBBIN are added to the list of foamOldDirs in the etc/bashrc script.
TagsNo tags attached.

Activities

wyldckat

2016-08-23 15:25

updater   ~0006724

OK, I've already got some preliminary information about this.

1. Back in issue #2031, a few of these issues were sorted out, although it was aiming towards cleaning up after the "site" path and not the user path.

This to say that wanting to clean up "$FOAM_USER_APPBIN $FOAM_USER_LIBBIN" will go in accordance with what it's already done for the SITE ones.


2. The issue with ".../openmpi-1.6.3/lib/openmpi/lib" has to do with the fact that this folder does not exist. I know, it's seems weird that a path that does not exist should be cleaned up either way, but "foamCleanPath" is aiming towards maintaining the possibility open for a custom build that will make the folder exist later on. Nonetheless, this still needs to be revised, given that there are several other folders that don't exist and are still removed from the list... at least for the PATH variable...


3. The existing workaround for these issues are the aliases that can be called before calling the "of*" aliases:

  - on OpenFOAM 2.2, use: wmUNSET
  - on OpenFOAM 4, use: wmUnset

These two alias commands are configured to (hopefully) properly clean up the shell environment, so that another environment can be loaded in later on.


----

I still need to look into this in more detail in the meantime. Hopefully I'll have a patch for this later today.

wyldckat

2016-08-23 17:11

updater   ~0006725

Further diagnosis lead me to the following issue:

  1- OpenFOAM 2.2 used a custom build of Open-MPI by default. This means that "OPAL_PREFIX" is defined in "etc/config/settings.sh" on purpose, so that the custom build of Open-MPI will work as intended.

  2- When we use "wmUNSET" in OpenFOAM 2.2 or "wmUnset" in OpenFOAM 4, it undefines the variable "OPAL_PREFIX".

  3- Therefore, the reason why the 2.2.x library pops back up is not due to "foamCleanPath" having a problem, it's because "OPAL_PREFIX" is still defined in the environment. Since OpenFOAM 4 uses the system's Open-MPI, this means that it relies on the command "mpicc --showme:link" to figure out the library paths... and since "OPAL_PREFIX" is still defined, this results in the previous command giving the path to the custom build of Open-MPI and not the system's one.

The problem now is that we cannot simply always unset "OPAL_PREFIX" within the "SYSTEMOPENMPI" case in "etc/config.sh/mpi". Doing so would result in the undesired situation where the user does have another system-wide location for the Open-MPI installation, which relies on "OPAL_PREFIX" in order for it to work properly. Which means that we should only unset this variable if it's pointing to the old "WM_THIRD_PARTY_DIR"...

I'll have the patch up in a few minutes to sort these two issues.

wyldckat

2016-08-23 17:26

updater  

wyldckat

2016-08-23 17:37

updater   ~0006726

@Henry: The attached package "sorting_environment_issues_v1.tar.gz" provides the updated files for OpenFOAM 4.x, which updates the following files:

  - etc/bashrc
  - etc/config.sh/mpi
  - etc/config.sh/unset

The changes made are as follows:

  - "$FOAM_USER_APPBIN" and "$FOAM_USER_LIBBIN" have been added to "foamOldDirs" in "etc/bashrc" and "etc/config.sh/unset"

  - "$OPAL_PREFIX" is now undefined in the option "SYSTEMOPENMPI" within "etc/config.sh/mpi", but only if the path defined in this variable is cleaned when using "foamCleanPath".

  - "$OPAL_PREFIX" is now also conditionally undefined in "etc/config.sh/unset" when the path is picked up by "foamCleanPath".

The attached file "sorting_environment_issues_v1.patch" also provides the changes made.

These changes should also work just fine on OpenFOAM-dev and it should be easily applicable by using "git cherry-pick", without having to provide another patch package.

----

@roenby: The attached file "sorting_environment_issues_v1.patch" can be used in your installation of OpenFOAM 4.0 by running:

  cd $WM_PROJECT_DIR
  patch -p1 < path/to/sorting_environment_issues_v1.patch

On the other hand, if you don't have "patch" application installed and if you choose to unpack the tarball, made sure to edit the file "etc/bashrc" and repair the version number at "WM_PROJECT_VERSION".

wyldckat

2016-08-23 17:37

updater  

sorting_environment_issues_v1.patch (2,188 bytes)   
diff --git a/etc/bashrc b/etc/bashrc
index 700599f..a4a01ef 100644
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -107,7 +107,8 @@ export FOAM_SIGFPE=
 ################################################################################
 
 # The old dirs to be cleaned from the environment variables
-foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR $HOME/$WM_PROJECT/$USER \
+foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
+    $HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
     $WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN"
 
 # Location of installation
diff --git a/etc/config.sh/mpi b/etc/config.sh/mpi
index 36b651e..8c679f6 100644
--- a/etc/config.sh/mpi
+++ b/etc/config.sh/mpi
@@ -37,6 +37,12 @@ SYSTEMOPENMPI)
     # Use the system installed openmpi, get library directory via mpicc
     export FOAM_MPI=openmpi-system
 
+    # Undefine OPAL_PREFIX if set to one of the paths on foamOldDirs
+    if [ -z "$($foamClean "$OPAL_PREFIX" "$foamOldDirs")" ]
+    then
+        unset OPAL_PREFIX
+    fi
+
     libDir=`mpicc --showme:link | sed -e 's/.*-L\([^ ]*\).*/\1/'`
 
     # Bit of a hack: strip off 'lib' and hope this is the path to openmpi
diff --git a/etc/config.sh/unset b/etc/config.sh/unset
index fa0a65b..75aefc6 100644
--- a/etc/config.sh/unset
+++ b/etc/config.sh/unset
@@ -34,7 +34,8 @@ foamClean=$WM_PROJECT_DIR/bin/foamCleanPath
 [ -f "$foamClean" -a -x "$foamClean" ] || unset foamClean
 
 # The old dirs to be cleaned from the environment variables
-foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR $HOME/$WM_PROJECT/$USER \
+foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
+    $HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
     $WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN $ParaView_DIR"
 
 #------------------------------------------------------------------------------
@@ -101,7 +102,12 @@ unset FOAM_UTILITIES
 
 unset MPI_ARCH_PATH
 unset MPI_BUFFER_SIZE
-unset OPAL_PREFIX
+
+# Undefine OPAL_PREFIX if set to one of the paths on foamOldDirs
+if [ -z "$($foamClean "$OPAL_PREFIX" "$foamOldDirs")" ]
+then
+    unset OPAL_PREFIX
+fi
 
 
 #------------------------------------------------------------------------------

henry

2016-08-23 21:06

manager   ~0006730

Thanks Bruno

Resolved in OpenFOAM-4.x by commit f7d4c9d055b04a787bc57fdb52a26cad2326b118
Resolved in OpenFOAM-dev by commit 73c48c5a7e149b87269b77258834c51526c86f2e

Issue History

Date Modified Username Field Change
2016-08-23 14:02 roenby New Issue
2016-08-23 15:25 wyldckat Note Added: 0006724
2016-08-23 17:11 wyldckat Note Added: 0006725
2016-08-23 17:26 wyldckat File Added: sorting_environment_issues_v1.tar.gz
2016-08-23 17:37 wyldckat Note Added: 0006726
2016-08-23 17:37 wyldckat File Added: sorting_environment_issues_v1.patch
2016-08-23 17:37 wyldckat Assigned To => henry
2016-08-23 17:37 wyldckat Status new => assigned
2016-08-23 21:06 henry Note Added: 0006730
2016-08-23 21:06 henry Status assigned => resolved
2016-08-23 21:06 henry Resolution open => fixed