big trouble !
we thought we were done, but when we tested the periodic functions (setting them to run each second), we discovered that the signals/traps we were using cause a segmentation fault and everything falls appart
here is an example that causes the crash:
Code:
#!/bin/bash
declare -r tmpoV=1 #this sets how often verificar.sh has to run
declare -r tmpoA=1 #this sets how often admin_modulos_per.sh has to run
FactCfgs=`ls -tcRn --full-time /etc/michelle | grep -w "$USER"$'\n'"periodicos.config"$'\n'"comando.config" -m 1 | awk '{print $6$7}'` #this is used to collect the actual modification date of a bunch of files, and store the newest
Tver () {
. /usr/bin/verificar.sh
}
Tadm_per () {
. /usr/bin/Desktop/admin_modulos_per.sh
}
/usr/bin/control_tmpo.sh $$ $tmpoV "USR1" &
/usr/bin/control_tmpo.sh $$ $tmpoA "USR2" &
trap Tver "USR1"
trap Tadm_per "USR2"
while true
do
read Com
done
control_tmpo looks like this:
Code:
#!/bin/bash
while true
do
sleep $2
kill -s $3 $1
done
verificar:
Code:
#!/bin/bash
FmodCfgs=`ls -tcRn --full-time /etc/michelle | grep -w "$USER"$'\n'"periodicos.config"$'\n'"comando.config" -m 1 | awk '{print $6$7}'`
if [ "$FactCfgs" != "$FmodCfgs" ]
FactCfgs=$FmodCfgs
echo -e -n "\nSthere is a change in the config files, executing regiter and initialize modules\n"
. /usr/bin/reg_e_ini_modulos.sh
fi
admin_modules_per
Code:
#!/bin/bash
for x in `seq 1 ${#ModuloP[*]}`
do
${ModuloP[$x-1]} Procesar
if [ $? = 1 ]
then
echo "A periodic module failed"
echo "A periodic module failed" >> /home/$USER/periodicos.log
exit 1
fi
done
If we set 1 of the periodic functions not to run, nothings bad happens. If we set both with the same time, it crashes really fast. If we use diferent times, eventually, they try to run at the same time, and for some reason verificar.sh runs while admin_modulos_per.sh is runing (the for cicle was not done), and administrar never ends... then the next time administrar wants to run... segmentation fault.
My partner discovered that if we just put 2 similar senteces inside admin_modulos_per and verificar, it crashes too, he thinks its related to using `` in assignations.
Code:
FmodCfgs=`ls -tcRn --full-time /etc/michelle | grep -w "$USER"$'\n'"periodicos.config"$'\n'"comando.config" -m 1 | awk '{print $6$7}'`
and we put something similar (or identical) in the other script, and everything still falls appart.. but if we dont use that or the `seq 1 ${#ModuloP[*]}`, it doesnt crash :/
are we doing something weird/wron with the signals ? we read that signals/traps dont interrupt each other, if one is running, the other just waits.
a capture of the "error""
Code:
[michelle]zero@debian:~$ /usr/bin/verificar.sh: line 2: wait_for: No record of process 841
Violación de segmento
Violacion de segmento = Segmentation fault
EDIT: also, we found that if we put sleep 1, or just a=a or whatever != than read inside the while cicle, there seems to be no problem :/ (but we need the read in the first place, its a read-eval loop :P )