mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-18 08:17:35 +08:00
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.
This commit is contained in:
@@ -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)
|
||||
#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
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user