-
Notifications
You must be signed in to change notification settings - Fork 0
/
mq_open.html
429 lines (313 loc) · 11.2 KB
/
mq_open.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:27:22 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>MQ_OPEN</title>
</head>
<body>
<h1 align="center">MQ_OPEN</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#ATTRIBUTES">ATTRIBUTES</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">mq_open - open
a message queue</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<fcntl.h></b> /* For O_* constants */ <b><br>
#include <sys/stat.h></b> /* For mode constants */
<b><br>
#include <mqueue.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>mqd_t
mq_open(const char *</b><i>name</i><b>, int</b>
<i>oflag</i><b>); <br>
mqd_t mq_open(const char *</b><i>name</i><b>, int</b>
<i>oflag</i><b>, mode_t</b> <i>mode</i><b>, <br>
struct mq_attr *</b><i>attr</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em">Link with
<i>-lrt</i>.</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>mq_open</b>()
creates a new POSIX message queue or opens an existing
queue. The queue is identified by <i>name</i>. For details
of the construction of <i>name</i>, see
<b>mq_overview</b>(7).</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>oflag</i> argument specifies flags that control the
operation of the call. (Definitions of the flags values can
be obtained by including <i><fcntl.h></i>.) Exactly
one of the following must be specified in <i>oflag</i>:
<b><br>
O_RDONLY</b></p>
<p style="margin-left:22%;">Open the queue to receive
messages only.</p>
<p style="margin-left:11%;"><b>O_WRONLY</b></p>
<p style="margin-left:22%;">Open the queue to send messages
only.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>O_RDWR</b></p></td>
<td width="2%"></td>
<td width="75%">
<p>Open the queue to both send and receive messages.</p></td>
<td width="3%">
</td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">Zero or more of
the following flags can additionally be <i>OR</i>ed in
<i>oflag</i>: <b><br>
O_CLOEXEC</b> (since Linux 2.6.26)</p>
<p style="margin-left:22%;">Set the close-on-exec flag for
the message queue descriptor. See <b>open</b>(2) for a
discussion of why this flag is useful.</p>
<p style="margin-left:11%;"><b>O_CREAT</b></p>
<p style="margin-left:22%;">Create the message queue if it
does not exist. The owner (user ID) of the message queue is
set to the effective user ID of the calling process. The
group ownership (group ID) is set to the effective group ID
of the calling process.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>O_EXCL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>If <b>O_CREAT</b> was specified in <i>oflag</i>, and a
queue with the given <i>name</i> already exists, then fail
with the error <b>EEXIST</b>.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>O_NONBLOCK</b></p>
<p style="margin-left:22%;">Open the queue in nonblocking
mode. In circumstances where <b>mq_receive</b>(3) and
<b>mq_send</b>(3) would normally block, these functions
instead fail with the error <b>EAGAIN</b>.</p>
<p style="margin-left:11%; margin-top: 1em">If
<b>O_CREAT</b> is specified in <i>oflag</i>, then two
additional arguments must be supplied. The <i>mode</i>
argument specifies the permissions to be placed on the new
queue, as for <b>open</b>(2). (Symbolic definitions for the
permissions bits can be obtained by including
<i><sys/stat.h></i>.) The permissions settings are
masked against the process umask.</p>
<p style="margin-left:11%; margin-top: 1em">The fields of
the <i>struct mq_attr</i> pointed to <i>attr</i> specify the
maximum number of messages and the maximum size of messages
that the queue will allow. This structure is defined as
follows:</p>
<p style="margin-left:17%; margin-top: 1em">struct mq_attr
{ <br>
long mq_flags; /* Flags (ignored for mq_open()) */ <br>
long mq_maxmsg; /* Max. # of messages on queue */ <br>
long mq_msgsize; /* Max. message size (bytes) */ <br>
long mq_curmsgs; /* # of messages currently in queue <br>
(ignored for mq_open()) */ <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">Only the
<i>mq_maxmsg</i> and <i>mq_msgsize</i> fields are employed
when calling <b>mq_open</b>(); the values in the remaining
fields are ignored.</p>
<p style="margin-left:11%; margin-top: 1em">If <i>attr</i>
is NULL, then the queue is created with
implementation-defined default attributes. Since Linux 3.5,
two <i>/proc</i> files can be used to control these
defaults; see <b>mq_overview</b>(7) for details.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>mq_open</b>() returns a message queue descriptor for use
by other message queue functions. On error, <b>mq_open</b>()
returns <i>(mqd_t) -1</i>, with <i>errno</i> set to
indicate the error.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">The queue exists, but the caller
does not have permission to open it in the specified
mode.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>name</i> contained more than one slash.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EEXIST</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Both <b>O_CREAT</b> and <b>O_EXCL</b> were specified in
<i>oflag</i>, but a queue with this <i>name</i> already
exists.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>name</i> doesn’t follow the format in
<b>mq_overview</b>(7).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><b>O_CREAT</b> was specified in <i>oflag</i>, and
<i>attr</i> was not NULL, but <i>attr->mq_maxmsg</i> or
<i>attr->mq_msqsize</i> was invalid. Both of these fields
must be greater than zero. In a process that is unprivileged
(does not have the <b>CAP_SYS_RESOURCE</b> capability),
<i>attr->mq_maxmsg</i> must be less than or equal to the
<i>msg_max</i> limit, and <i>attr->mq_msgsize</i> must be
less than or equal to the <i>msgsize_max</i> limit. In
addition, even in a privileged process,
<i>attr->mq_maxmsg</i> cannot exceed the <b>HARD_MAX</b>
limit. (See <b>mq_overview</b>(7) for details of these
limits.)</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EMFILE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The per-process limit on the number of open file and
message queue descriptors has been reached (see the
description of <b>RLIMIT_NOFILE</b> in
<b>getrlimit</b>(2)).</p> </td></tr>
</table>
<p style="margin-left:11%;"><b>ENAMETOOLONG</b></p>
<p style="margin-left:22%;"><i>name</i> was too long.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENFILE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The system-wide limit on the total number of open files
and message queues has been reached.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOENT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The <b>O_CREAT</b> flag was not specified in
<i>oflag</i>, and no queue with this <i>name</i> exists.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOENT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>name</i> was just "/" followed by no other
characters.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Insufficient memory.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOSPC</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Insufficient space for the creation of a new message
queue. This probably occurred because the <i>queues_max</i>
limit was encountered; see <b>mq_overview</b>(7).</p></td></tr>
</table>
<h2>ATTRIBUTES
<a name="ATTRIBUTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">For an
explanation of the terms used in this section, see
<b>attributes</b>(7).</p>
<p align="center" style="margin-top: 1em"><img src="grohtml-566391.png" alt="Image grohtml-566391.png"></p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">POSIX.1-2001,
POSIX.1-2008.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>C
library/kernel differences</b> <br>
The <b>mq_open</b>() library function is implemented on top
of a system call of the same name. The library function
performs the check that the <i>name</i> starts with a slash
(/), giving the <b>EINVAL</b> error if it does not. The
kernel system call expects <i>name</i> to contain no
preceding slash, so the C library function passes
<i>name</i> without the preceding slash (i.e.,
<i>name+1</i>) to the system call.</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">In kernels
before 2.6.14, the process umask was not applied to the
permissions specified in <i>mode</i>.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>mq_close</b>(3),
<b>mq_getattr</b>(3), <b>mq_notify</b>(3),
<b>mq_receive</b>(3), <b>mq_send</b>(3),
<b>mq_unlink</b>(3), <b>mq_overview</b>(7)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>