On Wed, 21 Jun 2006, Zoran Marceta wrote:

> I was looking at catching a signal using usbfs to tell when a device has been 
> detached.
> I used an ioctl call with USBDEVFS_DISCSIGNAL to set a signal handler, and I 
> was able to detect the detachment.
> >From inode.c (drivers/usb/core/inode.c) file in kernel source I concluded 
> >that disc_signal.context is copied
> into si_addr field of siginfo_t structure, but when signal handler was called 
> (when I remove USB device)
> I'm always get NULL in info->si_addr (it is not value that I put into 
> disc_signal.context field).
...
> After analyzing real-time signal handling in kernel (kernel/signal.c) I 
> modified function usbfs_remove_device in
> drivers/usb/core/inode.c file at line 699.
> 
> static void usbfs_remove_device(struct usb_device *dev)
> {
>       .
>       .
>       .
>       if (ds->discsignr) {
>               sinfo.si_signo = ds->discsignr; /* SIGPIPE replaced with 
> ds->discsignr */
>               sinfo.si_errno = EPIPE;
>               sinfo.si_code = SI_ASYNCIO;
>               sinfo.si_addr = ds->disccontext;
>               kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, 
> ds->disc_uid, ds->disc_euid);
>       }
>       .
>       .
> }
> 
> Into field si_signo of siginfo_t structure instead of SIGPIPE I put 
> ds->discsignr value.
> 
> After this change in kernel source I was able to get correct value (equal to 
> disc_signal.context) in si_addr field in signal handler.
> Kernel version is 2.6.16-1.2115_FC4. I check latest kernel stable version 
> 2.6.17.1 and it has same code in inode.c file.
> 
> Is this a bug in usb device removal signal generating or I something missed 
> in signal handler registering.

It looks like you are right and this is a bug in inode.c.

It's also not clear why si_errno is set to EPIPE, but I guess that's as
good as anything else.  There's a corresponding line in devio.c:

                sinfo.si_errno = as->urb->status;

Since urb->status is a negative error code, this should really be

                sinfo.si_errno = - as->urb->status;

But such a change would be visible to user programs.

Alan Stern



_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to