xref: /netbsd-src/lib/librt/mq_open.3 (revision a973b3648672c82fea3adf859ae478382ab03e9d)
1*a973b364Snjoly.\"	$NetBSD: mq_open.3,v 1.6 2012/03/15 19:04:47 njoly Exp $
257babc49Srmind.\"
357babc49Srmind.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
457babc49Srmind.\"
500b42ad8Sjruoho.Dd June 7, 2010
657babc49Srmind.Dt MQ_OPEN 3
757babc49Srmind.Os
857babc49Srmind.Sh NAME
957babc49Srmind.Nm mq_open
1057babc49Srmind.Nd open a message queue (REALTIME)
1157babc49Srmind.Sh LIBRARY
1257babc49Srmind.Lb librt
1357babc49Srmind.Sh SYNOPSIS
1457babc49Srmind.In mqueue.h
1557babc49Srmind.Ft mqd_t
1657babc49Srmind.Fn mq_open "const char *name" "int oflag"
1757babc49Srmind.Ft mqd_t
1857babc49Srmind.Fn mq_open "const char *name" "int oflag" "mode_t mode" "struct mq_attr *attr"
1957babc49Srmind.Sh DESCRIPTION
2057babc49SrmindThe
2157babc49Srmind.Fn mq_open
2257babc49Srmindfunction establishes the connection between a process and a message queue
2357babc49Srmindwith a message queue descriptor.
2457babc49SrmindIt creates an open message queue description that refers to the message
2557babc49Srmindqueue, and a message queue descriptor that refers to that open message
2657babc49Srmindqueue description.
2757babc49SrmindThe message queue descriptor is used by other functions to refer to that
2857babc49Srmindmessage queue.
2957babc49SrmindThe
3057babc49Srmind.Fa name
3157babc49Srmindargument points to a string naming a message queue,
3257babc49Srmindwhich should conform to the construction rules for a pathname.
3357babc49SrmindThe
3457babc49Srmind.Fa name
3557babc49Srmindshould begin with a slash character.
3657babc49SrmindThe processes calling
3757babc49Srmind.Fn mq_open
3857babc49Srmindwith the same value of
3957babc49Srmind.Fa name
4057babc49Srmindwill refer to the same message queue object,
4157babc49Srmindas long as that name has not been removed.
4257babc49SrmindIf the
4357babc49Srmind.Fa name
4457babc49Srmindargument is not
4557babc49Srmindthe name of an existing message queue and creation is not requested,
4657babc49Srmind.Fn mq_open
4757babc49Srmindfails and returns an error.
4857babc49Srmind.Pp
4957babc49SrmindThe
5057babc49Srmind.Fa oflag
5157babc49Srmindargument requests the desired receive and/or send access to the message queue.
5257babc49SrmindThe requested access permission to receive messages or send messages are
5357babc49Srmindgranted if the calling process would be granted read or write access,
5457babc49Srmindrespectively, to an equivalently protected file.
5557babc49Srmind.Pp
5657babc49SrmindThe value of
5757babc49Srmind.Fa oflag
5857babc49Srmindis the bitwise-inclusive OR of values from the following list.
5957babc49SrmindApplications must specify exactly one of the first three values
6057babc49Srmind(access modes) below in the value of
6157babc49Srmind.Fa oflag :
624f27706eSjoerg.Bl -tag -width ".Dv O_RDONLY"
6357babc49Srmind.It Dv O_RDONLY
6457babc49SrmindOpen the message queue for receiving messages.
6557babc49SrmindThe process can use the returned message queue descriptor with
6657babc49Srmind.Xr mq_receive 3 ,
6757babc49Srmindbut not
6857babc49Srmind.Xr mq_send 3 .
6957babc49Srmind.It Dv O_WRONLY
7057babc49SrmindOpen the queue for sending messages.
7157babc49SrmindThe process can use the returned message queue descriptor with
7257babc49Srmind.Xr mq_send 3
7357babc49Srmindbut not
7457babc49Srmind.Xr mq_receive 3 .
7557babc49Srmind.It Dv O_RDWR
7657babc49SrmindOpen the queue for both receiving and sending messages.
7757babc49SrmindThe process can use any of the functions allowed for
7857babc49Srmind.Dv O_RDONLY
7957babc49Srmindand
8057babc49Srmind.Dv O_WRONLY .
8157babc49Srmind.El
8257babc49Srmind.Pp
8357babc49SrmindIn all cases, a message queue may be open multiple times in the same
8457babc49Srmindor different processes for sending/receiving messages.
8557babc49Srmind.Pp
8657babc49SrmindAny combination of the remaining flags may be specified in the value of
8757babc49Srmind.Fa oflag :
884f27706eSjoerg.Bl -tag -width ".Dv O_NONBLOCK"
8957babc49Srmind.It Dv O_CREAT
9057babc49SrmindCreate a message queue.
9157babc49SrmindIt requires two additional arguments:
9257babc49Srmind.Fa mode
9357babc49Srmindand
9457babc49Srmind.Fa attr .
9557babc49SrmindIf the pathname
9657babc49Srmind.Fa name
9757babc49Srmindhas already been used to create a message queue that still exists,
9857babc49Srmindthen this flag will have no effect, except as noted under
9957babc49Srmind.Dv O_EXCL .
10057babc49SrmindOtherwise, a message queue will be created without any messages in it.
10157babc49SrmindThe user ID of the message queue will be set to the effective user ID
10257babc49Srmindof the process, and the group ID of the message queue will be set to
10357babc49Srmindthe effective group ID of the process.
10457babc49SrmindThe permission bits of the message queue will be set to the value of the
10557babc49Srmind.Fa mode
10657babc49Srmindargument, except those set in the file mode creation mask of
10757babc49Srmindthe process.
10857babc49SrmindWhen bits in
10957babc49Srmind.Fa mode
11057babc49Srmindother than the file permission bits are specified, the effect
11157babc49Srmindis unspecified.
11257babc49SrmindIf
11357babc49Srmind.Fa attr
11457babc49Srmindis
11557babc49Srmind.Dv NULL ,
11657babc49Srmindthe message queue will be created with implementation-defined default
11757babc49Srmindmessage queue attributes.
11857babc49SrmindIf
11957babc49Srmind.Fa attr
12057babc49Srmindis
12157babc49Srmind.No non- Ns Dv NULL
12257babc49Srmindand the calling process has the appropriate privilege on
12357babc49Srmind.Fa name ,
12457babc49Srmindthe message queue
12557babc49Srmind.Va mq_maxmsg
12657babc49Srmindand
12757babc49Srmind.Va mq_msgsize
12857babc49Srmindattributes will be set to the values of the corresponding members in the
12957babc49Srmind.Vt mq_attr
13057babc49Srmindstructure referred to by
13157babc49Srmind.Fa attr .
13257babc49SrmindIf
13357babc49Srmind.Fa attr
13457babc49Srmindis
13557babc49Srmind.No non- Ns Dv NULL ,
13657babc49Srmindbut the calling process does not have the
13757babc49Srmindappropriate privilege on
13857babc49Srmind.Fa name ,
13957babc49Srmindthe
14057babc49Srmind.Fn mq_open
14157babc49Srmindfunction will fail and return an error without creating the message queue.
14257babc49Srmind.It Dv O_EXCL
14357babc49SrmindIf
14457babc49Srmind.Dv O_EXCL
14557babc49Srmindand
14657babc49Srmind.Dv O_CREAT
14757babc49Srmindare set,
14857babc49Srmind.Fn mq_open
14957babc49Srmindfails if the message queue
15057babc49Srmind.Fa name
15157babc49Srmindexists.
15257babc49SrmindThe check for the existence of the message queue and the creation of the
15357babc49Srmindmessage queue if it does not exist will be atomic with respect to other
15457babc49Srmindthreads executing
15557babc49Srmind.Fn mq_open
15657babc49Srmindnaming the same
15757babc49Srmind.Fa name
15857babc49Srmindwith
15957babc49Srmind.Dv O_EXCL
16057babc49Srmindand
16157babc49Srmind.Dv O_CREAT
16257babc49Srmindset.
16357babc49SrmindIf
16457babc49Srmind.Dv O_EXCL
16557babc49Srmindis set and
16657babc49Srmind.Dv O_CREAT
16757babc49Srmindis not set, the result is undefined.
16857babc49Srmind.It Dv O_NONBLOCK
16957babc49SrmindDetermines whether an
17057babc49Srmind.Xr mq_send 3
17157babc49Srmindor
17257babc49Srmind.Xr mq_receive 3
17357babc49Srmindwaits for resources or messages that are not currently available,
17457babc49Srmindor fails with errno set to
17557babc49Srmind.Er EAGAIN .
17657babc49Srmind.El
17757babc49Srmind.Pp
17857babc49SrmindThe
17957babc49Srmind.Fn mq_open
18057babc49Srmindfunction does not add or remove messages from the queue.
181a9d1f49aSjruoho.Sh IMPLEMENTATION NOTES
18257babc49SrmindThe
18357babc49Srmind.Xr select 2
18457babc49Srmindand
18557babc49Srmind.Xr poll 2
18657babc49Srmindsystem calls to the message queue descriptor are supported by
18757babc49Srmind.Nx ,
18857babc49Srmindhowever, it is not portable.
18957babc49Srmind.Sh RETURN VALUES
19057babc49SrmindUpon successful completion,
19157babc49Srmind.Fn mq_open
19257babc49Srmindreturns a message queue descriptor.
19357babc49SrmindOtherwise, the function returns
19457babc49Srmind.Pq Dv mqd_t
19557babc49Srmind\-1 and sets the global variable
19657babc49Srmind.Va errno
19757babc49Srmindto indicate the error.
19857babc49Srmind.Sh ERRORS
19957babc49SrmindThe
20057babc49Srmind.Fn mq_open
20157babc49Srmindfunction fails if:
20257babc49Srmind.Bl -tag -width Er
20357babc49Srmind.It Bq Er EACCES
20457babc49SrmindThe message queue exists and the permissions specified by
20557babc49Srmind.Fa oflag
20657babc49Srmindare denied, or the message queue does not exist and permission
20757babc49Srmindto create the message queue is denied.
20857babc49Srmind.It Bq Er EEXIST
20957babc49Srmind.Dv O_CREAT
21057babc49Srmindand
21157babc49Srmind.Dv O_EXCL
21257babc49Srmindare set and the named message queue already exists.
21357babc49Srmind.It Bq Er EINTR
21457babc49SrmindThe
21557babc49Srmind.Fn mq_open
21657babc49Srmindfunction was interrupted by a signal.
21757babc49Srmind.It Bq Er EINVAL
21857babc49SrmindThe
21957babc49Srmind.Fn mq_open
22057babc49Srmindfunction is not supported for the given name, or
22157babc49Srmind.Dv O_CREAT
22257babc49Srmindwas specified in
22357babc49Srmind.Fa oflag ,
22457babc49Srmindthe value of
22557babc49Srmind.Fa attr
22657babc49Srmindis not
22757babc49Srmind.Dv NULL ,
22857babc49Srmindand either
22957babc49Srmind.Va mq_maxmsg
23057babc49Srmindor
23157babc49Srmind.Va mq_msgsize
23257babc49Srmindwas less than or equal to zero.
23357babc49Srmind.It Bq Er EMFILE
23457babc49SrmindToo many message queue descriptors or file descriptors are currently
23557babc49Srmindin use by this process.
23657babc49Srmind.It Bq Er ENAMETOOLONG
23757babc49SrmindThe length of the
23857babc49Srmind.Fa name
23957babc49Srmindargument exceeds
24057babc49Srmind.Brq Dv PATH_MAX
24157babc49Srmindor a pathname component is longer than
24257babc49Srmind.Brq Dv NAME_MAX .
24357babc49Srmind.It Bq Er ENFILE
24457babc49SrmindToo many message queues are currently open in the system.
24557babc49Srmind.It Bq Er ENOENT
24657babc49Srmind.Dv O_CREAT
24757babc49Srmindis not set and the named message queue does not exist.
24857babc49Srmind.It Bq Er ENOSPC
24957babc49SrmindThere is insufficient space for the creation of the new message queue.
25057babc49Srmind.El
25157babc49Srmind.Sh SEE ALSO
25200b42ad8Sjruoho.Xr mq 3 ,
25357babc49Srmind.Xr mq_close 3 ,
25457babc49Srmind.Xr mq_unlink 3
25557babc49Srmind.Sh STANDARDS
25657babc49SrmindThis function conforms to the
25757babc49Srmind.St -p1003.1-2001
25857babc49Srmindstandard.
25957babc49Srmind.Sh HISTORY
26057babc49SrmindThis function first appeared in
26157babc49Srmind.Nx 5.0 .
26257babc49Srmind.Sh COPYRIGHT
26357babc49SrmindPortions of this text are reprinted and reproduced in electronic form
26457babc49Srmindfrom IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
26557babc49Srmind-- Portable Operating System Interface (POSIX), The Open Group Base
26657babc49SrmindSpecifications Issue 6, Copyright (C) 2001-2003 by the Institute of
26757babc49SrmindElectrical and Electronics Engineers, Inc and The Open Group.
26857babc49SrmindIn the
26957babc49Srmindevent of any discrepancy between this version and the original IEEE and
27057babc49SrmindThe Open Group Standard, the original IEEE and The Open Group Standard
27157babc49Srmindis the referee document.
27257babc49SrmindThe original Standard can be obtained online at
273*a973b364Snjoly.Lk http://www.opengroup.org/unix/online.html .
274