From: Ammar Faizi <[email protected]>
To: Willy Tarreau <[email protected]>
Cc: Ammar Faizi <[email protected]>,
Shuah Khan <[email protected]>,
"Paul E. McKenney" <[email protected]>,
Gilang Fachrezy <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>,
GNU/Weeb Mailing List <[email protected]>,
Linux Kernel Mailing List <[email protected]>,
Linux Kselftest Mailing List <[email protected]>
Subject: [PATCH v3 2/5] nolibc/sys: Implement `signal(2)` function
Date: Sun, 8 Jan 2023 20:59:01 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
From: Ammar Faizi <[email protected]>
signal() function is the simpler version of sigaction(). Unlike
sigaction(), which fully controls the `struct sigaction`, the caller
only cares about the sa_handler when calling the signal() function.
signal() internally calls sigaction().
Signed-off-by: Ammar Faizi <[email protected]>
---
tools/include/nolibc/sys.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 7d594155e77f..54e51f154b1f 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -1119,6 +1119,31 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
return ret;
}
+/*
+ * sighandler_t signal(int signum, sighandler_t handler);
+ */
+
+static __attribute__((unused))
+sighandler_t signal(int signum, sighandler_t handler)
+{
+ const struct sigaction act = {
+ .sa_handler = handler,
+ .sa_flags = SA_RESTORER,
+ .sa_restorer = __restore_rt
+ };
+ sighandler_t old_sah;
+ struct sigaction old;
+ int ret;
+
+ ret = sys_sigaction(signum, &act, &old);
+ if (ret < 0) {
+ SET_ERRNO(-ret);
+ old_sah = SIG_ERR;
+ } else {
+ old_sah = old.sa_handler;
+ }
+ return old_sah;
+}
/*
* int stat(const char *path, struct stat *buf);
--
Ammar Faizi
next prev parent reply other threads:[~2023-01-08 13:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-08 13:58 [PATCH v3 0/5] nolibc signal handling support Ammar Faizi
2023-01-08 13:59 ` [PATCH v3 1/5] nolibc/sys: Implement `sigaction(2)` function Ammar Faizi
2023-01-08 13:59 ` Ammar Faizi [this message]
2023-01-08 13:59 ` [PATCH v3 3/5] selftests/nolibc: Add `fork(2)` selftest Ammar Faizi
2023-01-08 13:59 ` [PATCH v3 4/5] selftests/nolibc: Add `sigaction(2)` selftest Ammar Faizi
2023-01-08 13:59 ` [PATCH v3 5/5] selftests/nolibc: Add `signal(2)` selftest Ammar Faizi
2023-01-08 17:58 ` [PATCH v3 0/5] nolibc signal handling support Willy Tarreau
2023-01-08 18:31 ` Ammar Faizi
2023-01-08 18:49 ` Willy Tarreau
2023-01-15 16:01 ` Ammar Faizi
2023-01-15 17:06 ` Alviro Iskandar Setiawan
2023-01-17 23:17 ` Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox