Felipe C. [email protected] wrote:
test.rb:4:in `read’: Invalid argument - /dev/input/event4 (Errno::EINVAL)
Well:
open(“/dev/input/event4”, O_RDONLY|O_CLOEXEC) = 7
fcntl(7, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fstat(7, {st_mode=S_IFCHR|0640, st_rdev=makedev(13, 68), …}) = 0
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or
TCGETS, 0x7fff295c31b0) = -1 EINVAL (Invalid argument)
ppoll([{fd=7, events=POLLIN}], 1, NULL, NULL, 8) = 1 ([{fd=7, revents=POLLIN}])
read(7, 0x1bc5ae8, 16) = -1 EINVAL (Invalid argument)
close(7) = 0
My equivalent C version failed, too (event3 is my mouse, I don’t
expect to read from my event4 (USB DAC)):
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
int fd = open(“/dev/input/event3”, O_RDONLY|O_CLOEXEC);
char buf[16];
read(fd, buf, sizeof(buf));
return 0;
}
I used event3 to capture my mouse with a bigger buffer and it worked
fine.
OK, reading the source of evdev_read() in drivers/input/evdev.c of the
Linux kernel, EINVAL seems to be caused by the buffer being too small:
if (count != 0 && count < input_event_size())
return -EINVAL;
I just used readpartial(64) since I didn’t feel like calculating
input_event_size() to get the exact size:
File.open(‘/dev/input/event3’, ‘r’) do |f|
p f.readpartial(64) # => 48 bytes
end
Bumping up the buf size in my C version to 64 succeeded, too.