Logo

Basics

  • Installing Modules on Unix
  • Installing Modules on Windows
  • New features
  • Release notes
  • Frequently Asked Questions
  • Changes between versions
  • Other module implementations

Examples

  • Cookbook

Reference

  • ml
  • module
  • modulefile
  • envml

Development

  • Contributing
  • Developer HowTos
  • Design notes
    • Advanced module version specifiers
    • Conflict unload
    • Control mode behaviors
    • Default and latest version specifiers
    • Evaluation errors
    • Extended default
    • Extra match search
    • Hide or forbid modulefile
    • Initial environment
    • Insensitive case
    • lint sub-command
    • Lmod Tcl modulefile compatibility
    • Module magic cookie check
      • Skipping check when searching modules
      • Implementation of eval mode
    • mod-to-sh sub-command
    • Mode select: irreversible module actions
    • Module cache
    • Module selection contexts
    • Module tags
    • module-warn modulefile command
    • --modulepath option
    • Output configuration
    • Shell completion
    • Source shell script in modulefile
    • spider sub-command
    • Stashing environment
    • Sticky modules
    • Variants
  • Modules Technical Charter
  • Modules Governance
  • Acknowledgments
Modules
  • Design notes
  • Module magic cookie check
  • Edit on GitHub

Module magic cookie check

A file should start with a specific string as header line to be considered as a modulefile. This specific string is called the magic cookie and is equal to #%Module optionally followed by a version number to indicate the minimum version of modulecmd.tcl required to interpret this file.

Magic cookie applies to modulefiles and module RC files. More recently it also applies to the initrc configuration file and collections.

Magic cookie is checked in two different situations:

  • When searching for a modulefile: all files located under a directory used as a modulepath are checked to determine if they are modulefiles to take them into account in the module search.

  • When evaluating a modulefile: when reading file to pass it down to the modulefile or modulerc interpreter, the magic cookie is checked to ensure file can be evaluated.

The mcookie_check configuration option is introduced to be able to disable the magic cookie check. Option accepts the following values:

  • always: This is the default value, magic cookie is checked in both situations described above

  • eval: magic cookie is only checked prior evaluating file, not when searching for modulefiles

The mcookie_check option works like the icase option with value determining a level of cumulative support.

FUTURE: a third value, never, may be interesting to disable the magic cookie check in all situations.

Skipping check when searching modules

When setting mcookie_check to eval, module magic cookie is not checked when analyzing the files located under an enabled modulepath. This mode significantly diminishes the I/O load when looking at the content of a modulepath as files are not opened and header read for the check.

This mode requires a perfect control on the files located within the hierarchy of the modulepath directories as:

  • non-modulefiles will be considered modulefiles and will be reported in module search results and used to locate a module corresponding to a query

  • files hidden through restrictive permissions are reported in search results and used to locate a module corresponding to a query

For these non-modulefiles or read-protected files an error is obtained when trying to evaluate them, as the magic cookie is checked at this step.

Also the files specified full path are not checked prior evaluation if mcookie_check is set to eval, so if these files are not modulefile an error will be obtained when trying to evaluate them.

The eval mode of mcookie_check configuration option has no impact on the initrc configuration file and collections as such files are not searched like modulefiles. Their header is only checked at evaluation time.

Implementation of eval mode

Modulefiles or modulercs are read through the readModuleContent procedure which is called by:

  • execute-modulerc or execute-modulefile procedures when files need to get fully read to get evaluated

  • checkValidModule procedure to verify file is a readable modulefile when search for modules

The checkValidModule procedure is the one to update when mcookie_check configuration option is not set to always as this procedure is called by all module search contexts. It is called by:

  • findModules to check files in directories within modulepaths

  • getModules to check files pointed by mfcmd:module-virtual

  • getPathToModule to check files transmitted as full path file

Note

File readability (permission check) is not verified when mcookie_check option is set to eval to keep the full benefit of this mode regarding the I/O load optimization.

Previous Next

© Copyright 1996-2025, Modules Contributors.

Built with Sphinx using a theme provided by Read the Docs.