OSDN Git Service

LDP: Update original to LDP v3.76
[linuxjm/LDP_man-pages.git] / original / 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 2014-12-31 "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 .B O_CREAT
172 was specified in
173 .IR oflag ,
174 and
175 .I attr
176 was not NULL, but
177 .I attr\->mq_maxmsg
178 or
179 .I attr\->mq_msqsize
180 was invalid.
181 Both of these fields must be greater than zero.
182 In a process that is unprivileged (does not have the
183 .B CAP_SYS_RESOURCE
184 capability),
185 .I attr\->mq_maxmsg
186 must be less than or equal to the
187 .I msg_max
188 limit, and
189 .I attr\->mq_msgsize
190 must be less than or equal to the
191 .I msgsize_max
192 limit.
193 In addition, even in a privileged process,
194 .I attr\->mq_maxmsg
195 cannot exceed the
196 .B HARD_MAX
197 limit.
198 (See
199 .BR mq_overview (7)
200 for details of these limits.)
201 .TP
202 .B EMFILE
203 The process already has the maximum number of files and
204 message queues open.
205 .TP
206 .B ENAMETOOLONG
207 .I name
208 was too long.
209 .TP
210 .B ENFILE
211 The system limit on the total number of open files and message queues
212 has been reached.
213 .TP
214 .B ENOENT
215 The
216 .B O_CREAT
217 flag was not specified in
218 .IR oflag ,
219 and no queue with this
220 .I name
221 exists.
222 .TP
223 .B ENOENT
224 .I name
225 was just "/" followed by no other characters.
226 .\" Note that this isn't consistent with the same case for sem_open()
227 .TP
228 .B ENOMEM
229 Insufficient memory.
230 .TP
231 .B ENOSPC
232 Insufficient space for the creation of a new message queue.
233 This probably occurred because the
234 .I queues_max
235 limit was encountered; see
236 .BR mq_overview (7).
237 .SH ATTRIBUTES
238 .SS Multithreading (see pthreads(7))
239 The
240 .BR mq_open ()
241 function is thread-safe.
242 .SH CONFORMING TO
243 POSIX.1-2001.
244 .SH BUGS
245 In kernels before 2.6.14,
246 the process umask was not applied to the permissions specified in
247 .IR mode .
248 .SH SEE ALSO
249 .BR mq_close (3),
250 .BR mq_getattr (3),
251 .BR mq_notify (3),
252 .BR mq_receive (3),
253 .BR mq_send (3),
254 .BR mq_unlink (3),
255 .BR mq_overview (7)
256 .SH COLOPHON
257 This page is part of release 3.76 of the Linux
258 .I man-pages
259 project.
260 A description of the project,
261 information about reporting bugs,
262 and the latest version of this page,
263 can be found at
264 \%http://www.kernel.org/doc/man\-pages/.