This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 237b13ad3a377b60faca12ca4e8a02d05389ff9e
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 10:04:55 2026 +0100

    fs/procfs: Skip the tasks that ended since opendir() of the root.
    
    opendir() of the procfs root takes a snapshot of the task IDs.
    procfs_readdir() returned -ENOENT for an ID of the snapshot whose task
    had ended since.  readdir() takes -ENOENT as the end of the directory,
    so the listing stopped there: the other tasks and the static entries
    were missing.  A walk of /proc (ps, for example) then saw a short list.
    
    Now readdir() skips the IDs that no longer refer to a task and goes on
    with the next entry, as Linux does.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/procfs/fs_procfs.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c
index e4314c6cf39..01754c747a2 100644
--- a/fs/procfs/fs_procfs.c
+++ b/fs/procfs/fs_procfs.c
@@ -932,6 +932,18 @@ static int procfs_readdir(FAR struct inode *mountpt,
     {
       level0 = (FAR struct procfs_level0_s *)priv;
 
+#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
+      /* Skip the tasks of the snapshot of opendir() that have ended since:
+       * the walk goes on with the next one, as on Linux.
+       */
+
+      while (priv->index < priv->nentries &&
+             nxsched_get_tcb(level0->pid[priv->index]) == NULL)
+        {
+          priv->index++;
+        }
+#endif
+
       /* Have we reached the end of the PID information */
 
       index = priv->index;
@@ -1030,16 +1042,9 @@ static int procfs_readdir(FAR struct inode *mountpt,
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
       else
         {
-          /* Verify that the pid still refers to an active task/thread */
+          /* The pid referred to an active task/thread above */
 
           pid_t pid = level0->pid[index];
-          FAR struct tcb_s *tcb = nxsched_get_tcb(pid);
-
-          if (!tcb)
-            {
-              ferr("ERROR: PID %d is no longer valid\n", pid);
-              return -ENOENT;
-            }
 
           /* Save the filename=pid and file type=directory */
 

Reply via email to