Repository navigation
Add umask modulefile command - #745
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the
umaskmodulefile 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 withputs, which was not undone on unload.umask valuetakes the mask as an octal number of one to four digits. Any other form, symbolic modes included, is a modulefile error.__MODULES_UMASKenvironment variable, with the same structure as thepushenvstacks. 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.umaskstate is fetched by aninitStateUmaskcommand added to the Tcl extension library, with a fallback procedure runningumaskthroughshwhen the library is not built. The mask is only read when a modulefile uses the command.umaskis a no-operation onrefresh, as the mask is inherited by sub-shells like environment variables.umaskextra specifier is added to search the modules setting a given mask.source-shandsh-to-modnow track the mask change made by the evaluated shell script, andumaskis accepted by the--ignoreoption ofsource-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