diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-21 05:14:47 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-21 05:14:47 +0000 |
commit | 1ea49760417b17e62a90cce3d736f777cbfd52b7 (patch) | |
tree | 24ebdc99ceddd7afb789e39ac025ee42c53ff6fe /thread_pthread.c | |
parent | e8bd56f5c34689d1211552863359a219ba2fce7e (diff) | |
download | ruby-1ea49760417b17e62a90cce3d736f777cbfd52b7.tar.gz |
* thread_pthread.c (native_set_thread_name): New function to
set thread name visible with ps command on GNU/Linux.
Ex. ps -o %c -L
* thread.c (thread_start_func_2): Call native_set_thread_name at
beginning.
(rb_thread_inspect_msg): Extract from rb_thread_inspect.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r-- | thread_pthread.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index eee60f373a..7e4d36c479 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1447,6 +1447,39 @@ timer_thread_sleep(rb_global_vm_lock_t* unused) # define SET_THREAD_NAME(name) (void)0 #endif +static VALUE rb_thread_inspect_msg(VALUE thread, int show_enclosure, int show_location, int show_status); + +static void +native_set_thread_name(rb_thread_t *th) +{ +#if defined(__linux__) && defined(PR_SET_NAME) + VALUE str; + char *name, *p; + char buf[16]; + size_t len; + + str = rb_thread_inspect_msg(th->self, 0, 1, 0); + name = StringValueCStr(str); + if (*name == '@') + name++; + p = strrchr(name, '/'); /* show only the basename of the path. */ + if (p && p[1]) + name = p + 1; + + len = strlen(name); + if (len < sizeof(buf)) { + memcpy(buf, name, len); + buf[len] = '\0'; + } + else { + memcpy(buf, name, sizeof(buf)-2); + buf[sizeof(buf)-2] = '*'; + buf[sizeof(buf)-1] = '\0'; + } + SET_THREAD_NAME(buf); +#endif +} + static void * thread_timer(void *p) { |