• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  * Copyright (c) 2012-2018 Cyril Hrubis <chrubis@suse.cz>
4  *
5  * This program is free software;  you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  * the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program;  if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * wait401 - check that a call to wait4() correctly waits for a child
22  *           process to exit
23  */
24 
25 #include <stdlib.h>
26 #include <errno.h>
27 #define _USE_BSD
28 #include <sys/types.h>
29 #include <sys/resource.h>
30 #include <sys/wait.h>
31 #include "tst_test.h"
32 
run(void)33 static void run(void)
34 {
35 	pid_t pid;
36 	int status = 1;
37 	struct rusage rusage;
38 
39 	pid = SAFE_FORK();
40 	if (!pid) {
41 		TST_PROCESS_STATE_WAIT(getppid(), 'S');
42 		exit(0);
43 	}
44 
45 	TEST(wait4(pid, &status, 0, &rusage));
46 	if (TST_RET == -1) {
47 		tst_res(TFAIL | TERRNO, "wait4() failed");
48 		return;
49 	}
50 
51 	if (TST_RET != pid) {
52 		tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i",
53 			TST_RET, pid);
54 	} else {
55 		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
56 	}
57 
58 	if (!WIFEXITED(status)) {
59 		tst_res(TFAIL, "WIFEXITED() not set in status (%s)",
60 		        tst_strstatus(status));
61 		return;
62 	}
63 
64 	tst_res(TPASS, "WIFEXITED() is set in status");
65 
66 	if (WEXITSTATUS(status))
67 		tst_res(TFAIL, "WEXITSTATUS() != 0 but %i", WEXITSTATUS(status));
68 	else
69 		tst_res(TPASS, "WEXITSTATUS() == 0");
70 
71 }
72 
73 static struct tst_test test = {
74 	.forks_child = 1,
75 	.test_all = run,
76 };
77