Operation not allowed

I want to run some command in python script

import fcntl

KDSETLED = 0x4B32
SCR_LED  = 0x01

console_fd = os.open('/dev/console', os.O_NOCTTY)
fcntl.ioctl(console_fd, KDSETLED, SCR_LED)

I installed a+rwfor /dev/console, but when I run the script on a regular user:

fcntl.ioctl (console_fd, KDSETLED, SCR_LED) IOError: [Errno 1] Operation not allowed

What if I need to run this script from a regular user?

+3
source share
1 answer

I believe you need to execute the script with CAP_SYS_TTY_CONFIG. Either this, or (if you work on the console), using a control tag (for example /dev/tty1) instead /dev/consolemay work.

The kernel code that applies this looks like the / tty / vt / vt _ioctl.c driver:

/*
 * To have permissions to do most of the vt ioctls, we either have
 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
 */
perm = 0;
if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
    perm = 1;
case KDSETLED:
    if (!perm)
        goto eperm;
    setledstate(kbd, arg);
    break;

So, it definitely looks like these are your two options.

+4
source

Source: https://habr.com/ru/post/1785527/


All Articles