mailing list of musl libc
 help / color / mirror / code / Atom feed
* Re: pthread_getname_np implementation
@ 2019-07-03  7:31 Poggiali, Antonio
  2019-07-09 18:19 ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Poggiali, Antonio @ 2019-07-03  7:31 UTC (permalink / raw)
  To: musl

On Fri, 21 Jun 2019 14:18:38 -0400, Rich Felker wrote:
> So the situation is nasty, but not as bad as I remember. The
> conflicting definitions are basically junk (unusable) or minor
> gratuitous differences (int vs size_t). However this does suggest that
> there's a decent motivation for discouraging the proliferation of its
> use in applications.

> Thoughts?

I think if you provide a way to set a name,  there should be a way to get it as well.
The majority of the systems lacks the API or have it as glibc does so why not implement it glibc style?

Antonio






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.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: pthread_getname_np implementation
  2019-07-03  7:31 pthread_getname_np implementation Poggiali, Antonio
@ 2019-07-09 18:19 ` Rich Felker
  0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2019-07-09 18:19 UTC (permalink / raw)
  To: Poggiali, Antonio; +Cc: musl

On Wed, Jul 03, 2019 at 07:31:56AM +0000, Poggiali, Antonio wrote:
> On Fri, 21 Jun 2019 14:18:38 -0400, Rich Felker wrote:
> > So the situation is nasty, but not as bad as I remember. The
> > conflicting definitions are basically junk (unusable) or minor
> > gratuitous differences (int vs size_t). However this does suggest that
> > there's a decent motivation for discouraging the proliferation of its
> > use in applications.
> 
> > Thoughts?
> 
> I think if you provide a way to set a name,  there should be a way to get it as well.
> The majority of the systems lacks the API or have it as glibc does so why not implement it glibc style?

Based on the previous discussion of this and others' comments, I think
adding it is probably the right thing to do. I'll look at it after
rolling the release. Ping the list again if I don't get around to it
soon.

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pthread_getname_np implementation
  2019-06-21 14:04 ` Rich Felker
@ 2019-06-21 18:18   ` Rich Felker
  0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2019-06-21 18:18 UTC (permalink / raw)
  To: musl

On Fri, Jun 21, 2019 at 10:04:59AM -0400, Rich Felker wrote:
> On Fri, Jun 21, 2019 at 01:36:49PM +0000, Poggiali, Antonio wrote:
> > 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.
> 
> I think this was brought up before and it was deemed not appropriate
> for inclusion because there are multiple incompatible historical
> functions by the same name. I'll see what I can find from past
> discussions.

It looks like:

- AIX has it with no size argument.
- QNX has it with an int size argument.
- Blackberry has it with an int size argument.
- PTC MKX has a char ** argument where it returns a pointer to the
  name and doesn't document the storage duration of the name.
- OSF/1 defines it matching glibc.
- OpenBSD defines it matching glibc.
- NetBSD defines it matching glibc.
- FreeBSD seems to lack both get and set (but has the
  differently-named pthread_set_name_np).
- Solaris defines it matching glibc.

So the situation is nasty, but not as bad as I remember. The
conflicting definitions are basically junk (unusable) or minor
gratuitous differences (int vs size_t). However this does suggest that
there's a decent motivation for discouraging the proliferation of its
use in applications.

Thoughts?

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pthread_getname_np implementation
  2019-06-21 13:36 Poggiali, Antonio
@ 2019-06-21 14:04 ` Rich Felker
  2019-06-21 18:18   ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2019-06-21 14:04 UTC (permalink / raw)
  To: musl

On Fri, Jun 21, 2019 at 01:36:49PM +0000, Poggiali, Antonio wrote:
> 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.

I think this was brought up before and it was deemed not appropriate
for inclusion because there are multiple incompatible historical
functions by the same name. I'll see what I can find from past
discussions.

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

* pthread_getname_np implementation
@ 2019-06-21 13:36 Poggiali, Antonio
  2019-06-21 14:04 ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Poggiali, Antonio @ 2019-06-21 13:36 UTC (permalink / raw)
  To: musl; +Cc: Malaguti, Filippo


[-- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-09 18:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03  7:31 pthread_getname_np implementation Poggiali, Antonio
2019-07-09 18:19 ` Rich Felker
  -- strict thread matches above, loose matches on Subject: below --
2019-06-21 13:36 Poggiali, Antonio
2019-06-21 14:04 ` Rich Felker
2019-06-21 18:18   ` Rich Felker

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).