mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user