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