简体   繁体   English

C队列创建权限被拒绝

[英]C permission denied for queue creation

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". 引发的错误是“ msqid1创建:权限被拒绝”。 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. 传统上,您将使用ipcs命令获取各种IPC系统(共享内存,信号量和消息队列)的状态,并使用ipcrm删除不再需要的IPC系统。

Your error seems to be EACCES and not EEXIST . 您的错误似乎是EACCES而不是EEXIST My linux man page says: 我的Linux手册页说:

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. EACCES密钥存在消息队列,但调用进程没有访问队列的权限,并且没有CAP_IPC_OWNER功能。

Did you check for these conditions? 您是否检查了这些条件?

You are using the current directory as a path for ftok . 您正在使用当前目录作为ftok的路径。 Maybe change to a plain local file in "/tmp" and not in your home folder (nfs?). 也许更改为“/ tmp”中的普通本地文件而不是您的主文件夹(nfs?)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM