This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e232af68d7ca633b5a768cbf155c4005456730e7 Author: Marco Casaroli <[email protected]> AuthorDate: Sat Oct 17 19:57:49 2026 +0200 signal: Add si_uid to siginfo_t. POSIX requires the si_uid member in siginfo_t. It is the real user ID of the process that sent the signal. NuttX has si_pid, but it does not have si_uid. Add si_uid next to si_pid, under the same CONFIG_SCHED_HAVE_PARENT condition. kill(), tgkill(), sigqueue(), pthread_sigqueue() and the sigevent notifications set it to the real user ID of the sender. SIGCHLD and waitid() set it to the real user ID of the child when it exited. For waitid(), the child status keeps this value in a new ch_uid member, only with CONFIG_SCHED_USER_IDENTITY. Without CONFIG_SCHED_USER_IDENTITY, the value is always 0. Each other place that sets si_pid sets si_uid to 0. signalfd() now also returns the value in ssi_uid. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- fs/vfs/fs_signalfd.c | 1 + include/nuttx/sched.h | 3 +++ include/signal.h | 1 + sched/pthread/pthread_sigqueue.c | 2 ++ sched/sched/sched_waitid.c | 5 +++++ sched/signal/sig_clockwait.c | 1 + sched/signal/sig_kill.c | 2 ++ sched/signal/sig_notification.c | 2 ++ sched/signal/sig_queue.c | 2 ++ sched/signal/sig_tgkill.c | 2 ++ sched/task/task_exithook.c | 23 ++++++++++++++++++----- sched/task/task_setup.c | 3 +++ 12 files changed, 42 insertions(+), 5 deletions(-) diff --git a/fs/vfs/fs_signalfd.c b/fs/vfs/fs_signalfd.c index 9a3da538a3b..390991d1830 100644 --- a/fs/vfs/fs_signalfd.c +++ b/fs/vfs/fs_signalfd.c @@ -207,6 +207,7 @@ static ssize_t signalfd_file_read(FAR struct file *filep, siginfo->ssi_code = info.si_code; #ifdef CONFIG_SCHED_HAVE_PARENT siginfo->ssi_pid = info.si_pid; + siginfo->ssi_uid = info.si_uid; siginfo->ssi_status = info.si_status; #endif siginfo->ssi_int = info.si_value.sival_int; diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 76ea460379e..cf08f12e2a7 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -366,6 +366,9 @@ struct child_status_s uint8_t ch_flags; /* Child status: See CHILD_FLAG_* defines */ pid_t ch_pid; /* Child task ID */ int ch_status; /* Child exit status */ +#ifdef CONFIG_SCHED_USER_IDENTITY + uid_t ch_uid; /* Child real user ID at exit */ +#endif }; #endif diff --git a/include/signal.h b/include/signal.h index 99bade0f945..ecf67334a0d 100644 --- a/include/signal.h +++ b/include/signal.h @@ -383,6 +383,7 @@ struct siginfo union sigval si_value; /* Data passed with signal */ #ifdef CONFIG_SCHED_HAVE_PARENT pid_t si_pid; /* Sending task ID */ + uid_t si_uid; /* Real user ID of sending task */ int si_status; /* Exit value or signal (SIGCHLD only). */ #endif #if 0 /* Not implemented */ diff --git a/sched/pthread/pthread_sigqueue.c b/sched/pthread/pthread_sigqueue.c index 2819e00dff5..e8dfbfa6ded 100644 --- a/sched/pthread/pthread_sigqueue.c +++ b/sched/pthread/pthread_sigqueue.c @@ -30,6 +30,7 @@ #include <nuttx/debug.h> #include <pthread.h> #include <signal.h> +#include <unistd.h> #include <nuttx/signal.h> @@ -65,6 +66,7 @@ int pthread_sigqueue(pthread_t thread, int sig, const union sigval value) info.si_value = value; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = rtcb->pid; + info.si_uid = getuid(); info.si_status = OK; #endif info.si_user = NULL; /* Will be set in sig_dispatch.c */ diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index ca7525cd778..8d78733736a 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -69,6 +69,11 @@ static void exited_child(FAR struct tcb_s *rtcb, info->si_errno = OK; info->si_value.sival_ptr = NULL; info->si_pid = child->ch_pid; +#ifdef CONFIG_SCHED_USER_IDENTITY + info->si_uid = child->ch_uid; +#else + info->si_uid = 0; +#endif info->si_status = child->ch_status; } diff --git a/sched/signal/sig_clockwait.c b/sched/signal/sig_clockwait.c index 972e484f687..c5a1b418efa 100644 --- a/sched/signal/sig_clockwait.c +++ b/sched/signal/sig_clockwait.c @@ -122,6 +122,7 @@ void nxsig_wait_irq(FAR struct tcb_s *wtcb, uint8_t signo, wtcb->sigunbinfo->si_value.sival_int = 0; # ifdef CONFIG_SCHED_HAVE_PARENT wtcb->sigunbinfo->si_pid = 0; /* Not applicable */ + wtcb->sigunbinfo->si_uid = 0; /* Not applicable */ wtcb->sigunbinfo->si_status = OK; # endif } diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 16927138eb8..f2df8d20ed0 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -29,6 +29,7 @@ #include <sys/types.h> #include <sched.h> #include <errno.h> +#include <unistd.h> #include <nuttx/debug.h> #include <nuttx/signal.h> @@ -114,6 +115,7 @@ int nxsig_kill(pid_t pid, int signo) info.si_value.sival_ptr = NULL; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = rtcb->pid; + info.si_uid = getuid(); info.si_status = OK; #endif diff --git a/sched/signal/sig_notification.c b/sched/signal/sig_notification.c index 2a3778f2ef6..b4389cdffde 100644 --- a/sched/signal/sig_notification.c +++ b/sched/signal/sig_notification.c @@ -30,6 +30,7 @@ #include <string.h> #include <signal.h> #include <assert.h> +#include <unistd.h> #include <nuttx/debug.h> #include <nuttx/signal.h> @@ -179,6 +180,7 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event, info.si_errno = OK; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = this_task()->pid; + info.si_uid = getuid(); info.si_status = OK; #endif info.si_user = NULL; diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index cd17c60b0a5..96fb9b7ba24 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -31,6 +31,7 @@ #include <nuttx/debug.h> #include <sched.h> #include <errno.h> +#include <unistd.h> #include <nuttx/signal.h> @@ -100,6 +101,7 @@ int nxsig_queue(int pid, int signo, union sigval value) info.si_value = value; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = rtcb->pid; + info.si_uid = getuid(); info.si_status = OK; #endif info.si_user = NULL; /* Will be set in sig_dispatch.c */ diff --git a/sched/signal/sig_tgkill.c b/sched/signal/sig_tgkill.c index c1d09be9cae..1c13c4ccc52 100644 --- a/sched/signal/sig_tgkill.c +++ b/sched/signal/sig_tgkill.c @@ -28,6 +28,7 @@ #include <signal.h> #include <errno.h> +#include <unistd.h> #include <nuttx/sched.h> #include <nuttx/signal.h> @@ -107,6 +108,7 @@ int nxsig_tgkill(pid_t pid, pid_t tid, int signo) info.si_value.sival_ptr = NULL; #ifdef CONFIG_SCHED_HAVE_PARENT info.si_pid = rtcb->pid; + info.si_uid = getuid(); info.si_status = OK; #endif diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index 8094c207ca0..e1852aab872 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -56,7 +56,7 @@ #ifdef CONFIG_SCHED_CHILD_STATUS static inline void nxtask_exitstatus(FAR struct task_group_s *group, - pid_t pid, int status) + FAR struct tcb_s *ctcb, int status) { FAR struct child_status_s *child; @@ -68,7 +68,7 @@ static inline void nxtask_exitstatus(FAR struct task_group_s *group, { /* No.. Find the exit status entry for this task in the parent TCB */ - child = group_find_child(group, pid); + child = group_find_child(group, ctcb->pid); if (child) { /* Save the exit status.. For the case of HAVE_GROUP_MEMBERS, @@ -77,6 +77,9 @@ static inline void nxtask_exitstatus(FAR struct task_group_s *group, */ child->ch_status = status; +#ifdef CONFIG_SCHED_USER_IDENTITY + child->ch_uid = ctcb->group->tg_uid; +#endif } } @@ -84,7 +87,7 @@ static inline void nxtask_exitstatus(FAR struct task_group_s *group, } #else -# define nxtask_exitstatus(group,pid,status) (group)->tg_exitcode = (status); +# define nxtask_exitstatus(group,ctcb,status) (group)->tg_exitcode = (status); #endif /* CONFIG_SCHED_CHILD_STATUS */ @@ -170,7 +173,7 @@ static inline void nxtask_sigchild(pid_t ppid, FAR struct tcb_s *ctcb, if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) #endif { - nxtask_exitstatus(pgrp, ctcb->pid, status); + nxtask_exitstatus(pgrp, ctcb, status); } /* But only the final exiting thread in a task group, whatever it is, @@ -193,6 +196,11 @@ static inline void nxtask_sigchild(pid_t ppid, FAR struct tcb_s *ctcb, info.si_errno = OK; info.si_value.sival_ptr = NULL; info.si_pid = chgrp->tg_pid; +#ifdef CONFIG_SCHED_USER_IDENTITY + info.si_uid = chgrp->tg_uid; +#else + info.si_uid = 0; +#endif info.si_status = pgrp->tg_exitcode; /* Send the signal to one thread in the group */ @@ -220,7 +228,7 @@ static inline void nxtask_sigchild(FAR struct tcb_s *ptcb, #ifdef CONFIG_SCHED_CHILD_STATUS /* Save the exit status now of the main thread */ - nxtask_exitstatus(ptcb->group, ctcb->pid, status); + nxtask_exitstatus(ptcb->group, ctcb, status); #else /* CONFIG_SCHED_CHILD_STATUS */ /* Exit status is not retained. Just decrement the number of @@ -242,6 +250,11 @@ static inline void nxtask_sigchild(FAR struct tcb_s *ptcb, info.si_errno = OK; info.si_value.sival_ptr = NULL; info.si_pid = ctcb->group->tg_pid; +#ifdef CONFIG_SCHED_USER_IDENTITY + info.si_uid = ctcb->group->tg_uid; +#else + info.si_uid = 0; +#endif info.si_status = status; /* Send the signal. We need to use this internal interface so that we diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index b418f313481..72eb2f10d49 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -304,6 +304,9 @@ static inline void nxtask_save_parent(FAR struct tcb_s *tcb, uint8_t ttype) child->ch_flags = ttype; child->ch_pid = tcb->pid; child->ch_status = 0; +#ifdef CONFIG_SCHED_USER_IDENTITY + child->ch_uid = 0; +#endif /* Add the entry into the group's list of children */
