• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 Linux Test Project
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * Check that pause() returns on signal with errno == EINTR.
15  */
16 #include <errno.h>
17 #include <signal.h>
18 #include <stdlib.h>
19 #include "tst_test.h"
20 
sig_handler(int sig LTP_ATTRIBUTE_UNUSED)21 static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)
22 {
23 }
24 
do_child(void)25 static void do_child(void)
26 {
27 	SAFE_SIGNAL(SIGINT, sig_handler);
28 
29 	TST_CHECKPOINT_WAKE(0);
30 
31 	TEST(pause());
32 	if (TST_RET != -1)
33 		tst_res(TFAIL, "pause() succeeded unexpectedly");
34 	else if (TST_ERR == EINTR)
35 		tst_res(TPASS, "pause() interrupted with EINTR");
36 	else
37 		tst_res(TFAIL | TTERRNO, "pause() unexpected errno");
38 
39 	TST_CHECKPOINT_WAKE(0);
40 	exit(0);
41 }
42 
do_test(void)43 static void do_test(void)
44 {
45 	int pid, status;
46 
47 	pid = SAFE_FORK();
48 	if (pid == 0)
49 		do_child();
50 
51 	TST_CHECKPOINT_WAIT(0);
52 	TST_PROCESS_STATE_WAIT(pid, 'S');
53 	kill(pid, SIGINT);
54 
55 	/*
56 	 * TST_CHECKPOINT_WAIT has built-in timeout, if pause() doesn't return,
57 	 * this checkpoint call will reliably end the test.
58 	 */
59 	TST_CHECKPOINT_WAIT(0);
60 	SAFE_WAIT(&status);
61 }
62 
63 static struct tst_test test = {
64 	.forks_child = 1,
65 	.needs_checkpoints = 1,
66 	.test_all = do_test,
67 };
68