/* martin
cc -g -o setnumlock setnumlock.c
cp setnumlock /usr/sbin
chmod 755 /usr/sbin/setnumlock && chown root:wheel /usr/sbin/setnumlock
echo /usr/sbin/setnumlock >> /etc/rc.conf.local
*/
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/kbio.h>
#define TRY_IOCTL(func, var) \
if ((ioctl(0, func, var)) == -1) { \
perror("ioctl"); \
return 1; \
}
int main() {
int leds,state;
leds = state = 0;
TRY_IOCTL(KDGKBSTATE, &state);
TRY_IOCTL(KDGETLED, &leds);
/* set the numlock */
state |= NLKED;
TRY_IOCTL(KDSKBSTATE, state);
/* toggle led */
leds |= LED_NUM;
TRY_IOCTL(KDSETLED, leds);
return 0;
}