3 * Copyright (c) International Business Machines Corp., 2002
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
21 /* 11/06/2002 Port to LTP dbarrera@us.ibm.com */
22 /* 12/03/2008 Fix concurrency issue mfertre@irisa.fr */
32 * Get and manipulate a message queue.
38 #include <sys/types.h> /* needed for test */
39 #include <sys/ipc.h> /* needed for test */
40 #include <sys/msg.h> /* needed for test */
41 #include <stdio.h> /* needed by testhead.h */
49 * * * These globals must be defined in the test.
52 char *TCID
= "msgctl06"; /* Test program identifier. */
53 int TST_TOTAL
= 1; /* Total number of test cases. */
54 extern int Tst_count
; /* Test Case counter for tst_* routines */
56 int exp_enos
[] = { 0 }; /* List must end with 0 */
59 * msgctl3_t -- union of msgctl(2)'s possible argument # 3 types.
61 typedef union msgctl3_u
{
62 struct msqid_ds
*msq_ds
; /* pointer to msqid_ds struct */
63 struct ipc_acl
*msq_acl
; /* pointer ACL buff and size */
66 extern int local_flag
;
71 /*--------------------------------------------------------------*/
73 int main(int argc
, char *argv
[])
79 TEST(msgget(key
, IPC_CREAT
| IPC_EXCL
));
81 if (TEST_RETURN
== -1) {
82 tst_resm(TFAIL
|TTERRNO
, "msgget() failed");
86 TEST(msgctl(msqid
, IPC_STAT
, &buf
));
88 if (TEST_RETURN
== -1) {
89 tst_resm(TFAIL
|TTERRNO
,
90 "msgctl(msqid, IPC_STAT, &buf) failed");
91 (void)msgctl(msqid
, IPC_RMID
, (struct msqid_ds
*)NULL
);
96 * Check contents of msqid_ds structure.
99 if (buf
.msg_qnum
!= 0) {
100 tst_resm(TFAIL
, "error: unexpected nbr of messages %d",
104 if (buf
.msg_perm
.uid
!= getuid()) {
105 tst_resm(TFAIL
, "error: unexpected uid %d", buf
.msg_perm
.uid
);
108 if (buf
.msg_perm
.gid
!= getgid()) {
109 tst_resm(TFAIL
, "error: unexpected gid %d", buf
.msg_perm
.gid
);
112 if (buf
.msg_perm
.cuid
!= getuid()) {
113 tst_resm(TFAIL
, "error: unexpected cuid %d", buf
.msg_perm
.cuid
);
116 if (buf
.msg_perm
.cgid
!= getgid()) {
117 tst_resm(TFAIL
, "error: unexpected cgid %d", buf
.msg_perm
.cgid
);
121 tst_resm(TPASS
, "msgctl06 ran successfully!");
122 /***************************************************************
124 ***************************************************************/
130 /***************************************************************
131 * * setup() - performs all ONE TIME setup for this test.
132 * ****************************************************************/
135 /* You will want to enable some signal handling so you can capture
136 * unexpected signals like SIGSEGV.
138 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
140 /* Pause if that option was specified */
141 /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
142 * fork the test with the -c option. You want to make sure you do this
143 * before you create your temporary directory.
148 * Create a temporary directory and cd into it.
149 * This helps to ensure that a unique msgkey is created.
150 * See ../lib/libipc.c for more information.
155 /***************************************************************
156 * * * cleanup() - performs all ONE TIME cleanup for this test at
157 * * * completion or premature exit.
158 * * ***************************************************************/
164 * print timing stats if that option was specified.
165 * print errno log if that option was specified.
170 * Remove the message queue from the system
173 tst_resm(TINFO
, "Remove the message queue");
176 (void)msgctl(msqid
, IPC_RMID
, (struct msqid_ds
*)NULL
);
177 if ((status
= msgctl(msqid
, IPC_STAT
, &buf
)) != -1) {
178 (void)msgctl(msqid
, IPC_RMID
, (struct msqid_ds
*)NULL
);
179 tst_resm(TFAIL
, "msgctl(msqid, IPC_RMID) failed");
185 /* Remove the temporary directory */
188 /* exit with return code appropriate for results */