Skip to content

Commit

Permalink
fs/proc: Fix groupfd to get fd by group instead of current tcb
Browse files Browse the repository at this point in the history
/proc/<pid>/group/fd should read the fds of <pid>, not current tcb.

Signed-off-by: Zhe Weng <[email protected]>
  • Loading branch information
wengzhe authored and xiaoxiang781216 committed Dec 5, 2023
1 parent c17fcb5 commit bffe858
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
31 changes: 21 additions & 10 deletions fs/inode/fs_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 5 additions & 3 deletions fs/procfs/fs_procfsproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit bffe858

Please sign in to comment.