• 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  *
5  * msgrcv error test for EINTR.
6  */
7 
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <signal.h>
11 #include <stdlib.h>
12 #include "tst_test.h"
13 #include "tst_safe_sysv_ipc.h"
14 #include "libnewipc.h"
15 
16 static key_t msgkey;
17 static int queue_id = -1;
18 static struct buf {
19 	long type;
20 	char mtext[MSGSIZE];
21 } rcv_buf;
22 
sighandler(int sig)23 static void sighandler(int sig)
24 {
25 	if (sig == SIGHUP)
26 		return;
27 	else
28 		_exit(TBROK);
29 }
30 
verify_msgrcv(void)31 static void verify_msgrcv(void)
32 {
33 	TST_EXP_FAIL2(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0), EINTR,
34 		"msgrcv(%i, %p, %d, 1, 0)", queue_id, &rcv_buf, MSGSIZE);
35 }
36 
do_test(void)37 static void do_test(void)
38 {
39 	int pid;
40 
41 	pid = SAFE_FORK();
42 	if (pid == 0) {
43 		verify_msgrcv();
44 		exit(0);
45 	}
46 	TST_PROCESS_STATE_WAIT(pid, 'S', 0);
47 	SAFE_KILL(pid, SIGHUP);
48 	tst_reap_children();
49 }
50 
setup(void)51 static void setup(void)
52 {
53 	msgkey = GETIPCKEY();
54 	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
55 	SAFE_SIGNAL(SIGHUP, sighandler);
56 }
57 
cleanup(void)58 static void cleanup(void)
59 {
60 	if (queue_id != -1)
61 		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
62 }
63 
64 static struct tst_test test = {
65 	.setup = setup,
66 	.cleanup = cleanup,
67 	.test_all = do_test,
68 	.needs_tmpdir = 1,
69 	.forks_child = 1,
70 };
71