From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs Subject: bug#38632: 27.0.50; Emacs process name is changed permanently upon creating a named thread Date: Thu, 19 Dec 2019 17:42:41 +0100 Message-ID: References: <87bls8ojoh.fsf@yantar92-laptop.i-did-not-set--mail-host-address--so-tickle-me> <83y2va3efz.fsf@gnu.org> <83v9qd3a0i.fsf@gnu.org> <83mubp362m.fsf@gnu.org> <8336dg2vvn.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="66552"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 38632@debbugs.gnu.org, yantar92@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 19 17:43:13 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ihytN-000H98-4r for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Dec 2019 17:43:13 +0100 Original-Received: from localhost ([::1]:44438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihytL-0002ho-Ui for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Dec 2019 11:43:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45278) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihytD-0002ew-Ox for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2019 11:43:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihytC-0005rM-Eo for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2019 11:43:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39483) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihytC-0005pp-8r for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2019 11:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ihytC-0005vE-5x for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2019 11:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Dec 2019 16:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38632 X-GNU-PR-Package: emacs Original-Received: via spool by 38632-submit@debbugs.gnu.org id=B38632.157677377522752 (code B ref 38632); Thu, 19 Dec 2019 16:43:02 +0000 Original-Received: (at 38632) by debbugs.gnu.org; 19 Dec 2019 16:42:55 +0000 Original-Received: from localhost ([127.0.0.1]:45456 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ihyt5-0005ut-0d for submit@debbugs.gnu.org; Thu, 19 Dec 2019 11:42:55 -0500 Original-Received: from mail-wr1-f45.google.com ([209.85.221.45]:39008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ihyt0-0005ua-9p for 38632@debbugs.gnu.org; Thu, 19 Dec 2019 11:42:53 -0500 Original-Received: by mail-wr1-f45.google.com with SMTP id y11so6659314wrt.6 for <38632@debbugs.gnu.org>; Thu, 19 Dec 2019 08:42:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:gmane-reply-to-list:date:in-reply-to :message-id:mime-version; bh=rss0myROeTiubFL8+ytZn1uac4VP46HCS4d6OGI8AGA=; b=CCD9qGD19G3KCq26DDFDimBcEV3pLZCVEbVBc04bH+EI8DVA+0WVWFblmvpcVHGVmI 4tBSYzwNKx13jkPYmNmNTWRUO+jDrIbjaez+k4e9bij5wEO9D5adoPGJMzQV0hBatUTO MwtxhvKj0WWimdpWC7CyK/1uHnbOnhh6AB+5SbGCaVdrwxI6Xn3epagR+gxId1KJwNv4 ho7HvTtthNVnAQtXpqkzWxuOCyzil5W0JvHNyJIsjwRv7+iL6rLq9V3CCFoIv8U8akM8 BSFc56lBwovUNj/cCVWyp6g/ZPmOabPtaaOSDFPH/VImtLJjJugSydd5TDfWAeYG/1Ub PsWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references :gmane-reply-to-list:date:in-reply-to:message-id:mime-version; bh=rss0myROeTiubFL8+ytZn1uac4VP46HCS4d6OGI8AGA=; b=uFbLU83ahBbiScVxEj2BNcSpe07VXbUBfXBERGRsU5amT3JNeXgdSF84AoEjKBcP6D K9P+JJvlAi2e6rS0pd4YGcspHUqSnok6v65WxGYpsoHuqGJq7jfP0zwdQ8hQPMtQmDrb 4XONR64DOwILDfrvuMNYoCkCAkXfztH539KnDp57yvbB0HMiD4OjsiuwAOJ0rTv5B3jZ gLCvLOnzdCfelPEEnubr7+lpDBcy25pMTG+R/fos+r7WDbujBNX9OAKj2Jwci8ZiF9pQ xJe2GBxnSh8sF+UDEVnzbAmQasFRpJl4QHBSJjxIwt+EZRzVZG5BG8ttz5Mv4apXB4Dz DltA== X-Gm-Message-State: APjAAAVsYJVRZ5stLJ1MrUwic/PdZ4Yipv5ykvuNKD7u93aruPJnC5iL UL/ZPfPidtAgAEyDsmvmJdI= X-Google-Smtp-Source: APXvYqzcRuy5LsNpEqXxzPoOgEkK7FTo7ludTLHtQ+X+6WY0vD3iZeLkxMmZ5qti4aIHyGy28RkwDg== X-Received: by 2002:a5d:4a91:: with SMTP id o17mr11041676wrq.232.1576773764243; Thu, 19 Dec 2019 08:42:44 -0800 (PST) Original-Received: from rpluim-mac ([149.5.228.1]) by smtp.gmail.com with ESMTPSA id 16sm6586480wmi.0.2019.12.19.08.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:42:43 -0800 (PST) Gmane-Reply-To-List: yes In-Reply-To: <8336dg2vvn.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 19 Dec 2019 17:11:24 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:173550 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> On Thu, 19 Dec 2019 17:11:24 +0200, Eli Zaretskii said: Eli> We need to truncate the names we store in the thread object (and Eli> document that). Eli> I think I'm going to change my mind on that. The complication her= e is Eli> that the name should be encoded by ENCODE_SYSTEM before we pass it= to Eli> pthread_setname_np etc., and if the locale-coding-system is not UT= F-8 Eli> and not single-byte, we don't really know where a character will e= nd Eli> after encoding. And encoding one character at a time sounds too Eli> gross. Eli> So perhaps we should just truncate the bytes, and leave this to the Eli> application to make sure the result makes sense, and also disregard Eli> the difference between list-threads and the thread name as the OS = and Eli> debuggers see it. Doing that will also avoid the complication of Eli> having the thread name return to the caller different from what the Eli> caller used. Here=CA=BCs what it looks like. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Use-pthread_setname_np-to-set-thread-name.patch >From bbb7e7837fcad3bac10aef69a1b331243c2b1c4c Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Thu, 19 Dec 2019 17:33:16 +0100 Subject: [PATCH] Use pthread_setname_np to set thread name * configure.ac: Remove check for sys/prctl.h and prctl, check for pthread_setname_np instead. * systhread.c: Remove sys/prctl.h include. (sys_thread_create) [HAVE_PTHREAD_SETNAME_NP]: Use pthread_setname_np to set the name of the newly created thread (Bug#38632). --- configure.ac | 4 ++-- src/systhread.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 3b6a2a6d16..34a2654494 100644 --- a/configure.ac +++ b/configure.ac @@ -1767,7 +1767,7 @@ AC_DEFUN sys/sysinfo.h coff.h pty.h sys/resource.h - sys/utsname.h pwd.h utmp.h util.h sys/prctl.h) + sys/utsname.h pwd.h utmp.h util.h) AC_CACHE_CHECK([for ADDR_NO_RANDOMIZE], [emacs_cv_personality_addr_no_randomize], @@ -4180,7 +4180,7 @@ AC_DEFUN sendto recvfrom getsockname getifaddrs freeifaddrs \ gai_strerror sync \ getpwent endpwent getgrent endgrent \ -cfmakeraw cfsetspeed __executable_start log2 prctl) +cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np) LIBS=$OLD_LIBS dnl No need to check for posix_memalign if aligned_alloc works. diff --git a/src/systhread.c b/src/systhread.c index 6f4de536fb..55bde837e3 100644 --- a/src/systhread.c +++ b/src/systhread.c @@ -98,10 +98,6 @@ sys_thread_yield (void) #include -#ifdef HAVE_SYS_PRCTL_H -#include -#endif - void sys_mutex_init (sys_mutex_t *mutex) { @@ -227,9 +223,18 @@ sys_thread_create (sys_thread_t *thread_ptr, const char *name, if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED)) { result = pthread_create (thread_ptr, &attr, func, arg) == 0; -#if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME) +#ifdef HAVE_PTHREAD_SETNAME_NP if (result && name != NULL) - prctl (PR_SET_NAME, name); + { + /* We need to truncate here otherwise pthread_setname_np + fails to set the name. TASK_COMM_LEN is what the length + is called in the Linux kernel headers (Bug#38632). */ +#define TASK_COMM_LEN 16 + char p_name[TASK_COMM_LEN]; + strncpy (p_name, name, TASK_COMM_LEN - 1); + p_name[TASK_COMM_LEN - 1] = '\0'; + pthread_setname_np (*thread_ptr, p_name); + } #endif } -- 2.23.0 --=-=-=--