开发者

C permission denied for queue creation

开发者 https://www.devze.com 2023-01-25 17:09 出处:网络
I\'m trying to create a queue, but I\'m getting a permission denied error. I got this error before, but then I added code for error catching on the key creation and it was working. The only thing I\'v

I'm trying to create a queue, but I'm getting a permission denied error. I got this error before, but then I added code for error catching on the key creation and it was working. The only thing I've changed since then is I put my queue creation code in a separate function. Here's something like what my code looks like:

key_t key1;
int msqid1;

int main(int arc, char *argv[])
{
        getKeys();            
        queueCreate();         
}

void getKeys()                  
{
        if ((key1 = ftok(".", '1')) == -1)  
        {
                perror("key1 creation");
                exit(1);
        }
}

void queueCreate()
{
        if ((msqid1 = msgget(key1, 0666 | IPC_CREAT)) == -1开发者_C百科)
        {
                perror("msqid1 creation");
                exit(1);
        }
}

The error thrown is "msqid1 creation: Permission denied". Any ideas?


Most likely you didn't destroy the message queue on the one occasion it was successfully created, so now you can't recreate it because it still exists.

You don't indicate which platform you're on. Classically, you'd use the ipcs command to obtain the status of the various IPC systems (shared memory, semaphores, and message queues), and ipcrm to remove IPC systems that are no longer wanted.


Your error seems to be EACCES and not EEXIST. My linux man page says:

EACCES A message queue exists for key, but the calling process does not have permission to access the queue, and does not have the CAP_IPC_OWNER capability.

Did you check for these conditions?

You are using the current directory as a path for ftok. Maybe change to a plain local file in "/tmp" and not in your home folder (nfs?).

0

精彩评论

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