Browse Source

px4_posix_tasks.cpp: make sure to copy the thread name into the thread data struct

The thread name is used from within the entry of the new thread, but the
provided name could live on the stack of the caller thread. Thus we need to
copy the name.
sbg
Beat Küng 9 years ago committed by Julian Oes
parent
commit
d7ed47e2e5
  1. 12
      src/platforms/posix/px4_layer/px4_posix_tasks.cpp

12
src/platforms/posix/px4_layer/px4_posix_tasks.cpp

@ -79,10 +79,10 @@ static task_entry taskmap[PX4_MAX_TASKS] = {}; @@ -79,10 +79,10 @@ static task_entry taskmap[PX4_MAX_TASKS] = {};
typedef struct {
px4_main_t entry;
const char *name;
char name[16]; //pthread_setname_np is restricted to 16 chars
int argc;
char *argv[];
// strings are allocated after the
// strings are allocated after the struct data
} pthdata_t;
static void *entry_adapter(void *ptr)
@ -95,10 +95,7 @@ static void *entry_adapter(void *ptr) @@ -95,10 +95,7 @@ static void *entry_adapter(void *ptr)
#ifdef __PX4_DARWIN
rv = pthread_setname_np(data->name);
#else
char buf[17];
snprintf(buf, 16, "%s", data->name);
buf[16] = '0';
rv = pthread_setname_np(pthread_self(), buf);
rv = pthread_setname_np(pthread_self(), data->name);
#endif
if (rv) {
@ -155,7 +152,8 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int @@ -155,7 +152,8 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
memset(taskdata, 0, structsize + len);
offset = ((unsigned long)taskdata) + structsize;
taskdata->name = name;
strncpy(taskdata->name, name, 16);
taskdata->name[15] = 0;
taskdata->entry = entry;
taskdata->argc = argc;

Loading…
Cancel
Save