You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/12/05 05:37:35 UTC

(nuttx) branch master updated: fs/proc: Fix groupfd to get fd by group instead of current tcb

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

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


The following commit(s) were added to refs/heads/master by this push:
     new bffe858e47 fs/proc: Fix groupfd to get fd by group instead of current tcb
bffe858e47 is described below

commit bffe858e47a15e7f2b7fb7a3e61569afe0f77d05
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Mon Dec 4 15:34:48 2023 +0800

    fs/proc: Fix groupfd to get fd by group instead of current tcb
    
    /proc/<pid>/group/fd should read the fds of <pid>, not current tcb.
    
    Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
 fs/inode/fs_files.c       | 31 +++++++++++++++++++++----------
 fs/procfs/fs_procfsproc.c |  8 +++++---
 include/nuttx/fs/fs.h     | 17 +++++++++++++++++
 3 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c
index 93ee037785..c5f047ba94 100644
--- a/fs/inode/fs_files.c
+++ b/fs/inode/fs_files.c
@@ -71,16 +71,6 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
   return filep;
 }
 
-/****************************************************************************
- * Name: files_fget
- ****************************************************************************/
-
-static FAR struct file *files_fget(FAR struct filelist *list, int fd)
-{
-  return files_fget_by_index(list, fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK,
-                             fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK);
-}
-
 /****************************************************************************
  * Name: files_extend
  ****************************************************************************/
@@ -347,6 +337,27 @@ int files_countlist(FAR struct filelist *list)
   return list->fl_rows * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
 }
 
+/****************************************************************************
+ * Name: files_fget
+ *
+ * Description:
+ *   Get the instance of struct file from file list by file descriptor.
+ *
+ * Input Parameters:
+ *   list - The list of files for a task.
+ *   fd   - A valid descriptor between 0 and files_countlist(list).
+ *
+ * Returned Value:
+ *   Pointer to file structure of list[fd].
+ *
+ ****************************************************************************/
+
+FAR struct file *files_fget(FAR struct filelist *list, int fd)
+{
+  return files_fget_by_index(list, fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK,
+                             fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK);
+}
+
 /****************************************************************************
  * Name: file_allocate_from_tcb
  *
diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c
index c0289f6436..d5f3532de2 100644
--- a/fs/procfs/fs_procfsproc.c
+++ b/fs/procfs/fs_procfsproc.c
@@ -1193,7 +1193,6 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
   size_t copysize;
   size_t totalsize;
   int count;
-  int ret;
   int i;
 
   DEBUGASSERT(group != NULL);
@@ -1226,8 +1225,11 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
 
   for (i = 0; i < count; i++)
     {
-      ret = fs_getfilep(i, &filep);
-      if (ret != OK || filep == NULL)
+      filep = files_fget(&group->tg_filelist, i);
+
+      /* Is there an inode associated with the file descriptor? */
+
+      if (filep->f_inode == NULL)
         {
           continue;
         }
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 4211d36470..032f1c6147 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -882,6 +882,23 @@ int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist,
                   FAR const posix_spawn_file_actions_t *actions,
                   bool cloexec);
 
+/****************************************************************************
+ * Name: files_fget
+ *
+ * Description:
+ *   Get the instance of struct file from file list by file descriptor.
+ *
+ * Input Parameters:
+ *   list - The list of files for a task.
+ *   fd   - A valid descriptor between 0 and files_countlist(list).
+ *
+ * Returned Value:
+ *   Pointer to file structure of list[fd].
+ *
+ ****************************************************************************/
+
+FAR struct file *files_fget(FAR struct filelist *list, int fd);
+
 /****************************************************************************
  * Name: file_allocate_from_tcb
  *