From 29238498b6e37aa504f285a23f103e950a243a43 Mon Sep 17 00:00:00 2001 From: Benjamin Lamowski Date: Mon, 24 Apr 2023 11:27:28 +0200 Subject: [PATCH] libc: implement signal(3) Fixes #4824 --- repos/libports/src/lib/libc/dummies.cc | 1 - repos/libports/src/lib/libc/signal.cc | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/repos/libports/src/lib/libc/dummies.cc b/repos/libports/src/lib/libc/dummies.cc index b1ad23c7ce..4d654c9dee 100644 --- a/repos/libports/src/lib/libc/dummies.cc +++ b/repos/libports/src/lib/libc/dummies.cc @@ -129,7 +129,6 @@ DUMMY(int , -1, sched_setparam, (pid_t, const sched_param *)) DUMMY(int , -1, sched_setscheduler, (pid_t, int, const sched_param *)) DUMMY(int , -1, sched_yield, (void)) DUMMY(int , -1, __semctl, (void)) -DUMMY_SILENT(sig_t, SIG_ERR, signal, (int, sig_t)); DUMMY_SILENT(int , -1, sigaltstack, (const stack_t *, stack_t *)) DUMMY(int , -1, setegid, (uid_t)) DUMMY(int , -1, seteuid, (uid_t)) diff --git a/repos/libports/src/lib/libc/signal.cc b/repos/libports/src/lib/libc/signal.cc index a08854a8c0..cf9740a096 100644 --- a/repos/libports/src/lib/libc/signal.cc +++ b/repos/libports/src/lib/libc/signal.cc @@ -131,6 +131,19 @@ extern "C" int sigaction(int signum, const struct sigaction *act, struct sigacti } +extern "C" __sighandler_t * signal(int sig, __sighandler_t * func) +{ + struct sigaction oact { }, act { }; + act.sa_handler = func; + + if (sigaction(sig, &act, &oact) == 0) + return oact.sa_handler; + + errno = EINVAL; + return SIG_ERR; +} + + extern "C" int _sigaction(int, const struct sigaction *, struct sigaction *) __attribute__((weak, alias("sigaction"))); extern "C" int __sys_sigaction(int, const struct sigaction *, struct sigaction *) __attribute__((weak, alias("sigaction"))); extern "C" int __libc_sigaction(int, const struct sigaction *, struct sigaction *) __attribute__((weak, alias("sigaction")));