0

I am trying to convert a csh script to a tcl script for use within the linux modules functionality. The csh script was originally used to set environment variables properly for a software package. Instead of asking an end-user to change his shell and run 3 commands every time he/she wishes to use the software, I wanted to create a simple one-line command that is shell independent and sets up the their environment appropriately. As such, using modulefile seems like the perfect way to accomplish this.

My problem arises when I try to set a limit on the coredumpsize, as there doesn't appear to be any way to set this value from within modules. The original csh command looks like this, limit coredumpsize 0. I understand that the original bash command line equivalent of this is, ulimit -c 0. Note: Both of these commands assume that I want to disable coredumpfiles while using this software.

My modulefile code tries to invoke this command in a shell-dependent manner, b/c there doesn't appear to be a "limit" command native to modulefiles.

set shell [module-info shell]
if { $shell=="bash"} {
    set XARCH amd64
    [exec /bin/bash -c "ulimit -c 0"]
} elseif {$shell=="tcsh"} {
    set XARCH linux
    [exec /bin/tcsh -c "limit coredumpsize 0"]

Based on my web-wide research, I can't find an environment variable that I can modify, although RLIMIT_CORE looks like it might be close to what I'm looking for. The problem w/ my current code is that the exec command spawns a process of $shell and runs the one command, as opposed to running the limit command on the shell that called the tcl module process.

Any help would be much appreciated for being able to change the environment variables and setting the limit for the coredumpsize in one simple way, ideally using modules.

twinoza
  • 3
  • 1
  • 4
  • I would either convert that csh script to Posix `sh` (or to `bash`), or even consider using [GNU guile](http://www.gnu.org/software/guile/) which is much more powerful (and IMHO, much more sexy) than Tcl. – Basile Starynkevitch Sep 10 '13 at 19:57
  • How would converting the script help? Are you suggesting that I make a complimentary script for bash users and have them run that? That wouldn't completely help in our instance because I'm also trying to alleviate the user from having to type 3-4 extra commands every time they run the software. I'm also trying to avoid having the end-user edit their general environment always (b/c they could just add the environment variable changes to their .bashrc file) – twinoza Sep 10 '13 at 20:44

2 Answers2

1

You cannot set limits by running a shell, because that limit will only affect the shell process you created (and not the tcl process itself).

You need to find out how to call the setrlimit(2) syscall directly. Perhaps tclx might help.

Take several hours to read Advanced Linux Programming.

You are misunderstanding some fundamental Unix concepts, notably processes.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • I understand that I can't set the limits by running the exec command to spawn a new process. I put that in my code sample so that reviewers could understand where I originally started. With that said, I'm looking to figure out if there is some environment variable that controls the coredumpsize that I can set OR if there is another way to change the coredumpsize. I'm not sure tclx will work b/c I don't understand how to use it with modulecmd. Could you offer insight with regards to this? Alternatively, do you know how to make a syscall from within modulecmd? – twinoza Sep 10 '13 at 20:37
  • Enable `TclX` inside your `Modules`; otherwise write (or copy) a simple wrapper in C for `setrlimit`. Tcl has since its beginning the ability to call C code. – Basile Starynkevitch Sep 10 '13 at 20:44
1

module evaluates on currently running shell what modulefile evaluation produces on stdout.

The following ulimit modulefile should help to set apply a given ulimit configuration on currently running shell

#%Module

switch -- [module-info shelltype] {
    {sh} {
        puts stdout "ulimit -c 0"
    }
    {csh} {
        puts stdout "limit coredumpsize 0"
    }
}

Loading modulefile we can check ulimit configuration has been changed on current shell:

$ ulimit -c
unlimited
$ module -V
Modules Release 4.1.3 (2018-06-18)
$ module load ./ulimit
$ ulimit -c
0