...
 
Commits (2)
......@@ -8,10 +8,10 @@ sourced in your script or directly from the interactive shell if you want
to use the functionalities of the LECA Bash Library from your interactive
session.
For activating the *LECA Bash Library* you must source the `util.sh` bash script.
For activating the *LECA Bash Library* you must source the `lecabashlib.sh` bash script.
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
```
once activated modules can be loaded using the `include` command.
......@@ -31,6 +31,15 @@ reload several time the same module. To force the reloading of a module, use the
The module is reloaded with all its dependancies. A logging message advertise the
name of each reloaded module.
You can specify alternative place where to look for non standard modules by setting
the `LECABASHLIB_PATH` environment variable. If several paths have to be declared, you
must separate them using colon
```{shell}
> export LECABASHLIB_PATH="/new/path/1:/new/path/2:${LECABASHLIB_PATH}"
```
----------------------------------------------------------
# Modules provided by the *LECA Bash Library*
......@@ -44,6 +53,7 @@ name of each reloaded module.
- **[logging](#logging)** : adds functionnalities for managing log files and log levels
- **[mutex](#mutex)** : manages concurent access to resources through locks and semaphores
- **[sets](#sets)** : manages *set* of values
- **[signal](#signal)** : manages signal handler functions
- **[stacks](#stacks)** : manages *stacks* of values
- **[tempdir](#tempdir)** : manages the creation of temporary directories and their erasements
- **[timeout](#timeout)** : provides a function for limiting the maximum execution time of a command
......@@ -58,7 +68,7 @@ name of each reloaded module.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include atexit
```
......@@ -87,7 +97,7 @@ empty one using a UNIX redirection.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include clobber
```
......@@ -177,7 +187,7 @@ Alias for the `popclobber` function. Using one of the both commands `popnoclobbe
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include download
```
......@@ -232,7 +242,7 @@ exiting in error.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include ifs
```
......@@ -263,7 +273,7 @@ where LECA ressources are stored on the LUKE cluster.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include lecaluke
```
......@@ -307,7 +317,7 @@ Therefore only `WARNING` and `ERROR` messages will be actually logged.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include logging
```
......@@ -385,7 +395,7 @@ Closes the current logfile and redirect the logging to stderr.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include mutex
```
......@@ -437,7 +447,7 @@ Closes the current logfile and redirect the logging to stderr.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include sets
```
......@@ -488,13 +498,39 @@ Closes the current logfile and redirect the logging to stderr.
----------------------------------------------------------
## signal
### Activating the module
```{shell}
> source $LECABASHHOME/lecabashlib.sh
> include signal
```
### Functions provided:
#### registertrap
```{shell}
registertrap <SIGNAME> <COMMAND>
```
#### run
```{shell}
run <SIGNAME1> <SIGNAME1> <COMMAND>
```
----------------------------------------------------------
## stacks
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include stacks
```
......@@ -545,7 +581,7 @@ and the return status is set to *1* instead of *0* usually.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include tempdir
```
......@@ -583,7 +619,7 @@ and the return status is set to *1* instead of *0* usually.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include timeout
```
......@@ -600,7 +636,7 @@ and the return status is set to *1* instead of *0* usually.
### Activating the module
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include path
### Functions provided:
......@@ -625,7 +661,7 @@ The *irods* module define a set of function wrapping the classical `iput` and
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include irods
```
......@@ -686,7 +722,7 @@ count is reached.
### Activating the module
```{shell}
> source $LECABASHHOME/utils.sh
> source $LECABASHHOME/lecabashlib.sh
> include xml
```
......
......@@ -49,8 +49,13 @@ __LECABASH__trap_function__() {
loginfo "Signal ${signal} trapped"
echo "#@#@#@"
eval echo "\${${stackname}[*]}"
echo "#@#@#@"
if [[ $(stacksize $stackname) > 0 ]]; then
while popvalue "$stackname" cmd ; do
logdebug "Running ${signal} command : $cmd"
eval "$cmd"
done
loginfo "Commands registered on signal $signal run."
......@@ -94,20 +99,31 @@ __LECABASH__registered_trap__() {
split($0,parts,"--");\
print parts[2]}')
eval "echo $command"
echo "$command"
}
__LECABASH__kill_running_command__() {
local signal=$1
local pid=$2
loginfo "Sending signal ${signal} to process ${pid}"
kill -s ${signal} ${pid}
}
function registertrap() {
local signal=$1
shift
local cmd="${*}"
local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})"
if ! __LECABASH__istrapregistred__ "$signal" ; then
local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})"
newstack $stackname
local oldcmd=$(__LECABASH__registered_trap__ "$signal")
if [[ oldcmd != "" ]] ; then
logdebug "Save previous trap function for signal $signal"
pushvalue "$stackname" "${oldcmd}"
fi
......@@ -115,11 +131,24 @@ function registertrap() {
trap "__LECABASH__trap_function__ $signal" "$signal"
fi
loginfo "Register new command on $signal : ${*}"
pushvalue "$stackname" "${*}"
loginfo "Register new command on $signal : ${cmd}"
pushvalue "$stackname" "${cmd}"
}
function run() {
${*} &
local signal=$1
shift
local signalto=$1
shift
local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})"
eval ${*} &
fpid=$!
registertrap ${signal} __LECABASH__kill_running_command__ ${signalto} ${fpid}
killid=$(( $(stacksize "$stackname") - 1 ))
wait
logdebug "Remove kill action on $fpid for $signal signal"
eval "${stackname}[${killid}]='sleep 0'"
}