Linux 2.4.21
I saw some inconsistency between the return value of
`bash -c command' and `su -c command'
when the command is cancelled by a signal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--~~
NS->cat a.c
int main()
{
sleep(10);
exit(35); //just a non-zero return value
NS->gcc a.cQuote:}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--~~
NS->bash -c ./a.out ; echo $? (^C SIGINT)
130
NS->bash -c ./a.out ; echo $? (^\ SIGQUIT)
Quit
131
NS->su -c ./a.out ; echo $? (^C)
0
NS->su -c ./a.out ; echo $? (^\)
0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--~~
why `su -c' always return 0 when it receive signals?
it may confuse the caller if the normal exit code is zero.
the more curious thing is as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--~~
NS->su -c './a.out' ; echo $? (^C)
0
NS->su -c './a.out' ; echo $? (^\)
0
NS->su -c './a.out >/dev/null' ; echo $? (^C)
0
NS->su -c './a.out >/dev/null' ; echo $? (^\)
131
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--~~
note the $? after receiving `^\' is changed (which is the desired
result) just with an io redirection, why?