User avatar
Fidelius
Posts: 459
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Permission problem when reading input devices directly

Wed Jan 29, 2014 8:42 am

With a normal non-admin user on a fresh installation of the current Raspbian OS, the default Java 7 reports errors when some programs try to read input devices directly (mouse, keyobard). Please see attached below two error messages from a) the OpenGL-ES binding Jogl, and b) JavaFX from Java 8 Early-Access. Normal Java applications using Swing components to read input, work however.

If I use sudo i.e. an admin account to run these Java applications which directly read the input devices, the "No permission" errors doesn't happen, so everything works. However, I need to run my Java programs also from non-admin accounts.
I'm not a Linux expert unfortunately, so maybe somebody could help me here. A standard USB mouse and USB keyboard is connected to my PI to its two USB sockets.

What I experienced on a similar topic, is that my Pi's non-admin users couldn't use omxplayer, because it complaint that it wasn't able to access some video-device with a name soundling like videoc-something.
I had to manually add once these non-admin users to a certain (already existing) group "video", and since then everything works fine, also with restarts of Raspbian.
Maybe there's something similar happening here with an "input" group?


a) With the default Java 7 from the current Raspbian OS, the Jogl (Joamp) OpenGL-ES binding brings this error message:

Code: Select all

java.io.FileNotFoundException: /dev/input/mice (No persmission)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at jogamp.newt.driver.linux.LinuxMouseTracker$MouseDevicePoller.run(LinuxMouseTracker.java:119)
at java.lang.Thread.run(Thread.java:724)

b) With the Java 8 Eearly-Access from Jan 2014, its JafaFX library reports this error message:

Code: Select all

com.sun.glass.ui.lens.LensApplication nativeEventLoop
SEVERE: 2810 udevInput.c:793 lens_input_deviceOpen: [device open] Failed to open Logitech USB Optical Mouse [/dev/input/event0], No permission

com.sun.glass.ui.lens.LensApplication nativeEventLoop
SEVERE: 2810 udevInput.c:793 lens_input_deviceOpen: [device open] Failed to open Logitech USB Optical Mouse [/dev/input/mouse0], No permission

com.sun.glass.ui.lens.LensApplication nativeEventLoop
SEVERE: 2810 udevInput.c:793 lens_input_deviceOpen: [device open] Failed to open Logitech USB Keyboard [/dev/input/event1], No permission

User avatar
joan
Posts: 14354
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: No permission to read input devices

Wed Jan 29, 2014 9:07 am

A possibility.

Check which groups are allowed to access the device in /dev

Generally ls -l /dev/device

In the case of the mouse (and some others) under /dev/input,

e.g. ls -l /dev/input/mice

It should show root followed by another, hopefully different, group.

Add yourself to that group.

sudo adduser yourself group

You'll need to log out and log back in for the change to take effect.

User avatar
Fidelius
Posts: 459
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: Permission problem when reading input devices directly

Wed Jan 29, 2014 9:51 am

Thank you Joan for your help. This is what my Pi says (some words may sound funny in English since I had to back-translate them from my localised Debian/Raspbian to English) :

Code: Select all

[email protected] ~ $ sudo ls -l /dev/device
ls: Access to /dev/device not possible: File or Folder not found

[email protected] ~ $ ls -l /dev/input/
insgesamt 0
drwxr-xr-x 2 root root     120 Jan  1  1970 by-id
drwxr-xr-x 2 root root     120 Jan  1  1970 by-path
crw-rw---T 1 root input 13, 64 Jan  1  1970 event0
crw-rw---T 1 root input 13, 65 Jan  1  1970 event1
crw-rw---T 1 root input 13, 66 Jan  1  1970 event2
crw-rw---T 1 root input 13, 63 Jan  1  1970 mice
crw-rw---T 1 root input 13, 32 Jan  1  1970 mouse0

[email protected] ~ $ sudo ls -l /dev/input/event0
crw-rw---T 1 root input 13, 64 Jan  1  1970 /dev/input/event0

[email protected] ~ $ sudo ls -l /dev/input/event1
crw-rw---T 1 root input 13, 65 Jan  1  1970 /dev/input/event1

[email protected] ~ $ sudo ls -l /dev/input/event2
crw-rw---T 1 root input 13, 66 Jan  1  1970 /dev/input/event2


[email protected] ~ $ sudo ls -l /dev/input/mice
crw-rw---T 1 root input 13, 63 Jan  1  1970 /dev/input/mice

[email protected] ~ $ sudo ls -l /dev/input/mouse0
crw-rw---T 1 root input 13, 32 Jan  1  1970 /dev/input/mouse0

User avatar
joan
Posts: 14354
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Permission problem when reading input devices directly

Wed Jan 29, 2014 9:54 am

Try

sudo adduser me input

I don't know if that will or should work but I can't see it doing any harm.

User avatar
Fidelius
Posts: 459
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: Permission problem when reading input devices directly

Wed Jan 29, 2014 10:13 am

Well, that worked, and now Java's permission errors are gone!
Thank you very much, Joan.

User avatar
joan
Posts: 14354
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Permission problem when reading input devices directly

Wed Jan 29, 2014 10:20 am

Fidelius wrote:Well, that worked, and now Java's permission errors are gone!
Thank you very much, Joan.
That's good to know.

I had a cursory Google and there don't appear to be any security issues involved with adding a user to the input group.

danielblaukopf
Posts: 42
Joined: Thu Dec 20, 2012 8:03 pm

Re: Permission problem when reading input devices directly

Wed Jan 29, 2014 10:47 am

The security issue to be aware of is that code running in the "input" group has access to all input events in the system.
However, Joan's solution is correct, and this is how Raspbian is set up for the default user "pi":

$cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
[..snipped..]
video:x:44:pi
[..]
input:x:999:pi
[..]

Daniel

Return to “Java”