Question

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)
        {
                perror("msqid1 creation");
                exit(1);
        }
}

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

Was it helpful?

Solution

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.

OTHER TIPS

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?).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top