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

NAME

6       mq_open - open a message queue (REALTIME)
7

SYNOPSIS

9       #include <mqueue.h>
10
11       mqd_t mq_open(const char *name, int oflag, ...);
12
13

DESCRIPTION

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

RETURN VALUE

108       Upon  successful  completion, the function shall return a message queue
109       descriptor; otherwise, the function  shall  return  (mqd_t)-1  and  set
110       errno to indicate the error.
111

ERRORS

113       The mq_open() function shall fail if:
114
115       EACCES The  message queue exists and the permissions specified by oflag
116              are denied, or the message queue does not exist  and  permission
117              to create the message queue is denied.
118
119       EEXIST O_CREAT  and  O_EXCL are set and the named message queue already
120              exists.
121
122       EINTR  The mq_open() function was interrupted by a signal.
123
124       EINVAL The mq_open() function is not supported for the given name.
125
126       EINVAL O_CREAT was specified in oflag, the value of attr is  not  NULL,
127              and  either  mq_maxmsg  or  mq_msgsize was less than or equal to
128              zero.
129
130       EMFILE Too many message queue descriptors or file descriptors are  cur‐
131              rently in use by this process.
132
133       ENAMETOOLONG
134              The length of the name argument exceeds {PATH_MAX} or a pathname
135              component is longer than {NAME_MAX}.
136
137       ENFILE Too many message queues are currently open in the system.
138
139       ENOENT O_CREAT is not set and the named message queue does not exist.
140
141       ENOSPC There is insufficient space for the creation of the new  message
142              queue.
143
144
145       The following sections are informative.
146

EXAMPLES

148       None.
149

APPLICATION USAGE

151       None.
152

RATIONALE

154       None.
155

FUTURE DIRECTIONS

157       None.
158

SEE ALSO

160       mq_close()  ,  mq_getattr() , mq_receive() , mq_send() , mq_setattr() ,
161       mq_timedreceive() , mq_timedsend() , mq_unlink() , msgctl() ,  msgget()
162       ,   msgrcv()   ,   msgsnd()   ,   the   Base   Definitions   volume  of
163       IEEE Std 1003.1-2001, <mqueue.h>
164
166       Portions of this text are reprinted and reproduced in  electronic  form
167       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
168       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
169       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
170       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
171       event of any discrepancy between this version and the original IEEE and
172       The Open Group Standard, the original IEEE and The Open Group  Standard
173       is  the  referee document. The original Standard can be obtained online
174       at http://www.opengroup.org/unix/online.html .
175
176
177
178IEEE/The Open Group                  2003                           MQ_OPEN(P)
Impressum