mq_open(3)mq_open(3)NAMEmq_open - Establishes the connection between a message queue and a mes‐
sage queue descriptor (P1003.1b)
SYNOPSIS
#include <mqueue.h>
mqd_t mq_open ( const char *name, int ooption, ...);
LIBRARY
Realtime Library (librt.so, librt.a)
PARAMETERS
Specifies a pointer to the name of a string naming the message queue.
The string can be a pathname. Specifies the request for receive or
send access to the message queue, as well as the blocking attributes of
the resulting open descriptor for the calling process.
This value of this argument is the bitwise inclusive OR of the values
from the following list of options. An application must specify
exactly one of the first three options: Opens the message queue for
receiving messages. This enables calls to the mq_receive function but
not calls to the mq_send function for the calling process. Note that
each process has its own read/write access to a queue. Opens the queue
for sending messages.
This enables calls to the mq_send function but not calls to the
mq_receive function for the calling process. Opens the queue for
receiving and sending messages for the calling process.
Any combination of the following options is valid: Creates a message
queue. Use of this option requires specification of two additional
arguments: mode, which is of type mode_t, and attr, which points to a
mq_attr structure. If name has already been used to create a message
queue that is still open, this option has no effect, except as noted
under O_EXCL. Otherwise, a message queue is created. The ID of the
message queue becomes the effective user ID, and the group ID of the
message queue becomes the effective group ID of the process. The mode
argument sets the file permission bits. If the attr argument is NULL,
the function creates the message queue with default attributes. If the
attr argument is not NULL, and the calling process has appropriate
privilege or permission, the message queue attributes are set as if the
mq_setattr function were called with the attribute argument attr. If
the attr argument is not NULL, but the calling process does not have
the appropriate privilege or permission, the mq_open argument fails and
returns an error. Prevents the opening of a message queue if O_CREAT
is set and the message queue already exists. Use this option only in
combination with O_CREAT. Allows calls to the mq_send and mq_receive
functions to continue execution while waiting for resources or mes‐
sages. When this option is set and resources are not available, the
mq_send and mq_receive functions fail and errno is set to EAGAIN. This
option is a per-open descriptor option, and applies to the calling
process only. Each process has its own blocking attributes for a queue.
DESCRIPTION
The mq_open function establishes the connection between a message queue
and a message queue descriptor. This function creates a new open mes‐
sage queue description that refers to a specified message queue and a
message queue descriptor that refers to that open message queue
description.
The message queue descriptor is then available for use by other func‐
tions for reference to the message queue from the calling process.
RETURN VALUES
On successful completion, this function returns a message queue
descriptor.
Otherwise, the function returns -1 and sets errno to indicate the
error.
ERRORS
The mq_open function fails under the following conditions: The message
queue exists and the permissions specified by ooption are denied, or
the message queue does not exist and permission to create the message
queue is denied. O_CREAT and O_EXCL are set, and the named message
queue already exists. An internal virtual memory error occurred. The
mq_open operation was interrupted by a signal. The mq_open operation
is not supported for the given name. O_CREAT was specified in ooption,
the value of attr is not NULL, and either mq_maxmsg or mq_msgsize was
less than or equal to zero.
POSIX message queues should be created and modified only through
POSIX message queue routines. It is possible for this error to
be returned if the given name refers to a file that cannot be
recognized, perhaps because it was created or modified by an
unsupported call. Too many message queue descriptors or file
descriptors are currently in use by this process. The length of
the name string exceeds {PATH_MAX}, or a pathname component is
longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect.
Too many message queues are currently open in the system.
O_CREAT is not set and the named message queue does not exist.
There is insufficient space for the creation of the new message
queue.
SEE ALSO
Functions: mq_close(3), mq_getattr(3), mq_receive(3), mq_send(3),
mq_setattr(3), mq_unlink(3), mkfifo(3)
Guide to Realtime Programming
mq_open(3)