Announcement

Collapse
No announcement yet.

IPC msgsnd with ftok returing msq_id = 0

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • IPC msgsnd with ftok returing msq_id = 0

    XPortPro Development Board
    Build Environment Fedora

    I am trying to create a message queue to pass messages between threads within an application as well as between applications.

    I have enabled system IPC in the kernel (via make menuconfig)

    I have tried several variations using ftok to create key for msgget as below but keep getting a value of 0 for the msq id (needs to be non-zero to work)

    /* devicename is /dev/ttyS0 */
    mq_Key = ftok(devicename, sizeof(devicename));
    --------
    or
    --------
    char *path = "/tmp";
    int id = 'S';
    mq_Key = ftok(path, id);
    ------------
    if ((msqid = msgget(mq_Key, IPC_CREAT)) < 0)
    ...

    keeps returning 0 for the msq id

    this causes msgsnd to fail with
    syslog: srxxx_main: msgsnd failed 22

    If I build the same application using gcc and run it under linux I get a non-zero value for msqid which in turn works with msgsnd

    Has anyone got any example code that they know works on XPortPro using the linux sdk?

  • #2
    I have tried to investigate further. I can create a non-zero msg id, but msgsnd still fails. It is possible to create 16 queues and the first queue created seems to always return 0. However msgsnd still fails

    for (i = 0; i < 16; i++)
    {
    mq_Key = i;
    if ((msqid = msgget(mq_Key, 0666 | IPC_CREAT)) < 0)
    {
    syslog(LOG_DEBUG, "init_iexportsrxxx: msgid already created\n", msqid);
    if ((msqid = msgget(mq_Key, 0)) < 0)
    {
    syslog(LOG_DEBUG, "init_iexportsrxxx: msgget failed");
    }
    }
    else
    {
    syslog(LOG_DEBUG, "init_iexportsrxxx: msgid 0x%lx", msqid);

    if ((ret = msgsnd(msqid, (struct msgbuf *) &thisCommandMsg, sizeof(commandMsgData), IPC_NOWAIT)) < 0)
    {
    syslog(LOG_DEBUG, "init_iexportsrxxx: msgsnd failed %i\n", errno);
    }
    else
    {
    syslog(LOG_DEBUG, "init_iexportsrxxx: command sent %i\n", msqid);
    }
    }

    //msgctl(msqid, IPC_RMID, NULL);
    }

    This is outputs the following

    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx:
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x0
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x8001
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x10002
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x18003
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x20004
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x28005
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x30006
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x38007
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x40008
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x48009
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x5000a
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x5800b
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x6000c
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x6800d
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x7000e
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgid 0x7800f
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: msgsnd failed 22
    Nov 30 00:00:08 10.1.1.200 main: [58]: init_iexportsrxxx: Initializing

    Comment


    • #3
      Problem resolved...

      The message being passed MUST have mtype set to 1
      thisCommandMsg.mtype = 1;

      Hope this helps someone else

      Comment

      Working...
      X