• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2001
4  *    07/2001 John George
5  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
6  */
7 
8 /*
9  * Check that when a child kills itself by SIGALRM the waiting parent is
10  * correctly notified.
11  *
12  * Fork a child that raises(SIGALRM), the parent checks that SIGALRM was
13  * returned.
14  */
15 #include <stdlib.h>
16 #include <sys/wait.h>
17 #include "tst_test.h"
18 
run(void)19 static void run(void)
20 {
21 	pid_t pid;
22 	int status;
23 
24 	pid = SAFE_FORK();
25 	if (!pid) {
26 		raise(SIGALRM);
27 		exit(0);
28 	}
29 
30 	TST_EXP_PID_SILENT(waitpid(pid, &status, 0));
31 	if (!TST_PASS)
32 		return;
33 
34 	if (TST_RET != pid) {
35 		tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i",
36 			TST_RET, pid);
37 	} else {
38 		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
39 	}
40 
41 	if (!WIFSIGNALED(status)) {
42 		tst_res(TFAIL, "WIFSIGNALED() not set in status (%s)",
43 		        tst_strstatus(status));
44 		return;
45 	}
46 
47 	tst_res(TPASS, "WIFSIGNALED() set in status");
48 
49 	if (WTERMSIG(status) != SIGALRM) {
50 		tst_res(TFAIL, "WTERMSIG() != SIGALRM but %s",
51 		        tst_strsig(WTERMSIG(status)));
52 		return;
53 	}
54 
55 	tst_res(TPASS, "WTERMSIG() == SIGALRM");
56 }
57 
58 static struct tst_test test = {
59 	.forks_child = 1,
60 	.test_all = run,
61 };
62