Question

I am trying to read events from an input device in ruby.

However

File.open('/dev/input/event9').read 16

returns an exception :

Errno::EINVAL: Invalid argument @ io_fread - /dev/input/event9
from (pry):1:in `read'

The signature for the read method in IO documentation explain the reference to fread method (read in ruby calls the corresponding fread in C).

However the EINVAL errors seems to refer to a bad advice sent to the input device but I don't really understand.

In an effort to understand the issue, I have chowned to file to give users group perm without any luck.

My question is: what does that "Invalid argument" error means in my situation ?

Was it helpful?

Solution

Please refer to man 2 read, which is the system call behind fread which failed.

   EINVAL fd is attached to an object which is unsuitable for reading;  or
          the  file  was  opened  with  the  O_DIRECT flag, and either the
          address specified in buf, the value specified in count,  or  the
          current file offset is not suitably aligned.

Which means basically that the driver attached to /dev/input/event9 isn't happy with the operation requested. In your case it's probably due to alignment issues (wrong read size), see https://www.kernel.org/doc/Documentation/input/input.txt for details about the event protocol and how event devices should be read.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top