showkey fails with "Couldn't get a file descriptor referring to the console"

Bug #1006676 reported by drevicko
70
This bug affects 16 people
Affects Status Importance Assigned to Milestone
kbd (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

When invoked in Gnome Terminal 3.0.1 (Ubuntu 11.10), showkey uninformatively exits after reporting:

  "Couldn't get a file descriptor referring to the console"

For one who doesn't know what this means (such as myself), showkey is thus rendered unusable. The man page has no information about this behaviour.

Installed kbd package: 1.15.2-3ubuntu1

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in kbd (Ubuntu):
status: New → Confirmed
Revision history for this message
Vibhav Pant (vibhavp) wrote :

showkey only works with root privileges. Did you try "sudo showkey"?

Changed in kbd (Ubuntu):
status: Confirmed → Invalid
Revision history for this message
Steven Van Maldeghem (steven-vanmaldeghem) wrote :

Running the command with root privileges indeed solves this issue, at least in my case.

Perhaps echoing "Are you root?" on exit 1 would practical for the end user.

Revision history for this message
WinEunuchs2Unix (ricklee518) wrote :

"Permission denied" would follow terse convention. "You must run as root" would be verbose convention I think.

Revision history for this message
Sondra Kinsey (sondra.kinsey) wrote :

I agree that a more helpful error message would be helpful here. I am an experience Ubuntu terminal user. However, it is not intuitive to me that showkey should require root privileges. I would not have guessed this as a solution to resolve this error.

A new error message could take several forms:
  Current user cannot access a file descriptor referring to the console.
  Permission denied.
  You must run as root user.
  Are you root?
I personally prefer the most descriptive and helpful:
  Current user cannot access a file descriptor referring to the console. Perhaps you intended to run this as root?

Revision history for this message
Eric S. Raymond (esr-thyrsus) wrote :

I am the author of showkey.

I only just became aware of this bug myself, by trying to run showkey in the terminal emulator under i3. The curious thing about it is that "Couldn't get a file descriptor referring to the console" does not occur as a string in the program source.

I think something else is emitting it, possibly the shell. When I googled to try to figure out what, I found this big thread.

The code ran fine under xfce, so there is likely some window-manager specific thing going on.

I confirm that going root works around the problem.

I think it would be annoying to force users to go root in environments where it's not necessary, so I'm going to document this as a known problem on the man page and give the workaround.

The 1,8 release has been shipped.

My apologies for not catching this sooner. It's not a program I use often.

Revision history for this message
Pablo Hörtner (redtux2000) wrote :

Hi there,

I also just had the same problem on an Ubuntu 16.04.3 LTS box (with both zsh and bash, on tty and on pseudo terminal running X). Is it already known where this error message comes from, so we could change the string to something more convenient recommending the user to become root or to run sudo?

Of course, as explained by ESR it would be nice if it was not even necessary to run the command as root, but (at least on my system) normal users have no permission to access the respective file descriptors.

ls -l /dev/console
crw------- 1 root root 5, 1 Aug 22 11:13 /dev/console

ls -l /dev/tty0
crw--w---- 1 root tty 4, 0 Aug 22 11:13 /dev/tty0

strace tells me that showkey (run as user) does not have enough privileges:
open("/dev/tty0", O_RDWR) = -1 EACCES (Permission denied)
open("/dev/tty0", O_WRONLY) = -1 EACCES (Permission denied)
open("/dev/tty0", O_RDONLY) = -1 EACCES (Permission denied)
open("/dev/console", O_RDWR) = -1 EACCES (Permission denied)
open("/dev/console", O_WRONLY) = -1 EACCES (Permission denied)
open("/dev/console", O_RDONLY) = -1 EACCES (Permission denied)

BTW: I am running the most recent kbd/showkey version that is available for Xenial. Maybe this bug has already been fixed upstream in version 2.0?

apt-cache policy kbd
kbd:
  Installed: 1.15.5-1ubuntu5
  Candidate: 1.15.5-1ubuntu5
  Version table:
 *** 1.15.5-1ubuntu5 500
        500 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     1.15.5-1ubuntu4 500
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.