Jack B. Nymbol has asked for the wisdom of the Perl Monks concerning the following question:

Playing with some ioctl but not having any success. This is supposed to turn off the CAPS-LOCK LED. I'm starting to think that maybe ioctl is out of favor and therefore not well supported. I ran h2ph -r -l -h . in /usr/include. I even came across something called h2pl but it appears to be vestigial.
require 'sys/ioctl.ph'; sysopen( FD, "/dev/console", 1 ) or die "Unable to open /dev/console"; select(FD);$|++; my $KDSETLED = 0x4B32; my $stat = ioctl(FD, $KDSETLED, 0x0) || -1; close(FD); print STDOUT "status = $stat\n";
  • Comment on ioctl - does it actually work? replaced or preferred by something else?
  • Download Code

Replies are listed 'Best First'.
Re: ioctl - does it actually work? replaced or preferred by something else?
by Khen1950fx (Canon) on Feb 19, 2007 at 03:04 UTC
    It worked for me. It turned off CAPS-LOCKED and returned Status = 0 but true.
Re: ioctl - does it actually work? replaced or preferred by something else?
by zentara (Cardinal) on Feb 19, 2007 at 14:20 UTC
    It worked for me too, but only as root. When running it as a user I get the error "Unable to open /dev/console". What errors or malfunction do you see?

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Yes, works as root, as user it doesn't work. The perms allow user access to /dev/console. Running in perl -d I can print FD "\a" and hear the bell. Since the user has permission for the device I don't understand what's preventing this.
      As for turning the LED back on, use your keyboard.
        I'm running a grsecurity kernel, and it does some things to limit users access to /dev/console for security reasons. As far as using the keyboard to reset the led, it dosn't. On my system, if I run the script I can turn off or turn on the led, but after I exit the script, the light no longer functions, when I toggle the Caps Lock key. It may be all because of my security kernel, but it's a fairly common patch people are using.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: ioctl - does it actually work? replaced or preferred by something else?
by zentara (Cardinal) on Feb 19, 2007 at 15:11 UTC
    Yikes, I found another glitch. As root, your script turns off the caps-lock-led, BUT..... it stays off. You wouldn't know how to turn it back on would you? :-)

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      There's a Lovecraft-ian quote which comes to mind, the gist of which is not calling forth that which you don't know how to send back; similar precaution should probably be applied when poking around with ioctls (and especially doing so as root :)

        Yeah, it took a reboot to clear it. The code above not only sets the LED, but screws up the keyboard LED flags. Its all in /usr/include/linux/kd.h , but resetting the flag to normal working order is not obvious. A logout/login did not reset it, only a reboot did.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum