ioperm is working without root permission

236 views Asked by At

I read that we need superuser permission to access I/O ports from user space. But i am saying different behavior. ioperm is successful under normal user.

#include <stdio.h>
#include <errno.h>
#include <sys/io.h>

int main(int argc, char *argv[])
{
    if (!ioperm(0x70, 3, 1)) {
        perror("ioperm failed");
    }
    else {
        printf("ioperm on 0x70 success\n");
    }

    return 0;
}

$ ./prog 
ioperm on 0x70 success

Is this the expected behavior

1

There are 1 answers

0
Joseph Sible-Reinstate Monica On BEST ANSWER

From the manual:

On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

You have this backwards. -1 means failure, but your code incorrectly assumes it means success.