2 * Copyright (c) International Business Machines Corp., 2007
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
10 * the GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 ***************************************************************************
19 * * The pidns17.c testcase verifies inside the container, if kill(-1, SIGUSR1)
20 * * terminates all children running inside.
22 * * Test Assertion & Strategy:
23 * * Create a PID namespace container.
24 * * Spawn many children inside it.
25 * * Invoke kill(-1, SIGUSR1) inside container and check if it terminates
28 * * Usage: <for command-line>
32 * * DATE NAME DESCRIPTION
33 * * 13/11/08 Gowrishankar M Creation of this test.
34 * * <gowrishankar.m@in.ibm.com>
36 ******************************************************************************/
39 #include <sys/types.h>
49 char *TCID
= "pidns17";
60 * child_fn() - Inside container
62 int child_fn(void *arg
)
65 int i
, children
[10], status
;
67 /* Set process id and parent pid */
70 if (pid
!= CHILD_PID
|| ppid
!= PARENT_PID
) {
71 tst_resm(TBROK
, "cinit: pidns is not created.");
75 /* Spawn many children */
76 for (i
= 0; i
< 10; i
++)
77 if ((children
[i
] = fork()) == 0)
80 /* wait for last child to get scheduled */
83 if (kill(-1, SIGUSR1
) == -1) {
84 tst_resm(TBROK
, "cinit: kill(-1, SIGUSR1) failed");
88 for (i
= 0; i
< 10; i
++) {
89 if (waitpid(children
[i
], &status
, WNOHANG
) == -1) {
90 tst_resm(TBROK
, "cinit: waitpid() failed(%s)",\
94 if (!(WIFSIGNALED(&status
) && WTERMSIG(status
) == SIGUSR1
)) {
95 tst_resm(TFAIL
, "cinit: found a child alive still.");
99 tst_resm(TPASS
, "cinit: all children are terminated.");
101 /* cleanup and exit */
106 /***********************************************************************
108 ***********************************************************************/
110 int main(int argc
, char *argv
[])
117 /* Container creation on PID namespace */
118 ret
= do_clone_unshare_test(T_CLONE
,\
119 CLONE_NEWPID
, child_fn
, NULL
);
121 tst_resm(TBROK
, "parent: clone() failed. rc=%d(%s)",\
122 ret
, strerror(errno
));
123 /* Cleanup & continue with next test case */
128 if (wait(&status
) < 0)
129 tst_resm(TWARN
, "parent: waitpid() failed.");
131 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0)
132 tst_resm(TWARN
, "parent: container was terminated by %s",\
133 strsignal(WTERMSIG(status
)));
135 /* cleanup and exit */
141 * cleanup() - performs all ONE TIME cleanup for this test at
142 * completion or premature exit.
146 /* Clean the test testcase as LTP wants*/
149 /* exit with return code appropriate for results */