|
Packit Service |
a2ae7a |
/* Test of sigaction() function.
|
|
Packit Service |
a2ae7a |
Copyright (C) 2008-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2ae7a |
(at your option) any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2ae7a |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Written by Eric Blake <ebb9@byu.net>, 2008. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <signal.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "signature.h"
|
|
Packit Service |
a2ae7a |
SIGNATURE_CHECK (sigaction, int, (int, struct sigaction const *,
|
|
Packit Service |
a2ae7a |
struct sigaction *));
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <stddef.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "macros.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#ifndef SA_NOCLDSTOP
|
|
Packit Service |
a2ae7a |
# define SA_NOCLDSTOP 0
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
#ifndef SA_ONSTACK
|
|
Packit Service |
a2ae7a |
# define SA_ONSTACK 0
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
#ifndef SA_RESETHAND
|
|
Packit Service |
a2ae7a |
# define SA_RESETHAND 0
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
#ifndef SA_RESTART
|
|
Packit Service |
a2ae7a |
# define SA_RESTART 0
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
#ifndef SA_SIGINFO
|
|
Packit Service |
a2ae7a |
# define SA_SIGINFO 0
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
#ifndef SA_NOCLDWAIT
|
|
Packit Service |
a2ae7a |
# define SA_NOCLDWAIT 0
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Define a mask of flags required by POSIX. Some implementations
|
|
Packit Service |
a2ae7a |
provide other flags as extensions, such as SA_RESTORER, that we
|
|
Packit Service |
a2ae7a |
must ignore in this test. */
|
|
Packit Service |
a2ae7a |
#define MASK_SA_FLAGS (SA_NOCLDSTOP | SA_ONSTACK | SA_RESETHAND | SA_RESTART \
|
|
Packit Service |
a2ae7a |
| SA_SIGINFO | SA_NOCLDWAIT | SA_NODEFER)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* This test is unsafe in the presence of an asynchronous SIGABRT,
|
|
Packit Service |
a2ae7a |
because we install a signal-handler that is intentionally not
|
|
Packit Service |
a2ae7a |
async-safe. Hopefully, this does not lead to too many reports of
|
|
Packit Service |
a2ae7a |
false failures, since people don't generally use 'kill -s SIGABRT'
|
|
Packit Service |
a2ae7a |
to end a runaway program. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
static void
|
|
Packit Service |
a2ae7a |
handler (int sig)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
static int entry_count;
|
|
Packit Service |
a2ae7a |
struct sigaction sa;
|
|
Packit Service |
a2ae7a |
ASSERT (sig == SIGABRT);
|
|
Packit Service |
a2ae7a |
ASSERT (sigaction (SIGABRT, NULL, &sa) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT ((sa.sa_flags & SA_SIGINFO) == 0);
|
|
Packit Service |
a2ae7a |
switch (entry_count++)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
case 0:
|
|
Packit Service |
a2ae7a |
ASSERT ((sa.sa_flags & SA_RESETHAND) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (sa.sa_handler == handler);
|
|
Packit Service |
a2ae7a |
break;
|
|
Packit Service |
a2ae7a |
case 1:
|
|
Packit Service |
a2ae7a |
/* This assertion fails on glibc-2.3.6 systems with LinuxThreads,
|
|
Packit Service |
a2ae7a |
when this program is linked with -lpthread, due to the sigaction()
|
|
Packit Service |
a2ae7a |
override in libpthread.so. */
|
|
Packit Service |
a2ae7a |
#if !(defined __GLIBC__ || defined __UCLIBC__)
|
|
Packit Service |
a2ae7a |
ASSERT (sa.sa_handler == SIG_DFL);
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
break;
|
|
Packit Service |
a2ae7a |
default:
|
|
Packit Service |
a2ae7a |
ASSERT (0);
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
main (void)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
struct sigaction sa;
|
|
Packit Service |
a2ae7a |
struct sigaction old_sa;
|
|
Packit Service |
a2ae7a |
sa.sa_handler = handler;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
sa.sa_flags = 0;
|
|
Packit Service |
a2ae7a |
ASSERT (sigemptyset (&sa.sa_mask) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (sigaction (SIGABRT, &sa, NULL) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (raise (SIGABRT) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
|
|
Packit Service |
a2ae7a |
ASSERT (sigaction (SIGABRT, &sa, &old_sa) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT ((old_sa.sa_flags & MASK_SA_FLAGS) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (old_sa.sa_handler == handler);
|
|
Packit Service |
a2ae7a |
ASSERT (raise (SIGABRT) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
sa.sa_handler = SIG_DFL;
|
|
Packit Service |
a2ae7a |
ASSERT (sigaction (SIGABRT, &sa, &old_sa) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT ((old_sa.sa_flags & SA_SIGINFO) == 0);
|
|
Packit Service |
a2ae7a |
#if !(defined __GLIBC__ || defined __UCLIBC__) /* see above */
|
|
Packit Service |
a2ae7a |
ASSERT (old_sa.sa_handler == SIG_DFL);
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
sa.sa_handler = SIG_IGN;
|
|
Packit Service |
a2ae7a |
ASSERT (sigaction (SIGABRT, &sa, NULL) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (raise (SIGABRT) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (sigaction (SIGABRT, NULL, &old_sa) == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (old_sa.sa_handler == SIG_IGN);
|
|
Packit Service |
a2ae7a |
ASSERT (raise (SIGABRT) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
return 0;
|
|
Packit Service |
a2ae7a |
}
|