|
Packit |
33f14e |
/* Convenience declarations when working with <signal.h>.
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
Copyright (C) 2008-2017 Free Software Foundation, Inc.
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
33f14e |
it under the terms of the GNU General Public License as published by
|
|
Packit |
33f14e |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
33f14e |
(at your option) any later version.
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
This program is distributed in the hope that it will be useful,
|
|
Packit |
33f14e |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
33f14e |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
33f14e |
GNU General Public License for more details.
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
You should have received a copy of the GNU General Public License
|
|
Packit |
33f14e |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
#ifndef _GL_SIG_HANDLER_H
|
|
Packit |
33f14e |
#define _GL_SIG_HANDLER_H
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
#include <signal.h>
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
#ifndef _GL_INLINE_HEADER_BEGIN
|
|
Packit |
33f14e |
#error "Please include config.h first."
|
|
Packit |
33f14e |
#endif
|
|
Packit |
33f14e |
_GL_INLINE_HEADER_BEGIN
|
|
Packit |
33f14e |
#ifndef SIG_HANDLER_INLINE
|
|
Packit |
33f14e |
# define SIG_HANDLER_INLINE _GL_INLINE
|
|
Packit |
33f14e |
#endif
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
/* Convenience type when working with signal handlers. */
|
|
Packit |
33f14e |
typedef void (*sa_handler_t) (int);
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
/* Return the handler of a signal, as a sa_handler_t value regardless
|
|
Packit |
33f14e |
of its true type. The resulting function can be compared to
|
|
Packit |
33f14e |
special values like SIG_IGN but it is not portable to call it. */
|
|
Packit |
33f14e |
SIG_HANDLER_INLINE sa_handler_t _GL_ATTRIBUTE_PURE
|
|
Packit |
33f14e |
get_handler (struct sigaction const *a)
|
|
Packit |
33f14e |
{
|
|
Packit |
33f14e |
#ifdef SA_SIGINFO
|
|
Packit |
33f14e |
/* POSIX says that special values like SIG_IGN can only occur when
|
|
Packit |
33f14e |
action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4,
|
|
Packit |
33f14e |
for example, sa_sigaction and sa_handler are aliases and a signal
|
|
Packit |
33f14e |
is ignored if sa_sigaction (after casting) equals SIG_IGN. So
|
|
Packit |
33f14e |
use (and cast) sa_sigaction in that case. */
|
|
Packit |
33f14e |
if (a->sa_flags & SA_SIGINFO)
|
|
Packit |
33f14e |
return (sa_handler_t) a->sa_sigaction;
|
|
Packit |
33f14e |
#endif
|
|
Packit |
33f14e |
return a->sa_handler;
|
|
Packit |
33f14e |
}
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
_GL_INLINE_HEADER_END
|
|
Packit |
33f14e |
|
|
Packit |
33f14e |
#endif /* _GL_SIG_HANDLER_H */
|