Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-20-2005, 06:48 PM   #1
LQ Newbie
Registered: Dec 2005
Posts: 2

Rep: Reputation: 0
ioctl as non-root user

I'm trying to get my keyboard leds (numlock, capslock, etc.) to blink and after some searching I found this can be done by using an ioctl function:

int fd = open( "/dev/console", O_RDWR | O_NOCTTY );
int led = LED_NUM;
ioctl( fd, KDSETLED, led );
At first it didn't work, but after a lot of time wasted, I found out it does work when run as root.

I tried changing permissions and ownership of /dev/console, but no luck.

I know there are some (X related) alternatives, and some ways to use fake keypresses, but I don't want that. I just want to know if there's any way to use the ioctl without being root. I even don't mind to patch my kernel if I knew where to change the code.

If anyone could help, I would be very grateful. Thanks in advance.
Old 12-20-2005, 10:13 PM   #2
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Try with /dev/tty
See the great article at
Old 12-20-2005, 10:53 PM   #3
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 122Reputation: 122
Easiest would be to create a helper program that just does the LED stuff and make it setuid.
Old 12-21-2005, 04:02 AM   #4
LQ Newbie
Registered: Dec 2005
Posts: 2

Original Poster
Rep: Reputation: 0

Thanks, but I already found that page (I've searched for hours in Google). I tried all kinds of devices, all kinds of open flags and no luck. In fact, if you look closely, you'll see that in the SET example, the author uses /dev/console also.


Not very elegant, but a possibility.

What I still don't know, is if it's the kernel that denies the command from any program that isn't root (only solution is to patch), or if the problem lies soomewhere else.

Does anyone know something more about this?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wvdial failing on ioctl call as regular user mugwump84 Linux - Software 3 11-27-2005 02:01 PM
Scanner to work as USER and not forced as ROOT Root (Suse 9.1) 1kyle Linux - Hardware 0 07-10-2004 09:51 AM
Games runs slow as normal user, but fast as root user mcore Linux - Software 2 06-08-2004 12:11 AM
IntelliMouse thumb buttons work as root, broken as non-root user, wheel works always digital vortex Linux - Hardware 7 03-02-2004 05:14 PM
Why does kppp.desktop require root userid for non-root user? Linux - Networking 4 08-27-2001 10:18 AM

All times are GMT -5. The time now is 02:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration