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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Aug 25 11:51:03 2015 +0200

copperplate/threadobj: name main thread after process

---

 lib/copperplate/internal.c  |    8 ++++++++
 lib/copperplate/internal.h  |    2 ++
 lib/copperplate/threadobj.c |   14 +++++++++-----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c
index 7f712de..b9751e4 100644
--- a/lib/copperplate/internal.c
+++ b/lib/copperplate/internal.c
@@ -153,6 +153,14 @@ static inline void prepare_wait_corespec(void)
 
 #endif  /* CONFIG_XENO_MERCURY */
 
+int copperplate_get_current_name(char *name, size_t maxlen)
+{
+       if (maxlen < 16)
+               return -ENOSPC;
+
+       return prctl(PR_GET_NAME, (unsigned long)name, 0, 0, 0);
+}
+
 static int thread_spawn_prologue(struct corethread_attributes *cta)
 {
        int ret;
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index 5d0d41e..6369694 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -81,6 +81,8 @@ extern "C" {
 
 void copperplate_set_current_name(const char *name);
 
+int copperplate_get_current_name(char *name, size_t maxlen);
+
 int copperplate_kill_tid(pid_t tid, int sig);
 
 int copperplate_create_thread(struct corethread_attributes *cta,
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index c10e46a..961d8c4 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -1309,17 +1309,21 @@ int threadobj_prologue(struct threadobj *thobj, const 
char *name)
                finalize_thread(current);
        }
 
-       if (name)
+       if (name) {
                namecpy(thobj->name, name);
-       else
-               *thobj->name = '\0';
+               copperplate_set_current_name(name);
+       } else {
+               ret = copperplate_get_current_name(thobj->name,
+                                                  sizeof(thobj->name));
+               if (ret)
+                       warning("cannot get process name, %s", symerror(ret));
+       }
 
        thobj->ptid = pthread_self();
        thobj->pid = get_thread_pid();
        thobj->errno_pointer = &errno;
        threadobj_set_agent(thobj);
        backtrace_init_context(&thobj->btd, name);
-       copperplate_set_current_name(thobj->name);
        ret = threadobj_setup_corespec(thobj);
        if (ret) {
                warning("prologue failed for thread %s, %s",
@@ -1741,7 +1745,7 @@ static inline int main_overlay(void)
        }
 
        tcb->status = __THREAD_S_STARTED|__THREAD_S_ACTIVE;
-       threadobj_prologue(tcb, "main");
+       threadobj_prologue(tcb, NULL);
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
 
        return 0;


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

Reply via email to