I\'ve found that on Linux, by making my own call to the rt_sigqueue
syscall, I can put whatever I like in the si_uid
and si_pid
fields and
I agree that si_uid
and si_pid
should be trustworthy, and if they are not it is a bug. However, this is only required if the signal is SIGCHLD
generated by a state change of a child process, or if si_code
is SI_USER
or SI_QUEUE
, or if the system supports the XSI option and si_code <= 0
. Linux/glibc also pass si_uid
and si_pid
values in other cases; these are often not trustworthy but that is not a POSIX conformance issue.
Of course, for kill()
the signal may not be queued in which case the siginfo_t
does not provide any additional information.
The reason that rt_sigqueueinfo
allows more than just SI_QUEUE
is probably to allow implementing POSIX asynchronous I/O, message queues and per-process timers with minimal kernel support. Implementing these in userland requires the ability to send a signal with SI_ASYNCIO
, SI_MESGQ
and SI_TIMER
respectively. I do not know how glibc allocates the resources to queue the signal beforehand; to me it looks like it does not and simply hopes rt_sigqueueinfo
does not fail. POSIX clearly forbids discarding a timer expiration (async I/O completion, message arrival on a message queue) notification because too many signals are queued at the time of the expiration; the implementation should have rejected the creation or registration if there were insufficient resources. The objects have been defined carefully such that each I/O request, message queue or timer can have at most one signal in flight at a time.