Module: xenomai-3 Branch: master Commit: 8c60d68e2296cf71f1b43ca6f0bc91788b1af78c URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=8c60d68e2296cf71f1b43ca6f0bc91788b1af78c
Author: Philippe Gerum <r...@xenomai.org> Date: Fri Mar 13 17:07:46 2015 +0100 copperplate/init: fix shared heap name with default session We need a valid session label to be defined before creating the shared heap. This fixes a regression introduced by ede23e4. --- lib/copperplate/init.c | 37 ++++++++++++++++++++++++++++++++++--- lib/copperplate/internal.h | 7 +++++-- lib/copperplate/registry.c | 19 ++----------------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c index 6a962e4..384d03e 100644 --- a/lib/copperplate/init.c +++ b/lib/copperplate/init.c @@ -26,6 +26,7 @@ #include <memory.h> #include <malloc.h> #include <assert.h> +#include <pwd.h> #include <signal.h> #include <errno.h> #include <getopt.h> @@ -45,10 +46,9 @@ struct coppernode __node_info = { .no_sanity = !CONFIG_XENO_SANITY, .reset_session = 0, .silent_mode = 0, -#ifdef CONFIG_XENO_REGISTRY - .session_label = NULL, .registry_root = DEFAULT_REGISTRY_ROOT, -#endif + .session_label = NULL, + .session_root = NULL, }; pid_t __node_id; @@ -517,6 +517,29 @@ fail: early_panic("initialization failed, %s", symerror(ret)); } +static int get_session_root(void) +{ + struct passwd *pw; + char *sessdir; + int ret; + + if (__node_info.session_label) { + pw = getpwuid(geteuid()); + if (pw == NULL) + return -errno; + ret = asprintf(&sessdir, "%s/%s/%s", __node_info.registry_root, + pw->pw_name, __node_info.session_label); + } else { + __node_info.session_label = DEFAULT_REGISTRY_SESSION; + ret = asprintf(&sessdir, "%s/%s", __node_info.registry_root, + DEFAULT_REGISTRY_SESSION); + } + + __node_info.session_root = sessdir; + + return ret < 0 ? -ENOMEM : 0; +} + /* The application-level copperplate init call. */ void copperplate_init(int *argcp, char *const **argvp) @@ -587,6 +610,14 @@ void copperplate_init(int *argcp, char *const **argvp) goto fail; } + /* + * We need the session label to be known before we create the + * shared heap, which is named after the former. + */ + ret = get_session_root(); + if (ret) + goto fail; + ret = heapobj_pkg_init_shared(); if (ret) { warning("failed to initialize main shared heap"); diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h index cc41101..a3f2fca 100644 --- a/lib/copperplate/internal.h +++ b/lib/copperplate/internal.h @@ -32,13 +32,16 @@ #ifdef CONFIG_XENO_REGISTRY #define DEFAULT_REGISTRY_ROOT CONFIG_XENO_REGISTRY_ROOT -#define DEFAULT_REGISTRY_SESSION "anon" +#else +#define DEFAULT_REGISTRY_ROOT NULL #endif +#define DEFAULT_REGISTRY_SESSION "anon" struct coppernode { unsigned int mem_pool; - const char *session_label; const char *registry_root; + const char *session_label; + const char *session_root; cpu_set_t cpu_affinity; int no_mlock; int no_registry; diff --git a/lib/copperplate/registry.c b/lib/copperplate/registry.c index 3053d0d..661562b 100644 --- a/lib/copperplate/registry.c +++ b/lib/copperplate/registry.c @@ -35,7 +35,6 @@ #include <pthread.h> #include <semaphore.h> #include <fuse.h> -#include <pwd.h> #include <xeno_config.h> #include "boilerplate/hash.h" #include "copperplate/heapobj.h" @@ -802,24 +801,10 @@ int __registry_pkg_init(const char *arg0, char *mountpt, int shared_registry) int registry_pkg_init(const char *arg0) { - struct passwd *pw = NULL; - char *mountpt, *sessdir; + char *mountpt; int ret; - if (__node_info.session_label) { - pw = getpwuid(geteuid()); - if (!pw) - return -errno; - ret = asprintf(&sessdir, "%s/%s/%s", __node_info.registry_root, - pw->pw_name, __node_info.session_label); - } else - ret = asprintf(&sessdir, "%s/%s", __node_info.registry_root, - DEFAULT_REGISTRY_SESSION); - if (ret < 0) - return -ENOMEM; - - ret = connect_regd(sessdir, &mountpt); - free(sessdir); + ret = connect_regd(__node_info.session_root, &mountpt); if (ret) return ret; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git