Merge branch 'vendor/XZ'
[dragonfly.git] / lib / librt / mq_open.2
1 .\"     $NetBSD: mq_open.3,v 1.1 2009/01/05 21:19:49 rmind Exp $
2 .\"
3 .\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
4 .\"
5 .Dd August 19, 2009
6 .Dt MQ_OPEN 2
7 .Os
8 .Sh NAME
9 .Nm mq_open
10 .Nd open a message queue (REALTIME)
11 .Sh LIBRARY
12 .Lb librt
13 .Sh SYNOPSIS
14 .In mqueue.h
15 .Ft mqd_t
16 .Fn mq_open "const char *name" "int oflag"
17 .Ft mqd_t
18 .Fn mq_open "const char *name" "int oflag" "mode_t mode" "struct mq_attr *attr"
19 .Sh DESCRIPTION
20 The
21 .Fn mq_open
22 function establishes the connection between a process and a message queue
23 with a message queue descriptor.
24 It creates an open message queue description that refers to the message
25 queue, and a message queue descriptor that refers to that open message
26 queue description.
27 The message queue descriptor is used by other functions to refer to that
28 message queue.
29 The
30 .Fa name
31 argument points to a string naming a message queue,
32 which should conform to the construction rules for a pathname.
33 The
34 .Fa name
35 should begin with a slash character.
36 The processes calling
37 .Fn mq_open
38 with the same value of
39 .Fa name
40 will refer to the same message queue object,
41 as long as that name has not been removed.
42 If the
43 .Fa name
44 argument is not
45 the name of an existing message queue and creation is not requested,
46 .Fn mq_open
47 fails and returns an error.
48 .Pp
49 The
50 .Fa oflag
51 argument requests the desired receive and/or send access to the message queue.
52 The requested access permission to receive messages or send messages are
53 granted if the calling process would be granted read or write access,
54 respectively, to an equivalently protected file.
55 .Pp
56 The value of
57 .Fa oflag
58 is the bitwise-inclusive OR of values from the following list.
59 Applications must specify exactly one of the first three values
60 (access modes) below in the value of
61 .Fa oflag :
62 .Bl -tag -width ".Dv O_RDONLY"
63 .It Dv O_RDONLY
64 Open the message queue for receiving messages.
65 The process can use the returned message queue descriptor with
66 .Xr mq_receive 2 ,
67 but not
68 .Xr mq_send 2 .
69 .It Dv O_WRONLY
70 Open the queue for sending messages.
71 The process can use the returned message queue descriptor with
72 .Xr mq_send 2
73 but not
74 .Xr mq_receive 2 .
75 .It Dv O_RDWR
76 Open the queue for both receiving and sending messages.
77 The process can use any of the functions allowed for
78 .Dv O_RDONLY
79 and
80 .Dv O_WRONLY .
81 .El
82 .Pp
83 In all cases, a message queue may be open multiple times in the same
84 or different processes for sending/receiving messages.
85 .Pp
86 Any combination of the remaining flags may be specified in the value of
87 .Fa oflag :
88 .Bl -tag -width ".Dv O_RDONLY"
89 .It Dv O_CREAT
90 Create a message queue.
91 It requires two additional arguments:
92 .Fa mode
93 and
94 .Fa attr .
95 If the pathname
96 .Fa name
97 has already been used to create a message queue that still exists,
98 then this flag will have no effect, except as noted under
99 .Dv O_EXCL .
100 Otherwise, a message queue will be created without any messages in it.
101 The user ID of the message queue will be set to the effective user ID
102 of the process, and the group ID of the message queue will be set to
103 the effective group ID of the process.
104 The permission bits of the message queue will be set to the value of the
105 .Fa mode
106 argument, except those set in the file mode creation mask of
107 the process.
108 When bits in
109 .Fa mode
110 other than the file permission bits are specified, the effect
111 is unspecified.
112 If
113 .Fa attr
114 is
115 .Dv NULL ,
116 the message queue will be created with implementation-defined default
117 message queue attributes.
118 If
119 .Fa attr
120 is
121 .No non- Ns Dv NULL
122 and the calling process has the appropriate privilege on
123 .Fa name ,
124 the message queue
125 .Va mq_maxmsg
126 and
127 .Va mq_msgsize
128 attributes will be set to the values of the corresponding members in the
129 .Vt mq_attr
130 structure referred to by
131 .Fa attr .
132 If
133 .Fa attr
134 is
135 .No non- Ns Dv NULL ,
136 but the calling process does not have the
137 appropriate privilege on
138 .Fa name ,
139 the
140 .Fn mq_open
141 function will fail and return an error without creating the message queue.
142 .It Dv O_EXCL
143 If
144 .Dv O_EXCL
145 and
146 .Dv O_CREAT
147 are set,
148 .Fn mq_open
149 fails if the message queue
150 .Fa name
151 exists.
152 The check for the existence of the message queue and the creation of the
153 message queue if it does not exist will be atomic with respect to other
154 threads executing
155 .Fn mq_open
156 naming the same
157 .Fa name
158 with
159 .Dv O_EXCL
160 and
161 .Dv O_CREAT
162 set.
163 If
164 .Dv O_EXCL
165 is set and
166 .Dv O_CREAT
167 is not set, the result is undefined.
168 .It Dv O_NONBLOCK
169 Determines whether an
170 .Xr mq_send 2
171 or
172 .Xr mq_receive 2
173 waits for resources or messages that are not currently available,
174 or fails with errno set to
175 .Er EAGAIN .
176 .El
177 .Pp
178 The
179 .Fn mq_open
180 function does not add or remove messages from the queue.
181 .Sh NOTES
182 The
183 .Xr select 2
184 and
185 .Xr poll 2
186 system calls to the message queue descriptor are supported by
187 .Dx ,
188 however, it is not portable.
189 .Sh RETURN VALUES
190 Upon successful completion,
191 .Fn mq_open
192 returns a message queue descriptor.
193 Otherwise, the function returns
194 .Pq Vt mqd_t
195 \-1 and sets the global variable
196 .Va errno
197 to indicate the error.
198 .Sh ERRORS
199 The
200 .Fn mq_open
201 function fails if:
202 .Bl -tag -width Er
203 .It Bq Er EACCES
204 The message queue exists and the permissions specified by
205 .Fa oflag
206 are denied, or the message queue does not exist and permission
207 to create the message queue is denied.
208 .It Bq Er EEXIST
209 .Dv O_CREAT
210 and
211 .Dv O_EXCL
212 are set and the named message queue already exists.
213 .It Bq Er EINTR
214 The
215 .Fn mq_open
216 function was interrupted by a signal.
217 .It Bq Er EINVAL
218 The
219 .Fn mq_open
220 function is not supported for the given name, or
221 .Dv O_CREAT
222 was specified in
223 .Fa oflag ,
224 the value of
225 .Fa attr
226 is not
227 .Dv NULL ,
228 and either
229 .Va mq_maxmsg
230 or
231 .Va mq_msgsize
232 was less than or equal to zero.
233 .It Bq Er EMFILE
234 Too many message queue descriptors or file descriptors are currently
235 in use by this process.
236 .It Bq Er ENAMETOOLONG
237 The length of the
238 .Fa name
239 argument exceeds
240 .Brq Dv PATH_MAX
241 or a pathname component is longer than
242 .Brq Dv NAME_MAX .
243 .It Bq Er ENFILE
244 Too many message queues are currently open in the system.
245 .It Bq Er ENOENT
246 .Dv O_CREAT
247 is not set and the named message queue does not exist.
248 .It Bq Er ENOSPC
249 There is insufficient space for the creation of the new message queue.
250 .El
251 .Sh SEE ALSO
252 .Xr mq_close 2 ,
253 .Xr mq_getattr 2 ,
254 .Xr mq_notify 2 ,
255 .Xr mq_receive 2 ,
256 .Xr mq_send 2 ,
257 .Xr mq_setattr 2 ,
258 .Xr mq_unlink 2
259 .Sh STANDARDS
260 This function conforms to the
261 .St -p1003.1-2001
262 standard.
263 .Sh HISTORY
264 This function first appeared in
265 .Dx 2.5 .
266 .Sh COPYRIGHT
267 Portions of this text are reprinted and reproduced in electronic form
268 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
269 -- Portable Operating System Interface (POSIX), The Open Group Base
270 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
271 Electrical and Electronics Engineers, Inc and The Open Group.
272 In the
273 event of any discrepancy between this version and the original IEEE and
274 The Open Group Standard, the original IEEE and The Open Group Standard
275 is the referee document.
276 The original Standard can be obtained online at
277 http://www.opengroup.org/unix/online.html .