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