7 #include "pthread_impl.h"
9 int pthread_setname_np(pthread_t thread
, const char *name
)
11 int fd
, cs
, status
= 0;
12 char f
[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
15 if ((len
= strnlen(name
, 16)) > 15) return ERANGE
;
17 if (thread
== pthread_self())
18 return prctl(PR_SET_NAME
, (unsigned long)name
, 0UL, 0UL, 0UL) ? errno
: 0;
20 snprintf(f
, sizeof f
, "/proc/self/task/%d/comm", thread
->tid
);
21 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, &cs
);
22 if ((fd
= open(f
, O_WRONLY
)) < 0 || write(fd
, name
, len
) < 0) status
= errno
;
23 if (fd
>= 0) close(fd
);
24 pthread_setcancelstate(cs
, 0);