繁体   English   中英

mq_open错误号13权限被拒绝

[英]mq_open err no 13 Permission denied

在尝试使用mq_open()调用创建posix mq时,我正在运行Permission问题。 我确实纳入了此处提到的更改mq_open权限被拒绝我查看了其他相关帖子,如https://groups.google.com/forum/#!topic/comp.unix.programmer/hnTZf6aPpbE,但这也指向同样的事情。

同时在尝试编译的时候我遇到了错误,其中mq调用未被识别,并且在线显示通过在gcc中添加-lrt进行编译,该帖子能够编译,提及它,因为我不完全了解它的原理并且没有通过阅读帖子了解它:)

gcc server_mq.c -lrt -o server

错误号码是13

哦亲爱的,mqd出了点问题! 没有权限

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <errno.h>
#include <string.h>

#include "client_server.h"

#define PATH "/tmp/servermq"

int main(void)
{
    mqd_t mqd;
    mode_t omask;
    omask = umask(0);
    int flags = O_RDWR | O_CREAT | O_EXCL;
    struct mq_attr attr, *attrp;

    attr.mq_maxmsg = 5;
    attr.mq_msgsize = 1024;

    attrp = &attr;

    mqd = mq_open(PATH, flags, S_IRUSR | S_IWUSR | S_IWGRP, attrp);


    if (mqd == (mqd_t)-1)
    {
        printf("error number is %d \n ",errno);
        printf(" Oh dear, something went wrong with mqd ! %s\n", strerror(errno));
    }

    umask(omask);
    mq_close(mqd);
    mq_unlink(PATH);
    return 0;
}

你不能使用/tmp/servermq作为你的名字......

引用男人mq_overvie

  Message queues are created and opened using mq_open(3); this function returns a message queue descriptor (mqd_t), which is used to refer to the open message queue in later calls. Each message queue is identi- fied by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX (ie, 255) characters consisting of an initial slash, followed by one or more characters, none of which are slashes. 

您很快就会发现此部分相关:

挂载消息队列文件系统
在Linux上,消息队列在虚拟文件系统中创建。 (其他实现也可能提供此类功能,但细节可能不同。)可以使用以下命令(超级用户)安装此文件系统:

  # mkdir /dev/mqueue # mount -t mqueue none /dev/mqueue The sticky bit is automatically enabled on the mount directory. 

暂无
暂无

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

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