views:

509

answers:

3

Hi,

I have a c program which calls ioctl() but it return -1 and errno set to EPERM. But I have changed mode of that file to "777".

Can you please tell me why it ioctl still return -1 with errno set to EPERM?

Thank you.

A: 

You probably have to be root. What ioctl are you trying to do and on which device?

Lars Wirzenius
A: 

Yea, EPERM (Operation not permitted) error indicate you don't have sufficient permissions to execute the operation.As liw.fi suggested,try executing with root privilege or tell us what is the operation to be done.

AIB
+1  A: 

The device you are calling ioctl on may include some code that checks for capabilities before performing the action you requested. Setting the permissions for the special file to 777 will not be sufficient in this case. If you want to dig into the source for the driver that supports the device in question you can look for something like the following to figure out what capability is actually required.

if (! capable (CAP_SYS_ADMIN))
    return -EPERM;

You may want to read up on capabilities or just run your application as root as others have suggested.

Linux Man Page for Capabilities

Tim Kryger