开发者

Operation not permitted

开发者 https://www.devze.com 2023-02-04 15:09 出处:网络
I want to run some command in python script import fcntl KDSETLED = 0x4B32 SCR_LED= 0x01 c开发者_Python百科onsole_fd = os.open(\'/dev/console\', os.O_NOCTTY)

I want to run some command in python script

import fcntl

KDSETLED = 0x4B32
SCR_LED  = 0x01

c开发者_Python百科onsole_fd = os.open('/dev/console', os.O_NOCTTY)
fcntl.ioctl(console_fd, KDSETLED, SCR_LED)

I've set a+rw for /dev/console but when I run script from regular user:

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

What should I do if I need to run that script from regular user?


I believe you need to get your script executed with CAP_SYS_TTY_CONFIG. Either that, or (if you're running on the console), using your controlling tty (e.g., /dev/tty1) instead of /dev/console might work.

The kernel code that enforces this appears to be drivers/tty/vt/vt_ioctl.c:

/*
 * 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, definitely looks like those are your two options.

0

精彩评论

暂无评论...
验证码 换一张
取 消