LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 12-20-2005, 06:48 PM   #1
cristianbdg
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:

Code:
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
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Try with /dev/tty
See the great article at http://www.w00w00.org/files/articles/conioctls.txt
 
Old 12-20-2005, 10:53 PM   #3
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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
cristianbdg
LQ Newbie
 
Registered: Dec 2005
Posts: 2

Original Poster
Rep: Reputation: 0
@primo

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.

@Matir

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?
 
  


Reply


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? rdaves@earthlink.net Linux - Networking 4 08-27-2001 10:18 AM


All times are GMT -5. The time now is 08:54 AM.

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