xref: /openbsd/lib/libc/sys/msgget.2 (revision a485a67c)
1.\"	$OpenBSD: msgget.2,v 1.12 2014/02/12 16:46:29 schwarze Exp $
2.\"	$NetBSD: msgget.2,v 1.1 1995/10/16 23:49:19 jtc Exp $
3.\"
4.\" Copyright (c) 1995 Frank van der Linden
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"      This product includes software developed for the NetBSD Project
18.\"      by Frank van der Linden
19.\" 4. The name of the author may not be used to endorse or promote products
20.\"    derived from this software without specific prior written permission
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"/
33.Dd $Mdocdate: February 12 2014 $
34.Dt MSGGET 2
35.Os
36.Sh NAME
37.Nm msgget
38.Nd get message queue
39.Sh SYNOPSIS
40.Fd #include <sys/types.h>
41.Fd #include <sys/ipc.h>
42.Fd #include <sys/msg.h>
43.Ft int
44.Fn msgget "key_t key" "int msgflg"
45.Sh DESCRIPTION
46.Fn msgget
47returns the message queue identifier associated with
48.Fa key .
49A message queue identifier is a unique integer greater than zero.
50.Pp
51A message queue is created if either
52.Fa key
53is equal to
54.Dv IPC_PRIVATE ,
55or
56.Fa key
57does not have a message queue identifier associated with it, and the
58.Dv IPC_CREAT
59bit is set in
60.Fa msgflg .
61.Pp
62If a new message queue is created, the data structure associated with it (the
63.Va msqid_ds
64structure, see
65.Xr msgctl 2 )
66is initialized as follows:
67.Bl -bullet
68.It
69.Va msg_perm.cuid
70and
71.Va msg_perm.uid
72are set to the effective UID of the calling process.
73.It
74.Va msg_perm.gid
75and
76.Va msg_perm.cgid
77are set to the effective GID of the calling process.
78.It
79.Va msg_perm.mode
80is set to the lower 9 bits of
81.Fa msgflg .
82.It
83.Va msg_cbytes ,
84.Va msg_qnum ,
85.Va msg_lspid ,
86.Va msg_lrpid ,
87.Va msg_rtime ,
88and
89.Va msg_stime
90are set to 0.
91.It
92.Va msg_qbytes
93is set to the system wide maximum value for the number of bytes in a queue
94.Pq Dv MSGMNB .
95.It
96.Va msg_ctime
97is set to the current time.
98.El
99.Sh RETURN VALUES
100Upon successful completion a positive message queue identifier is returned.
101Otherwise, \-1 is returned and the global variable
102.Va errno
103is set to indicate the error.
104.Sh ERRORS
105.Bl -tag -width Er
106.It Bq Er EACCES
107A message queue is already associated with
108.Fa key
109and the caller has no permission to access it.
110.It Bq Er EEXIST
111Both
112.Dv IPC_CREAT
113and
114.Dv IPC_EXCL
115are set in
116.Fa msgflg ,
117and a message queue is already associated with
118.Fa key .
119.It Bq Er ENOSPC
120A new message queue could not be created because the system limit for
121the number of message queues has been reached.
122.It Bq Er ENOENT
123.Dv IPC_CREAT
124was not set in
125.Fa msgflg
126and no message queue associated with
127.Fa key
128was found.
129.El
130.Sh SEE ALSO
131.Xr msgctl 2 ,
132.Xr msgrcv 2 ,
133.Xr msgsnd 2 ,
134.Xr ftok 3
135.Sh HISTORY
136Message queues appeared in
137.At V.1 .
138