1*3a90a445SMark Johnston /*-
2*3a90a445SMark Johnston * SPDX-License-Identifier: BSD-2-Clause
3*3a90a445SMark Johnston *
4*3a90a445SMark Johnston * Copyright (c) 2023 Andreas Bock <[email protected]>
5*3a90a445SMark Johnston * Copyright (c) 2023 Mark Johnston <[email protected]>
6*3a90a445SMark Johnston *
7*3a90a445SMark Johnston * Redistribution and use in source and binary forms, with or without
8*3a90a445SMark Johnston * modification, are permitted provided that the following conditions are
9*3a90a445SMark Johnston * met:
10*3a90a445SMark Johnston * 1. Redistributions of source code must retain the above copyright
11*3a90a445SMark Johnston * notice, this list of conditions and the following disclaimer.
12*3a90a445SMark Johnston * 2. Redistributions in binary form must reproduce the above copyright
13*3a90a445SMark Johnston * notice, this list of conditions and the following disclaimer in
14*3a90a445SMark Johnston * the documentation and/or other materials provided with the distribution.
15*3a90a445SMark Johnston *
16*3a90a445SMark Johnston * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*3a90a445SMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*3a90a445SMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*3a90a445SMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*3a90a445SMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*3a90a445SMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*3a90a445SMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*3a90a445SMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*3a90a445SMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*3a90a445SMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*3a90a445SMark Johnston * SUCH DAMAGE.
27*3a90a445SMark Johnston */
28*3a90a445SMark Johnston
29*3a90a445SMark Johnston #include <sys/event.h>
30*3a90a445SMark Johnston #include <sys/wait.h>
31*3a90a445SMark Johnston
32*3a90a445SMark Johnston #include <err.h>
33*3a90a445SMark Johnston #include <signal.h>
34*3a90a445SMark Johnston #include <unistd.h>
35*3a90a445SMark Johnston
36*3a90a445SMark Johnston #include <atf-c.h>
37*3a90a445SMark Johnston
38*3a90a445SMark Johnston /*
39*3a90a445SMark Johnston * A regression test for bugzilla 275286.
40*3a90a445SMark Johnston */
41*3a90a445SMark Johnston ATF_TC_WITHOUT_HEAD(shared_table_filt_sig);
ATF_TC_BODY(shared_table_filt_sig,tc)42*3a90a445SMark Johnston ATF_TC_BODY(shared_table_filt_sig, tc)
43*3a90a445SMark Johnston {
44*3a90a445SMark Johnston struct sigaction sa;
45*3a90a445SMark Johnston pid_t pid;
46*3a90a445SMark Johnston int error, status;
47*3a90a445SMark Johnston
48*3a90a445SMark Johnston sa.sa_handler = SIG_IGN;
49*3a90a445SMark Johnston sigemptyset(&sa.sa_mask);
50*3a90a445SMark Johnston sa.sa_flags = 0;
51*3a90a445SMark Johnston error = sigaction(SIGINT, &sa, NULL);
52*3a90a445SMark Johnston ATF_REQUIRE(error == 0);
53*3a90a445SMark Johnston
54*3a90a445SMark Johnston pid = rfork(RFPROC);
55*3a90a445SMark Johnston ATF_REQUIRE(pid != -1);
56*3a90a445SMark Johnston if (pid == 0) {
57*3a90a445SMark Johnston struct kevent ev;
58*3a90a445SMark Johnston int kq;
59*3a90a445SMark Johnston
60*3a90a445SMark Johnston kq = kqueue();
61*3a90a445SMark Johnston if (kq < 0)
62*3a90a445SMark Johnston err(1, "kqueue");
63*3a90a445SMark Johnston EV_SET(&ev, SIGINT, EVFILT_SIGNAL, EV_ADD | EV_ENABLE, 0, 0,
64*3a90a445SMark Johnston NULL);
65*3a90a445SMark Johnston if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0)
66*3a90a445SMark Johnston err(2, "kevent");
67*3a90a445SMark Johnston if (kevent(kq, NULL, 0, &ev, 1, NULL) < 0)
68*3a90a445SMark Johnston err(3, "kevent");
69*3a90a445SMark Johnston _exit(0);
70*3a90a445SMark Johnston }
71*3a90a445SMark Johnston
72*3a90a445SMark Johnston /* Wait for the child to block in kevent(). */
73*3a90a445SMark Johnston usleep(100000);
74*3a90a445SMark Johnston
75*3a90a445SMark Johnston error = kill(pid, SIGINT);
76*3a90a445SMark Johnston ATF_REQUIRE(error == 0);
77*3a90a445SMark Johnston
78*3a90a445SMark Johnston error = waitpid(pid, &status, 0);
79*3a90a445SMark Johnston ATF_REQUIRE(error != -1);
80*3a90a445SMark Johnston ATF_REQUIRE(WIFEXITED(status));
81*3a90a445SMark Johnston ATF_REQUIRE_EQ(WEXITSTATUS(status), 0);
82*3a90a445SMark Johnston }
83*3a90a445SMark Johnston
ATF_TP_ADD_TCS(tp)84*3a90a445SMark Johnston ATF_TP_ADD_TCS(tp)
85*3a90a445SMark Johnston {
86*3a90a445SMark Johnston ATF_TP_ADD_TC(tp, shared_table_filt_sig);
87*3a90a445SMark Johnston
88*3a90a445SMark Johnston return (atf_no_error());
89*3a90a445SMark Johnston }
90