diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 99de8b70021..e59651ea528 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -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, diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index e2f69308c7b..703ea64f5c5 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -1073,6 +1073,25 @@ FAR struct task_tcb_s *nxtask_setup_vfork(start_t retaddr); pid_t nxtask_start_vfork(FAR struct task_tcb_s *child); void nxtask_abort_vfork(FAR struct task_tcb_s *child, int errcode); +/**************************************************************************** + * Name: group_argvstr + * + * Description: + * Safely read the contents of a task's argument vector, into a a safe + * buffer. Function skips the process's name. + * + * Input Parameters: + * tcb - tcb of the task. + * args - Output buffer for the argument vector. + * size - Size of the buffer. + * + * Returned Value: + * The actual string length that was written. + * + ****************************************************************************/ + +size_t group_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size); + /**************************************************************************** * Name: group_exitinfo * diff --git a/sched/group/Make.defs b/sched/group/Make.defs index 016fb98c7f2..de6fdbb2495 100644 --- a/sched/group/Make.defs +++ b/sched/group/Make.defs @@ -21,6 +21,7 @@ CSRCS += group_create.c group_join.c group_leave.c group_find.c CSRCS += group_setupstreams.c group_setupidlefiles.c group_setuptaskfiles.c CSRCS += group_foreachchild.c group_killchildren.c group_signal.c +CSRCS += group_argvstr.c ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) ifeq ($(CONFIG_SCHED_CHILD_STATUS),y) diff --git a/sched/group/group_argvstr.c b/sched/group/group_argvstr.c new file mode 100644 index 00000000000..6b608575359 --- /dev/null +++ b/sched/group/group_argvstr.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * sched/group/group_argvstr.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "sched/sched.h" +#include "group/group.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: group_argvstr + * + * Description: + * Safely read the contents of a task's argument vector, into a a safe + * buffer. Function skips the process's name. + * + * Input Parameters: + * tcb - tcb of the task. + * args - Output buffer for the argument vector. + * size - Size of the buffer. + * + * Returned Value: + * The actual string length that was written. + * + ****************************************************************************/ + +size_t group_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size) +{ + size_t n = 0; +#ifdef CONFIG_ARCH_ADDRENV + bool saved = false; +#endif + + /* Perform sanity checks */ + + if (!tcb || !tcb->group || !tcb->group->tg_info) + { + /* Something is very wrong -> get out */ + + *args = '\0'; + return 0; + } + +#ifdef CONFIG_ARCH_ADDRENV + if (tcb->addrenv_own != NULL) + { + addrenv_select(tcb->addrenv_own); + saved = true; + } +#endif + +#ifndef CONFIG_DISABLE_PTHREAD + if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) + { + FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)tcb; + + n += snprintf(args, size, " %p %p", ptcb->cmn.entry.main, ptcb->arg); + } + else +#endif + { + FAR char **argv = tcb->group->tg_info->argv + 1; + + while (*argv != NULL && n < size) + { + n += snprintf(args + n, size - n, " %s", *argv++); + } + } + +#ifdef CONFIG_ARCH_ADDRENV + if (saved) + { + addrenv_restore(); + } +#endif + + return n < size - 1 ? n : size - 1; +} diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 20ef2f047b3..6f1a0cee52e 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -24,7 +24,6 @@ #include -#include #include #include #include @@ -43,6 +42,7 @@ #include "irq/irq.h" #include "sched/sched.h" +#include "group/group.h" /**************************************************************************** * Pre-processor Definitions @@ -214,66 +214,6 @@ static void show_stacks(FAR struct tcb_s *rtcb) #endif -/**************************************************************************** - * Name: get_argv_str - * - * Description: - * Safely read the contents of a task's argument vector, into a a safe - * buffer. - * - ****************************************************************************/ - -static void get_argv_str(FAR struct tcb_s *tcb, FAR char *args, size_t size) -{ -#ifdef CONFIG_ARCH_ADDRENV - bool saved = false; -#endif - - /* Perform sanity checks */ - - if (!tcb || !tcb->group || !tcb->group->tg_info) - { - /* Something is very wrong -> get out */ - - *args = '\0'; - return; - } - -#ifdef CONFIG_ARCH_ADDRENV - if (tcb->addrenv_own != NULL) - { - addrenv_select(tcb->addrenv_own); - saved = true; - } -#endif - -#ifndef CONFIG_DISABLE_PTHREAD - if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) - { - FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)tcb; - - snprintf(args, size, " %p %p", ptcb->cmn.entry.main, ptcb->arg); - } - else -#endif - { - FAR char **argv = tcb->group->tg_info->argv + 1; - size_t npos = 0; - - while (*argv != NULL && npos < size) - { - npos += snprintf(args + npos, size - npos, " %s", *argv++); - } - } - -#ifdef CONFIG_ARCH_ADDRENV - if (saved) - { - addrenv_restore(); - } -#endif -} - /**************************************************************************** * Name: dump_task ****************************************************************************/ @@ -313,7 +253,7 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg) /* Stringify the argument vector */ - get_argv_str(tcb, args, sizeof(args)); + group_argvstr(tcb, args, sizeof(args)); /* Dump interesting properties of this task */