diff options
Diffstat (limited to 'nuttx/sched/prctl.c')
-rw-r--r-- | nuttx/sched/prctl.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/nuttx/sched/prctl.c b/nuttx/sched/prctl.c index 93d69ee02..c4ed373b9 100644 --- a/nuttx/sched/prctl.c +++ b/nuttx/sched/prctl.c @@ -88,9 +88,29 @@ int prctl(int option, ...) case PR_GET_NAME: #if CONFIG_TASK_NAME_SIZE > 0 { - int pid = va_arg(ap, int); + /* Get the prctl arguments */ + char *name = va_arg(ap, char *); - FAR _TCB *tcb = sched_gettcb(pid); + int pid = va_arg(ap, int); + FAR _TCB *tcb; + + /* Get the TCB associated with the PID (handling the special case of + * pid==0 meaning "this thread" + */ + + if (!pid) + { + tcb = (FAR _TCB *)g_readytorun.head; + } + else + { + tcb = sched_gettcb(pid); + } + + /* An invalid pid be indicated by a NULL TCB returned from + * sched_gettcb() + */ + if (!tcb) { sdbg("Pid does not correspond to a task: %d\n", pid); @@ -105,12 +125,18 @@ int prctl(int option, ...) goto errout; } + /* Now get or set the name */ + if (option == PR_SET_NAME) { + /* tcb->name may not be null-terminated */ + strncpy(tcb->name, name, CONFIG_TASK_NAME_SIZE); } else { + /* The returned value will be null-terminated, truncating if necessary */ + strncpy(name, tcb->name, CONFIG_TASK_NAME_SIZE-1); name[CONFIG_TASK_NAME_SIZE-1]; } |