We make extensive use of the module utility here at our work and I am
trying to integrate some Linux tools into the normal scheme of AIX tools.
Lots of our groups make use of 'project' modulefiles that will set a couple
of environment variables and load other modules from within their module
files.
I wanted to craft a module that would not give a loading error, but would
display a message indicating that the modulefile that they tried to load
was not supported on a particular platform (ie. Linux) and not actually get
added to the list of LOADEDMODULES. I posted a message earlier this year
regarding this same topic to this mailing list, but I wanted to now post my
solution to this problem. For other logistical reasons I do not want to
edit the all of the existing AIX modulefiles (namely, I am not the AIX
sysadmin...) to add an if statement construct to test the [uname sysname]
and do nothing if the tool is not on Linux -- this was suggested as a
solution to my original post.
My first attempt was to add a 'return' to the end of my "not_available"
module. This had the desired effect of causing the module that was loaded
not to be added to the LOADEDMODULES list, but I recently found out that it
has the bad side effect of un-doing all of the other module loads that had
occured in my project_module modulefile prior to my notavail module load.
Here was my original notavail module:
#%Module1.0#####################################################################
##
## notavail modulefile
##
proc ModulesHelp { } {
global version
puts stderr "\tThis module does absolutely nothing."
puts stderr "\tIt's meant simply as notice to the user"
puts stderr "\tthat the [module-info name] module"
puts stderr "\tis not available at this time."
puts stderr "\n\tVersion $version\n"
}
module-whatis "Notifies user that module is not available."
# for Tcl script use only
set version "3.1.3"
set curMod [module-info name]
if { [ module-info mode load ] } {
puts stderr "Note: The module '$curMod' is not available for [uname
sysname]."
}
#Return code 11 == do not add this module to the loaded modules list
return 11
##########################################################################
The problem with this module is that when it was loaded (usually through a
symbolic link from some other module in my Linux modulefile directory for a
product that is normally available on our AIX platforms, but is not
available on Linux) the module program would 'unwind' all of the other
successful module loads that had occured prior to the notavail module being
run.
In order to achieve the behavior that I wanted, I ended up having to patch
the source for the ModuleCmd_Load.c file and change my notavail module to
replace the 'return 11' at the end of the file with a 'break'. This causes
the module to return a unique TCL_BREAK code that can be interpreted as
"don't add this module to the list of LOADEDMODULES".
Attached is my patch file:
(See attached file:
tcl_break_to_skip_module_add-to-list_modules.3.1.5.patch)
Also attached is an example project_module and three other modules to
demonstrate my desired effect. Just un-tar this file into /tmp then do a
'module load /tmp/project_module' to see what I am trying to accomplish.
And if you are running without my patch, you should see that module1 is not
properly loaded due to the notavail module being loaded second.
(See attached file: modules_break_example.tar.gz)
If anyone can think of a better way to accomplish this (maybe even without
editing the source code), I am open to changing my method again.
Thanks,
-------------------------------------------
W. Scott Gaskins
T/L 441-9863
(919) 543-9863
sga...@us...
IBM Bldg062/C215
P.O. Box 12195 - YM6A/062
3039 Cornwallis Rd
RTP, NC 27709 |