Skip to content

Commit

Permalink
remove pthread_getname_np calls
Browse files Browse the repository at this point in the history
This allows to preserve compatiblity with musl libc which lacks this function
  • Loading branch information
JuniorJPDJ committed Jul 9, 2021
1 parent 4567bc7 commit 207e0bd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
2 changes: 2 additions & 0 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "libtcmu_priv.h"
#include "be_byteshift.h"

__thread int __tcmu_is_ework_thread = 0;

int tcmu_cdb_get_length(uint8_t *cdb)
{
uint8_t group_code = cdb[0] >> 5;
Expand Down
6 changes: 1 addition & 5 deletions libtcmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,17 +843,13 @@ const char *tcmu_dev_get_uio_name(struct tcmu_device *dev)
void tcmu_set_thread_name(const char *prefix, struct tcmu_device *dev)
{
const char *uio = dev ? tcmu_dev_get_uio_name(dev) : NULL;
char cname[TCMU_THREAD_NAME_LEN];
char *pname;

if (pthread_getname_np(pthread_self(), cname, TCMU_THREAD_NAME_LEN))
return;

/*
* If we are trying to set the pthread name in the
* event work thread, we must ignore it.
*/
if (!strcmp(cname, "ework-thread")) {
if (__tcmu_is_ework_thread) {
tcmu_dev_warn(dev, "Do not set name for event work thread in the callback fn\n");
return;
}
Expand Down
2 changes: 2 additions & 0 deletions libtcmu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ void __tcmu_sense_set_data(uint8_t *sense_buf, uint8_t key, uint16_t asc_ascq);
*/
void tcmu_thread_cancel(pthread_t thread);

extern __thread int __tcmu_is_ework_thread;

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 1 addition & 5 deletions libtcmu_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ static int output_to_fd(int pri, const char *timestamp,
int fd = (intptr_t) data;
char *buf, *msg;
int count, ret, written = 0, r, pid = 0;
char pname[TCMU_THREAD_NAME_LEN];

if (fd == -1)
return -1;
Expand All @@ -412,13 +411,10 @@ static int output_to_fd(int pri, const char *timestamp,
if (pid <= 0)
return -1;

if (pthread_getname_np(pthread_self(), pname, TCMU_THREAD_NAME_LEN))
return -1;

/*
* format: timestamp pid [loglevel] msg
*/
ret = asprintf(&msg, "%s %d:%s [%s] %s", timestamp, pid, pname,
ret = asprintf(&msg, "%s %d [%s] %s", timestamp, pid,
loglevel_string(pri), str);
if (ret < 0)
return -1;
Expand Down
8 changes: 2 additions & 6 deletions tcmur_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ struct tcmur_work *tcmur_create_work(void)

static void __tcmur_flush_work(struct tcmur_work *work)
{
char pname[TCMU_THREAD_NAME_LEN];

if (pthread_getname_np(pthread_self(), pname, TCMU_THREAD_NAME_LEN))
return;

/*
* The event work thread may need to do a handler reopen
* call and try to flush itself. Just ignore.
*/
if (!strcmp(pname, "ework-thread"))
if (__tcmu_is_ework_thread)
return;

/*
Expand Down Expand Up @@ -79,6 +74,7 @@ static void *tcmur_work_fn(void *data)
struct private *p = data;

tcmu_set_thread_name("ework-thread", NULL);
__tcmu_is_ework_thread = 1;

p->work_fn(p->data);

Expand Down

0 comments on commit 207e0bd

Please sign in to comment.