threadlocal: Copy thread name
commitb5f194fa4ad6a496babd1aa5fac5d8b5a1f06829
authorEric Blake <eblake@redhat.com>
Thu, 16 Nov 2017 20:54:57 +0000 (16 14:54 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 17 Nov 2017 20:34:22 +0000 (17 14:34 -0600)
treedbbe7a0dc3f9e9754202cea330a2913913d3c601
parentd02d9c9d670f1d7b6888d8ade7ea95e5084ffe2e
threadlocal: Copy thread name

We can't guarantee what storage duration the caller's request
for a thread name has; and in fact, if the caller uses
plugin_name() for their thread name, then the moment .unload
is called, our threadlocal storage is pointing to la-la-land
and we get a nice SEGV while trying to print any debug message.
So copy the user's string instead.

Make the update best-effort, since we may be creating a new
thread while an existing connection is already in service.  If
strdup fails, we'll mention the failure, but it's better to
still keep the program running with no thread name than to
die [of course, if strdup fails, we'll probably face other
failures quite soon].

Signed-off-by: Eric Blake <eblake@redhat.com>
src/threadlocal.c