]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mq_open.3
perf_event_open.2: srcfix
[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 2015-12-28 "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 .sp
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 .sp
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
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
121 The
122 .I attr
123 argument specifies attributes for the queue.
124 See
125 .BR mq_getattr (3)
126 for details.
127 If
128 .I attr
129 is NULL, then the queue is created with implementation-defined
130 default attributes.
131 Since Linux 3.5, two
132 .I /proc
133 files can be used to control these defaults; see
134 .BR mq_overview (7)
135 for details.
136 .SH RETURN VALUE
137 On success,
138 .BR mq_open ()
139 returns a message queue descriptor for use by other
140 message queue functions.
141 On error,
142 .BR mq_open ()
143 returns
144 .IR "(mqd_t)\ \-1",
145 with
146 .I errno
147 set to indicate the error.
148 .SH ERRORS
149 .TP
150 .B EACCES
151 The queue exists, but the caller does not have permission to
152 open it in the specified mode.
153 .TP
154 .B EACCES
155 .I name
156 contained more than one slash.
157 .\" Note that this isn't consistent with the same case for sem_open()
158 .TP
159 .B EEXIST
160 Both
161 .B O_CREAT
162 and
163 .B O_EXCL
164 were specified in
165 .IR oflag ,
166 but a queue with this
167 .I name
168 already exists.
169 .TP
170 .B EINVAL
171 .\" glibc checks whether the name starts with a "/" and if not,
172 .\" gives this error
173 .I name
174 doesn't follow the format in
175 .BR mq_overview (7).
176 .TP
177 .B EINVAL
178 .B O_CREAT
179 was specified in
180 .IR oflag ,
181 and
182 .I attr
183 was not NULL, but
184 .I attr\->mq_maxmsg
185 or
186 .I attr\->mq_msqsize
187 was invalid.
188 Both of these fields must be greater than zero.
189 In a process that is unprivileged (does not have the
190 .B CAP_SYS_RESOURCE
191 capability),
192 .I attr\->mq_maxmsg
193 must be less than or equal to the
194 .I msg_max
195 limit, and
196 .I attr\->mq_msgsize
197 must be less than or equal to the
198 .I msgsize_max
199 limit.
200 In addition, even in a privileged process,
201 .I attr\->mq_maxmsg
202 cannot exceed the
203 .B HARD_MAX
204 limit.
205 (See
206 .BR mq_overview (7)
207 for details of these limits.)
208 .TP
209 .B EMFILE
210 The per-process limit on the number of open file
211 and message queue descriptors has been reached
212 (see the description of
213 .BR RLIMIT_NOFILE
214 in
215 .BR getrlimit (2)).
216 .TP
217 .B ENAMETOOLONG
218 .I name
219 was too long.
220 .TP
221 .B ENFILE
222 The system-wide limit on the total number of open files
223 and message queues has been reached.
224 .TP
225 .B ENOENT
226 The
227 .B O_CREAT
228 flag was not specified in
229 .IR oflag ,
230 and no queue with this
231 .I name
232 exists.
233 .TP
234 .B ENOENT
235 .I name
236 was just "/" followed by no other characters.
237 .\" Note that this isn't consistent with the same case for sem_open()
238 .TP
239 .B ENOMEM
240 Insufficient memory.
241 .TP
242 .B ENOSPC
243 Insufficient space for the creation of a new message queue.
244 This probably occurred because the
245 .I queues_max
246 limit was encountered; see
247 .BR mq_overview (7).
248 .SH ATTRIBUTES
249 For an explanation of the terms used in this section, see
250 .BR attributes (7).
251 .TS
252 allbox;
253 lb lb lb
254 l l l.
255 Interface Attribute Value
256 T{
257 .BR mq_open ()
258 T} Thread safety MT-Safe
259 .TE
260 .SH CONFORMING TO
261 POSIX.1-2001, POSIX.1-2008.
262 .SH NOTES
263 .SS C library/kernel differences
264 The
265 .BR mq_open ()
266 library function is implemented on top of a system call of the same name.
267 The library function performs the check that the
268 .I name
269 starts with a slash (/), giving the
270 .B EINVAL
271 error if it does not.
272 The kernel system call expects
273 .I name
274 to contain no preceding slash,
275 so the C library function passes
276 .I name
277 without the preceding slash (i.e.,
278 .IR name+1 )
279 to the system call.
280 .SH BUGS
281 In kernels before 2.6.14,
282 the process umask was not applied to the permissions specified in
283 .IR mode .
284 .SH SEE ALSO
285 .BR mq_close (3),
286 .BR mq_getattr (3),
287 .BR mq_notify (3),
288 .BR mq_receive (3),
289 .BR mq_send (3),
290 .BR mq_unlink (3),
291 .BR mq_overview (7)