diff options
Diffstat (limited to 'lib/libc/signal')
| -rw-r--r-- | lib/libc/signal/Kbuild | 1 | ||||
| -rw-r--r-- | lib/libc/signal/sig2str.c | 13 | ||||
| -rw-r--r-- | lib/libc/signal/sigabbrev.h | 22 | ||||
| -rw-r--r-- | lib/libc/signal/siglist.c | 47 | ||||
| -rw-r--r-- | lib/libc/signal/sysv_signal.c | 15 |
5 files changed, 93 insertions, 5 deletions
diff --git a/lib/libc/signal/Kbuild b/lib/libc/signal/Kbuild index b8881c92..f8122caf 100644 --- a/lib/libc/signal/Kbuild +++ b/lib/libc/signal/Kbuild @@ -19,3 +19,4 @@ obj-y += sigtimedwait.o obj-y += sigwait.o obj-y += sigwaitinfo.o obj-y += str2sig.o +obj-y += sysv_signal.o diff --git a/lib/libc/signal/sig2str.c b/lib/libc/signal/sig2str.c index 209cb4c3..2532d539 100644 --- a/lib/libc/signal/sig2str.c +++ b/lib/libc/signal/sig2str.c @@ -6,25 +6,28 @@ int sig2str(int signum, char *str) { if (signum >= SIGHUP && signum <= SIGSYS) { - strcpy(str, __sys_signame[signum - SIGHUP]); + strlcpy(str, __sys_signame[signum - SIGHUP], + sizeof(__sys_signame[signum - SIGHUP])); return 0; } if (signum == SIGRTMIN) { - strcpy(str, "SIGRTMIN"); + strlcpy(str, "SIGRTMIN", sizeof("SIGRTMIN")); return 0; } if (signum == SIGRTMAX) { - strcpy(str, "RTMAX"); + strlcpy(str, "SIGRTMAX", sizeof("SIGRTMAX")); return 0; } if (signum > SIGRTMIN && signum < SIGRTMAX) { if (signum - SIGRTMIN <= SIGRTMAX - signum) { - sprintf(str, "RTMIN+%d", signum - SIGRTMIN); + snprintf(str, sizeof("RTMIN+") + 1, "RTMIN+%d", + signum - SIGRTMIN); } else { - sprintf(str, "RTMAX-%d", SIGRTMAX - signum); + snprintf(str, sizeof("RTMAX-") + 1, "RTMAX-%d", + SIGRTMAX - signum); } return 0; } diff --git a/lib/libc/signal/sigabbrev.h b/lib/libc/signal/sigabbrev.h new file mode 100644 index 00000000..fa0ef1ce --- /dev/null +++ b/lib/libc/signal/sigabbrev.h @@ -0,0 +1,22 @@ +#include <signal.h> +#include <unistd.h> + +const char *const sys_sigabbrev[64] = { + [SIGABRT] = "ABRT", [SIGALRM] = "ALRM", [SIGBUS] = "BUS", + [SIGCHLD] = "CHLD", [SIGFPE] = "FPE", [SIGHUP] = "HUP", + [SIGILL] = "ILL", [SIGINT] = "INT", [SIGIO] = "IO", +#if defined(SIGIOT) && (SIGIOT != SIGABRT) + [SIGIOT] = "IOT", +#endif + [SIGKILL] = "KILL", [SIGPIPE] = "PIPE", +#if defined(SIGPOLL) && (SIGPOLL != SIGIO) + [SIGPOLL] = "POLL", +#endif + [SIGPROF] = "PROF", [SIGPWR] = "PWR", [SIGQUIT] = "QUIT", + [SIGSEGV] = "SEGV", [SIGSTKFLT] = "STKFLT", [SIGSTOP] = "STOP", + [SIGSYS] = "SYS", [SIGTERM] = "TERM", [SIGTSTP] = "TSTP", + [SIGTTIN] = "TTIN", [SIGTTOU] = "TTOU", [SIGURG] = "URG", + [SIGUSR1] = "USR1", [SIGUSR2] = "USR2", [SIGVTALRM] = "VTALRM", + [SIGWINCH] = "WINCH", [SIGXCPU] = "XCPU", [SIGXFSZ] = "XFSZ", + [SIGCONT] = "CONT", [SIGTRAP] = "TRAP", +}; diff --git a/lib/libc/signal/siglist.c b/lib/libc/signal/siglist.c new file mode 100644 index 00000000..ba9ec746 --- /dev/null +++ b/lib/libc/signal/siglist.c @@ -0,0 +1,47 @@ +#include <signal.h> +#include <unistd.h> + +const char *const sys_siglist[64] = { + [SIGABRT] = "Aborted", + [SIGALRM] = "Alarm clock", + [SIGBUS] = "Bus error", + [SIGCHLD] = "Child exited", +#if defined(SIGCLD) && (SIGCHLD != SIGCLD) + [SIGCLD] = "Child exited", +#endif + [SIGHUP] = "Hangup", + [SIGILL] = "Illegal instruction", + [SIGINT] = "Interrupt", + [SIGIO] = "I/O possible", +#if defined(SIGIOT) && (SIGIOT != SIGABRT) + [SIGIOT] = "I/O trap", +#endif + [SIGKILL] = "Killed", +#if defined(SIGLOST) && (SIGLOST != SIGIO) && (SIGLOST != SIGPWR) + [SIGLOST] = "Lock lost", +#endif + [SIGPIPE] = "Broken pipe", +#if defined(SIGPOLL) && (SIGPOLL != SIGIO) + [SIGPOLL] = "Pollable event", +#endif + [SIGPROF] = "Profiling timer expired", + [SIGPWR] = "Power failure", + [SIGQUIT] = "Quit", + [SIGSEGV] = "Segment violation", + [SIGSTKFLT] = "Stack fault", + [SIGSTOP] = "Stopped (signal)", + [SIGSYS] = "Bad system call", + [SIGTERM] = "Terminated", + [SIGTSTP] = "Stopped", + [SIGTTIN] = "Stopped (tty input)", + [SIGTTOU] = "Stopped (tty output)", + [SIGURG] = "Urgent I/O condition", + [SIGUSR1] = "User signal 1", + [SIGUSR2] = "User signal 2", + [SIGVTALRM] = "Virtual timer expired", + [SIGWINCH] = "Window size changed", + [SIGXCPU] = "CPU time limit exceeded", + [SIGXFSZ] = "File size limit exceeded", + [SIGTRAP] = "Trace/breakpoint trap", + [SIGCONT] = "Continue", +}; diff --git a/lib/libc/signal/sysv_signal.c b/lib/libc/signal/sysv_signal.c new file mode 100644 index 00000000..2aa0221a --- /dev/null +++ b/lib/libc/signal/sysv_signal.c @@ -0,0 +1,15 @@ +#include <signal.h> + +sighandler_t sysv_signal(int signum, sighandler_t handler) +{ + struct sigaction new_action, old_action; + + new_action.sa_handler = handler; + sigemptyset(&new_action.sa_mask); + new_action.sa_flags = 0; + + if (sigaction(signum, &new_action, &old_action) < 0) + return SIG_ERR; + + return old_action.sa_handler; +} |
