Module: xenomai-3
Branch: master
Commit: ce832bea54c65bf00e09fd1b0460722e6b62ed12
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=ce832bea54c65bf00e09fd1b0460722e6b62ed12

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Mar 14 08:34:12 2015 +0100

copperplate: drop useless session reset option

We don't need --reset-session, since a shared heap left over by a dead
application will be automatically overwritten. Otherwise, any conflict
with a running process must be resolved by the user.

---

 lib/copperplate/heapobj-pshared.c |   57 ++++++++++++++++---------------------
 lib/copperplate/init.c            |   22 ++++----------
 lib/copperplate/internal.h        |    1 -
 3 files changed, 31 insertions(+), 49 deletions(-)

diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index 29a1a29..20b5b44 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -582,7 +582,7 @@ out:
        return ret;
 }
 
-static int create_main_heap(void)
+static int create_main_heap(pid_t *cnode_r)
 {
        const char *session = __node_info.session_label;
        size_t size = __node_info.mem_pool;
@@ -601,6 +601,7 @@ static int create_main_heap(void)
         */
        assert(HOBJ_PAGE_SIZE > sizeof(struct shared_extent));
 
+       *cnode_r = -1;
        size += internal_overhead(size);
        size = __align_to(size, HOBJ_PAGE_SIZE);
        if (size > HOBJ_MAXEXTSZ)
@@ -614,9 +615,6 @@ static int create_main_heap(void)
        /*
         * 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.
@@ -627,9 +625,6 @@ static int create_main_heap(void)
        snprintf(hobj->name, sizeof(hobj->name), "%s.main-heap", session);
        snprintf(hobj->fsname, sizeof(hobj->fsname), "/xeno:%s", hobj->name);
 
-       if (__node_info.reset_session)
-               shm_unlink(hobj->fsname);
-
        fd = shm_open(hobj->fsname, O_RDWR|O_CREAT, 0600);
        if (fd < 0)
                return __bt(-errno);
@@ -642,24 +637,28 @@ static int create_main_heap(void)
        if (ret)
                goto errno_fail;
 
-       if (sbuf.st_size > 0) {
-               m_heap = __STD(mmap(NULL, len, PROT_READ|PROT_WRITE, 
MAP_SHARED, fd, 0));
-               if (m_heap == MAP_FAILED)
-                       goto errno_fail;
-               if (m_heap->cpid && kill(m_heap->cpid, 0) == 0) {
-                       if (m_heap->maplen == len) {
-                               hobj->pool = &m_heap->base;
-                               __main_heap = m_heap;
-                               __main_sysgroup = &m_heap->sysgroup;
-                               goto done;
-                       }
-                       munmap(m_heap, len);
-                       __STD(close(fd));
-                       return __bt(-EEXIST);
+       if (sbuf.st_size == 0)
+               goto init;
+
+       m_heap = __STD(mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 
0));
+       if (m_heap == MAP_FAILED)
+               goto errno_fail;
+
+       if (m_heap->cpid && kill(m_heap->cpid, 0) == 0) {
+               if (m_heap->maplen == len) {
+                       hobj->pool = &m_heap->base;
+                       __main_heap = m_heap;
+                       __main_sysgroup = &m_heap->sysgroup;
+                       goto done;
                }
+               *cnode_r = m_heap->cpid;
                munmap(m_heap, len);
+               __STD(close(fd));
+               return __bt(-EEXIST);
        }
 
+       munmap(m_heap, len);
+init:
        ret = ftruncate(fd, 0);  /* Clear all previous contents if any. */
        if (ret)
                goto unlink_fail;
@@ -943,19 +942,13 @@ char *xnstrdup(const char *ptr)
 
 int heapobj_pkg_init_shared(void)
 {
+       pid_t cnode;
        int ret;
 
-       ret = create_main_heap();
-       if (ret == -EEXIST) {
-               if (__node_info.reset_session)
-                       /* Init failed despite override. */
-                       warning("active session %s is conflicting\n",
-                               __node_info.session_label);
-               else
-                       warning("non-matching session %s already exists,\n"
-                               "pass --reset to override.",
-                               __node_info.session_label);
-       }
+       ret = create_main_heap(&cnode);
+       if (ret == -EEXIST)
+               warning("session %s is still active (pid %d)\n",
+                       __node_info.session_label, cnode);
 
        return __bt(ret);
 }
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index 384d03e..32a31aa 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -44,7 +44,6 @@ struct coppernode __node_info = {
        .no_mlock = 0,
        .no_registry = 0,
        .no_sanity = !CONFIG_XENO_SANITY,
-       .reset_session = 0,
        .silent_mode = 0,
        .registry_root = DEFAULT_REGISTRY_ROOT,
        .session_label = NULL,
@@ -103,49 +102,42 @@ static const struct option base_options[] = {
                .val = 0
        },
        {
-#define reset_session_opt      6
-               .name = "reset-session",
-               .has_arg = 0,
-               .flag = &__node_info.reset_session,
-               .val = 1
-       },
-       {
-#define affinity_opt   7
+#define affinity_opt   6
                .name = "cpu-affinity",
                .has_arg = 1,
                .flag = NULL,
                .val = 0
        },
        {
-#define silent_opt     8
+#define silent_opt     7
                .name = "silent",
                .has_arg = 0,
                .flag = &__node_info.silent_mode,
                .val = 1
        },
        {
-#define version_opt    9
+#define version_opt    8
                .name = "version",
                .has_arg = 0,
                .flag = NULL,
                .val = 0
        },
        {
-#define dumpconfig_opt 10
+#define dumpconfig_opt 9
                .name = "dump-config",
                .has_arg = 0,
                .flag = NULL,
                .val = 0
        },
        {
-#define no_sanity_opt  11
+#define no_sanity_opt  10
                .name = "no-sanity",
                .has_arg = 0,
                .flag = &__node_info.no_sanity,
                .val = 1
        },
        {
-#define sanity_opt     12
+#define sanity_opt     11
                .name = "sanity",
                .has_arg = 0,
                .flag = &__node_info.no_sanity,
@@ -184,7 +176,6 @@ static void usage(void)
         fprintf(stderr, "--registry-root=<path>           root path of 
registry\n");
         fprintf(stderr, "--no-registry                    suppress object 
registration\n");
         fprintf(stderr, "--session=<label>                label of shared 
multi-processing session\n");
-        fprintf(stderr, "--reset                          remove any older 
session\n");
         fprintf(stderr, "--cpu-affinity=<cpu[,cpu]...>    set CPU affinity of 
threads\n");
         fprintf(stderr, "--[no-]sanity                    disable/enable 
sanity checks\n");
         fprintf(stderr, "--silent                         tame down 
verbosity\n");
@@ -397,7 +388,6 @@ static int parse_base_options(int *argcp, char *const 
**argvp,
                case no_mlock_opt:
                case no_sanity_opt:
                case no_registry_opt:
-               case reset_session_opt:
                case sanity_opt:
                case silent_opt:
                        break;
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index a3f2fca..ed176b2 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -46,7 +46,6 @@ struct coppernode {
        int no_mlock;
        int no_registry;
        int no_sanity;
-       int reset_session;
        int silent_mode;
 };
 


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

Reply via email to