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

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Jan 13 18:29:50 2015 +0100

copperplate/registry: Establish per-user namespaces for named sessions

This moves non-anonymous sessions into user-specific namespaces:
/registry-root/user. This helps to isolate users from each other. The
layout for the shared anon session remains unmodified.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 doc/asciidoc/MIGRATION.adoc           |   15 ++++++++-------
 doc/asciidoc/README.APPLICATIONS.adoc |    6 +++---
 doc/asciidoc/README.INSTALL.adoc      |   11 ++++++-----
 lib/copperplate/init.c                |    2 +-
 lib/copperplate/regd/regd.c           |   16 +++++++++++++++-
 lib/copperplate/registry.c            |   13 +++++++++++--
 6 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/doc/asciidoc/MIGRATION.adoc b/doc/asciidoc/MIGRATION.adoc
index 72206bf..5aaf7fb 100644
--- a/doc/asciidoc/MIGRATION.adoc
+++ b/doc/asciidoc/MIGRATION.adoc
@@ -104,13 +104,14 @@ filesystem.  The hierarchy of the Xenomai registry is 
organized as
 follows:
 
 ----------------------------------------------------------------------------   
 
-    /mount-point            /* registry fs root, defaults to /var/run/xenomai*/
-        /session            /* shared session name or "anon" */
-            /pid            /* application (main) pid */
-               /skin        /* API name: alchemy/vxworks/psos/... */
-                  /family   /* object class (task, semaphore, ...) */
-                     { exported objects... }
-            /system         /* session-wide information */
+  /mount-point              /* registry fs root, defaults to /var/run/xenomai*/
+   [/user]                  /* user name, missing if "anon" session */
+      /session              /* shared session name or "anon" */
+        /pid                /* application (main) pid */
+          /skin             /* API name: alchemy/vxworks/psos/... */
+            /family         /* object class (task, semaphore, ...) */
+              { exported objects... }
+        /system             /* session-wide information */
 ----------------------------------------------------------------------------   
 
     
 Each leaf entry under a session hierarchy is normally viewable, for
diff --git a/doc/asciidoc/README.APPLICATIONS.adoc 
b/doc/asciidoc/README.APPLICATIONS.adoc
index b44cde6..920b458 100644
--- a/doc/asciidoc/README.APPLICATIONS.adoc
+++ b/doc/asciidoc/README.APPLICATIONS.adoc
@@ -78,7 +78,7 @@ link:installing-xenomai-3-x[configuration switch]).
 *--no-registry*::
 
        This switch disables registry support at runtime. No real-time
-       objects will be exported to +/var/run/xenomai/<session>/<pid>+,
+       objects will be exported to +/var/run/xenomai/[<user>/]<session>/<pid>+,
        despite the registry code was compiled in.
 
 *--no-sanity*::
@@ -111,8 +111,8 @@ link:installing-xenomai-3-x[configuration switch]).
 
 [normal]
        This label is also used to form the registry mount point for
-       each process, e.g. +/var/run/xenomai/<session>/<pid>+. See
-       +--enable-registry+ from the build options.
+       each process, e.g. +/var/run/xenomai/[<user>/]<session>/<pid>+.
+       See +--enable-registry+ from the build options.
 
 [normal]
        By default, _anon_ is used as the session label.
diff --git a/doc/asciidoc/README.INSTALL.adoc b/doc/asciidoc/README.INSTALL.adoc
index 445b0d9..4538396 100644
--- a/doc/asciidoc/README.INSTALL.adoc
+++ b/doc/asciidoc/README.INSTALL.adoc
@@ -413,11 +413,12 @@ Generic configuration options (both cores)
 
 [normal]
        When this option is enabled, the system creates a file
-       hierachy under `/var/run/xenomai/<session>/<pid>` (by default),
-       where you can access the internal state of the active
-       real-time objects. The session label is obtained from the
-       --session runtime switch. E.g. looking at the properties of a
-       VxWorks task could be done as follows:
+       hierachy under `/var/run/xenomai/[<user>/]<session>/<pid>`
+       (by default), where you can access the internal state of the
+       active real-time objects. The session label is obtained from
+       the --session runtime switch. If left out, it is "anon" and
+       the user name is not inserted as well. E.g. looking at the
+       properties of a VxWorks task could be done as follows:
 
 --------------------------------------------------------------------
                $ cat /var/run/xenomai/anon/12656/vxworks/tasks/windTask
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index 0aba4c3..50ca596 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -46,7 +46,7 @@ struct coppernode __node_info = {
        .reset_session = 0,
        .silent_mode = 0,
 #ifdef CONFIG_XENO_REGISTRY
-       .session_label = DEFAULT_REGISTRY_SESSION,
+       .session_label = NULL,
        .registry_root = DEFAULT_REGISTRY_ROOT,
 #endif
 };
diff --git a/lib/copperplate/regd/regd.c b/lib/copperplate/regd/regd.c
index 8a66290..6ce1089 100644
--- a/lib/copperplate/regd/regd.c
+++ b/lib/copperplate/regd/regd.c
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <pwd.h>
 #include <boilerplate/list.h>
 #include <boilerplate/hash.h>
 #include "../internal.h"
@@ -50,7 +51,7 @@
                        printf("regd: " fmt "\n", ##args);      \
        } while (0)
 
-static const char *rootdir = DEFAULT_REGISTRY_ROOT"/"DEFAULT_REGISTRY_SESSION;
+static char *rootdir;
 
 static int sockfd;
 
@@ -406,6 +407,7 @@ static void create_system_fs(const char *arg0, const char 
*rootdir)
 
 int main(int argc, char *const *argv)
 {
+       struct passwd *pw = NULL;
        int lindex, opt, ret;
        struct sigaction sa;
 
@@ -431,6 +433,18 @@ int main(int argc, char *const *argv)
                }
        }
 
+       if (rootdir == NULL) {
+               pw = getpwuid(geteuid());
+               if (!pw)
+                       return -errno;
+               ret = asprintf(&rootdir, "%s/%s/%s",
+                              DEFAULT_REGISTRY_ROOT,
+                              pw->pw_name,
+                              DEFAULT_REGISTRY_SESSION);
+               if (ret < 0)
+                       return -ENOMEM;
+       }
+
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = SIG_IGN;
        sigaction(SIGCHLD, &sa, NULL);
diff --git a/lib/copperplate/registry.c b/lib/copperplate/registry.c
index 720093c..92443e7 100644
--- a/lib/copperplate/registry.c
+++ b/lib/copperplate/registry.c
@@ -35,6 +35,7 @@
 #include <pthread.h>
 #include <semaphore.h>
 #include <fuse.h>
+#include <pwd.h>
 #include <xeno_config.h>
 #include "boilerplate/hash.h"
 #include "copperplate/heapobj.h"
@@ -787,11 +788,19 @@ 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;
        int ret;
 
-       ret = asprintf(&sessdir, "%s/%s",
-                      __node_info.registry_root, __node_info.session_label);
+       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;
 


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

Reply via email to