Found it!!!! It woks within usbfs (/proc/bus/usb/999/999) and not within udev (/dev/bus/usb/999/999). Alan, I can see that in 2.6.28 at commit [1] you tried to make the kernel behave correctly for /dev/bus/usb devices. But apparently it does not work for me, can you please instruct me how to use your modification so that systems with udev and without usbfs will be able to detect device disconnect? Thank you! Alon. [1] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=cd9f03759d3eb588e185b04e1854c778b050833e On 12/31/08, Alon Bar-Lev <alon.barlev@xxxxxxxxx> wrote: > > Hello, > > I am trying to detect USB device removal using its file descriptor within > the /dev/bus/usb/999/999 filesystem. > > I believe this is why the USBDEVFS_DISCSIGNAL ioctl is available. > > But it looks like the poll never wakes up and the signal is never called. > > I noticed some people who succeeded in making this work, but I cannot figure > out what is wrong. > > I am using linux-2.6.28. > > Can anyone help? Maybe there is a different way to achieve this task. > > Thank you, > Alon. > > --- > > #include <sys/ioctl.h> > #include <sys/poll.h> > #include <string.h> > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > #include <signal.h> > #include <unistd.h> > #include <fcntl.h> > #include <linux/usbdevice_fs.h> > > #define USB_DISCONNECT_SIGNAL (SIGRTMIN) > > static void disconnect_action( int sig_num, siginfo_t *sinfo, void *pinfo) > { > (void)sig_num;(void)sinfo;(void)pinfo; > printf("SIGNAL!\n"); > } > > int main(int argc, char *argv[]) { > struct sigaction act; > struct usbdevfs_disconnectsignal ds; > struct pollfd pfd; > char *device; > int fd; > > if (argc != 2) { > printf("Usage: device\n"); > exit(1); > } > device = argv[1]; > > if ((fd = open(device, O_RDWR)) == -1) { > perror("open"); > exit(1); > } > > if (sigaction(USB_DISCONNECT_SIGNAL, NULL, &act) == -1) { > perror("sigaction"); > exit(1); > } > act.sa_sigaction = disconnect_action; > act.sa_flags = SA_SIGINFO; > if (sigaction(USB_DISCONNECT_SIGNAL, &act, NULL) == -1) { > perror("sigaction"); > exit(1); > } > > memset(&ds, 0, sizeof(ds)); > ds.signr = USB_DISCONNECT_SIGNAL; > if (ioctl(fd, USBDEVFS_DISCSIGNAL, &ds) == -1) { > perror("ioctl"); > exit(1); > } > > pfd.fd = fd; > pfd.events = POLLIN | POLLOUT; > printf("Before poll\n"); > if (poll(&pfd, 1, -1) == -1) { > perror("poll"); > exit(1); > } > printf("After poll\n"); > > close(fd); > return 0; > } > > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html