mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Poggiali, Antonio" <Antonio.Poggiali@datalogic.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Cc: "Malaguti, Filippo" <Filippo.Malaguti@datalogic.com>
Subject: pthread_getname_np implementation
Date: Fri, 21 Jun 2019 13:36:49 +0000	[thread overview]
Message-ID: <AM0PR07MB442007DDD4FECFF99BB5EBF48BE70@AM0PR07MB4420.eurprd07.prod.outlook.com> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 954 bytes --]

Hello,

I've written the missing API pthread_getname_np for the latest version of the library.
 In attachment the patch to apply in on the master branch.

I'd really like to see it integrated in the next release.

Regards


Antonio Poggiali
R&D Senior SW Engineer Automation Products

[cid:image003.png@01D4CACC.0F48DEC0]

Phone: +39 051 676 5613
Datalogic S.r.l.
via Lavino, 265
40050 Monte San Pietro - Bologna - Italy
antonio.poggiali@datalogic.com<mailto:antonio.poggiali@datalogic.com>  |  www.datalogic.com<http://www.datalogic.com/>






CONFIDENTIALITY NOTICE. This message is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. Any unauthorized review, use, disclosure, or distribution is prohibited. If you are not the intended recipient, please destroy all copies of the original message, including any and all attachments, and notify the sender immediately.


[-- Attachment #1.1.2: Type: text/html, Size: 6287 bytes --]

[-- Attachment #1.2: image001.png --]
[-- Type: image/png, Size: 4840 bytes --]

[-- Attachment #2: 0001-Add-pthread_getname_np-API.patch --]
[-- Type: application/octet-stream, Size: 1975 bytes --]

From 20cea82579d482b90bd3db956fb0aecde8fd9fc8 Mon Sep 17 00:00:00 2001
From: apoggiali <antonio.poggiali@datalogic.com>
Date: Fri, 21 Jun 2019 14:57:04 +0200
Subject: [PATCH] Add pthread_getname_np API

---
 include/pthread.h               |  1 +
 src/thread/pthread_getname_np.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 src/thread/pthread_getname_np.c

diff --git a/include/pthread.h b/include/pthread.h
index e238321b..57fa905c 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -218,6 +218,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
 int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
 int pthread_getattr_np(pthread_t, pthread_attr_t *);
 int pthread_setname_np(pthread_t, const char *);
+int pthread_getname_np(pthread_t, char *, size_t);
 int pthread_getattr_default_np(pthread_attr_t *);
 int pthread_setattr_default_np(const pthread_attr_t *);
 int pthread_tryjoin_np(pthread_t, void **);
diff --git a/src/thread/pthread_getname_np.c b/src/thread/pthread_getname_np.c
new file mode 100644
index 00000000..3b5584ca
--- /dev/null
+++ b/src/thread/pthread_getname_np.c
@@ -0,0 +1,27 @@
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/prctl.h>
+
+#include "pthread_impl.h"
+
+int pthread_getname_np(pthread_t thread, char *name, size_t len)
+{
+	int fd, cs, status = 0;
+	ssize_t nlen;
+	char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
+
+	if (len < 16) return ERANGE;
+
+	if (thread == pthread_self())
+		return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
+
+	snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+	if ((fd = open(f, O_RDONLY)) < 0 || (nlen =read(fd, name, len)) < 0) status = errno;
+	if (fd >= 0) close(fd);
+	pthread_setcancelstate(cs, 0);
+    name[nlen-1] = '\0';	
+	return status;
+}
-- 
2.19.1


             reply	other threads:[~2019-06-21 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-21 13:36 Poggiali, Antonio [this message]
2019-06-21 14:04 ` Rich Felker
2019-06-21 18:18   ` Rich Felker
2019-07-03  7:31 Poggiali, Antonio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM0PR07MB442007DDD4FECFF99BB5EBF48BE70@AM0PR07MB4420.eurprd07.prod.outlook.com \
    --to=antonio.poggiali@datalogic.com \
    --cc=Filippo.Malaguti@datalogic.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).