2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\" This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH MQ_OPEN 3C "Feb 5, 2008"
14 mq_open \- open a message queue
20 \fBmqd_t\fR \fBmq_open\fR(\fBconst char *\fR\fIname\fR, \fBint\fR \fIoflag\fR,
21 \fB/* unsigned long\fR \fImode\fR, \fBmq_attr\fR \fIattr\fR */ ...);
27 The \fBmq_open()\fR function establishes the connection between a process and a
28 message queue with a message queue descriptor. It creates a open message queue
29 description that refers to the message queue, and a message queue descriptor
30 that refers to that open message queue description. The message queue
31 descriptor is used by other functions to refer to that message queue.
34 The \fIname\fR argument points to a string naming a message queue. The
35 \fIname\fR argument must conform to the construction rules for a path-name. If
36 \fIname\fR is not the name of an existing message queue and its creation is not
37 requested, \fBmq_open()\fR fails and returns an error. The first character of
38 \fIname\fR must be a slash (\fB/\fR) character and the remaining characters of
39 \fIname\fR cannot include any slash characters. For maximum portability,
40 \fIname\fR should include no more than 14 characters, but this limit is not
44 The \fIoflag\fR argument requests the desired receive and/or send access to the
45 message queue. The requested access permission to receive messages or send
46 messages is granted if the calling process would be granted read or write
47 access, respectively, to a file with the equivalent permissions.
50 The value of \fIoflag\fR is the bitwise inclusive \fBOR\fR of values from the
51 following list. Applications must specify exactly one of the first three values
52 (access modes) below in the value of \fIoflag\fR:
59 Open the message queue for receiving messages. The process can use the returned
60 message queue descriptor with \fBmq_receive\fR(3C), but not \fBmq_send\fR(3C).
61 A message queue may be open multiple times in the same or different processes
62 for receiving messages.
71 Open the queue for sending messages. The process can use the returned message
72 queue descriptor with \fBmq_send\fR(3C) but not \fBmq_receive\fR(3C). A message
73 queue may be open multiple times in the same or different processes for sending
83 Open the queue for both receiving and sending messages. The process can use any
84 of the functions allowed for \fBO_RDONLY\fR and \fBO_WRONLY\fR. A message queue
85 may be open multiple times in the same or different processes for sending
91 Any combination of the remaining flags may additionally be specified in the
99 This option is used to create a message queue, and it requires two additional
100 arguments: \fImode\fR, which is of type \fBmode_t\fR, and \fIattr\fR, which is
101 pointer to a \fBmq_attr\fR structure. If the pathname, \fIname\fR, has already
102 been used to create a message queue that still exists, then this flag has no
103 effect, except as noted under \fBO_EXCL\fR (see below). Otherwise, a message
104 queue is created without any messages in it.
106 The user ID of the message queue is set to the effective user ID of process,
107 and the group ID of the message queue is set to the effective group ID of the
108 process. The file permission bits are set to the value of \fImode\fR, and
109 modified by clearing all bits set in the file mode creation mask of the process
110 (see \fBumask\fR(2)).
112 If \fIattr\fR is non-\fINULL\fR and the calling process has the appropriate
113 privilege on \fIname\fR, the message queue \fImq_maxmsg\fR and \fImq_msgsize\fR
114 attributes are set to the values of the corresponding members in the
115 \fBmq_attr\fR structure referred to by \fIattr\fR. If \fIattr\fR is
116 non-\fINULL\fR, but the calling process does not have the appropriate privilege
117 on \fIname\fR, the \fBmq_open()\fR function fails and returns an error without
118 creating the message queue.
127 If both \fBO_EXCL\fR and \fBO_CREAT\fR are set, \fBmq_open()\fR will fail if
128 the message queue \fIname\fR exists. The check for the existence of the message
129 queue and the creation of the message queue if it does not exist are atomic
130 with respect to other processes executing \fBmq_open()\fR naming the same
131 \fIname\fR with both \fBO_EXCL\fR and \fBO_CREAT\fR set. If \fBO_EXCL\fR and
132 \fBO_CREAT\fR are not set, the result is undefined.
138 \fB\fBO_NONBLOCK\fR \fR
141 The setting of this flag is associated with the open message queue description
142 and determines whether a \fBmq_send\fR(3C) or \fBmq_receive\fR(3C) waits for
143 resources or messages that are not currently available, or fails with
144 \fBerrno\fR set to \fBEAGAIN\fR. See \fBmq_send\fR(3C) and \fBmq_receive\fR(3C)
151 Upon successful completion, \fBmq_open()\fR returns a message queue descriptor;
152 otherwise the function returns \fB(mqd_t)\(mi1\fR and sets \fBerrno\fR to
153 indicate the error condition.
157 The \fBmq_open()\fR function will fail if:
164 The message queue exists and the permissions specified by \fIoflag\fR are
165 denied, or the message queue does not exist and permission to create the
166 message queue is denied.
175 \fBO_CREAT\fR and \fBO_EXCL\fR are set and the named message queue already
185 The \fBmq_open()\fR operation was interrupted by a signal.
194 The \fBmq_open()\fR operation is not supported for the given name, or
195 \fBO_CREAT\fR was specified in \fIoflag\fR, the value of \fIattr\fR is not
196 \fINULL,\fR and either \fBmq_maxmsg\fR or \fBmq_msgsize\fR was less than or
206 The number of open message queue descriptors in this process exceeds
207 \fBMQ_OPEN_MAX,\fR of the number of open file descriptors in this process
208 exceeds \fBOPEN_MAX.\fR
214 \fB\fBENAMETOOLONG\fR \fR
217 The length of the \fIname\fR string exceeds \fBPATH_MAX,\fR or a pathname
218 component is longer than \fINAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
228 Too many message queues are currently open in the system.
237 \fBO_CREAT\fR is not set and the named message queue does not exist.
246 There is insufficient space for the creation of the new message queue.
255 The \fBmq_open()\fR function is not supported by the system.
261 See \fBattributes\fR(5) for descriptions of the following attributes:
269 ATTRIBUTE TYPE ATTRIBUTE VALUE
271 Interface Stability Committed
275 Standard See \fBstandards\fR(5).
281 \fBexec\fR(2), \fBexit\fR(2), \fBumask\fR(2), \fBsysconf\fR(3C),
282 \fBmqueue.h\fR(3HEAD), \fBmq_close\fR(3C), \fBmq_receive\fR(3C),
283 \fBmq_send\fR(3C), \fBmq_setattr\fR(3C), \fBmq_unlink\fR(3C),
284 \fBattributes\fR(5), \fBstandards\fR(5)
288 Due to the manner in which message queues are implemented, they should not be
289 considered secure and should not be used in security-sensitive applications.
292 Solaris 2.6 was the first release to support the Asynchronous Input and Output
293 option. Prior to this release, this function always returned \fB\(mi1\fR and
294 set \fBerrno\fR to \fBENOSYS\fR.