I'm using xenomai 2.2 rc3 on a MPC8247, on linux 2.6.14.
 
I have a problem using mq_open. Please see the attached code.
If I fork before the mq_open the kernel, I get a kernel oops.

Why this behaviour?

//***************************************************************
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/select.h>
#include <error.h>
#include <errno.h>

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/mount.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>
#include <mqueue.h>
#include <sys/mman.h>
pthread_t Main_Exec_thread_id;


#define MAIN_TASK_PRI 20
#define MAIN_STACK_SIZE 8192

pthread_attr_t Main_Exec_attr;
struct sched_param Main_Exec_parm;

int Main_PID = 0;
int Mains_Parent = 0;
int Child_PID = 0;

void split (void);

void *MainExecThread (void *dummy)
{

        struct mq_attr buf;
        int perms = 0666;
        buf.mq_msgsize = 4;
        buf.mq_maxmsg = 20;
        printf ("mq_open\n");
        sleep (2);
        mq_open ("/con_to_R01", O_CREAT | O_RDWR , perms, &buf);

        pause ();

        return 0;

}

int child (void)
{

        Main_PID = getpid ();

        printf ("main pid = %08x\n", Main_PID) ;
        printf ("main parent = %08x\n", Mains_Parent);


        mlockall (MCL_CURRENT | MCL_FUTURE);

        pthread_attr_init (&Main_Exec_attr);

        pthread_attr_setinheritsched(&Main_Exec_attr, 1);
        pthread_attr_setschedpolicy(&Main_Exec_attr, SCHED_FIFO);
        pthread_attr_setstacksize(&Main_Exec_attr, MAIN_STACK_SIZE);
        Main_Exec_parm.sched_priority = MAIN_TASK_PRI;
        pthread_attr_setschedparam(&Main_Exec_attr, &Main_Exec_parm);

        pthread_create (&Main_Exec_thread_id, &Main_Exec_attr, 
(void*(*)(void*))MainExecThread, 0); 

        while (true)
                pause ();

        printf ("MAIN PAUSE RETURNED\n") ;
        
}

void parent (void)
{
        while (true)
                pause ();
}

void split (void)
{
        int pid = fork ();

        if (pid == 0) // child
        {
                child ();
        }
        else // parent
        {

                Child_PID = pid;
                parent ();
        }
}
                

int main (int argc, char *argv[])
{

        Mains_Parent = getpid ();
        
#if 1
        split ();
#endif

#if 0
        child ();
#endif

}
***********************************************************************************
This email message and any attachments thereto are intended only for use by the 
addressee(s) named above, and may contain legally privileged and/or 
confidential information. If the reader of this message is not the intended 
recipient, or the employee or agent responsible to deliver it to the intended 
recipient, you are hereby notified that any dissemination, distribution or 
copying of this communication is strictly prohibited. If you have received this 
communication in error, please immediately notify the [EMAIL PROTECTED] and 
destroy the original message.
***********************************************************************************

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to