* [Xenomai-help] kernel oops using mq_open after fork
[not found] <200607111736.k6BHaCme029123@domain.hid>
@ 2006-07-19 10:47 ` Landau, Bracha
2006-07-19 11:51 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: Landau, Bracha @ 2006-07-19 10:47 UTC (permalink / raw)
To: xenomai
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 postmaster@domain.hid and destroy the original message.
***********************************************************************************
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] kernel oops using mq_open after fork
2006-07-19 10:47 ` [Xenomai-help] kernel oops using mq_open after fork Landau, Bracha
@ 2006-07-19 11:51 ` Gilles Chanteperdrix
2006-07-19 12:10 ` Philippe Gerum
2006-07-19 12:59 ` Gilles Chanteperdrix
0 siblings, 2 replies; 4+ messages in thread
From: Gilles Chanteperdrix @ 2006-07-19 11:51 UTC (permalink / raw)
To: Landau, Bracha; +Cc: xenomai
Landau, Bracha wrote:
> 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?
The child process has not "bound" the interface, so, it has no
per-process data. If this is the cause of the oops, the solution is to
add a pthread_atfork call in xeno_user_skin_init in order for the
process children to also call xeno_user_skin_init.
--
Gilles Chanteperdrix.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] kernel oops using mq_open after fork
2006-07-19 11:51 ` Gilles Chanteperdrix
@ 2006-07-19 12:10 ` Philippe Gerum
2006-07-19 12:59 ` Gilles Chanteperdrix
1 sibling, 0 replies; 4+ messages in thread
From: Philippe Gerum @ 2006-07-19 12:10 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai, Landau, Bracha
On Wed, 2006-07-19 at 13:51 +0200, Gilles Chanteperdrix wrote:
> Landau, Bracha wrote:
> > 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?
>
> The child process has not "bound" the interface, so, it has no
> per-process data. If this is the cause of the oops, the solution is to
> add a pthread_atfork call in xeno_user_skin_init in order for the
> process children to also call xeno_user_skin_init.
Additionally, don't fiddle with SIGCHLD: we use it internally.
>
--
Philippe.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] kernel oops using mq_open after fork
2006-07-19 11:51 ` Gilles Chanteperdrix
2006-07-19 12:10 ` Philippe Gerum
@ 2006-07-19 12:59 ` Gilles Chanteperdrix
1 sibling, 0 replies; 4+ messages in thread
From: Gilles Chanteperdrix @ 2006-07-19 12:59 UTC (permalink / raw)
To: Landau, Bracha, xenomai
[-- Attachment #1: message body and .signature --]
[-- Type: text/plain, Size: 897 bytes --]
Gilles Chanteperdrix wrote:
> Landau, Bracha wrote:
> > 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?
>
> The child process has not "bound" the interface, so, it has no
> per-process data. If this is the cause of the oops, the solution is to
> add a pthread_atfork call in xeno_user_skin_init in order for the
> process children to also call xeno_user_skin_init.
Actually, this issue is specific to skins using the per-process data
feature, i.e. only the posix skin now. So, here is a fix that only fixes
the posix skin initialization. If it solve your issue I will commit it.
You only have to rebuild the user-space support, kernel-space support is
unchanged.
--
Gilles Chanteperdrix.
[-- Attachment #2: xeno-posix-fork-handler.diff --]
[-- Type: text/plain, Size: 5285 bytes --]
Index: src/skins/posix/init.c
===================================================================
--- src/skins/posix/init.c (revision 1357)
+++ src/skins/posix/init.c (working copy)
@@ -30,6 +30,7 @@
int __pse51_muxid = -1;
int __rtdm_muxid = -1;
int __rtdm_fd_start = INT_MAX;
+static int fork_handler_registered;
int __wrap_pthread_setschedparam(pthread_t, int, const struct sched_param *);
@@ -58,9 +59,9 @@
}
parm.sched_priority = 0;
- if ((err =
- __wrap_pthread_setschedparam(pthread_self(), SCHED_OTHER,
- &parm))) {
+ err = __wrap_pthread_setschedparam(pthread_self(), SCHED_OTHER,
+ &parm);
+ if (err) {
fprintf(stderr, "Xenomai Posix skin init: "
"pthread_setschedparam: %s\n", strerror(err));
exit(EXIT_FAILURE);
@@ -70,4 +71,14 @@
perror("Xenomai Posix skin init: munlockall");
exit(EXIT_FAILURE);
}
+
+ if (!fork_handler_registered) {
+ err = pthread_atfork(NULL, NULL, &__init_posix_interface);
+ if (err) {
+ fprintf(stderr, "Xenomai Posix skin init: "
+ "pthread_atfork: %s\n", strerror(err));
+ exit(EXIT_FAILURE);
+ }
+ fork_handler_registered = 1;
+ }
}
Index: src/testsuite/switchtest/Makefile.am
===================================================================
--- src/testsuite/switchtest/Makefile.am (revision 1357)
+++ src/testsuite/switchtest/Makefile.am (working copy)
@@ -9,8 +9,7 @@
switch_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
switch_LDADD = \
- -lpthread -lrt \
- ../../skins/posix/.libs/libpthread_rt.a
+ ../../skins/posix/.libs/libpthread_rt.a -lpthread -lrt
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(testdir)
Index: src/testsuite/switchtest/Makefile.in
===================================================================
--- src/testsuite/switchtest/Makefile.in (revision 1357)
+++ src/testsuite/switchtest/Makefile.in (working copy)
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# Makefile.in generated by automake 1.9.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -14,6 +14,8 @@
@SET_MAKE@
+SOURCES = $(switch_SOURCES)
+
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@@ -229,8 +231,7 @@
switch_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -g -I$(top_srcdir)/include
switch_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
switch_LDADD = \
- -lpthread -lrt \
- ../../skins/posix/.libs/libpthread_rt.a
+ ../../skins/posix/.libs/libpthread_rt.a -lpthread -lrt
EXTRA_DIST = runinfo
all: all-am
Index: src/testsuite/cyclic/Makefile.am
===================================================================
--- src/testsuite/cyclic/Makefile.am (revision 1357)
+++ src/testsuite/cyclic/Makefile.am (working copy)
@@ -9,8 +9,7 @@
cyclictest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
cyclictest_LDADD = \
- -lpthread -lrt \
- ../../skins/posix/.libs/libpthread_rt.a
+ ../../skins/posix/.libs/libpthread_rt.a -lpthread -lrt
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(testdir)
Index: src/testsuite/cyclic/Makefile.in
===================================================================
--- src/testsuite/cyclic/Makefile.in (revision 1357)
+++ src/testsuite/cyclic/Makefile.in (working copy)
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# Makefile.in generated by automake 1.9.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -14,6 +14,8 @@
@SET_MAKE@
+SOURCES = $(cyclictest_SOURCES)
+
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@@ -229,8 +231,7 @@
cyclictest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -DIPIPE_TRACE=1 -I$(top_srcdir)/include
cyclictest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
cyclictest_LDADD = \
- -lpthread -lrt \
- ../../skins/posix/.libs/libpthread_rt.a
+ ../../skins/posix/.libs/libpthread_rt.a -lpthread -lrt
EXTRA_DIST = runinfo
all: all-am
Index: src/testsuite/irqbench/Makefile.am
===================================================================
--- src/testsuite/irqbench/Makefile.am (revision 1357)
+++ src/testsuite/irqbench/Makefile.am (working copy)
@@ -19,8 +19,7 @@
$(XENO_USER_LDFLAGS)
irqloop_LDADD = \
- -lpthread \
- ../../skins/posix/.libs/libpthread_rt.a
+ ../../skins/posix/.libs/libpthread_rt.a -lpthread
irqbench_SOURCES = irqbench.c
Index: src/testsuite/irqbench/Makefile.in
===================================================================
--- src/testsuite/irqbench/Makefile.in (revision 1357)
+++ src/testsuite/irqbench/Makefile.in (working copy)
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# Makefile.in generated by automake 1.9.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -14,6 +14,8 @@
@SET_MAKE@
+SOURCES = $(irqbench_SOURCES) $(irqloop_SOURCES)
+
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@@ -241,8 +243,7 @@
$(XENO_USER_LDFLAGS)
irqloop_LDADD = \
- -lpthread \
- ../../skins/posix/.libs/libpthread_rt.a
+ ../../skins/posix/.libs/libpthread_rt.a -lpthread
irqbench_SOURCES = irqbench.c
irqbench_CPPFLAGS = \
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-07-19 12:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <200607111736.k6BHaCme029123@domain.hid>
2006-07-19 10:47 ` [Xenomai-help] kernel oops using mq_open after fork Landau, Bracha
2006-07-19 11:51 ` Gilles Chanteperdrix
2006-07-19 12:10 ` Philippe Gerum
2006-07-19 12:59 ` Gilles Chanteperdrix
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.