xref: /openbsd/lib/libc/sys/msgctl.2 (revision 3d8817e4)
1.\"	$OpenBSD: msgctl.2,v 1.13 2007/05/31 19:19:33 jmc Exp $
2.\"	$NetBSD: msgctl.2,v 1.2 1997/03/27 08:20:35 mikel 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: May 31 2007 $
34.Dt MSGCTL 2
35.Os
36.Sh NAME
37.Nm msgctl
38.Nd message control operations
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 msgctl "int msqid" "int cmd" "struct msqid_ds *buf"
45.Sh DESCRIPTION
46The
47.Fn msgctl
48system call performs some control operations on the message queue specified
49by
50.Fa msqid .
51.Pp
52Each message queue has a data structure associated with it, parts of which
53may be altered by
54.Fn msgctl
55and parts of which determine the actions of
56.Fn msgctl .
57The data structure is defined in
58.Aq Pa sys/msg.h
59and contains (amongst others) the following members:
60.Bd -literal
61struct msqid_ds {
62	struct ipc_perm msg_perm;	/* msg queue permission bits */
63	u_long		msg_cbytes;	/* # of bytes in use on the queue */
64	u_long		msg_qnum;	/* # of msgs in the queue */
65	u_long		msg_qbytes;	/* max # of bytes on the queue */
66	pid_t		msg_lspid;	/* pid of last msgsnd() */
67	pid_t		msg_lrpid;	/* pid of last msgrcv() */
68	time_t		msg_stime;	/* time of last msgsnd() */
69	time_t		msg_rtime;	/* time of last msgrcv() */
70	time_t		msg_ctime;	/* time of last msgctl() */
71};
72.Ed
73.Pp
74The
75.Fa ipc_perm
76structure used inside the
77.Fa msqid_ds
78structure is defined in
79.Aq Pa sys/ipc.h
80and looks like this:
81.Bd -literal
82struct ipc_perm {
83	uid_t	cuid;	/* creator user id */
84	gid_t	cgid;	/* creator group id */
85	uid_t	uid;	/* user id */
86	gid_t	gid;	/* group id */
87	mode_t	mode;	/* permission (9 bits, see chmod(2)) */
88	u_short	seq;	/* sequence # (to generate unique id) */
89	key_t	key;	/* user specified msg/sem/shm key */
90};
91.Ed
92.Pp
93The operation to be performed by
94.Fn msgctl
95is specified in
96.Fa cmd
97and is one of:
98.Bl -tag -width IPC_RMIDX
99.It Dv IPC_STAT
100Gather information about the message queue and place it in the
101structure pointed to by
102.Fa buf .
103.It Dv IPC_SET
104Set the value of the
105.Va msg_perm.uid ,
106.Va msg_perm.gid ,
107.Va msg_perm.mode
108and
109.Va msg_qbytes
110fields in the structure associated with
111.Fa msqid .
112The values are taken from the corresponding fields in the structure
113pointed to by
114.Fa buf .
115This operation can only be executed by the superuser, or a process that
116has an effective user ID equal to either
117.Va msg_perm.cuid
118or
119.Va msg_perm.uid
120in the data structure associated with the message queue.
121The value of
122.Va msg_qbytes
123can only be increased by the superuser.
124Values for
125.Va msg_qbytes
126that exceed the system limit
127.Pf ( Dv MSGMNB
128from
129.Aq Pa sys/msg.h )
130are silently truncated to that limit.
131.Pp
132.It Dv IPC_RMID
133Remove the message queue specified by
134.Fa msqid
135and destroy the data associated with it.
136Only the superuser or a process with an effective UID equal to the
137.Va msg_perm.cuid
138or
139.Va msg_perm.uid
140values in the data structure associated with the queue can do this.
141.El
142.Pp
143The permission to read from or write to a message queue (see
144.Xr msgsnd 2
145and
146.Xr msgrcv 2 )
147is determined by the
148.Va msg_perm.mode
149field in the same way as is
150done with files (see
151.Xr chmod 2 ) ,
152but the effective UID can match either the
153.Va msg_perm.cuid
154field or the
155.Va msg_perm.uid
156field, and the
157effective GID can match either
158.Va msg_perm.cgid
159or
160.Va msg_perm.gid .
161.Sh RETURN VALUES
162Upon successful completion, a value of 0 is returned.
163Otherwise, \-1 is returned and the global variable
164.Va errno
165is set to indicate the error.
166.Sh ERRORS
167.Fn msgctl
168will fail if:
169.Bl -tag -width Er
170.It Bq Er EPERM
171.Fa cmd
172is equal to
173.Dv IPC_SET
174or
175.Dv IPC_RMID
176and the caller is not the superuser, nor does
177the effective UID match either the
178.Va msg_perm.uid
179or
180.Va msg_perm.cuid
181fields of the data structure associated with the message queue.
182.Pp
183An attempt is made to increase the value of
184.Va msg_qbytes
185through
186.Dv IPC_SET
187but the caller is not the superuser.
188.It Bq Er EACCES
189The command is
190.Dv IPC_STAT
191and the caller has no read permission for this message queue.
192.It Bq Er EINVAL
193.Fa msqid
194is not a valid message queue identifier.
195.Pp
196.Va cmd
197is not a valid command.
198.It Bq Er EFAULT
199.Fa buf
200specifies an invalid address.
201.El
202.Sh SEE ALSO
203.Xr msgget 2 ,
204.Xr msgrcv 2 ,
205.Xr msgsnd 2
206.Sh HISTORY
207Message queues appeared in the first release of AT&T Unix System V.
208