Thread (5 messages) 5 messages, 2 authors, 2009-03-02

Re: Notification when a new device is added or removed

From: Alessio Sangalli <hidden>
Date: 2009-03-01 02:58:17

Dmitry Torokhov wrote:
You should be able to poll (select) /proc/bus/input/devices.
Yeah that would be great; anyway, I tried and... well nothing happens. I
am obviously missing something here:


#include <poll.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

int main()
{
        int fd, c;
        struct pollfd pfd;

        fd=open("/proc/bus/input/devices", O_RDONLY);
        if(fd==-1)
                return -1;
        pfd.fd=fd;
        pfd.events=POLLIN;
        while(1) {
                c=poll(&pfd, 1, 20000);
                if(c==-1)
                        printf("Error polling\n");
                else if(c==0)
                        printf("Timeout\n");
                else
                        printf("Something changed");
        }
}



The result, while I detach or attach new devices is:

Timeout
Timeout
Timeout
Timeout
Timeout



bye
Alessio
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help