From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.253.183.184]) by gnuweeb.org (Postfix) with ESMTPSA id CD0CA7E6E2; Sun, 8 Jan 2023 13:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673186357; bh=qZ0V/QjSoT8k1kLlfLdweTxUATQfYPsfP6+ph+Sfr8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RB64m+AB1XK8vdgDRU/KjXiWnlN2eQoEmCPrdjyFaGEGDB06IKlgbodUBwbI6Exje Om7eSpgg/hsKm4jwktmOEvyxOqFeZ2k4t1G/PpWOoX7P78HhtRVAoy73NcwlM0rx+W PlEs1vWkH1HB8xEPUZvCn0s2jKkLdHUsTtBTUVbhnR6aBKggEM7GiMtBeyBO+mdktV iSmO6GJTUYCE97dbx69U+DdNdkk2ssU8PSQjrbzljfAtQ5kFew0U4xXxnmffoXJ0hf ZxTdYvG4bKnzGnlLXFh12XfGHqAn98qva1wcR3/AAJvljMv2xn+TLkTNA6EgAQx5bp IOejifY8aBBqA== From: Ammar Faizi To: Willy Tarreau Cc: Ammar Faizi , Shuah Khan , "Paul E. McKenney" , Gilang Fachrezy , Alviro Iskandar Setiawan , GNU/Weeb Mailing List , Linux Kernel Mailing List , Linux Kselftest Mailing List Subject: [PATCH v3 2/5] nolibc/sys: Implement `signal(2)` function Date: Sun, 8 Jan 2023 20:59:01 +0700 Message-Id: <20230108135904.851762-3-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108135904.851762-1-ammar.faizi@intel.com> References: <20230108135904.851762-1-ammar.faizi@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi 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 --- 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