RT-Thread / RT-Thread/rt-thread
[Feature] sigaction support siginfo
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
Describe problem solved by the proposed feature
sigaction信号处理支持siginfo。多个软件timer就可以使用一个信号处理函数,通过sigval进行区分。同时某些可能使用到信号的设备驱动也能传递更多的参数到用户层。
Describe your preferred solution
比如下面的例子
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define CLOCKID CLOCK_REALTIME
#define SIG SIGRTMIN
#define errExit(msg) \
do { \
perror(msg); \
exit(EXIT_FAILURE); \
} while (0)
static void print_siginfo(siginfo_t* si)
{
timer_t* tidp;
tidp = si->si_value.sival_ptr;
printf("si_signo = %d\n", si->si_signo);
printf("si_code = %d\n", si->si_code);
printf("si_errno = %d\n", si->si_errno);
printf("timer ID is %#lx\n", (uintmax_t)*tidp);
}
static void handler(int sig, siginfo_t* si, void* uc)
{
printf("Caught signal %d\n", sig);
print_siginfo(si);
}
int main(int argc, char* argv[])
{
timer_t timerid;
struct sigevent sev;
struct sigaction sa;
struct itimerspec its;
/* Establish handler for timer signal. */
printf("Establishing handler for signal %d\n", SIG);
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIG, &sa, NULL) == -1)
errExit("sigaction");
/* Create the timer. */
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIG;
sev.sigev_value.sival_ptr = &timerid;
if (timer_create(CLOCKID, &sev, &timerid) == -1)
errExit("timer_create");
printf("timer ID is %#lx\n", (uintmax_t)timerid);
/* Start the timer. */
its.it_value.tv_sec = 1;
its.it_value.tv_nsec = 0;
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
if (timer_settime(timerid, 0, &its, NULL) == -1)
errExit("timer_settime");
sleep(2);
exit(EXIT_SUCCESS);
}
Describe possible alternatives
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files, tests, or entry points; it provides a C example using sigaction, SA_SIGINFO, siginfo_t, and timer signals. Start by locating the existing signal-handling implementation and tests, then determine how the requested siginfo data should be exposed. Done means the API supports the described handler and timer use case with coverage for the new behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100