Red Hat Bugzilla – Bug 113002
raise implemented via tkill breaks si_code
Last modified: 2007-11-30 17:10:35 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1)
Description of problem:
It seems that raise is implemented as tkill, as evidenced by the fact
that for sigaction handlers, si_code is set to SI_TKILL for raise()ed
signals, when the manpages for sigaction indicate that raise should
cause si_code to be set to SI_USER instead.
I would think that SI_USER is the more standards correct flag to set
Version-Release number of selected component (if applicable):
Steps to Reproduce:
void action_hdlr(int sig, siginfo_t *si, void *p)
fprintf(stderr, "%d\n", si->si_code);
int main(int argc, char **argv)
struct sigaction sa;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = action_hdlr;
sigaction(SIGILL, &sa, NULL);
Actual Results: -6 is printed, which is the si_code for SI_TKILL, not
SI_USER, as expected.
Expected Results: SI_USER's value should be printed.. which is 0.
I haven't looked at the source for raise, but be wary just changing
that tkill.. It may exist for threads to be able to use raise() nicely..
POSIX says that:
"If the implementation supports the Threads option, the effect of the raise() function shall be equivalent to calling:
(otherwise kill(getpid(), sig);).
SI_USER's reason is written as "Signal sent by kill()."
and no si_code is mentioned for pthread_kill.
So I don't think POSIX mandates SI_USER in this case, but mandates
that it will be the same si_code as with pthread_kill
(which uses SI_TKILL as well).
I concur. The standard requires that pthread_kill result in an
implementation-defined value that is not equal to SI_USER or one of
the other specified values. SI_TKILL is our implementation-defined
value for pthread_kill. The standard further requires that raise
behave as if it were a call to pthread_kill. Ergo, SI_TKILL is the
correct implementation-defined value. Using SI_USER here would be in
violation of the standard.
Well can we get a documentation update for sigaction then? Becuase
those docs only mention SI_USER, and state that it is the si_code for
raise(), which is very misleading, and can lead developers to produce
buggy and non-portable software (which happened to me).
With linuxthreads it actually will be SI_USER, but with NPTL SI_TKILL.
fixed in 1.66 (look at the man page in both the regular section vs the
new POSIX section)