• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2016 Linux Test Project
4  */
5 #include <errno.h>
6 #include <signal.h>
7 #include <stdlib.h>
8 #include "tst_test.h"
9 
sig_handler(int sig LTP_ATTRIBUTE_UNUSED)10 static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)
11 {
12 }
13 
do_child(void)14 static void do_child(void)
15 {
16 	SAFE_SIGNAL(SIGINT, sig_handler);
17 
18 	TST_CHECKPOINT_WAKE(0);
19 
20 	TEST(pause());
21 	if (TST_RET != -1)
22 		tst_res(TFAIL, "pause() succeeded unexpectedly");
23 	else if (TST_ERR == EINTR)
24 		tst_res(TPASS, "pause() interrupted with EINTR");
25 	else
26 		tst_res(TFAIL | TTERRNO, "pause() unexpected errno");
27 
28 	TST_CHECKPOINT_WAKE(0);
29 	exit(0);
30 }
31 
do_test(void)32 static void do_test(void)
33 {
34 	int pid, status;
35 
36 	pid = SAFE_FORK();
37 	if (pid == 0)
38 		do_child();
39 
40 	TST_CHECKPOINT_WAIT(0);
41 	TST_PROCESS_STATE_WAIT(pid, 'S', 0);
42 	kill(pid, SIGINT);
43 
44 	/*
45 	 * TST_CHECKPOINT_WAIT has built-in timeout, if pause() doesn't return,
46 	 * this checkpoint call will reliably end the test.
47 	 */
48 	TST_CHECKPOINT_WAIT(0);
49 	SAFE_WAIT(&status);
50 }
51 
52 static struct tst_test test = {
53 	.forks_child = 1,
54 	.needs_checkpoints = 1,
55 	.test_all = do_test,
56 };
57