iopl() fails intermittently

Viewed 179

I am working on a hardware device, where I have to do some GPIO operations. At the start of my program, I invoke iopl(3). The executable is not root owned, but has capabilities set - cap_sys_rawio+eip. Though this works most of the times sometimes the process fails with:

iopl: Operation not permitted

Is the capability insufficient ? I cannot run the program as root. The device is running Ubuntu 14.04.2. dmesg / syslogs are not giving any hints!

More details:

The start of my main has this:

if (iopl(3) != 0) {
    perror("iopl");
    assert(!"Failed to set privilege!");
}

Though this works most of the times, sometimes on the hardware platform (Intel Atom based), this fails with perror printing iopl: Operation not permitted.

1 Answers

Knowing that you cannot run the program as root, I am guessing if you have tried:

 chmod u+s /usr/bin/xinit

or if you have root access,

sudo chmod u+s /usr/bin/xinit

If no setuid has been set (considering running without sudo --since you have already root access)

sudo chown root $prefix/Xorg

sudo chmod u+s $prefix/Xorg

Related