• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************/
2 /* Copyright (c) Crackerjack Project., 2007                                   */
3 /*                                                                            */
4 /* This program is free software;  you can redistribute it and/or modify      */
5 /* it under the terms of the GNU General Public License as published by       */
6 /* the Free Software Foundation; either version 2 of the License, or          */
7 /* (at your option) any later version.                                        */
8 /*                                                                            */
9 /* This program is distributed in the hope that it will be useful,            */
10 /* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
12 /* the GNU General Public License for more details.                           */
13 /*                                                                            */
14 /* You should have received a copy of the GNU General Public License          */
15 /* along with this program;  if not, write to the Free Software Foundation,   */
16 /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
17 /*                                                                            */
18 /******************************************************************************/
19 /******************************************************************************/
20 /*                                                                            */
21 /* Description: This tests the waitid() syscall                               */
22 /*                                                                            */
23 /* Test Name:   waitid01                                                      */
24 /* History:     Porting from Crackerjack to LTP is done by                    */
25 /*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
26 /******************************************************************************/
27 
28 #include <stdio.h>
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <sys/wait.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <sys/stat.h>
35 
36 #include "test.h"
37 
38 char *TCID = "waitid01";
39 int testno;
40 int TST_TOTAL = 3;
41 
setup(void)42 void setup(void)
43 {
44 	TEST_PAUSE;
45 }
46 
display_status(siginfo_t * infop)47 void display_status(siginfo_t * infop)
48 {
49 	tst_resm(TINFO, "Process %d terminated:", infop->si_pid);
50 	tst_resm(TINFO, "code = %d", infop->si_code);
51 	if (infop->si_code == CLD_EXITED)
52 		tst_resm(TINFO, "exit value = %d", infop->si_status);
53 	else
54 		tst_resm(TINFO, "signal = %d", infop->si_status);
55 }
56 
main(int ac,char ** av)57 int main(int ac, char **av)
58 {
59 	id_t pid;
60 	siginfo_t infop;
61 	int lc;
62 
63 	tst_parse_opts(ac, av, NULL, NULL);
64 
65 	setup();
66 
67 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
68 		tst_count = 0;
69 		for (testno = 0; testno < TST_TOTAL; ++testno) {
70 
71 			TEST(fork());
72 			if (TEST_RETURN < 0)
73 				tst_brkm(TBROK | TTERRNO, NULL,
74 					"fork() failed");
75 
76 			if (TEST_RETURN == 0) {
77 				exit(123);
78 			} else {
79 				TEST(waitid(P_ALL, getpid(), &infop, WEXITED));
80 				if (TEST_RETURN == -1) {
81 					tst_brkm(TFAIL | TTERRNO,
82 						 NULL,
83 						 "waitid(getpid()) failed");
84 				} else
85 					display_status(&infop);	//CLD_EXITED = 1
86 			}
87 
88 			TEST(fork());
89 			if (TEST_RETURN < 0)
90 				tst_brkm(TBROK | TTERRNO, NULL,
91 					"fork() failed");
92 
93 			if (TEST_RETURN == 0) {
94 				int a, b = 0;
95 				a = 1 / b;
96 				tst_exit();
97 			} else {
98 				TEST(waitid(P_ALL, 0, &infop, WEXITED));
99 				if (TEST_RETURN == -1) {
100 					tst_brkm(TFAIL | TTERRNO,
101 						 NULL, "waitid(0) failed");
102 				} else
103 					display_status(&infop);	//CLD_DUMPED = 3 ; SIGFPE = 8
104 			}
105 
106 			TEST(pid = fork());
107 			if (TEST_RETURN < 0)
108 				tst_brkm(TBROK | TTERRNO, NULL,
109 					"fork() failed");
110 
111 			if (TEST_RETURN == 0) {
112 				TEST(sleep(10));
113 				tst_exit();
114 			}
115 			TEST(kill(pid, SIGHUP));
116 			TEST(waitid(P_ALL, 0, &infop, WEXITED));
117 			if (TEST_RETURN == -1) {
118 				tst_brkm(TFAIL | TTERRNO, NULL,
119 					 "waitid(0) failed");
120 			} else
121 				display_status(&infop);	//CLD_KILLED = 2 ; SIGHUP = 1
122 		}
123 	}
124 	tst_resm(TPASS, "waitid(): system call passed");
125 	tst_exit();
126 }
127