1mq_open(3C)              Standard C Library Functions              mq_open(3C)
2
3
4

NAME

6       mq_open - open a message queue
7

SYNOPSIS

9       #include <mqueue.h>
10
11       mqd_t mq_open(const char *name, int oflag,
12            /* unsigned long mode, mq_attr attr */  ...);
13
14

DESCRIPTION

16       The mq_open() function establishes the connection between a process and
17       a message queue with a message queue descriptor. It creates a open mes‐
18       sage  queue description that refers to the message queue, and a message
19       queue descriptor that refers to that open  message  queue  description.
20       The  message  queue  descriptor  is used by other functions to refer to
21       that message queue.
22
23
24       The name argument points to a string naming a message queue. The   name
25       argument  must  conform  to the construction rules for a  path-name. If
26       name is not the name of an existing message queue and its  creation  is
27       not  requested, mq_open() fails and returns an error. The first charac‐
28       ter of  name must be a slash  (/) character and the  remaining  charac‐
29       ters  of  name cannot include any slash characters.  For maximum porta‐
30       bility,  name should include no more than 14 characters, but this limit
31       is not enforced.
32
33
34       The  oflag  argument requests the desired receive and/or send access to
35       the message queue. The requested access permission to receive  messages
36       or  send  messages  is  granted if the calling process would be granted
37       read or write access, respectively, to a file with the equivalent  per‐
38       missions.
39
40
41       The  value of oflag is the bitwise inclusive OR of values from the fol‐
42       lowing list. Applications must specify exactly one of the  first  three
43       values (access modes) below in the value of oflag:
44
45       O_RDONLY     Open the message queue for receiving messages. The process
46                    can  use  the  returned  message  queue  descriptor   with
47                    mq_receive(3C),  but  not mq_send(3C). A message queue may
48                    be open multiple times in the same or different  processes
49                    for receiving messages.
50
51
52       O_WRONLY     Open  the  queue for sending messages. The process can use
53                    the returned message queue descriptor with mq_send(3C) but
54                    not  mq_receive(3C).  A message queue may be open multiple
55                    times in the same or different processes for sending  mes‐
56                    sages.
57
58
59       O_RDWR       Open  the  queue  for both receiving and sending messages.
60                    The process can use  any  of  the  functions  allowed  for
61                    O_RDONLY  and O_WRONLY. A message queue may be open multi‐
62                    ple times in the same or different processes  for  sending
63                    messages.
64
65
66
67       Any combination of the remaining flags may additionally be specified in
68       the value of oflag:
69
70       O_CREAT        This option is used to create a message  queue,  and  it
71                      requires  two  additional  arguments:  mode, which is of
72                      type mode_t, and  attr, which is pointer  to  a  mq_attr
73                      structure.  If the pathname, name, has already been used
74                      to create a message queue that still exists,  then  this
75                      flag  has  no  effect, except as noted under O_EXCL (see
76                      below). Otherwise, a message queue  is  created  without
77                      any messages in it.
78
79                      The user ID of the message queue is set to the effective
80                      user ID of process, and the  group  ID  of  the  message
81                      queue  is  set to the effective group ID of the process.
82                      The file permission bits are set to the value  of  mode,
83                      and  modified  by clearing all bits set in the file mode
84                      creation mask of the process (see umask(2)).
85
86                      If attr is non-NULL and  the  calling  process  has  the
87                      appropriate   privilege   on  name,  the  message  queue
88                      mq_maxmsg and mq_msgsize attributes are set to the  val‐
89                      ues  of  the corresponding members in the mq_attr struc‐
90                      ture referred to by attr. If attr is non-NULL,  but  the
91                      calling  process does not have the appropriate privilege
92                      on name, the mq_open() function  fails  and  returns  an
93                      error without creating the message queue.
94
95
96       O_EXCL         If  both O_EXCL and O_CREAT are set, mq_open() will fail
97                      if the message queue name  exists.  The  check  for  the
98                      existence  of  the message queue and the creation of the
99                      message queue if it  does  not  exist  are  atomic  with
100                      respect  to  other  processes executing mq_open() naming
101                      the same name with both  O_EXCL  and  O_CREAT  set.   If
102                      O_EXCL and O_CREAT are not set, the result is undefined.
103
104
105       O_NONBLOCK     The  setting  of  this  flag is associated with the open
106                      message  queue  description  and  determines  whether  a
107                      mq_send(3C)  or  mq_receive(3C)  waits  for resources or
108                      messages that are not currently available, or fails with
109                      errno  set to EAGAIN. See mq_send(3C) and mq_receive(3C)
110                      for details.
111
112

RETURN VALUES

114       Upon successful completion, mq_open() returns a message queue  descrip‐
115       tor;  otherwise  the function returns (mqd_t)−1 and sets errno to indi‐
116       cate the error condition.
117

ERRORS

119       The  mq_open() function will fail if:
120
121       EACCES           The message queue exists and the permissions specified
122                        by  oflag  are  denied,  or the message queue does not
123                        exist and permission to create the  message  queue  is
124                        denied.
125
126
127       EEXIST           O_CREAT and O_EXCL are set and the named message queue
128                        already exists.
129
130
131       EINTR            The mq_open() operation was interrupted by a signal.
132
133
134       EINVAL           The mq_open() operation is not supported for the given
135                        name,  or O_CREAT was specified in oflag, the value of
136                        attr is not NULL, and either mq_maxmsg  or  mq_msgsize
137                        was less than or equal to zero.
138
139
140       EMFILE           The  number  of open message queue descriptors in this
141                        process exceeds MQ_OPEN_MAX, of  the  number  of  open
142                        file descriptors in this process exceeds OPEN_MAX.
143
144
145       ENAMETOOLONG     The  length  of the name string exceeds PATH_MAX, or a
146                        pathname  component  is  longer  than  NAME_MAX  while
147                        _POSIX_NO_TRUNC is in effect.
148
149
150       ENFILE           Too many message queues are currently open in the sys‐
151                        tem.
152
153
154       ENOENT           O_CREAT is not set and the named  message  queue  does
155                        not exist.
156
157
158       ENOSPC           There  is  insufficient  space for the creation of the
159                        new message queue.
160
161
162       ENOSYS           The mq_open() function is not supported by the system.
163
164

ATTRIBUTES

166       See attributes(5) for descriptions of the following attributes:
167
168
169
170
171       ┌─────────────────────────────┬─────────────────────────────┐
172ATTRIBUTE TYPE               ATTRIBUTE VALUE              
173       ├─────────────────────────────┼─────────────────────────────┤
174       │Interface Stability          │Committed                    │
175       ├─────────────────────────────┼─────────────────────────────┤
176       │MT-Level                     │MT-Safe                      │
177       ├─────────────────────────────┼─────────────────────────────┤
178       │Standard                     │See standards(5).            │
179       └─────────────────────────────┴─────────────────────────────┘
180

SEE ALSO

182       exec(2), exit(2), umask(2), sysconf(3C), mqueue.h(3HEAD), mq_close(3C),
183       mq_receive(3C),     mq_send(3C),     mq_setattr(3C),     mq_unlink(3C),
184       attributes(5), standards(5)
185

NOTES

187       Due to the manner in which message queues are implemented, they  should
188       not  be  considered secure and should not be used in security-sensitive
189       applications.
190
191
192       Solaris 2.6 was the first release to support the Asynchronous Input and
193       Output  option. Prior to this release, this function always returned −1
194       and set errno to ENOSYS.
195
196
197
198SunOS 5.11                        5 Feb 2008                       mq_open(3C)
Impressum