• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * NAME
22  *	msgctl03.c
23  *
24  * DESCRIPTION
25  *	msgctl03 - create a message queue, then issue the IPC_RMID command
26  *
27  * ALGORITHM
28  *	create a message queue
29  *	loop if that option was specified
30  *	call msgctl() with the IPC_RMID command
31  *	check the return code
32  *	  if failure, issue a FAIL message and break remaining tests
33  *	otherwise,
34  *	  if doing functionality testing
35  *		issue an IPC_STAT on the queue that was just removed
36  *	  	if the call fails
37  *			issue a PASS message
38  *		otherwise
39  *			issue a FAIL message
40  *	  else issue a PASS message
41  *	call cleanup
42  *
43  * USAGE:  <for command-line>
44  *  msgctl03 [-c n] [-f] [-I x] [-P x] [-t]
45  *     where,  -c n : Run n copies concurrently.
46  *             -f   : Turn off functionality Testing.
47  *	       -I x : Execute test for x seconds.
48  *	       -P x : Pause for x seconds between iterations.
49  *	       -t   : Turn on syscall timing.
50  *
51  * HISTORY
52  *	03/2001 - Written by Wayne Boyer
53  *
54  * RESTRICTIONS
55  *	This test does not support looping.
56  */
57 
58 #include "test.h"
59 
60 #include "ipcmsg.h"
61 
62 char *TCID = "msgctl03";
63 int TST_TOTAL = 1;
64 
65 int msg_q_1 = -1;		/* to hold the message queue id */
66 
67 struct msqid_ds qs_buf;
68 
main(int ac,char ** av)69 int main(int ac, char **av)
70 {
71 
72 	tst_parse_opts(ac, av, NULL, NULL);
73 
74 	setup();		/* global setup */
75 
76 	/*
77 	 * Remove the queue that was created in setup()
78 	 */
79 
80 	TEST(msgctl(msg_q_1, IPC_RMID, NULL));
81 
82 	if (TEST_RETURN == -1) {
83 		tst_brkm(TFAIL | TTERRNO, cleanup, "msgctl() call failed");
84 	} else {
85 		/*
86 		 * if the queue is gone, then an IPC_STAT msgctl()
87 		 * call should generate an EINVAL error.
88 		 */
89 		if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)) {
90 			if (errno == EINVAL) {
91 				tst_resm(TPASS, "The queue is gone");
92 			} else {
93 				tst_resm(TFAIL, "IPC_RMID succeeded ,"
94 					 " but functional test did not"
95 					 " get expected EINVAL error");
96 			}
97 		}
98 	}
99 
100 	msg_q_1 = -1;
101 
102 	cleanup();
103 	tst_exit();
104 }
105 
106 /*
107  * setup() - performs all the ONE TIME setup for this test.
108  */
setup(void)109 void setup(void)
110 {
111 
112 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
113 
114 	TEST_PAUSE;
115 
116 	/*
117 	 * Create a temporary directory and cd into it.
118 	 * This helps to ensure that a unique msgkey is created.
119 	 * See ../lib/libipc.c for more information.
120 	 */
121 	tst_tmpdir();
122 
123 	/* get a message key */
124 	msgkey = getipckey();
125 
126 	/* now we have a key, so let's create a message queue */
127 	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
128 		tst_brkm(TBROK, cleanup, "Can't create message queue");
129 	}
130 }
131 
132 /*
133  * cleanup() - performs all the ONE TIME cleanup for this test at completion
134  * 	       or premature exit.
135  */
cleanup(void)136 void cleanup(void)
137 {
138 	/* if it exists, remove the message queue */
139 	rm_queue(msg_q_1);
140 
141 	tst_rmdir();
142 
143 }
144