[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-usb
Subject: Cannot make USBDEVFS_DISCSIGNAL work
From: Alon Bar-Lev <alon.barlev () gmail ! com>
Date: 2008-12-31 21:33:41
Message-ID: 200812312333.41750.alon.barlev () gmail ! com
[Download RAW message or body]
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic