1MQ_OPEN(3P)                POSIX Programmer's Manual               MQ_OPEN(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       mq_open — open a message queue (REALTIME)
13

SYNOPSIS

15       #include <mqueue.h>
16
17       mqd_t mq_open(const char *name, int oflag, ...);
18

DESCRIPTION

20       The mq_open() function shall establish the connection between a process
21       and a message queue with a message queue descriptor. It shall create an
22       open message queue description that refers to the message queue, and  a
23       message  queue  descriptor  that  refers  to  that  open  message queue
24       description. The message queue descriptor is used by other functions to
25       refer  to that message queue. The name argument points to a string nam‐
26       ing a message queue. It is unspecified whether the name appears in  the
27       file  system  and  is visible to other functions that take pathnames as
28       arguments. The name argument conforms to the construction rules  for  a
29       pathname,  except  that  the interpretation of <slash> characters other
30       than the leading <slash> character in name  is  implementation-defined,
31       and  that  the  length limits for the name argument are implementation-
32       defined and need not be the same as the pathname limits {PATH_MAX}  and
33       {NAME_MAX}.   If name begins with the <slash> character, then processes
34       calling mq_open() with the same value of name shall refer to  the  same
35       message  queue  object,  as  long as that name has not been removed. If
36       name does not begin with the <slash> character, the effect is implemen‐
37       tation-defined.  If  the  name  argument is not the name of an existing
38       message queue and creation is not requested, mq_open() shall  fail  and
39       return an error.
40
41       A  message queue descriptor may be implemented using a file descriptor,
42       in which case applications can open up to at least {OPEN_MAX} file  and
43       message queues.
44
45       The  oflag  argument requests the desired receive and/or send access to
46       the message queue. The requested access permission to receive  messages
47       or  send  messages  shall  be  granted  if the calling process would be
48       granted read or write access, respectively,  to  an  equivalently  pro‐
49       tected file.
50
51       The  value of oflag is the bitwise-inclusive OR of values from the fol‐
52       lowing list.  Applications shall specify exactly one of the first three
53       values (access modes) below in the value of oflag:
54
55       O_RDONLY    Open  the message queue for receiving messages. The process
56                   can  use  the  returned  message  queue   descriptor   with
57                   mq_receive(),  but  not  mq_send().  A message queue may be
58                   open multiple times in the same or different processes  for
59                   receiving messages.
60
61       O_WRONLY    Open  the  queue  for sending messages. The process can use
62                   the returned message queue descriptor  with  mq_send()  but
63                   not  mq_receive().   A  message  queue may be open multiple
64                   times in the same or different processes for  sending  mes‐
65                   sages.
66
67       O_RDWR      Open the queue for both receiving and sending messages. The
68                   process can use any of the functions allowed  for  O_RDONLY
69                   and O_WRONLY. A message queue may be open multiple times in
70                   the same or different processes for sending messages.
71
72       Any combination of the remaining flags may be specified in the value of
73       oflag:
74
75       O_CREAT     Create  a  message  queue. It requires two additional argu‐
76                   ments: mode, which shall be of type mode_t, and attr, which
77                   shall be a pointer to an mq_attr structure. If the pathname
78                   name has already been used to create a message  queue  that
79                   still  exists,  then this flag shall have no effect, except
80                   as noted under O_EXCL.  Otherwise, a message queue shall be
81                   created without any messages in it. The user ID of the mes‐
82                   sage queue shall be set to the effective  user  ID  of  the
83                   process.  The group ID of the message queue shall be set to
84                   the effective group ID of the process; however, if the name
85                   argument is visible in the file system, the group ID may be
86                   set to the group ID of the containing directory. When  bits
87                   in  mode other than the file permission bits are specified,
88                   the effect is unspecified. If attr  is  NULL,  the  message
89                   queue  shall be created with implementation-defined default
90                   message queue attributes. If attr is non-NULL and the call‐
91                   ing process has appropriate privileges on name, the message
92                   queue mq_maxmsg and mq_msgsize attributes shall be  set  to
93                   the  values  of  the  corresponding  members in the mq_attr
94                   structure referred to by attr.  The values of the  mq_flags
95                   and  mq_curmsgs  members  of the mq_attr structure shall be
96                   ignored. If attr is non-NULL, but the calling process  does
97                   not  have  appropriate  privileges  on  name, the mq_open()
98                   function shall fail and return an  error  without  creating
99                   the message queue.
100
101       O_EXCL      If  O_EXCL and O_CREAT are set, mq_open() shall fail if the
102                   message queue name exists. The check for the  existence  of
103                   the  message queue and the creation of the message queue if
104                   it does not exist shall be atomic  with  respect  to  other
105                   threads  executing  mq_open()  naming  the  same  name with
106                   O_EXCL and O_CREAT set. If O_EXCL is set and O_CREAT is not
107                   set, the result is undefined.
108
109       O_NONBLOCK  Determines  whether  an mq_send() or mq_receive() waits for
110                   resources or messages that are not currently available,  or
111                   fails  with  errno  set  to  [EAGAIN];  see  mq_send()  and
112                   mq_receive() for details.
113
114       The mq_open() function does not add or remove messages from the queue.
115

RETURN VALUE

117       Upon successful completion, the function shall return a  message  queue
118       descriptor;  otherwise,  the  function  shall  return (mqd_t)-1 and set
119       errno to indicate the error.
120

ERRORS

122       The mq_open() function shall fail if:
123
124       EACCES The message queue exists and the permissions specified by  oflag
125              are  denied,  or the message queue does not exist and permission
126              to create the message queue is denied.
127
128       EEXIST O_CREAT and O_EXCL are set and the named message  queue  already
129              exists.
130
131       EINTR  The mq_open() function was interrupted by a signal.
132
133       EINVAL The mq_open() function is not supported for the given name.
134
135       EINVAL O_CREAT  was  specified in oflag, the value of attr is not NULL,
136              and either mq_maxmsg or mq_msgsize was less  than  or  equal  to
137              zero.
138
139       EMFILE Too  many message queue descriptors or file descriptors are cur‐
140              rently in use by this process.
141
142       ENFILE Too many message queues are currently open in the system.
143
144       ENOENT O_CREAT is not set and the named message queue does not exist.
145
146       ENOSPC There is insufficient space for the creation of the new  message
147              queue.
148
149       If  any  of  the following conditions occur, the mq_open() function may
150       return (mqd_t)-1 and set errno to the corresponding value.
151
152       ENAMETOOLONG
153              The length of the name  argument  exceeds  {_POSIX_PATH_MAX}  on
154              systems   that   do  not  support  the  XSI  option  or  exceeds
155              {_XOPEN_PATH_MAX} on XSI systems, or has  a  pathname  component
156              that  is  longer  than  {_POSIX_NAME_MAX} on systems that do not
157              support the XSI option or longer than {_XOPEN_NAME_MAX}  on  XSI
158              systems.
159
160       The following sections are informative.
161

EXAMPLES

163       None.
164

APPLICATION USAGE

166       None.
167

RATIONALE

169       None.
170

FUTURE DIRECTIONS

172       A  future version might require the mq_open() and mq_unlink() functions
173       to have semantics similar to normal file system operations.
174

SEE ALSO

176       mq_close(),  mq_getattr(),   mq_receive(),   mq_send(),   mq_setattr(),
177       mq_unlink(), msgctl(), msgget(), msgrcv(), msgsnd()
178
179       The Base Definitions volume of POSIX.1‐2017, <mqueue.h>
180
182       Portions  of  this text are reprinted and reproduced in electronic form
183       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
184       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
185       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
186       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
187       event of any discrepancy between this version and the original IEEE and
188       The  Open Group Standard, the original IEEE and The Open Group Standard
189       is the referee document. The original Standard can be  obtained  online
190       at http://www.opengroup.org/unix/online.html .
191
192       Any  typographical  or  formatting  errors that appear in this page are
193       most likely to have been introduced during the conversion of the source
194       files  to  man page format. To report such errors, see https://www.ker
195       nel.org/doc/man-pages/reporting_bugs.html .
196
197
198
199IEEE/The Open Group                  2017                          MQ_OPEN(3P)
Impressum