Module: xenomai-forge
Branch: next
Commit: 1f8e85436e6a596a0b8c63416aef5105bd346510
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1f8e85436e6a596a0b8c63416aef5105bd346510

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue May 27 08:14:40 2014 +0200

copperplate/heapobj: clear orphaned heap contents

Make sure to clear all previous contents from orphaned heaps we are
recycling.

This fixes a random EBUSY error when reinitializing the main heap of a
dead session (i.e. setting up the heap mutex lock), in absence of
--reset-session on the command line.

---

 lib/copperplate/heapobj-pshared.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index 32d5203..cdafceb 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -612,6 +612,19 @@ static int create_main_heap(void)
 
        len = size + sizeof(*m_heap);
 
+       /*
+        * Bind to (and optionally create) the main session's heap:
+        *
+        * If --reset-session was given, drop any previous heap for
+        * the same session name.
+        *
+        * If the heap already exists, check whether the leading
+        * process who created it is still alive, in which case we'll
+        * bind to it, unless the requested size differs.
+        *
+        * Otherwise, create the heap for the new emerging session and
+        * bind to it.
+        */
        snprintf(hobj->name, sizeof(hobj->name), "%s.main-heap", session);
        snprintf(hobj->fsname, sizeof(hobj->fsname), "/xeno:%s", hobj->name);
 
@@ -648,6 +661,8 @@ static int create_main_heap(void)
                munmap(m_heap, len);
        }
 
+       ftruncate(fd, 0);  /* Clear all previous contents if any. */
+
        ret = ftruncate(fd, len);
        if (ret)
                goto unlink_fail;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to