Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, I was hoping someone might be able to point me in the right direction with my problem. I have a very simple project to test reading the /dev/input/event[X] character ...
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    1

    Using read() on character device - getting random EBADF error

    Hello, I was hoping someone might be able to point me in the right direction with my problem. I have a very simple project to test reading the /dev/input/event[X] character devices. It is very simple and open()'s the file descriptor /dev/input/event0 then it enters an infinite loop that read()'s the file descriptor, passing a pointer to an array of input_event structures, and the size of them. I then print out the results of myInputEvent[0].

    The problem is that if I click alot with the mouse, its quite hard to get it to happen, but suddenly the file descriptor seems to close, and read() then just returns -1 and gives an EBADF error (bad file descriptor). I have googled and I cant find anything that says read() will close the fd in any circumstance. Any advice would be appriciated.

    Rob.

  2. #2
    Just Joined!
    Join Date
    Jan 2010
    Posts
    7
    Quote Originally Posted by rmawatson View Post
    Hello, I was hoping someone might be able to point me in the right direction with my problem. I have a very simple project to test reading the /dev/input/event[X] character devices. It is very simple and open()'s the file descriptor /dev/input/event0 then it enters an infinite loop that read()'s the file descriptor, passing a pointer to an array of input_event structures, and the size of them. I then print out the results of myInputEvent[0].

    The problem is that if I click alot with the mouse, its quite hard to get it to happen, but suddenly the file descriptor seems to close, and read() then just returns -1 and gives an EBADF error (bad file descriptor). I have googled and I cant find anything that says read() will close the fd in any circumstance. Any advice would be appriciated.

    Rob.
    Read doesnt close the file descriptor. Read returns -1 because the file descriptor was closed. I dont know exactly who closed it, ( your app or the kernel ), but you can find that out by debugging your program a bit with strace and look for signals received just before the read call fails, that should tell you what's the problem. Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...