Message-ID: <509BB2BE.5040500@basystemes.fr> Date: Thu, 08 Nov 2012 14:25:18 +0100 From: Jean-Baptiste Tredez MIME-Version: 1.0 References: <50991915.7050500@basystemes.fr> <509927B2.7010305@xenomai.org> In-Reply-To: <509927B2.7010305@xenomai.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Xenomai] pthread_set_name_np List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gilles Chanteperdrix Cc: xenomai@xenomai.org Le 06/11/2012 16:07, Gilles Chanteperdrix a =C3=A9crit : > On 11/06/2012 03:05 PM, Jean-Baptiste Tredez wrote: >> Hello, >> >> I have some issues when I change the name of a task (created with the >> native skin) with the posix skin (pthread_set_name_np) on xenomai 2.6.= 1 >> (kernel 2.6.38.8). This is a task created by a external library and we >> can not set the right name at the first place. >> pthread_set_name_np seems to work only on tasks created with the posix= skin. > Yes, pthread_set_name_np only works for posix skin threads, I do not > think we have a simple way of retrieving the native skin thread > associated with a given pthread_t identifier. > > We have some way of doing it that will only work for pthread_self(). > >> Here is a test program (that worked with linux 2.6.38.8 + xenomai-2.6.= 0 >> and crash with linux 2.6.38 + xenomai 2.6.1) : > I doubt very much it has ever worked. It did not crash, but did not do > anything (and returned ESRCH by the way). Ok, it did not crash but did nothing. > Anyway, we can try the > following patch, that should restore pthread_set_name_np as a nop for > non-posix threads as in 2.6.0: > > diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c > index 9b1c266..6c78244 100644 > --- a/ksrc/skins/posix/syscall.c > +++ b/ksrc/skins/posix/syscall.c > @@ -435,9 +435,11 @@ static int __pthread_set_name_np(struct pt_regs *r= egs) > hkey.u_tid =3D __xn_reg_arg1(regs); > hkey.mm =3D current->mm; > k_tid =3D __pthread_find(&hkey); > - p =3D xnthread_user_task(&k_tid->threadbase); > - strncpy(p->comm, name, sizeof(p->comm)); > - p->comm[sizeof(p->comm) - 1] =3D '\0'; > + if (k_tid) { > + p =3D xnthread_user_task(&k_tid->threadbase); > + strncpy(p->comm, name, sizeof(p->comm)); > + p->comm[sizeof(p->comm) - 1] =3D '\0'; > + } > > return -pthread_set_name_np(k_tid, name); > } This is working (nop operation). > If you want to set a thread name for display in top or ps, you should u= se > prctl(PR_SET_NAME). If you want to set the thread name for display in > /proc/xenomai/stat or /proc/xenomai/sched, you have no other choice tha= n > using the native API for native skin threads. >