The existing function does not return a correct result for all signal types.
################################################################################
# check_sig_type() #
# Usage: check_signal [ -{signal} | {signal}
] #
# #
# Purpose: Check if signal is a program termination signal or a control
signal #
# This is not defined by any LSB draft, however, it is required
to #
# check the signals to determine if they are intended to end
a #
# program or simply to control
it. #
# #
# Inputs: Accepts a single string value in the form or -{signal} or
{signal} #
# #
# Return values: #
# 0 - Signal is used for program
termination #
# 1 - Signal is used for program
control #
################################################################################
Original less empty lines
check_sig_type()
{
local valsig
# The list of termination signals (limited to generally used items)
valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9
-14 -15"
echo "${valsig}" | grep -- " ${1} " > /dev/null
if [ "${?}" -eq "0" ]; then
return 0
else
return 1
fi
}
Corrected:
function _check_sig_type {
local sig="${1}"
sig=${sig#-}
case "${sig}" in
ALRM | INT | KILL | TERM | PWR | STOP | ABRT | QUIT) true ;;
2 | 3 | 6 | 9 | 14 | 15 ) true ;;
*) false ;;
esac
}
test script (partial)
#function check_sig_type
_msg "function check_signal_type"
unset list
list="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15
BARF"
list+=" ALRM INT KILL TERM PWR STOP ABRT QUIT 2 3 6 9 14 15 BARF"
for i in ${list}; do
_msg_line "Testing signal: [${i}]: "
if check_sig_type "${i}"; then _msg_success; else _msg_failure; fi
done
_msg "function check_signal_type"
_msg "function _check_signal_type"
unset list
list="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15
BARF"
list+=" ALRM INT KILL TERM PWR STOP ABRT QUIT 2 3 6 9 14 15 BARF"
for i in ${list}; do
_msg_line "Testing signal: [${i}]: "
if _check_sig_type "${i}"; then _msg_success; else _msg_failure; fi
done
_msg "function _check_signal_type"
The first set of results are from the lfs init-functions script verbatium
./test-init-functions.sh
function check_signal_type
Testing signal: [-ALRM]: FAILURE
Testing signal: [-INT]: SUCCESS
Testing signal: [-KILL]: SUCCESS
Testing signal: [-TERM]: SUCCESS
Testing signal: [-PWR]: SUCCESS
Testing signal: [-STOP]: SUCCESS
Testing signal: [-ABRT]: SUCCESS
Testing signal: [-QUIT]: SUCCESS
Testing signal: [-2]: SUCCESS
Testing signal: [-3]: SUCCESS
Testing signal: [-6]: SUCCESS
Testing signal: [-9]: SUCCESS
Testing signal: [-14]: SUCCESS
Testing signal: [-15]: FAILURE
Testing signal: [-BARF]: FAILURE
Testing signal: [ALRM]: FAILURE
Testing signal: [INT]: FAILURE
Testing signal: [KILL]: FAILURE
Testing signal: [TERM]: FAILURE
Testing signal: [PWR]: FAILURE
Testing signal: [STOP]: FAILURE
Testing signal: [ABRT]: FAILURE
Testing signal: [QUIT]: FAILURE
Testing signal: [2]: FAILURE
Testing signal: [3]: FAILURE
Testing signal: [6]: FAILURE
Testing signal: [9]: FAILURE
Testing signal: [14]: FAILURE
Testing signal: [15]: FAILURE
Testing signal: [BARF]: FAILURE
function check_signal_type
Result from corrected function
function _check_signal_type
Testing signal: [-ALRM]: SUCCESS
Testing signal: [-INT]: SUCCESS
Testing signal: [-KILL]: SUCCESS
Testing signal: [-TERM]: SUCCESS
Testing signal: [-PWR]: SUCCESS
Testing signal: [-STOP]: SUCCESS
Testing signal: [-ABRT]: SUCCESS
Testing signal: [-QUIT]: SUCCESS
Testing signal: [-2]: SUCCESS
Testing signal: [-3]: SUCCESS
Testing signal: [-6]: SUCCESS
Testing signal: [-9]: SUCCESS
Testing signal: [-14]: SUCCESS
Testing signal: [-15]: SUCCESS
Testing signal: [-BARF]: FAILURE
Testing signal: [ALRM]: SUCCESS
Testing signal: [INT]: SUCCESS
Testing signal: [KILL]: SUCCESS
Testing signal: [TERM]: SUCCESS
Testing signal: [PWR]: SUCCESS
Testing signal: [STOP]: SUCCESS
Testing signal: [ABRT]: SUCCESS
Testing signal: [QUIT]: SUCCESS
Testing signal: [2]: SUCCESS
Testing signal: [3]: SUCCESS
Testing signal: [6]: SUCCESS
Testing signal: [9]: SUCCESS
Testing signal: [14]: SUCCESS
Testing signal: [15]: SUCCESS
Testing signal: [BARF]: FAILURE
function _check_signal_type
SUCCESS = return value $? of 0
FAILURE = return value $? of 1
All signal types should return SUCCESS, if I am reading the intent of
the function correctly.
All signals listed in the function should return 0 otherwise return 1 if
not in list
If I read correctly that function should return SUCCESS for
-ALRM and ALRM....Correct?
Also shouldn't the list of signal be as follows?
UNIX System V Signals.
Name Number Action Description
SIGHUP 1 exit Hangs up
SIGINT 2 exit Interrupts.
SIGQUIT 3 core dump Quits.
SIGILL 4 core dump Illegal instruction.
SIGTRAP 5 core dump Trace trap.
SIGIOT 6 core dump IOT instruction.
SIGEMT 7 core dump MT instruction.
SIGFPE 8 core dump Floating point exception.
SIGKILL 9 exit Kills (cannot be caught or ignored).
SIGBUS 10 core dump Bus error.
SIGSEGV 11 core dump Segmentation violation.
SIGSYS 12 core dump Bad argument to system call.
SIGPIPE 13 exit Writes on a pipe with no one to read it.
SIGALRM 14 exit Alarm clock.
SIGTERM 15 exit Software termination signal.
--
http://lists.linuxfromscratch.org/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page
Do not top post on this list.
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
http://en.wikipedia.org/wiki/Posting_style