group/tg_info/argv: Make utility function to read argv as string

This creates a generic and safe way to read a process argument vector
as string from any context.
This commit is contained in:
Ville Juven
2023-02-16 14:38:47 +02:00
committed by Xiang Xiao
parent a8e5dcbfa9
commit 905cba3ee3
5 changed files with 139 additions and 101 deletions
+7 -39
View File
@@ -680,7 +680,6 @@ static ssize_t proc_cmdline(FAR struct proc_file_s *procfile,
size_t buflen, off_t offset)
{
FAR const char *name;
FAR char **argv;
size_t remaining;
size_t linesize;
size_t copysize;
@@ -710,45 +709,14 @@ static ssize_t proc_cmdline(FAR struct proc_file_s *procfile,
return totalsize;
}
#ifndef CONFIG_DISABLE_PTHREAD
/* Show the pthread argument */
/* Show the task / thread argument list (skipping over the name) */
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
{
FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)tcb;
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
" %p %p\n",
ptcb->cmn.entry.main, ptcb->arg);
copysize = procfs_memcpy(procfile->line, linesize, buffer,
remaining, &offset);
totalsize += copysize;
buffer += copysize;
remaining -= copysize;
return totalsize;
}
#endif
/* Show the task argument list (skipping over the name) */
for (argv = tcb->group->tg_info->argv + 1; *argv; argv++)
{
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
" %s", *argv);
copysize = procfs_memcpy(procfile->line, linesize, buffer,
remaining, &offset);
totalsize += copysize;
buffer += copysize;
remaining -= copysize;
if (totalsize >= buflen)
{
return totalsize;
}
}
linesize = group_argvstr(tcb, procfile->line, remaining);
copysize = procfs_memcpy(procfile->line, linesize, buffer,
remaining, &offset);
totalsize += copysize;
buffer += copysize;
remaining -= copysize;
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "\n");
copysize = procfs_memcpy(procfile->line, linesize, buffer,