1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * msgrcv error test for EIDRM. 6 */ 7 8#include <errno.h> 9#include <unistd.h> 10#include <sys/types.h> 11#include <sys/ipc.h> 12#include <sys/msg.h> 13#include <stdlib.h> 14#include "tst_test.h" 15#include "tst_safe_sysv_ipc.h" 16#include "libnewipc.h" 17 18static key_t msgkey; 19static int queue_id = -1; 20static struct buf { 21 long type; 22 char text[MSGSIZE]; 23} rcv_buf = {1, "hello"}; 24 25static void verify_msgrcv(void) 26{ 27 TST_EXP_FAIL2(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0), EIDRM, 28 "msgrcv(%i, %p, %d, 1, 0)", queue_id, &rcv_buf, MSGSIZE); 29} 30 31static void do_test(void) 32{ 33 int pid; 34 35 queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW); 36 pid = SAFE_FORK(); 37 if (pid == 0) { 38 verify_msgrcv(); 39 exit(0); 40 } 41 TST_PROCESS_STATE_WAIT(pid, 'S', 0); 42 SAFE_MSGCTL(queue_id, IPC_RMID, NULL); 43 tst_reap_children(); 44} 45 46static void setup(void) 47{ 48 msgkey = GETIPCKEY(); 49} 50 51static void cleanup(void) 52{ 53 if (queue_id != -1) 54 SAFE_MSGCTL(queue_id, IPC_RMID, NULL); 55} 56 57static struct tst_test test = { 58 .needs_tmpdir = 1, 59 .forks_child = 1, 60 .setup = setup, 61 .cleanup = cleanup, 62 .test_all = do_test, 63}; 64