1*cb71f1faSJilles Tjoelker /*-
2*cb71f1faSJilles Tjoelker * Copyright (c) 2018 Jilles Tjoelker
3*cb71f1faSJilles Tjoelker * All rights reserved.
4*cb71f1faSJilles Tjoelker *
5*cb71f1faSJilles Tjoelker * Redistribution and use in source and binary forms, with or without
6*cb71f1faSJilles Tjoelker * modification, are permitted provided that the following conditions
7*cb71f1faSJilles Tjoelker * are met:
8*cb71f1faSJilles Tjoelker * 1. Redistributions of source code must retain the above copyright
9*cb71f1faSJilles Tjoelker * notice, this list of conditions and the following disclaimer.
10*cb71f1faSJilles Tjoelker * 2. Redistributions in binary form must reproduce the above copyright
11*cb71f1faSJilles Tjoelker * notice, this list of conditions and the following disclaimer in the
12*cb71f1faSJilles Tjoelker * documentation and/or other materials provided with the distribution.
13*cb71f1faSJilles Tjoelker *
14*cb71f1faSJilles Tjoelker * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*cb71f1faSJilles Tjoelker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*cb71f1faSJilles Tjoelker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*cb71f1faSJilles Tjoelker * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*cb71f1faSJilles Tjoelker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*cb71f1faSJilles Tjoelker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*cb71f1faSJilles Tjoelker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*cb71f1faSJilles Tjoelker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*cb71f1faSJilles Tjoelker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*cb71f1faSJilles Tjoelker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*cb71f1faSJilles Tjoelker * SUCH DAMAGE.
25*cb71f1faSJilles Tjoelker */
26*cb71f1faSJilles Tjoelker
27*cb71f1faSJilles Tjoelker #include <sys/cdefs.h>
28*cb71f1faSJilles Tjoelker #include <sys/wait.h>
29*cb71f1faSJilles Tjoelker
30*cb71f1faSJilles Tjoelker #include <atf-c.h>
31*cb71f1faSJilles Tjoelker #include <signal.h>
32*cb71f1faSJilles Tjoelker #include <unistd.h>
33*cb71f1faSJilles Tjoelker
34*cb71f1faSJilles Tjoelker ATF_TC_WITHOUT_HEAD(kill_zombie);
ATF_TC_BODY(kill_zombie,tc)35*cb71f1faSJilles Tjoelker ATF_TC_BODY(kill_zombie, tc)
36*cb71f1faSJilles Tjoelker {
37*cb71f1faSJilles Tjoelker pid_t child, pid;
38*cb71f1faSJilles Tjoelker int status, r;
39*cb71f1faSJilles Tjoelker
40*cb71f1faSJilles Tjoelker child = fork();
41*cb71f1faSJilles Tjoelker ATF_REQUIRE(child != -1);
42*cb71f1faSJilles Tjoelker if (child == 0) {
43*cb71f1faSJilles Tjoelker _exit(42);
44*cb71f1faSJilles Tjoelker }
45*cb71f1faSJilles Tjoelker
46*cb71f1faSJilles Tjoelker r = waitid(P_PID, child, NULL, WEXITED | WNOWAIT);
47*cb71f1faSJilles Tjoelker ATF_REQUIRE(r == 0);
48*cb71f1faSJilles Tjoelker
49*cb71f1faSJilles Tjoelker r = kill(child, SIGTERM);
50*cb71f1faSJilles Tjoelker ATF_CHECK(r == 0);
51*cb71f1faSJilles Tjoelker
52*cb71f1faSJilles Tjoelker status = -1;
53*cb71f1faSJilles Tjoelker pid = waitpid(child, &status, 0);
54*cb71f1faSJilles Tjoelker ATF_REQUIRE(pid == child);
55*cb71f1faSJilles Tjoelker ATF_CHECK(WIFEXITED(status) && WEXITSTATUS(status) == 42);
56*cb71f1faSJilles Tjoelker }
57*cb71f1faSJilles Tjoelker
ATF_TP_ADD_TCS(tp)58*cb71f1faSJilles Tjoelker ATF_TP_ADD_TCS(tp)
59*cb71f1faSJilles Tjoelker {
60*cb71f1faSJilles Tjoelker
61*cb71f1faSJilles Tjoelker ATF_TP_ADD_TC(tp, kill_zombie);
62*cb71f1faSJilles Tjoelker return (atf_no_error());
63*cb71f1faSJilles Tjoelker }
64