? foo.c ? foo.s ? foo1.s ? o ? x Index: Makefile =================================================================== RCS file: /cvsroot/src/lib/libpthread/Makefile,v retrieving revision 1.100 diff -u -p -u -r1.100 Makefile --- Makefile 7 Apr 2025 16:07:05 -0000 1.100 +++ Makefile 26 Oct 2025 20:35:10 -0000 @@ -98,6 +98,7 @@ SRCS+= pthread_md.S .if exists(${ARCHDIR}/Makefile.inc) .include "${ARCHDIR}/Makefile.inc" .endif +.include "${.CURDIR}/compat/Makefile.inc" # The PTHREAD__COMPAT flag builds a libpthread that can be dropped # into a NetBSD 2/3/4 chroot with a NetBSD 5 or later kernel. @@ -122,7 +123,7 @@ pthread_specific.po: pthread_specific.o ${_MKTARGET_CREATE} cp pthread_specific.o pthread_specific.po -COPTS.pthread.c += -Wno-stack-protector -Wno-format-nonliteral +COPTS.pthread.c += -Wno-stack-protector COPTS.pthread_attr.c += -Wno-format-nonliteral LINTFLAGS+= -Ac11 # for _Atomic Index: pthread.c =================================================================== RCS file: /cvsroot/src/lib/libpthread/pthread.c,v retrieving revision 1.188 diff -u -p -u -r1.188 pthread.c --- pthread.c 6 Oct 2025 13:12:29 -0000 1.188 +++ pthread.c 26 Oct 2025 20:35:10 -0000 @@ -54,6 +54,7 @@ __RCSID("$NetBSD: pthread.c,v 1.188 2025 #include #include #include +#include #include #include #include @@ -832,10 +833,11 @@ pthread_getname_np(pthread_t thread, cha int -pthread_setname_np(pthread_t thread, const char *name, void *arg) +pthread_setname_np(pthread_t thread, const char *name, ...) { char *oldname, *cp, newname[PTHREAD_MAX_NAMELEN_NP]; int namelen; + va_list ap; pthread__error(EINVAL, "Invalid thread", thread->pt_magic == PT_MAGIC); @@ -843,7 +845,9 @@ pthread_setname_np(pthread_t thread, con if (pthread__find(thread) != 0) return ESRCH; - namelen = snprintf(newname, sizeof(newname), name, arg); + va_start(ap, name); + namelen = vsnprintf(newname, sizeof(newname), name, ap); + va_end(ap); if (namelen >= PTHREAD_MAX_NAMELEN_NP) return EINVAL; Index: pthread.h =================================================================== RCS file: /cvsroot/src/lib/libpthread/pthread.h,v retrieving revision 1.42 diff -u -p -u -r1.42 pthread.h --- pthread.h 6 Oct 2025 13:12:29 -0000 1.42 +++ pthread.h 26 Oct 2025 20:35:10 -0000 @@ -157,7 +157,8 @@ int pthread_setcanceltype(int, int *); void pthread_testcancel(void); int pthread_getname_np(pthread_t, char *, size_t); -int pthread_setname_np(pthread_t, const char *, void *); +int pthread_setname_np(pthread_t, const char *, ...) \ + __RENAME(__pthread_setname_np120) __printflike(2, 3); int pthread_attr_setcreatesuspend_np(pthread_attr_t *); int pthread_suspend_np(pthread_t); Index: pthread_getname_np.3 =================================================================== RCS file: /cvsroot/src/lib/libpthread/pthread_getname_np.3,v retrieving revision 1.5 diff -u -p -u -r1.5 pthread_getname_np.3 --- pthread_getname_np.3 22 Oct 2017 16:37:24 -0000 1.5 +++ pthread_getname_np.3 26 Oct 2025 20:35:10 -0000 @@ -25,7 +25,7 @@ .\" SUCH DAMAGE. .\" .\" ------------------------------------------------------------ -.Dd July 9, 2010 +.Dd October 26, 2025 .Dt PTHREAD_GETNAME_NP 3 .Os .Sh NAME @@ -41,7 +41,7 @@ .Ft int .Fn pthread_getname_np "pthread_t thread" "char *name" "size_t len" .Ft int -.Fn pthread_setname_np "pthread_t thread" "const char *name" "void *arg" +.Fn pthread_setname_np "pthread_t thread" "const char *name" "..." .\" ------------------------------------------------------------ .Sh DESCRIPTION The @@ -72,11 +72,12 @@ The format string to be used to construct the descriptive name of the thread. The resulted descriptive name should be shorter than .Dv PTHREAD_MAX_NAMELEN_NP . -.It Fa arg +.It Fa ... The .Xr printf 3 -argument used with -.Fa name . +arguments used with the +.Fa name +format string. .El .\" ------------------------------------------------------------ .Sh RETURN VALUES @@ -106,3 +107,26 @@ There was insufficient memory for the op .Sh SEE ALSO .Xr pthread_attr_get_np 3 , .Xr pthread_attr_getname_np 3 +.Sh HISTORY +Jason Thorpe added the +.Fn pthread_setname_np +API by copying the Tru64 API in 2003. +This was: +.Pp +.Ft int +.Fn pthread_setname_np "pthread_t thread" "const char *name" "void *" +.Pp +In 2012 GLIBC added a two argument version for glibc 2.12. +.Pp +.Ft int +.Fn pthread_setname_np "pthread_t thread" "const char *name" +.Pp +Later, in 2020, +.Fx +adopted the GLIBC two argument version. +Unfortunately this creates compatibility issues because code that expects +two arguments does not compile anymore. +To address this, in 2025, +.Nx +changed to a variadic version that retains the current functionality and +provides compatibility. Index: pthread_mi.expsym =================================================================== RCS file: /cvsroot/src/lib/libpthread/pthread_mi.expsym,v retrieving revision 1.3 diff -u -p -u -r1.3 pthread_mi.expsym --- pthread_mi.expsym 6 Oct 2025 13:12:30 -0000 1.3 +++ pthread_mi.expsym 26 Oct 2025 20:35:10 -0000 @@ -49,6 +49,7 @@ __msync13 __nanosleep50 __pollts50 __pselect50 +__pthread_setname_np120 __res_get_state __res_put_state __res_state Index: shlib_version =================================================================== RCS file: /cvsroot/src/lib/libpthread/shlib_version,v retrieving revision 1.21 diff -u -p -u -r1.21 shlib_version --- shlib_version 19 Oct 2025 23:52:44 -0000 1.21 +++ shlib_version 26 Oct 2025 20:35:10 -0000 @@ -21,4 +21,4 @@ # remove remnants of libpthread_dbg: pthread__dbg # major=1 -minor=6 +minor=7 Index: compat/Makefile.inc =================================================================== RCS file: compat/Makefile.inc diff -N compat/Makefile.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ compat/Makefile.inc 26 Oct 2025 20:35:10 -0000 @@ -0,0 +1,8 @@ +# $NetBSD$ + +COMPAT:= ${.PARSEDIR} +.PATH.c: ${COMPAT} + +SRCS += compat_pthread_setname_np.c +CPPFLAGS.compat_pthread_setname_np.c += -I${COMPAT} +COPTS.compat_pthread_setname_np.c += -Wno-format-nonliteral Index: compat/compat_pthread_setname_np.c =================================================================== RCS file: compat/compat_pthread_setname_np.c diff -N compat/compat_pthread_setname_np.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ compat/compat_pthread_setname_np.c 26 Oct 2025 20:35:10 -0000 @@ -0,0 +1,84 @@ +/* $NetBSD: pthread.c,v 1.188 2025/10/06 13:12:29 riastradh Exp $ */ + +/*- + * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020 + * The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nathan J. Williams and Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: pthread.c,v 1.188 2025/10/06 13:12:29 riastradh Exp $"); + +#include +#include +#include +#include +#include + +#define __LIBC12_SOURCE__ +#include "pthread.h" +#include "pthread_int.h" +#include "pthread_makelwp.h" +#include "reentrant.h" + +__warn_references(pthread_setname_np, + "warning: reference to compatibility pthread_setname_np(); include to generate correct reference") + +__strong_alias(pthread_setname_np, __compat_pthread_setname_np) + + +int +__compat_pthread_setname_np(pthread_t thread, const char *name, void *arg) +{ + char *oldname, *cp, newname[PTHREAD_MAX_NAMELEN_NP]; + int namelen; + + pthread__error(EINVAL, "Invalid thread", + thread->pt_magic == PT_MAGIC); + + if (pthread__find(thread) != 0) + return ESRCH; + + namelen = snprintf(newname, sizeof(newname), name, arg); + if (namelen >= PTHREAD_MAX_NAMELEN_NP) + return EINVAL; + + cp = strdup(newname); + if (cp == NULL) + return ENOMEM; + + pthread_mutex_lock(&thread->pt_lock); + oldname = thread->pt_name; + thread->pt_name = cp; + (void)_lwp_setname(thread->pt_lid, cp); + pthread_mutex_unlock(&thread->pt_lock); + + if (oldname != NULL) + free(oldname); + + return 0; +} Index: compat/pthread.h =================================================================== RCS file: compat/pthread.h diff -N compat/pthread.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ compat/pthread.h 26 Oct 2025 20:35:10 -0000 @@ -0,0 +1,10 @@ +/* $NetBSD$ */ + +#ifndef COMPAT_PTHREAD_H +#define COMPAT_PTHREAD_H +#include + +#define PTHREAD_MAX_NAMELEN_NP 32 + +int __compat_pthread_setname_np(pthread_t, const char *, void *) __dso_hidden; +#endif