TACC / Lmod

Lmod: An Environment Module System based on Lua, Reads TCL Modules, Supports a Software Hierarchy
http://lmod.readthedocs.org
Other
475 stars 122 forks source link

LD_PRELOAD in a module (works but emits error) #591

Closed kc9qey closed 2 years ago

kc9qey commented 2 years ago

Notes Please note that we do not provide patches to older versions of Lmod, To speed up fixing your issue please test your bug against the latest version of Lmod. See: https://lmod.readthedocs.io/en/latest/045_transition.html if you want to install the latest version in your own account.

We're on lmod 8.2.7 .

Describe the bug A clear and concise description of what the bug is. If it helps, please include a module tree that shows the issue.

using prepend_path, append_path, or pushenv to set LD_PRELOAD to works, but all following lmod commands emit: bash: syntax error near unexpected token `('

I've tested the exact lmod module with LD_BLAH in place of LD_PRELOAD and everything is fine if I manipulate LD_BLAH (which is not used by anything). It's a unique interaction with LD_PRELOAD and lmod it would seem. I've searched the web for this and not found anything relevant. I had high hopes for the "issues" here having a report and fix. To Reproduce Steps to reproduce the behavior:

Make a module that sets LD_PRELOAD. Load that module. Then run "module list" more try to unload the module.

If you are having an issue with a moduletree that is using the hierarchy consider using the moduletree provided in the source repo: To use do the following:

Expected behavior A clear and concise description of what you expected to happen.

module unload my_ldpreload_module # would work and emit no errors

Desktop (please complete the following information):

[arnoldg@dt-login03 arnoldg]$ module --version

Modules based on Lua: Version 8.2.7 2019-11-30 09:41 -06:00 by Robert McLay mclay@tacc.utexas.edu

Additional context Add any other context about the problem here.

rtmclay commented 2 years ago

Since the XALT project has been modifying LD_PRELOAD through Lmod since 2015, I know that Lmod can prepend_path on LD_PRELOAD. So there is something special about your setup.

So please try the following:

$ module --config 2>&1 | grep LD_PRELOAD

This will tell you if Lmod is configured with a value through configure

$ $LMOD_CMD bash load my_ldpreload_module > out 2> /dev/null

Then take the file "out" and pair it down to see what line is causing the problem. It is most likely the line that contains LD_PRELOAD. You can pair out down and source it.

Finally, you will have to test this issue with Lmod 8.7.7 or whatever the latest version of Lmod is. This is the only version of Lmod that I control.

kc9qey commented 2 years ago

Thanks for getting back to me. The module we LD_PRELOAD is doing this to stdout and I see the shell throwing an error when module commands are involved. It's the leading paren that's getting parsed somehow via lmod.

[arnoldg@dt-login03 ~]$ uptime POSIX 2 IME Library Loaded (opendir to BFS: off, large dir buffer: off, mknod create: off) 09:18:06 up 21 days, 39 min, 4 users, load average: 0.00, 0.00, 0.00

xalt ( which we've deployed before...thanks for the reminder) is quiet wrt stdout/stderr.

I've altered the code for the shared lib (we have the source) and the offending printf has been changed to: [arnoldg@dt-login03 posix_2_ime]$ uptime # POSIX 2 IME Library Loaded [opendir to BFS: off, large dir buffer: off, mknod create: off] 09:33:18 up 21 days, 54 min, 3 users, load average: 0.03, 0.02, 0.00

...turning it into a shell comment with no subshell parens when lmod runs across it. That seems to have resolved the issue and I can live with the minor cosmetic alterations. Thanks for getting back to me. You can close this one out.

rtmclay commented 2 years ago

Thanks for the clear explanation of the issue. Note that all module commands are evaluating what is generated from stdout. Another choice for your IME library is to write to stderr. Then it won't interfere with the module command evaluation.

kc9qey commented 2 years ago

That works better. I've implemented fprintf(stderr, ... It also fixed an interaction with another script we use on the backend. Thanks again.