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 pidns10.c testcase verifies inside the container, if kill(-1, signal)
20 * * fails with ESRCH when there are no processes in container.
22 * * Test Assertion & Strategy:
23 * * Create a PID namespace container.
24 * * Invoke kill(-1, SIGUSR1) inside container and check return code and error.
25 * * kill() should have failed;except swapper & init, no process is inside.
27 * * Usage: <for command-line>
31 * * DATE NAME DESCRIPTION
32 * * 13/11/08 Gowrishankar M Creation of this test.
33 * * <gowrishankar.m@in.ibm.com>
35 ******************************************************************************/
38 #include <sys/types.h>
48 char *TCID
= "pidns10";
59 * child_fn() - Inside container
61 int child_fn(void *arg
)
65 /* Set process id and parent pid */
68 if (pid
!= CHILD_PID
|| ppid
!= PARENT_PID
) {
69 tst_resm(TBROK
, "cinit: pidns is not created.");
73 if (kill(-1, SIGUSR1
) != -1) {
74 tst_resm(TFAIL
, "cinit: kill(-1, sig) should have failed");
79 tst_resm(TPASS
, "cinit: expected kill(-1, sig) failure.");
81 tst_resm(TFAIL
, "cinit: kill(-1, sig) failure is not ESRCH, "
82 "but %s", strerror(errno
));
84 /* cleanup and exit */
89 /***********************************************************************
91 ***********************************************************************/
93 int main(int argc
, char *argv
[])
100 /* Container creation on PID namespace */
101 ret
= do_clone_unshare_test(T_CLONE
,\
102 CLONE_NEWPID
, child_fn
, NULL
);
104 tst_resm(TBROK
, "parent: clone() failed. rc=%d(%s)",\
105 ret
, strerror(errno
));
106 /* Cleanup & continue with next test case */
111 if (wait(&status
) < 0)
112 tst_resm(TWARN
, "parent: waitpid() failed.");
114 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0)
115 tst_resm(TBROK
, "parent: container was terminated by %s",\
116 strsignal(WTERMSIG(status
)));
123 * cleanup() - performs all ONE TIME cleanup for this test at
124 * completion or premature exit.
128 /* Clean the test testcase as LTP wants*/
131 /* exit with return code appropriate for results */