2 * Automated Testing Framework (atf)
4 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #if defined(HAVE_CONFIG_H)
34 #include <sys/types.h>
40 #include "atf-c/error.h"
41 #include "atf-c/sanity.h"
42 #include "atf-c/signals.h"
44 const int atf_signals_last_signo
= LAST_SIGNO
;
46 /* ---------------------------------------------------------------------
47 * The "atf_signal_holder" type.
48 * --------------------------------------------------------------------- */
50 static bool happened
[LAST_SIGNO
+ 1];
54 holder_handler(int signo
)
56 happened
[signo
] = true;
60 * Constructors/destructors.
64 atf_signal_holder_init(atf_signal_holder_t
*sh
, int signo
)
68 err
= atf_signal_programmer_init(&sh
->m_sp
, signo
, holder_handler
);
69 if (atf_is_error(err
))
72 atf_object_init(&sh
->m_object
);
74 happened
[signo
] = false;
76 INV(!atf_is_error(err
));
82 atf_signal_holder_fini(atf_signal_holder_t
*sh
)
84 atf_signal_programmer_fini(&sh
->m_sp
);
86 if (happened
[sh
->m_signo
])
87 kill(getpid(), sh
->m_signo
);
89 atf_object_fini(&sh
->m_object
);
97 atf_signal_holder_process(atf_signal_holder_t
*sh
)
99 if (happened
[sh
->m_signo
]) {
103 atf_signal_programmer_fini(&sh
->m_sp
);
104 happened
[sh
->m_signo
] = false;
106 ret
= kill(getpid(), sh
->m_signo
);
109 err
= atf_signal_programmer_init(&sh
->m_sp
, sh
->m_signo
,
111 INV(!atf_is_error(err
));
115 /* ---------------------------------------------------------------------
116 * The "atf_signal_programmer" type.
117 * --------------------------------------------------------------------- */
120 * Constructors/destructors.
124 atf_signal_programmer_init(atf_signal_programmer_t
*sp
, int signo
,
125 atf_signal_handler_t handler
)
130 sa
.sa_handler
= handler
;
131 sigemptyset(&sa
.sa_mask
);
134 if (sigaction(signo
, &sa
, &sp
->m_oldsa
) == -1)
135 err
= atf_libc_error(errno
, "Failed to program signal %d", signo
);
137 atf_object_init(&sp
->m_object
);
139 err
= atf_no_error();
146 atf_signal_programmer_fini(atf_signal_programmer_t
*sp
)
148 if (sigaction(sp
->m_signo
, &sp
->m_oldsa
, NULL
) == -1)
151 atf_object_fini(&sp
->m_object
);
154 /* ---------------------------------------------------------------------
156 * --------------------------------------------------------------------- */
159 atf_signal_reset(int signo
)
163 sa
.sa_handler
= SIG_DFL
;
164 sigemptyset(&sa
.sa_mask
);
167 (void)sigaction(signo
, &sa
, NULL
);