ferry ferry - 5 months ago 82
Linux Question

writing to /dev/uinput (on ubuntu 12.04)

I'm developing a little program that creates virtual joysticks on linux, with a python front end. It is a fork of Linux-Virtual-Joystick.

I need to write to dev/uinput in order to create the user-defined joystick.
The file is opened with O_RDWR (I temporarily added read/write access others for the file whilst debugging). When I do

write(uifd, &uidev, sizeof(uinput_user_dev));

it returns -1 and sets errno to 22(EINVAL). The arguments are correct, and the file was successfully opened.

Did anyone else encounter this problem? I shelved the project for about a month, but I remember that it worked in the last version of Ubuntu.

Update: uinput works on ubuntu 12.10

Answer Source

I think the problem you have is with access rights to uinput. The error message you receive is typical of that and I have seen the identical behaviour before with other devices.

In order to test that assumption, change the /dev/uinput permissions to allow access to all:

chmod +0666 /dev/uinput

Then try again your code. If now it works fine, you will need to make that change permanent, since otherwise it will revert back to the original permissions after reboot.

To do that in a safe fashion, add a rule file to be located at: /etc/dev/rules.d

with the following line:

KERNEL=="uinput", GROUP="udev_group"

To see how a rule file should look like, check the udev rules file located at:


When ready, add a a group named udev_group and add your user name to it (or any user that is supposed to have write access to uinput).

You may need to reboot to get the new rule working.

The outcome would be that any user who's member of that group will have full access to uinput, which is exactly what you wanted.

to add the group you can install "Users and Groups":

sudo apt-get install gnome-system-tools

and launch it at:

Application -> System Tools -> Administration -> Users and Groups**

or in terminal:


Hope that helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download