1*09d4459fSDaniel Fojt /* Convenience declarations when working with <signal.h>. 2*09d4459fSDaniel Fojt 3*09d4459fSDaniel Fojt Copyright (C) 2008-2020 Free Software Foundation, Inc. 4*09d4459fSDaniel Fojt 5*09d4459fSDaniel Fojt This program is free software: you can redistribute it and/or modify 6*09d4459fSDaniel Fojt it under the terms of the GNU General Public License as published by 7*09d4459fSDaniel Fojt the Free Software Foundation; either version 3 of the License, or 8*09d4459fSDaniel Fojt (at your option) any later version. 9*09d4459fSDaniel Fojt 10*09d4459fSDaniel Fojt This program is distributed in the hope that it will be useful, 11*09d4459fSDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 12*09d4459fSDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*09d4459fSDaniel Fojt GNU General Public License for more details. 14*09d4459fSDaniel Fojt 15*09d4459fSDaniel Fojt You should have received a copy of the GNU General Public License 16*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 17*09d4459fSDaniel Fojt 18*09d4459fSDaniel Fojt #ifndef _GL_SIG_HANDLER_H 19*09d4459fSDaniel Fojt #define _GL_SIG_HANDLER_H 20*09d4459fSDaniel Fojt 21*09d4459fSDaniel Fojt #include <signal.h> 22*09d4459fSDaniel Fojt 23*09d4459fSDaniel Fojt #ifndef _GL_INLINE_HEADER_BEGIN 24*09d4459fSDaniel Fojt #error "Please include config.h first." 25*09d4459fSDaniel Fojt #endif 26*09d4459fSDaniel Fojt _GL_INLINE_HEADER_BEGIN 27*09d4459fSDaniel Fojt #ifndef SIG_HANDLER_INLINE 28*09d4459fSDaniel Fojt # define SIG_HANDLER_INLINE _GL_INLINE 29*09d4459fSDaniel Fojt #endif 30*09d4459fSDaniel Fojt 31*09d4459fSDaniel Fojt /* Convenience type when working with signal handlers. */ 32*09d4459fSDaniel Fojt typedef void (*sa_handler_t) (int); 33*09d4459fSDaniel Fojt 34*09d4459fSDaniel Fojt /* Return the handler of a signal, as a sa_handler_t value regardless 35*09d4459fSDaniel Fojt of its true type. The resulting function can be compared to 36*09d4459fSDaniel Fojt special values like SIG_IGN but it is not portable to call it. */ 37*09d4459fSDaniel Fojt SIG_HANDLER_INLINE sa_handler_t _GL_ATTRIBUTE_PURE get_handler(struct sigaction const * a)38*09d4459fSDaniel Fojtget_handler (struct sigaction const *a) 39*09d4459fSDaniel Fojt { 40*09d4459fSDaniel Fojt /* POSIX says that special values like SIG_IGN can only occur when 41*09d4459fSDaniel Fojt action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4, 42*09d4459fSDaniel Fojt for example, sa_sigaction and sa_handler are aliases and a signal 43*09d4459fSDaniel Fojt is ignored if sa_sigaction (after casting) equals SIG_IGN. In 44*09d4459fSDaniel Fojt this case, this implementation relies on the fact that the two 45*09d4459fSDaniel Fojt are aliases, and simply returns sa_handler. */ 46*09d4459fSDaniel Fojt return a->sa_handler; 47*09d4459fSDaniel Fojt } 48*09d4459fSDaniel Fojt 49*09d4459fSDaniel Fojt _GL_INLINE_HEADER_END 50*09d4459fSDaniel Fojt 51*09d4459fSDaniel Fojt #endif /* _GL_SIG_HANDLER_H */ 52