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 ca08a71aea7eceec672e9567b8c1dd7a8cad2e75 Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 23 16:32:17 2026 +0200 fs/procfs: Show the user and group of a process. A program that finds a process by its user reads the Uid: and Gid: lines of /proc/<pid>/status, or the owner of the /proc/<pid> directory, as on Linux. NuttX showed neither: the owner was always 0. With CONFIG_SCHED_USER_IDENTITY, /proc/<pid>/status shows two new lines. "Uid:" gives the real and the effective user ID of the task group, in this order. "Gid:" gives the real and the effective group ID. stat() of /proc/<pid> and of the files in it gives the effective user and group ID of the task group as st_uid and st_gid. Without CONFIG_SCHED_USER_IDENTITY, nothing changes. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- fs/procfs/fs_procfsproc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 15008cf74c8..47fcef55f4f 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -465,6 +465,10 @@ static FAR const struct proc_node_s *proc_findnode(FAR const char *relpath) * Type: xxxxxxx {Task, pthread, Kthread, Invalid} * PPID: xxxxx Parent thread ID * Group: xxxxx Group ID + * Uid: xxxxx xxxxx Real, effective user ID + * (CONFIG_SCHED_USER_IDENTITY only) + * Gid: xxxxx xxxxx Real, effective group ID + * (CONFIG_SCHED_USER_IDENTITY only) * CPU: xxx CPU (CONFIG_SMP only) * State: xxxxxxxx,xxxxxxxxx {Invalid, Waiting, Ready, Running, * Inactive}, @@ -542,6 +546,31 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, return totalsize; } +#ifdef CONFIG_SCHED_USER_IDENTITY + /* Show the real and the effective user and group IDs */ + + if (tcb->group != NULL) + { + linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, + "%-12s%u %u\n%-12s%u %u\n", + "Uid:", tcb->group->tg_uid, + tcb->group->tg_euid, + "Gid:", tcb->group->tg_gid, + tcb->group->tg_egid); + copysize = procfs_memcpy(procfile->line, linesize, buffer, + remaining, &offset); + + totalsize += copysize; + buffer += copysize; + remaining -= copysize; + + if (totalsize >= buflen) + { + return totalsize; + } + } +#endif + #ifdef CONFIG_SMP if (tcb->task_state >= FIRST_ASSIGNED_STATE && tcb->task_state <= LAST_ASSIGNED_STATE) @@ -2196,6 +2225,19 @@ static int proc_stat(const char *relpath, struct stat *buf) /* Was the <pid> the final element of the path? */ memset(buf, 0, sizeof(struct stat)); + +#ifdef CONFIG_SCHED_USER_IDENTITY + /* The directory and its files belong to the effective user and group of + * the task group. + */ + + if (tcb->group != NULL) + { + buf->st_uid = tcb->group->tg_euid; + buf->st_gid = tcb->group->tg_egid; + } +#endif + if (*ptr == '\0' || strcmp(ptr, "/") == 0) { /* Yes ... It's a read-only directory */
