1

I have written this code to make a POSIX message queue, but I am receiving an error:

"Function not implemented".

This platform, QNX, is supposed to support message queues.

Can someone please explain?

#include <fcntl.h>
#include <mqueue.h>

#define DIAG_CLIENT "/DIAG_CLIENT"

#define MAX_MSG_SIZE 4096
#define MAX_MSGS 1024

mqd_t msg_queue = -1;
struct mq_attr attrs;

void
message_init()
{
    memset(&attrs, 0, sizeof(attrs));
    attrs.mq_maxmsg = MAX_MSGS;
    attrs.mq_msgsize = MAX_MSG_SIZE;
    msg_queue = mq_open(
      DIAG_CLIENT, O_RDWR | O_CREAT | O_NONBLOCK, S_IRWXU | S_IRWXG, &attrs);
    LOG("create or open msg_queue_log msg_queue:%d", msg_queue);
    if (msg_queue == -1) {
        ERR("create or open msg_queue failed! err=%d", errno);
    }
}

And use this setting in my common.mk file:

LIBS += mq
Oka
  • 23,367
  • 6
  • 42
  • 53
xkou
  • 11
  • 1
  • When cleaning this question up I surprisingly encountered a name collision with [Error implementing posix message queue - "Function not implemented"](https://stackoverflow.com/q/8879408/2505965), which is mainly discussing Ubuntu, but there is a small mention of needing to *"[start] the mqueue server before actually using message queues"* on QNX. – Oka Jul 04 '23 at 03:46

1 Answers1

1

From mq_open, one of the reasons the function can fail is if the message queue manager is not running.

In that event mq_open returns -1 and sets errno to ENOSYS:

ENOSYS
The mq_open() function isn't implemented for the filesystem underlying the path specified in name, or the message queue manager (mq or mqueue) isn't running.

To start a message queue manager you must use one of the utilities:

  • mq - Alternate message queue manager
  • mqueue - Traditional message queue manager

Either one must be run as root.

An overview reference can be found in POSIX Message Queues: Two Implementations.

Oka
  • 23,367
  • 6
  • 42
  • 53
  • thank you .in automatic/recursive builds, use this setting in my common.mk file:LIBS += mq but it is no use.errno is 89. – xkou Jul 04 '23 at 05:33
  • Right, `errno` 89 *is* `ENOSYS`. That line in your makefile is for specifying libraries to *link* with. You also need to start the message queue manager by running [`mq`](https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.utilities/topic/m/mq.html) as **root**. Is your message queue manager running? – Oka Jul 04 '23 at 05:52
  • yes , it looks working.# pidin a|grep mq 40989 mq 1474638 grep mq – xkou Jul 04 '23 at 07:38
  • If that's the case, then it might be time to focus on the other reason for `ENOSYS`: *function isn't implemented for the filesystem underlying the path specified in name*. What is your filesystem? Do other POSIX functions that manipulate the filesystem succeed or fail? A good one to test might be [link](https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/l/link.html) or [symlink](https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/symlink.html). – Oka Jul 04 '23 at 16:35
  • I'll try this,butBut I haven't seen a successful similar use case on the same platform.Maybe I'm missing something, I'll keep checking – xkou Jul 05 '23 at 07:00