]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mq_open.3
fuse.4: ffix
[thirdparty/man-pages.git] / man3 / mq_open.3
1 '\" t
2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH MQ_OPEN 3 2017-09-15 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 mq_open \- open a message queue
29 .SH SYNOPSIS
30 .nf
31 .BR "#include <fcntl.h>" " /* For O_* constants */"
32 .BR "#include <sys/stat.h>" " /* For mode constants */"
33 .B #include <mqueue.h>
34 .PP
35 .BI "mqd_t mq_open(const char *" name ", int " oflag );
36 .BI "mqd_t mq_open(const char *" name ", int " oflag ", mode_t " mode ,
37 .BI " struct mq_attr *" attr );
38 .fi
39 .PP
40 Link with \fI\-lrt\fP.
41 .SH DESCRIPTION
42 .BR mq_open ()
43 creates a new POSIX message queue or opens an existing queue.
44 The queue is identified by
45 .IR name .
46 For details of the construction of
47 .IR name ,
48 see
49 .BR mq_overview (7).
50 .PP
51 The
52 .I oflag
53 argument specifies flags that control the operation of the call.
54 (Definitions of the flags values can be obtained by including
55 .IR <fcntl.h> .)
56 Exactly one of the following must be specified in
57 .IR oflag :
58 .TP
59 .B O_RDONLY
60 Open the queue to receive messages only.
61 .TP
62 .B O_WRONLY
63 Open the queue to send messages only.
64 .TP
65 .B O_RDWR
66 Open the queue to both send and receive messages.
67 .PP
68 Zero or more of the following flags can additionally be
69 .IR OR ed
70 in
71 .IR oflag :
72 .TP
73 .BR O_CLOEXEC " (since Linux 2.6.26)"
74 .\" commit 269f21344b23e552c21c9e2d7ca258479dcd7a0a
75 Set the close-on-exec flag for the message queue descriptor.
76 See
77 .BR open (2)
78 for a discussion of why this flag is useful.
79 .TP
80 .B O_CREAT
81 Create the message queue if it does not exist.
82 The owner (user ID) of the message queue is set to the effective
83 user ID of the calling process.
84 The group ownership (group ID) is set to the effective group ID
85 of the calling process.
86 .\" In reality the filesystem IDs are used on Linux.
87 .TP
88 .B O_EXCL
89 If
90 .B O_CREAT
91 was specified in
92 .IR oflag ,
93 and a queue with the given
94 .I name
95 already exists, then fail with the error
96 .BR EEXIST .
97 .TP
98 .B O_NONBLOCK
99 Open the queue in nonblocking mode.
100 In circumstances where
101 .BR mq_receive (3)
102 and
103 .BR mq_send (3)
104 would normally block, these functions instead fail with the error
105 .BR EAGAIN .
106 .PP
107 If
108 .B O_CREAT
109 is specified in
110 .IR oflag ,
111 then two additional arguments must be supplied.
112 The
113 .I mode
114 argument specifies the permissions to be placed on the new queue,
115 as for
116 .BR open (2).
117 (Symbolic definitions for the permissions bits can be obtained by including
118 .IR <sys/stat.h> .)
119 The permissions settings are masked against the process umask.
120 .PP
121 The fields of the
122 .IR "struct mq_attr"
123 pointed to
124 .I attr
125 specify the maximum number of messages and
126 the maximum size of messages that the queue will allow.
127 This structure is defined as follows:
128 .PP
129 .PP
130 .in +4n
131 .EX
132 struct mq_attr {
133 long mq_flags; /* Flags (ignored for mq_open()) */
134 long mq_maxmsg; /* Max. # of messages on queue */
135 long mq_msgsize; /* Max. message size (bytes) */
136 long mq_curmsgs; /* # of messages currently in queue
137 (ignored for mq_open()) */
138 };
139 .EE
140 .in
141 .PP
142 Only the
143 .I mq_maxmsg
144 and
145 .I mq_msgsize
146 fields are employed when calling
147 .BR mq_open ();
148 the values in the remaining fields are ignored.
149 .PP
150 If
151 .I attr
152 is NULL, then the queue is created with implementation-defined
153 default attributes.
154 Since Linux 3.5, two
155 .I /proc
156 files can be used to control these defaults; see
157 .BR mq_overview (7)
158 for details.
159 .SH RETURN VALUE
160 On success,
161 .BR mq_open ()
162 returns a message queue descriptor for use by other
163 message queue functions.
164 On error,
165 .BR mq_open ()
166 returns
167 .IR "(mqd_t)\ \-1",
168 with
169 .I errno
170 set to indicate the error.
171 .SH ERRORS
172 .TP
173 .B EACCES
174 The queue exists, but the caller does not have permission to
175 open it in the specified mode.
176 .TP
177 .B EACCES
178 .I name
179 contained more than one slash.
180 .\" Note that this isn't consistent with the same case for sem_open()
181 .TP
182 .B EEXIST
183 Both
184 .B O_CREAT
185 and
186 .B O_EXCL
187 were specified in
188 .IR oflag ,
189 but a queue with this
190 .I name
191 already exists.
192 .TP
193 .B EINVAL
194 .\" glibc checks whether the name starts with a "/" and if not,
195 .\" gives this error
196 .I name
197 doesn't follow the format in
198 .BR mq_overview (7).
199 .TP
200 .B EINVAL
201 .B O_CREAT
202 was specified in
203 .IR oflag ,
204 and
205 .I attr
206 was not NULL, but
207 .I attr\->mq_maxmsg
208 or
209 .I attr\->mq_msqsize
210 was invalid.
211 Both of these fields must be greater than zero.
212 In a process that is unprivileged (does not have the
213 .B CAP_SYS_RESOURCE
214 capability),
215 .I attr\->mq_maxmsg
216 must be less than or equal to the
217 .I msg_max
218 limit, and
219 .I attr\->mq_msgsize
220 must be less than or equal to the
221 .I msgsize_max
222 limit.
223 In addition, even in a privileged process,
224 .I attr\->mq_maxmsg
225 cannot exceed the
226 .B HARD_MAX
227 limit.
228 (See
229 .BR mq_overview (7)
230 for details of these limits.)
231 .TP
232 .B EMFILE
233 The per-process limit on the number of open file
234 and message queue descriptors has been reached
235 (see the description of
236 .BR RLIMIT_NOFILE
237 in
238 .BR getrlimit (2)).
239 .TP
240 .B ENAMETOOLONG
241 .I name
242 was too long.
243 .TP
244 .B ENFILE
245 The system-wide limit on the total number of open files
246 and message queues has been reached.
247 .TP
248 .B ENOENT
249 The
250 .B O_CREAT
251 flag was not specified in
252 .IR oflag ,
253 and no queue with this
254 .I name
255 exists.
256 .TP
257 .B ENOENT
258 .I name
259 was just "/" followed by no other characters.
260 .\" Note that this isn't consistent with the same case for sem_open()
261 .TP
262 .B ENOMEM
263 Insufficient memory.
264 .TP
265 .B ENOSPC
266 Insufficient space for the creation of a new message queue.
267 This probably occurred because the
268 .I queues_max
269 limit was encountered; see
270 .BR mq_overview (7).
271 .SH ATTRIBUTES
272 For an explanation of the terms used in this section, see
273 .BR attributes (7).
274 .TS
275 allbox;
276 lb lb lb
277 l l l.
278 Interface Attribute Value
279 T{
280 .BR mq_open ()
281 T} Thread safety MT-Safe
282 .TE
283 .SH CONFORMING TO
284 POSIX.1-2001, POSIX.1-2008.
285 .SH NOTES
286 .SS C library/kernel differences
287 The
288 .BR mq_open ()
289 library function is implemented on top of a system call of the same name.
290 The library function performs the check that the
291 .I name
292 starts with a slash (/), giving the
293 .B EINVAL
294 error if it does not.
295 The kernel system call expects
296 .I name
297 to contain no preceding slash,
298 so the C library function passes
299 .I name
300 without the preceding slash (i.e.,
301 .IR name+1 )
302 to the system call.
303 .SH BUGS
304 In kernels before 2.6.14,
305 the process umask was not applied to the permissions specified in
306 .IR mode .
307 .SH SEE ALSO
308 .BR mq_close (3),
309 .BR mq_getattr (3),
310 .BR mq_notify (3),
311 .BR mq_receive (3),
312 .BR mq_send (3),
313 .BR mq_unlink (3),
314 .BR mq_overview (7)