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,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.253.88.132]) by gnuweeb.org (Postfix) with ESMTPSA id DBEC181A18; Thu, 22 Dec 2022 03:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671681144; bh=VUWgZx5aCGOd+rMsLp7+4gysuZVXd6vPkv96NwcpuWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qtf2fx3CmLBFG2dkzGK7t/5NNmia4RS1/LNt9kPbJxG/kh+CHXxF4xfS+R1JP5zjo T2ownYIeIUoiSPXCY+95CalZU5s8QHXrEylRROILdjmjt5ApwCuhmaaiTDowobCGn5 22yHxF9gdcDoYephNcVsv02j8mNYGt9BlcL253JdgFHT+dVvOSPLct2G+VfMH6n0xi 9Dthi66U2qU3ioEx/bIEIAHvQ2m1uGrJrjIXjCvgQakPxLHI/f4tLGQ0jqCNv185ma 0cNrVJS0RHFzqrfcxpBSnn44vM6GHoNVqy+fTtwGhHJvd5VXOy2i/2S3PDhu5Anb2N U9jCvUdu96y8A== From: Ammar Faizi To: Willy Tarreau , Shuah Khan , "Paul E. McKenney" Cc: Ammar Faizi , Gilang Fachrezy , VNLX Kernel Department , Alviro Iskandar Setiawan , Kanna Scarlet , Muhammad Rizki , GNU/Weeb Mailing List , Linux Kernel Mailing List , Linux Kselftest Mailing List Subject: [RFC PATCH v1 2/8] nolibc/sys: Implement `signal(2)` function Date: Thu, 22 Dec 2022 10:51:28 +0700 Message-Id: <20221222035134.3467659-3-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222035134.3467659-1-ammar.faizi@intel.com> References: <20221222035134.3467659-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(). This implementation is currently only available on the x86-64 arch. Signed-off-by: Ammar Faizi --- tools/include/nolibc/sys.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 91532a2fbe2c..ca348939eb50 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1106,6 +1106,36 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #endif } +/* + * sighandler_t signal(int signum, sighandler_t handler); + */ + +static __attribute__((unused)) +sighandler_t signal(int signum, sighandler_t handler) +{ +#ifdef __HAVE_ARCH_RESTORE_RT + const struct sigaction act = { + .sa_handler = handler, + .sa_flags = SA_RESTORER, + .sa_restorer = __arch_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; +#else + SET_ERRNO(ENOSYS); + return SIG_ERR; +#endif +} /* * int stat(const char *path, struct stat *buf); -- Ammar Faizi