Skip to content

Add umask modulefile command - #745

Merged
xdelaruelle merged 4 commits into
envmodules:mainfrom
xdelaruelle:issue649
Nov 20, 2026
Merged

xdelaruelle merged 4 commits into
envmodules:mainfrom
xdelaruelle:issue649

Conversation

@xdelaruelle

Copy link
Copy Markdown
Collaborator

Add the umask modulefile command, which sets the file mode creation mask of the shell session when a modulefile is loaded and restores the previous mask when it is unloaded. Until now the only way was to output shell-specific code with puts, which was not undone on unload.

  • umask value takes the mask as an octal number of one to four digits. Any other form, symbolic modes included, is a modulefile error.
  • Code setting the mask is rendered for sh, bash, ksh, zsh, csh, tcsh, fish, perl, python, ruby, r and lisp. The command is ignored for tcl, cmake, cmd and pwsh, which cannot change their own mask. An error is raised on Windows platform.
  • Masks set by loaded modules are stacked in the new __MODULES_UMASK environment variable, with the same structure as the pushenv stacks. On unload, the previous mask is restored only if the mask set by the module is still the current one, so a mask changed afterward by another module or by the user is preserved.
  • Tcl cannot read the mask of its process. A new umask state is fetched by an initStateUmask command added to the Tcl extension library, with a fallback procedure running umask through sh when the library is not built. The mask is only read when a modulefile uses the command.
  • umask is a no-operation on refresh, as the mask is inherited by sub-shells like environment variables.
  • A umask extra specifier is added to search the modules setting a given mask.
  • source-sh and sh-to-mod now track the mask change made by the evaluated shell script, and umask is accepted by the --ignore option of source-sh.

A separate commit makes the top-level Makefile rebuild the Tcl extension library and the testsuite utility libraries when their source files change. These targets had no prerequisite, so tests ran against a stale library after a change in lib/envmodules.c.

The version of the Tcl extension library is left unchanged here, it is to be raised when version 5.8 is released.

Fixes #649

Describe how the file mode creation mask of the shell session is set
by a modulefile, how the mask in effect is read by modulecmd.tcl and
when the previous mask is restored on unload.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
The file mode creation mask is a property of the shell process that
cannot be set through an environment variable. Setting it from a
modulefile required to output shell-specific code with puts, which
was not undone when the module was unloaded.

The umask command takes the mask as an octal number and renders the
code that sets it for the sh, csh and fish shells and for the perl,
python, ruby, r and lisp languages. Other shells have no mean to
change their own mask, so the command is ignored for them.

Masks set by loaded modules are stacked in the __MODULES_UMASK
environment variable, along with the mask in effect prior the first
umask command. On unload, the previous mask is restored only if the
mask set by the module is still the current one, to preserve a mask
changed in the meantime by another module or by the user.

Tcl cannot read the mask of its process. An initStateUmask command is
added to the Tcl extension library for that purpose, with a fallback
procedure that runs umask through sh when the library is not built.

Modules setting a given mask can be searched with the new umask extra
specifier.

Fixes envmodules#649

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
The rules of the top-level Makefile building the Tcl extension library
and the utility libraries of the testsuite had no prerequisite. Once
built, these libraries were never rebuilt by "make" or "make test"
after a change in their source file, so tests ran against a stale
library.

Declare the source files as prerequisites of these targets. Also make
the object file depend on the header files it includes.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
A shell script evaluated with the source-sh modulefile command or the
sh-to-mod sub-command may change the file mode creation mask. This
change was lost as only environment variables, aliases, functions,
completions and current working directory were compared prior and
after script evaluation.

Query the mask with the umask shell command before and after the
script is evaluated and produce a umask modulefile command if it has
changed. Masks are normalized prior comparison as shells do not
report them with the same number of digits.

The umask element is accepted by the --ignore option of source-sh to
skip this change.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
@xdelaruelle
xdelaruelle merged commit bdd02ed into envmodules:main Nov 20, 2026
25 checks passed
@xdelaruelle
xdelaruelle deleted the issue649 branch November 20, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to set umask

1 participant