what's the return value of 'su -c command' should be ?

what's the return value of 'su -c command' should be ?

Post by MickeyJe.. » Sat, 03 Sep 2005 11:10:37



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

Quote:}

NS->gcc a.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--~~
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?