166d00febSPaula Toth //===-- Linux implementation of signal ------------------------------------===// 2ca04d0c8SAlex Brachet // 3ca04d0c8SAlex Brachet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4ca04d0c8SAlex Brachet // See https://llvm.org/LICENSE.txt for license information. 5ca04d0c8SAlex Brachet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ca04d0c8SAlex Brachet // 7ca04d0c8SAlex Brachet //===----------------------------------------------------------------------===// 8ca04d0c8SAlex Brachet 9ca04d0c8SAlex Brachet #include "src/signal/signal.h" 10133492feSSchrodinger ZHU Yifan #include "hdr/signal_macros.h" 11*73514f68Swldfngrs #include "hdr/types/sighandler_t.h" 12ca04d0c8SAlex Brachet #include "src/__support/common.h" 135ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 14133492feSSchrodinger ZHU Yifan #include "src/signal/sigaction.h" 15215c9fa4SSiva Chandra Reddy 165ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 17ca04d0c8SAlex Brachet 18a0b65a7bSMichael Jones LLVM_LIBC_FUNCTION(sighandler_t, signal, (int signum, sighandler_t handler)) { 19215c9fa4SSiva Chandra Reddy struct sigaction action, old; 20ca04d0c8SAlex Brachet action.sa_handler = handler; 21ca04d0c8SAlex Brachet action.sa_flags = SA_RESTART; 22ca04d0c8SAlex Brachet // Errno will already be set so no need to worry about changing errno here. 23b6bc9d72SGuillaume Chatelet return LIBC_NAMESPACE::sigaction(signum, &action, &old) == -1 24b6bc9d72SGuillaume Chatelet ? SIG_ERR 25ca04d0c8SAlex Brachet : old.sa_handler; 26ca04d0c8SAlex Brachet } 27ca04d0c8SAlex Brachet 285ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 29