From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gilles Chanteperdrix MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mH9IF9wenn" Content-Transfer-Encoding: 7bit Message-ID: <17598.11417.970717.5621@domain.hid> Date: Wed, 19 Jul 2006 14:59:05 +0200 Subject: Re: [Xenomai-help] kernel oops using mq_open after fork In-Reply-To: <17598.7383.550897.877061@domain.hid> References: <200607111736.k6BHaCme029123@domain.hid> <02AA386EB831044F8537A696BA785C78A66846@domain.hid> <17598.7383.550897.877061@domain.hid> List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Landau, Bracha" , xenomai@xenomai.org --mH9IF9wenn Content-Type: text/plain; charset=us-ascii Content-Description: message body and .signature Content-Transfer-Encoding: 7bit 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. --mH9IF9wenn Content-Type: text/plain Content-Disposition: inline; filename="xeno-posix-fork-handler.diff" Content-Transfer-Encoding: 7bit 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 = \ --mH9IF9wenn--