1 //===-- Linux implementation of signal ------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #define __LLVM_LIBC_INTERNAL_SIGACTION 10 #include "src/signal/signal.h" 11 #include "src/signal/sigaction.h" 12 13 #include "src/__support/common.h" 14 15 namespace __llvm_libc { 16 LLVM_LIBC_ENTRYPOINT(signal)17sighandler_t LLVM_LIBC_ENTRYPOINT(signal)(int signum, sighandler_t handler) { 18 struct __sigaction action, old; 19 action.sa_handler = handler; 20 action.sa_flags = SA_RESTART; 21 // Errno will already be set so no need to worry about changing errno here. 22 return __llvm_libc::sigaction(signum, &action, &old) == -1 ? SIG_ERR 23 : old.sa_handler; 24 } 25 26 } // namespace __llvm_libc 27