I am working on the signal handler
to deal with reap signals, randomly I am getting the signal with offset when I call sigwaitinfo
function. All the signal attributes are right, except for info.si_addr
. This offset in info.si_addr
is causing a segmentation fault.
This offset seems to be the same - I have tried removing the offset and that works, but I need a correct solution to go forward.
static void *signalHandler(void *vptr_args __attribute__((unused)))
{
sigset_t signal_set;
siginfo_t info;
sigemptyset(&signal_set);
sigaddset(&signal_set, SIG_REAP);
sigaddset(&signal_set, SIG_ISOC_CANCEL);
sigaddset(&signal_set, SIGTERM);
sigaddset(&signal_set, SIGPIPE);
while (true) {
int rc = sigwaitinfo(&signal_set, &info);
//...
if (rc > 0)
{
if(info.si_signo == SIG_REAP)
{
// Reap URBs after some simple checks
if ((info.si_code != SI_ASYNCIO) &&
(info.si_code != SI_KERNEL)) {
printf("Bad si_code %d in SIG_REAP", info.si_code);
continue;
}
else {
printf("OK si_code %d in SIG_REAP", info.si_code);
}
struct usbdevfs_urb *ioctl_urb = (struct usbdevfs_urb*)info.si_addres
if (!ioctl_urb) {
printf("SIG_REAP gave NULL ioctl_urb");
continue;
}
UrbInfo *urbInfo = ioctl_urb->usercontext;
if (!urbInfo) {
printf("SIG_REAP gave NULL urbInfo");
continue;
}
You are misusing
si_addr
. It is available for only a limited number of signals, and those do not include any real-time signals.Per POSIX,
si_addr
is not applicable for signals other thanSIGILL
,SIGFPE
,SIGSEGV
, andSIGBUS
. Linux also providessi_addr
data forSIGTRAP
:No other signals provide a value for
si_addr
.The source code
linux/kernel/signal.c
that fills insi_addr
clearly shows thatsi_addr
is not used for any signals other than those listed.Note that per the Linux
signal(7)
man page: